added some events, utility code, container handling and testint code
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 19 Dec 2005 18:06:54 +0000 (18:06 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 19 Dec 2005 18:06:54 +0000 (18:06 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@2449 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/extras/ils_events.xml
Open-ILS/src/perlmods/OpenILS/Application/Actor/Container.pm
Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm
Open-ILS/src/support-scripts/test-scripts/container.pl

index 768595e..9080479 100644 (file)
 
        <event code='1504' textcode='CONTAINER_NOT_FOUND'>
                <desc>
-                       Someone attempted to retrieve a transit object from the 
+                       Someone attempted to retrieve a container object from the 
                        system and the object was not found.
                </desc>
        </event>
 
+       <event code='1505' textcode='CONTAINER_ITEM_NOT_FOUND'>
+               <desc>
+                       Someone attempted to retrieve a container item object from the 
+                       system and the object was not found.
+               </desc>
+       </event>
+
+
 
        <event code='1700' textcode='ROUTE_COPY'>
                <desc>
index 5fcaf08..081de65 100644 (file)
@@ -155,7 +155,7 @@ sub bucket_create {
        $logger->debug("Creating new container object: " . Dumper($bucket));
 
        my $method = $types{$class} . ".create";
-       my $id = $apputils->simplreq( $svc, $method, $bucket );
+       my $id = $apputils->simplereq( $svc, $method, $bucket );
 
        $logger->debug("Creatined new container with id $id");
 
@@ -179,14 +179,12 @@ __PACKAGE__->register_method(
 sub bucket_delete {
        my( $self, $client, $authtoken, $class, $bucketid ) = @_;
 
-       my $bucket = $apputils->simplereq( 
-               $svc, $types{$class} . ".retrieve", $bucketid );
+       my( $bucket, $staff, $target, $evt );
 
-       if(!$bucket) {
-               return OpenILS::Event->new('CONTAINER_NOT_FOUND');
-       }
+       ( $bucket, $evt ) = $apputils->fetch_container($bucketid, $class);
+       return $evt if $evt;
 
-       my( $staff, $target, $evt ) = $apputils->checkses_requestor( 
+       ( $staff, $target, $evt ) = $apputils->checkses_requestor( 
                $authtoken, $bucket->owner, 'DELETE_CONTAINER' );
        return $evt if $evt;
 
@@ -194,12 +192,72 @@ sub bucket_delete {
                " deleting continer $bucketid for user " . $bucket->owner );
 
        my $method = $types{$class} . ".delete";
-       my $resp = $apputils->simplreq( $svc, $method, $bucketid );
+       my $resp = $apputils->simplereq( $svc, $method, $bucketid );
 
-       if(!$resp) { throw OpenSRF::EX 
-               ("Unable to create new bucket object"); }
+       throw OpenSRF::EX ("Unable to create new bucket object") unless $resp;
+       return $resp;
+}
+
+
+__PACKAGE__->register_method(
+       method  => "item_create",
+       api_name        => "open-ils.actor.container.bucket.item.create",
+       notes           => <<"  NOTES");
+               PARAMS(authtoken, class, item)
+       NOTES
+
+sub item_create {
+       my( $self, $client, $authtoken, $class, $item ) = @_;
+       my( $bucket, $staff, $target, $evt);
+
+       ( $bucket, $evt ) = $apputils->fetch_container($item->bucket, $class);
+       return $evt if $evt;
+
+       ( $staff, $target, $evt ) = $apputils->checkses_requestor( 
+               $authtoken, $bucket->owner, 'CREATE_CONTAINER_ITEM' );
+       return $evt if $evt;
+
+       $logger->activity( "User " . $staff->id . 
+               " creating continer item  " . Dumper($item) . " for user " . $bucket->owner );
+
+       my $method = $types{$class} . "_item.create";
+       my $resp = $apputils->simplreq( $svc, $method, $item );
+
+       throw OpenSRF::EX ("Unable to delete container item") unless $resp;
        return $resp;
+}
+
+
+
+__PACKAGE__->register_method(
+       method  => "item_create",
+       api_name        => "open-ils.actor.container.bucket.item.delete",
+       notes           => <<"  NOTES");
+               PARAMS(authtoken, class, itemId)
+       NOTES
+
+sub item_delete {
+       my( $self, $client, $authtoken, $class, $itemid ) = @_;
+       my( $bucket, $item, $staff, $target, $evt);
 
+       
+       ( $item, $evt ) = $apputils->fetch_container_item( $itemid, $class );
+       return $evt if $evt;
+       ( $bucket, $evt ) = $apputils->fetch_container($item->bucket, $class);
+       return $evt if $evt;
+
+       ( $staff, $target, $evt ) = $apputils->checkses_requestor( 
+               $authtoken, $bucket->owner, 'DELETE_CONTAINER_ITEM' );
+       return $evt if $evt;
+
+       $logger->activity( "User " . $staff->id . 
+               " deleting continer item  $itemid for user " . $bucket->owner );
+
+       my $method = $types{$class} . "_item.delete";
+       my $resp = $apputils->simplreq( $svc, $method, $itemid );
+
+       throw OpenSRF::EX ("Unable to delete container item") unless $resp;
+       return $resp;
 }
 
 
index d3a90dc..9c34f00 100644 (file)
@@ -494,9 +494,58 @@ sub fetch_open_billable_transaction {
                'open-ils.storage',
                'open-ils.storage.direct.money.open_billable_transaction_summary.retrieve',  $transid);
 
-       $evt = OpenILS::Event->new('TRANSACTION_NOT_FOUND', transid => $transid ) unless $transaction;
+       $evt = OpenILS::Event->new(
+               'TRANSACTION_NOT_FOUND', transid => $transid ) unless $transaction;
 
        return ($transaction, $evt);
 }
 
+
+
+my %buckets;
+$buckets{'biblio'} = 'biblio_record_entry_bucket';
+$buckets{'callnumber'} = 'call_number_bucket';
+$buckets{'copy'} = 'copy_bucket';
+$buckets{'user'} = 'user_bucket';
+
+sub fetch_container {
+       my( $self, $id, $type ) = @_;
+       my( $bucket, $evt );
+
+       $logger->debug("Fetching container $id with type $type");
+
+       my $meth = $buckets{$type};
+       $bucket = $self->simplereq(
+               'open-ils.storage',
+               "open-ils.storage.direct.container.$meth.retrieve", $id );
+
+       $evt = OpenILS::Event->new(
+               'CONTAINER_NOT_FOUND', container => $id, 
+                       container_type => $type ) unless $bucket;
+
+       return ($bucket, $evt);
+}
+
+
+sub fetch_container_item {
+       my( $self, $id, $type ) = @_;
+       my( $bucket, $evt );
+
+       $logger->debug("Fetching container item $id with type $type");
+
+       my $meth = $buckets{$type} . "_item";
+
+       $bucket = $self->simplereq(
+               'open-ils.storage',
+               "open-ils.storage.direct.container.$meth.retrieve", $id );
+
+       $evt = OpenILS::Event->new(
+               'CONTAINER_ITEM_NOT_FOUND', itemid => $id, 
+                       container_type => $type ) unless $bucket;
+
+       return ($bucket, $evt);
+}
+
+
+
 1;
index 936184c..510958e 100755 (executable)
@@ -16,17 +16,30 @@ oils_fetch_session($authtoken);
 
 my %types;
 my $meth = 'open-ils.storage.direct.container';
-$types{'biblio'} = "biblio_record_entry_bucket";
-$types{'callnumber'} = "call_number_bucket";
-$types{'copy'} = "copy_bucket";
-$types{'user'} = "user_bucket";
+$types{'biblio'}                       = "biblio_record_entry_bucket";
+$types{'callnumber'}           = "call_number_bucket";
+$types{'copy'}                         = "copy_bucket";
+$types{'user'}                         = "user_bucket";
+
+# XXX These will depend on the data you have available.
+# we need a "fetch_any" method to resolve this
+$ttest{'biblio'}                       = 40791;
+$ttest{'callnumber'}           = 1;
+$ttest{'copy'}                         = 420795;
+$ttest{'user'}                         = 3;
+
+my $testcopy = 420795;
+my $testrec = 40791;
+my $testcn = 1;
+my $testuser = 3;
 
 my %containers;
+my %items;
 
 containers_create();
+#items_create();
 containers_delete();
 
-
 sub containers_create {
 
        for my $type ( keys %types ) {
@@ -46,6 +59,45 @@ sub containers_create {
        }
 }
 
+
+sub items_create {
+       for my $type ( keys %types ) {
+               my $id = $containers{$type};
+
+               my $item = "Fieldmapper::container::" . $types{$type} . "_item";
+               $item = $item->new;
+
+               $item->bucket($id);
+               $item->target_copy($test{$type}) if $type eq 'copy';
+               $item->target_call_number($test{$type}) if $type eq 'callnumber';
+               $item->target_biblio_record_entry($test{$type}) if $type eq 'biblio';
+               $item->target_user($test{$type}) if $type eq 'user';
+       
+               my $resp = simplereq($ACTOR, 
+                       'open-ils.actor.container.item.create',
+                       $authtoken, $type, $item );
+       
+               oils_event_die($resp);
+               printl("Created new $type bucket item with id $resp");
+               $items{$type} = $resp;
+       }
+}
+
+
+sub items_delete {
+       for my $type ( keys %types ) {
+               my $id = $containers{$type};
+
+               my $resp = simplereq($ACTOR, 
+                       'open-ils.actor.container.item.delete',
+                       $authtoken, $type, $id );
+       
+               oils_event_die($resp);
+               printl("Deleted $type bucket item with id $id");
+       }
+}
+
+
 sub containers_delete {
        for my $type (keys %containers) {
                my $id = $containers{$type};