CheckOut and CheckIn Handlers
authorChris Cormack <chrisc@catalyst.net.nz>
Thu, 2 Jan 2014 22:19:24 +0000 (11:19 +1300)
committerChris Cormack <chrisc@catalyst.net.nz>
Thu, 2 Jan 2014 22:19:24 +0000 (11:19 +1300)
lib/NCIP/Handler/CheckInItem.pm [new file with mode: 0644]
lib/NCIP/Handler/CheckOutItem.pm [new file with mode: 0644]

diff --git a/lib/NCIP/Handler/CheckInItem.pm b/lib/NCIP/Handler/CheckInItem.pm
new file mode 100644 (file)
index 0000000..89581d2
--- /dev/null
@@ -0,0 +1,44 @@
+package NCIP::Handler::CheckInItem;
+
+=head1
+
+  NCIP::Handler::CheckInItem
+
+=head1 SYNOPSIS
+
+    Not to be called directly, NCIP::Handler will pick the appropriate Handler 
+    object, given a message type
+
+=head1 FUNCTIONS
+
+=cut
+
+use Modern::Perl;
+
+use NCIP::Handler;
+
+our @ISA = qw(NCIP::Handler);
+
+sub handle {
+    my $self   = shift;
+    my $xmldoc = shift;
+    if ($xmldoc) {
+        my $root = $xmldoc->documentElement();
+        my $userid =
+          $root->findnodes('CheckInItem/UniqueUserId/UserIdentifierValue');
+        my $itemid =
+          $root->findnodes('CheckInItem/UniqueItemId/ItemIdentifierValue');
+        my @elements = $root->findnodes('CheckInItem/ItemElementType/Value');
+
+        # checkin the item
+        my $checkin = $self->ils->checkin( $userid, $itemid );
+        my $vars;
+        $vars->{'messagetype'} = 'CheckInItemResponse';
+        $vars->{'elements'}    = \@elements;
+        $vars->{'checkin'}     = $checkin;
+        my $output = $self->render_output( 'response.tt', $vars );
+        return $output;
+    }
+}
+
+1;
diff --git a/lib/NCIP/Handler/CheckOutItem.pm b/lib/NCIP/Handler/CheckOutItem.pm
new file mode 100644 (file)
index 0000000..d92e579
--- /dev/null
@@ -0,0 +1,44 @@
+package NCIP::Handler::CheckOutItem;
+
+=head1
+
+  NCIP::Handler::CheckOutItem
+
+=head1 SYNOPSIS
+
+    Not to be called directly, NCIP::Handler will pick the appropriate Handler 
+    object, given a message type
+
+=head1 FUNCTIONS
+
+=cut
+
+use Modern::Perl;
+
+use NCIP::Handler;
+
+our @ISA = qw(NCIP::Handler);
+
+sub handle {
+    my $self   = shift;
+    my $xmldoc = shift;
+    if ($xmldoc) {
+        my $root = $xmldoc->documentElement();
+        my $userid =
+          $root->findnodes('CheckOutItem/UniqueUserId/UserIdentifierValue');
+        my $itemid =
+          $root->findnodes('CheckOutItem/UniqueItemId/ItemIdentifierValue');
+        my @elements = $root->findnodes('CheckOutItem/ItemElementType/Value');
+
+        # checkout the item
+        my $checkout = $self->ils->checkout( $userid, $itemid );
+        my $vars;
+        $vars->{'messagetype'} = 'CheckOutItemResponse';
+        $vars->{'elements'}    = \@elements;
+        $vars->{'checkout'}    = $checkout;
+        my $output = $self->render_output( 'response.tt', $vars );
+        return $output;
+    }
+}
+
+1;