Add handling of ItemElementType in NIP::ILS::Evergreen.
authorJason Stephenson <jason@sigio.com>
Sat, 11 Oct 2014 15:45:52 +0000 (11:45 -0400)
committerJason Stephenson <jason@sigio.com>
Sat, 11 Oct 2014 15:45:52 +0000 (11:45 -0400)
This includes some template changes to output the ItemOptionalFields
element data.

Signed-off-by: Jason Stephenson <jason@sigio.com>
lib/NCIP/ILS/Evergreen.pm
templates/includes/CancelRequestItemResponse.inc
templates/includes/CheckInItemResponse.inc
templates/includes/ItemOptionalFields.inc [new file with mode: 0644]
templates/includes/RequestItemResponse.inc

index df9d6cc..126fc58 100644 (file)
@@ -52,6 +52,11 @@ use NCIP::StructuredAddress;
 use NCIP::ElectronicAddress;
 use NCIP::RequestId;
 use NCIP::Item::Id;
+use NCIP::Item::OptionalFields;
+use NCIP::Item::BibliographicDescription;
+use NCIP::Item::BibliographicItemId;
+use NCIP::Item::BibliographicRecordId;
+use NCIP::Item::Description;
 
 # Inherit from NCIP::ILS.
 use parent qw(NCIP::ILS);
@@ -477,6 +482,12 @@ sub checkinitem {
             my $optionalfields = $self->handle_user_elements($circ_user, $elements);
             $data->{UserOptionalFields} = $optionalfields;
         }
+        $elements = $request->{$message}->{ItemElementType};
+        if ($elements) {
+            $elements = [$elements] unless (ref $elements eq 'ARRAY');
+            my $optionalfields = $self->handle_item_elements($copy, $elements);
+            $data->{ItemOptionalFields} = $optionalfields;
+        }
 
         $response->data($data);
 
@@ -674,6 +685,12 @@ sub renewitem {
             my $optionalfields = $self->handle_user_elements($user, $elements);
             $data->{UserOptionalFields} = $optionalfields;
         }
+        $elements = $request->{$message}->{ItemElementType};
+        if ($elements) {
+            $elements = [$elements] unless (ref $elements eq 'ARRAY');
+            my $optionalfields = $self->handle_item_elements($details->{copy}, $elements);
+            $data->{ItemOptionalFields} = $optionalfields;
+        }
 
         $response->data($data);
     }
@@ -841,6 +858,12 @@ sub checkoutitem {
             my $optionalfields = $self->handle_user_elements($user, $elements);
             $data->{UserOptionalFields} = $optionalfields;
         }
+        $elements = $request->{$message}->{ItemElementType};
+        if ($elements) {
+            $elements = [$elements] unless (ref $elements eq 'ARRAY');
+            my $optionalfields = $self->handle_item_elements($details->{copy}, $elements);
+            $data->{ItemOptionalFields} = $optionalfields;
+        }
 
         $response->data($data);
     }
@@ -1000,6 +1023,12 @@ sub requestitem {
             my $optionalfields = $self->handle_user_elements($user, $elements);
             $data->{UserOptionalFields} = $optionalfields;
         }
+        $elements = $request->{$message}->{ItemElementType};
+        if ($elements && $copy_details) {
+            $elements = [$elements] unless (ref($elements) eq 'ARRAY');
+            my $optionalfields = $self->handle_item_elements($copy_details->{copy}, $elements);
+            $data->{ItemOptionalFields} = $optionalfields;
+        }
 
         $response->data($data);
     }
@@ -1163,6 +1192,12 @@ sub cancelrequestitem {
                     my $optionalfields = $self->handle_user_elements($user, $elements);
                     $data->{UserOptionalFields} = $optionalfields;
                 }
+                $elements = $request->{$message}->{ItemElementType};
+                if ($elements && $copy_details) {
+                    $elements = [$elements] unless (ref $elements eq 'ARRAY');
+                    my $optionalfields = $self->handle_item_elements($copy_details->{copy}, $elements);
+                    $data->{ItemOptionalFields} = $optionalfields;
+                }
                 $response->data($data);
             }
         } else {
@@ -1202,22 +1237,34 @@ sub cancelrequestitem {
                 )
             } elsif ($hold) {
                 $self->cancel_hold($hold);
-                $response->data(
-                    {
-                        RequestId => NCIP::RequestId->new(
-                            {
-                                RequestIdentifierType => 'SYSNUMBER',
-                                RequestIdentifierValue => $hold->id()
-                            }
-                        ),
-                        UserId => NCIP::User::Id->new(
-                            {
-                                UserIdentifierType => 'Barcode Id',
-                                UserIdentifierValue => $user->card->barcode()
-                            }
-                        )
-                    }
-                )
+                my $data = {
+                    RequestId => NCIP::RequestId->new(
+                        {
+                            RequestIdentifierType => 'SYSNUMBER',
+                            RequestIdentifierValue => $hold->id()
+                        }
+                    ),
+                    UserId => NCIP::User::Id->new(
+                        {
+                            UserIdentifierType => 'Barcode Id',
+                            UserIdentifierValue => $user->card->barcode()
+                        }
+                    )
+                };
+                # Look for UserElements requested and add it to the response:
+                my $elements = $request->{$message}->{UserElementType};
+                if ($elements) {
+                    $elements = [$elements] unless (ref $elements eq 'ARRAY');
+                    my $optionalfields = $self->handle_user_elements($user, $elements);
+                    $data->{UserOptionalFields} = $optionalfields;
+                }
+                $elements = $request->{$message}->{ItemElementType};
+                if ($elements && $copy_details) {
+                    $elements = [$elements] unless (ref $elements eq 'ARRAY');
+                    my $optionalfields = $self->handle_item_elements($copy_details->{copy}, $elements);
+                    $data->{ItemOptionalFields} = $optionalfields;
+                }
+                $response->data($data);
             } else {
                 $response->problem(
                     NCIP::Problem->new(
@@ -1396,6 +1443,103 @@ sub handle_user_elements {
     return $optionalfields;
 }
 
+=head2 handle_item_elements
+
+=cut
+
+sub handle_item_elements {
+    my $self = shift;
+    my $copy = shift;
+    my $elments = shift;
+    my $optionalfields = NCIP::Item::OptionalFields->new();
+
+    my $details; # In case we need for more than one.
+
+    if (grep {$_ eq 'Bibliographic Description'} @$elements) {
+        my $description;
+        # Check for a precat copy, 'cause it is simple.
+        if ($copy->dummy_title()) {
+            $description = NCIP::Item::BibliographicDescription->new();
+            $description->Title($copy->dummy_title());
+            $description->Author($copy->dummy_author());
+            if ($copy->dummy_isbn()) {
+                $description->BibliographicItemId(
+                    NCIP::Item::BibliographicItemId->new(
+                        BibliographicItemIdentifier => $copy->dummy_isbn(),
+                        BibliographicItemIdentifierCode => 'ISBN'
+                    )
+                );
+            }
+        } else {
+            $details = $self->retrieve_copy_details_by_barcode($copy->barcode()) unless($details);
+            $description = NCIP::Item::BibliographicDescription->new();
+            $description->Title($details->{mvr}->title());
+            $description->Authort($details->{mvr}->author());
+            $description->BibliographicRecordId(
+                NCIP::Item::BibliographicRecordId->new(
+                    BibliographicRecordIdentifier => $details->{mvr}->doc_id(),
+                    BibliographicRecordIdentifierCode => 'SYSNUMBER'
+                )
+            );
+            if ($details->{mvr}->publisher()) {
+                $description->Publisher($details->{mvr}->publisher());
+            }
+            if ($details->{mvr}->pubdate()) {
+                $description->PublicationDate($details->{mvr}->pubdate());
+            }
+            if ($details->{mvr}->edition()) {
+                $description->Edition($details->{mvr}->edition());
+            }
+        }
+        $optionalfields->BibliographicDescription($description) if ($description);
+    }
+
+    if (grep {$_ eq 'Item Description'} @$elements) {
+        $details = $self->retrieve_copy_details_by_barcode($copy->barcode()) unless($details);
+        # Call Number is the only field we currently return. We also
+        # do not attempt to retun a prefix and suffix. Someone else
+        # can deal with that if they want it.
+        if ($details->{volume}) {
+            $optionalfields->ItemDescription(
+                NCIP::Item::Description->new(
+                    CallNumber => $details->{volume}->label();
+                )
+            );
+        }
+    }
+
+    if (grep {$_ eq 'Circulation Status'} @$elements) {
+        my $status = $copy->status();
+        $status = $self->retrieve_copy_status($status) unless (ref($status));
+        $optionalfields->CirculationStatus($status->name()) if ($status);
+    }
+
+    if (grep {$_ eq 'Date Due'} @$elements) {
+        $details = $self->retrieve_copy_details_by_barcode($copy->barcode()) unless($details);
+        if ($details->{circ}) {
+            if (!$details->{circ}->checkin_time()) {
+                my $due = DateTime::Format::ISO8601->parse_datetime(cleanse_ISO8601($circ->due_date()));
+                $due->set_time_zone('UTC');
+                $optionalfields->DateDue($due->iso8601());
+            }
+        }
+    }
+
+    if (grep {$_ eq 'Item Use Restriction Type'} @$elements) {
+        $optionalfields->ItemUseRestrictionType('None');
+    }
+
+    if (grep {$_ eq 'Physical Condition'} @$elements) {
+        $optionalfields->PhysicalCondition(
+            NCIP::Item::PhysicalCondition->new(
+                PhysicalConditionType => 'Unknown'
+            )
+        );
+    }
+
+    return $optionalfields;
+}
+
 =head2 login
 
     $ils->login();
@@ -1707,6 +1851,28 @@ sub retrieve_copy_details_by_barcode {
     return $copy;
 }
 
+=head2 retrieve_copy_status
+
+    $status = $ils->retrieve_copy_status($id);
+
+Retrive a copy status object by database ID.
+
+=cut
+
+sub retrieve_copy_status {
+    my $self = shift;
+    my $id = shift;
+
+    my $status = $U->simplereq(
+        'open-ils.pcrud',
+        'open-ils.pcrud.retrieve.ccs',
+        $self->{session}->{authtoken},
+        $id
+    );
+
+    return $status;
+}
+
 =head2 retrieve_org_unit_by_shortname
 
     $org_unit = $ils->retrieve_org_unit_by_shortname($shortname);
index d912704..ea3aa3d 100644 (file)
@@ -17,3 +17,4 @@
 [% END -%]
 </UserId>
 [% INCLUDE "includes/UserOptionalFields.inc" -%]
+[% INCLUDE "includes/ItemOptionalFields.inc" -%]
index 5a27e1e..29943b0 100644 (file)
@@ -19,3 +19,4 @@
 </UserId>
 [% END -%]
 [% INCLUDE "includes/UserOptionalFields.inc" -%]
+[% INCLUDE "includes/ItemOptionalFields.inc" -%]
diff --git a/templates/includes/ItemOptionalFields.inc b/templates/includes/ItemOptionalFields.inc
new file mode 100644 (file)
index 0000000..35928f9
--- /dev/null
@@ -0,0 +1,91 @@
+[% IF data.ItemOptionalFields -%]
+<ItemOptionalFields>
+[% IF data.ItemOptionalFields.BibliographicDescription -%]
+<BibliographicDescription>
+[% IF data.ItemOptionalFields.BibliographicDescription.Author -%]
+<Author>
+[% data.ItemOptionalFields.BibliographicDescription.Author | xml %]
+</Author>
+[% END -%]
+[% IF data.ItemOptionalFields.BibliographicDescription.Title -%]
+<Title>
+[% data.ItemOptionalFields.BibliographicDescription.Title | xml %]
+</Title>
+[% END -%]
+[% IF data.ItemOptionalFields.BibliographicDescription.Publisher -%]
+<Publisher>
+[% data.ItemOptionalFields.BibliographicDescription.Publisher | xml %]
+</Publisher>
+[% END -%]
+[% IF data.ItemOptionalFields.BibliographicDescription.PublicationDate -%]
+<PublicationDate>
+[% data.ItemOptionalFields.BibliographicDescription.PublicationDate | xml %]
+</PublicationDate>
+[% END -%]
+[% IF data.ItemOptionalFields.BibliographicDescription.Edition -%]
+<Edition>
+[% data.ItemOptionalFields.BibliographicDescription.Edition | xml %]
+</Edition>
+[% END -%]
+[% IF data.ItemOptionalFields.BibliographicDescription.BibliographicRecordId;
+      id = data.ItemOptionalFields.BibliographicDescription.BibliographicRecordId -%]
+<BibliographicRecordId>
+<BibliographicRecordIdentifier>
+[% id.BibliographicRecordIdentifier | xml %]
+</BibliographicRecordIdentifer>
+[% IF id.BibliographicRecordIdentifierCode -%]
+<BibliographicRecordIdentifierCode>
+[% id.BibliographicRecordIdentifierCode | xml %]
+</BibliographicRecordIdentifierCode>
+[% END -%]
+[% IF id.AgencyId -%]
+<AgencyId>
+[% id.AgencyId | xml %]
+</AgencyId>
+[% END -%]
+</BibliographicRecordId>
+[% END -%]
+[% IF data.ItemOptionalFields.BibliographicDescription.BibliographicItemId;
+      id = data.ItemOptionalFields.BibliographicDescription.BibliographicItemId -%]
+<BibliographicItemId>
+<BibliographicItemIdentifier>
+[% id.BibliographicItemIdentifier | xml %]
+</BibliographicItemIdentifier>
+[% IF id.BibliographicItemIdentifierCode -%]
+<BibliographicItemIdentifierCode>
+[% id.BibliographicItemIdentifierCode | xml %]
+</BibliographicItemIdentifierCode>
+[% END -%]
+</BibliographicItemId>
+[% END -%]
+</BibliographicDescription>
+[% END -%]
+[% IF data.ItemOptionalFields.ItemDescription -%]
+<ItemDescription>
+<CallNumber>
+[% data.ItemOptionalFields.ItemDescription.CallNumber | xml %]
+</CallNumber>
+</ItemDescription>
+[% END -%]
+[% IF data.ItemOptionalFields.CirculationStatus -%]
+<CirculationStatus>
+[% data.ItemOptionalFields.CirculationStatus | xml %]
+</CirculationStatus>
+[% END -%]
+[% IF data.ItemOptionalFields.DateDue -%]
+<DateDue>
+[% data.ItemOptionalFields.DateDue | xml %]
+</DateDue>
+[% END -%]
+[% IF data.ItemOptionalFields.ItemUseRestrictionType -%]
+<ItemUseRestrictionType>
+[% data.ItemOptionalFields.ItemUseRestrictionType | xml %]
+</ItemUseRestrictionType>
+[% END -%]
+[% IF data.ItemOptionalFields.PhysicalCondition -%]
+<PhysicalCondition>
+[% data.ItemOptionalFields.PhysicalCondition | xml %]
+</PhysicalCondition>
+[% END -%]
+</ItemOptionalFields>
+[% END -%]
index 5f0ef28..1aaadb3 100644 (file)
@@ -19,3 +19,4 @@
 <RequestType>[% data.RequestType | xml %]</RequestType>
 <RequestScopeType>[% data.RequestScopeType | xml %]</RequestScopeType>
 [% INCLUDE "includes/UserOptionalFields.inc" -%]
+[% INCLUDE "includes/ItemOptionalFields.inc" -%]