1 package OpenILS::Application::Circ;
2 use base qw/OpenSRF::Application/;
3 use strict; use warnings;
5 use OpenILS::Application::Circ::Circulate;
6 use OpenILS::Application::Circ::Survey;
7 use OpenILS::Application::Circ::StatCat;
8 use OpenILS::Application::Circ::Holds;
9 use OpenILS::Application::Circ::HoldNotify;
10 use OpenILS::Application::Circ::Money;
11 use OpenILS::Application::Circ::NonCat;
12 use OpenILS::Application::Circ::CopyLocations;
15 use DateTime::Format::ISO8601;
17 use OpenILS::Application::AppUtils;
19 use OpenSRF::Utils qw/:datetime/;
20 use OpenILS::Utils::ModsParser;
22 use OpenSRF::EX qw(:try);
23 use OpenSRF::Utils::Logger qw(:logger);
24 use OpenILS::Utils::Fieldmapper;
25 use OpenILS::Utils::Editor;
26 use OpenILS::Utils::CStoreEditor q/:funcs/;
27 use OpenILS::Const qw/:const/;
28 use OpenSRF::Utils::SettingsClient;
30 my $apputils = "OpenILS::Application::AppUtils";
34 # ------------------------------------------------------------------------
35 # Top level Circ package;
36 # ------------------------------------------------------------------------
40 OpenILS::Application::Circ::Circulate->initialize();
44 __PACKAGE__->register_method(
45 method => 'retrieve_circ',
46 api_name => 'open-ils.circ.retrieve',
48 Retrieve a circ object by id
49 @param authtoken Login session key
50 @pararm circid The id of the circ object
54 my( $s, $c, $a, $i ) = @_;
55 my $e = new_editor(authtoken => $a);
56 return $e->event unless $e->checkauth;
57 my $circ = $e->retrieve_action_circulation($i) or return $e->event;
58 if( $e->requestor->id ne $circ->usr ) {
59 return $e->event unless $e->allowed('VIEW_CIRCULATIONS');
65 __PACKAGE__->register_method(
66 method => 'fetch_circ_mods',
67 api_name => 'open-ils.circ.circ_modifier.retrieve.all');
69 my $conf = OpenSRF::Utils::SettingsClient->new;
70 return $conf->config_value(
71 'apps', 'open-ils.circ', 'app_settings', 'circ_modifiers', 'mod' );
74 __PACKAGE__->register_method(
75 method => 'fetch_bill_types',
76 api_name => 'open-ils.circ.billing_type.retrieve.all');
77 sub fetch_bill_types {
78 my $conf = OpenSRF::Utils::SettingsClient->new;
79 return $conf->config_value(
80 'apps', 'open-ils.circ', 'app_settings', 'billing_types', 'type' );
84 # ------------------------------------------------------------------------
85 # Returns an array of {circ, record} hashes checked out by the user.
86 # ------------------------------------------------------------------------
87 __PACKAGE__->register_method(
88 method => "checkouts_by_user",
89 api_name => "open-ils.circ.actor.user.checked_out",
91 Returns a list of open circulations as a pile of objects. each object
92 contains the relevant copy, circ, and record
95 sub checkouts_by_user {
96 my( $self, $client, $user_session, $user_id ) = @_;
98 my( $requestor, $target, $copy, $record, $evt );
100 ( $requestor, $target, $evt ) =
101 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
104 my $circs = $apputils->simplereq(
106 "open-ils.cstore.direct.action.open_circulation.search.atomic",
107 { usr => $target->id, checkin_time => undef } );
108 # { usr => $target->id } );
111 for my $circ (@$circs) {
113 ( $copy, $evt ) = $apputils->fetch_copy($circ->target_copy);
116 $logger->debug("Retrieving record for copy " . $circ->target_copy);
118 ($record, $evt) = $apputils->fetch_record_by_copy( $circ->target_copy );
121 my $mods = $apputils->record_to_mvr($record);
123 push( @results, { copy => $copy, circ => $circ, record => $mods } );
132 __PACKAGE__->register_method(
133 method => "checkouts_by_user_slim",
134 api_name => "open-ils.circ.actor.user.checked_out.slim",
135 NOTES => <<" NOTES");
136 Returns a list of open circulation objects
140 sub checkouts_by_user_slim {
141 my( $self, $client, $user_session, $user_id ) = @_;
143 my( $requestor, $target, $copy, $record, $evt );
145 ( $requestor, $target, $evt ) =
146 $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS');
149 $logger->debug( 'User ' . $requestor->id .
150 " retrieving checked out items for user " . $target->id );
152 # XXX Make the call correct..
153 return $apputils->simplereq(
155 "open-ils.cstore.direct.action.open_circulation.search.atomic",
156 { usr => $target->id, checkin_time => undef } );
157 # { usr => $target->id } );
161 __PACKAGE__->register_method(
162 method => "checkouts_by_user_opac",
163 api_name => "open-ils.circ.actor.user.checked_out.opac",);
166 sub checkouts_by_user_opac {
167 my( $self, $client, $auth, $user_id ) = @_;
169 my $e = OpenILS::Utils::Editor->new( authtoken => $auth );
170 return $e->event unless $e->checkauth;
171 $user_id ||= $e->requestor->id;
172 return $e->event unless
173 my $patron = $e->retrieve_actor_user($user_id);
176 my $search = {usr => $user_id, stop_fines => undef};
178 if( $user_id ne $e->requestor->id ) {
179 $data = $e->search_action_circulation(
180 $search, {checkperm=>1, permorg=>$patron->home_ou})
184 $data = $e->search_action_circulation($search);
191 __PACKAGE__->register_method(
192 method => "title_from_transaction",
193 api_name => "open-ils.circ.circ_transaction.find_title",
194 NOTES => <<" NOTES");
195 Returns a mods object for the title that is linked to from the
196 copy from the hold that created the given transaction
199 sub title_from_transaction {
200 my( $self, $client, $login_session, $transactionid ) = @_;
202 my( $user, $circ, $title, $evt );
204 ( $user, $evt ) = $apputils->checkses( $login_session );
207 ( $circ, $evt ) = $apputils->fetch_circulation($transactionid);
210 ($title, $evt) = $apputils->fetch_record_by_copy($circ->target_copy);
213 return $apputils->record_to_mvr($title);
217 __PACKAGE__->register_method(
218 method => "set_circ_lost",
219 api_name => "open-ils.circ.circulation.set_lost",
220 NOTES => <<" NOTES");
221 Params are login, barcode
222 login must have SET_CIRC_LOST perms
223 Sets a circulation to lost
226 __PACKAGE__->register_method(
227 method => "set_circ_lost",
228 api_name => "open-ils.circ.circulation.set_claims_returned",
229 NOTES => <<" NOTES");
230 Params are login, barcode
231 login must have SET_CIRC_MISSING perms
232 Sets a circulation to lost
236 my( $self, $client, $login, $args ) = @_;
237 my( $user, $circ, $copy, $evt );
239 my $barcode = $$args{barcode};
240 my $backdate = $$args{backdate};
242 ( $user, $evt ) = $U->checkses($login);
245 # Grab the related copy
246 ($copy, $evt) = $U->fetch_copy_by_barcode($barcode);
249 my $isclaims = $self->api_name =~ /claims_returned/;
250 my $islost = $self->api_name =~ /lost/;
251 my $session = $U->start_db_session();
253 # grab the circulation
254 # ( $circ ) = $U->fetch_open_circulation( $copy->id );
255 # return 1 unless $circ;
257 $circ = new_editor()->search_action_circulation(
258 { checkin_time => undef, target_copy => $copy->id } )->[0];
259 return 1 unless $circ;
262 $evt = _set_circ_lost($copy, $circ, $user, $session) if $islost;
267 $evt = _set_circ_claims_returned(
268 $user, $circ, $session, $backdate );
273 $circ->stop_fines_time('now') unless $circ->stop_fines_time;
274 my $s = $session->request(
275 "open-ils.storage.direct.action.circulation.update", $circ )->gather(1);
277 return $U->DB_UPDATE_FAILED($circ) unless defined($s);
278 $U->commit_db_session($session);
284 my( $copy, $circ, $reqr, $session ) = @_;
286 my $evt = $U->check_perms($reqr->id, $circ->circ_lib, 'SET_CIRC_LOST');
289 $logger->activity("user ".$reqr->id." marking copy ".$copy->id.
290 " lost for circ ". $circ->id. " and checking for necessary charges");
292 if( $copy->status ne OILS_COPY_STATUS_LOST ) {
293 $copy->status(OILS_COPY_STATUS_LOST);
297 session => $session);
300 # if the copy has a price defined and/or a processing fee, bill the patron
302 # if the location that owns the copy has a processing fee, charge the user
303 my $owner = $U->fetch_copy_owner($copy->id);
304 $logger->info("circ fetching org settings for $owner ".
305 "to determine processing fee and default copy price");
307 my $settings = $U->simplereq(
308 'open-ils.actor', 'open-ils.actor.org_unit.settings.retrieve', $owner );
309 my $fee = $settings->{'circ.lost_materials_processing_fee'} || 0;
311 # If the copy has a price configured, charge said price to the user
312 my $s = OILS_SETTING_DEF_ITEM_PRICE;
313 my $copy_price = $copy->price || 0;
314 $copy_price = $settings->{$s} unless $copy_price and $copy_price > 0;
315 if($copy_price and $copy_price > 0) {
316 $logger->debug("lost copy has a price of $copy_price");
317 $evt = _make_bill($session, $copy_price, 'Lost Materials', $circ->id);
323 $evt = _make_bill($session, $fee, 'Lost Materials Processing Fee', $circ->id);
327 $circ->stop_fines(OILS_STOP_FINES_LOST);
332 my( $session, $amount, $type, $xactid ) = @_;
334 $logger->activity("The system is charging $amount ".
335 " [$type] for lost materials on circulation $xactid");
337 my $bill = Fieldmapper::money::billing->new;
339 $bill->xact($xactid);
340 $bill->amount($amount);
341 $bill->billing_type($type); # - XXX these strings should be configurable some day
342 $bill->note('SYSTEM GENERATED');
344 my $id = $session->request(
345 'open-ils.storage.direct.money.billing.create', $bill )->gather(1);
347 return $U->DB_UPDATE_FAILED($bill) unless defined $id;
351 sub _set_circ_claims_returned {
352 my( $reqr, $circ, $session, $backdate ) = @_;
354 my $evt = $U->check_perms($reqr->id, $circ->circ_lib, 'SET_CIRC_CLAIMS_RETURNED');
356 $circ->stop_fines("CLAIMSRETURNED");
358 $logger->activity("user ".$reqr->id.
359 " marking circ". $circ->id. " as claims returned");
361 # allow the caller to backdate the circulation and void any fines
362 # that occurred after the backdate
364 OpenILS::Application::Circ::Circulate::_checkin_handle_backdate(
365 $backdate, $circ, $reqr, $session );
366 $circ->stop_fines_time(clense_ISO8601($backdate))
374 __PACKAGE__->register_method (
375 method => 'set_circ_due_date',
376 api_name => 'open-ils.circ.circulation.due_date.update',
378 Updates the due_date on the given circ
380 @param circid The id of the circ to update
381 @param date The timestamp of the new due date
385 sub set_circ_due_date {
386 my( $s, $c, $authtoken, $circid, $date ) = @_;
387 my ($circ, $evt) = $U->fetch_circulation($circid);
391 ($reqr, $evt) = $U->checkses($authtoken);
394 $evt = $U->check_perms($reqr->id, $circ->circ_lib, 'CIRC_OVERRIDE_DUE_DATE');
397 $date = clense_ISO8601($date);
398 $logger->activity("user ".$reqr->id.
399 " updating due_date on circ $circid: $date");
401 $circ->due_date($date);
402 my $stat = $U->storagereq(
403 'open-ils.storage.direct.action.circulation.update', $circ);
404 return $U->DB_UPDATE_FAILED unless defined $stat;
409 __PACKAGE__->register_method(
410 method => "create_in_house_use",
411 api_name => 'open-ils.circ.in_house_use.create',
413 Creates an in-house use action.
414 @param $authtoken The login session key
415 @param params A hash of params including
416 'location' The org unit id where the in-house use occurs
417 'copyid' The copy in question
418 'count' The number of in-house uses to apply to this copy
419 @return An array of id's representing the id's of the newly created
420 in-house use objects or an event on an error
423 __PACKAGE__->register_method(
424 method => "create_in_house_use",
425 api_name => 'open-ils.circ.non_cat_in_house_use.create',
429 sub ___create_in_house_use {
430 my( $self, $client, $authtoken, $params ) = @_;
432 my( $staff, $evt, $copy );
433 my $org = $params->{location};
434 my $copyid = $params->{copyid};
435 my $count = $params->{count} || 1;
436 my $nc_type = $params->{non_cat_type};
437 my $use_time = $params->{use_time} || 'now';
439 my $non_cat = 1 if $self->api_name =~ /non_cat/;
443 my $barcode = $params->{barcode};
444 ($copy, $evt) = $U->fetch_copy_by_barcode($barcode);
448 ($copy, $evt) = $U->fetch_copy($copyid) unless $copy;
452 ($staff, $evt) = $U->checkses($authtoken);
455 $evt = $U->check_perms($staff->id, $org, 'CREATE_IN_HOUSE_USE');
458 if( $use_time ne 'now' ) {
459 $use_time = clense_ISO8601($use_time);
460 $logger->debug("in_house_use setting use time to $use_time");
470 $ihu = Fieldmapper::action::non_cat_in_house_use->new;
471 $ihu->noncat_type($nc_type);
472 $method = 'open-ils.storage.direct.action.non_cat_in_house_use.create';
474 $ihu = Fieldmapper::action::in_house_use->new;
476 $method = 'open-ils.storage.direct.action.in_house_use.create';
479 $ihu->staff($staff->id);
480 $ihu->org_unit($org);
481 $ihu->use_time($use_time);
483 my $id = $U->simplereq('open-ils.storage', $method, $ihu );
485 return $U->DB_UPDATE_FAILED($ihu) unless $id;
496 sub create_in_house_use {
497 my( $self, $client, $auth, $params ) = @_;
500 my $org = $params->{location};
501 my $copyid = $params->{copyid};
502 my $count = $params->{count} || 1;
503 my $nc_type = $params->{non_cat_type};
504 my $use_time = $params->{use_time} || 'now';
506 my $e = new_editor(xact=>1,authtoken=>$auth);
507 return $e->event unless $e->checkauth;
508 return $e->event unless $e->allowed('CREATE_IN_HOUSE_USE');
510 my $non_cat = 1 if $self->api_name =~ /non_cat/;
514 $copy = $e->retrieve_asset_copy($copyid) or return $e->event;
516 $copy = $e->search_asset_copy({barcode=>$params->{barcode}, deleted => 'f'})->[0]
522 if( $use_time ne 'now' ) {
523 $use_time = clense_ISO8601($use_time);
524 $logger->debug("in_house_use setting use time to $use_time");
535 $ihu = Fieldmapper::action::non_cat_in_house_use->new;
536 $ihu->item_type($nc_type);
537 $method = 'open-ils.storage.direct.action.non_cat_in_house_use.create';
538 $cmeth = "create_action_non_cat_in_house_use";
541 $ihu = Fieldmapper::action::in_house_use->new;
543 $method = 'open-ils.storage.direct.action.in_house_use.create';
544 $cmeth = "create_action_in_house_use";
547 $ihu->staff($e->requestor->id);
548 $ihu->org_unit($org);
549 $ihu->use_time($use_time);
551 $ihu = $e->$cmeth($ihu) or return $e->event;
552 push( @ids, $ihu->id );
562 __PACKAGE__->register_method(
563 method => "view_circs",
564 api_name => "open-ils.circ.copy_checkout_history.retrieve",
566 Retrieves the last X circs for a given copy
567 @param authtoken The login session key
568 @param copyid The copy to check
569 @param count How far to go back in the item history
570 @return An array of circ ids
576 my( $self, $client, $authtoken, $copyid, $count ) = @_;
578 my( $requestor, $evt ) = $U->checksesperm(
579 $authtoken, 'VIEW_COPY_CHECKOUT_HISTORY' );
582 return [] unless $count;
584 my $circs = $U->cstorereq(
585 'open-ils.cstore.direct.action.circulation.search.atomic',
587 target_copy => $copyid,
591 order_by => { circ => "xact_start DESC" }
599 __PACKAGE__->register_method(
600 method => "circ_count",
601 api_name => "open-ils.circ.circulation.count",
603 Returns the number of times the item has circulated
604 @param copyid The copy to check
608 my( $self, $client, $copyid, $range ) = @_;
609 my $e = OpenILS::Utils::Editor->new;
610 return $e->request('open-ils.storage.asset.copy.circ_count', $copyid, $range);
615 __PACKAGE__->register_method(
616 method => 'fetch_notes',
617 api_name => 'open-ils.circ.copy_note.retrieve.all',
619 Returns an array of copy note objects.
620 @param args A named hash of parameters including:
621 authtoken : Required if viewing non-public notes
622 itemid : The id of the item whose notes we want to retrieve
623 pub : True if all the caller wants are public notes
624 @return An array of note objects
627 __PACKAGE__->register_method(
628 method => 'fetch_notes',
629 api_name => 'open-ils.circ.call_number_note.retrieve.all',
630 signature => q/@see open-ils.circ.copy_note.retrieve.all/);
632 __PACKAGE__->register_method(
633 method => 'fetch_notes',
634 api_name => 'open-ils.circ.title_note.retrieve.all',
635 signature => q/@see open-ils.circ.copy_note.retrieve.all/);
638 # NOTE: VIEW_COPY/VOLUME/TITLE_NOTES perms should always be global
640 my( $self, $connection, $args ) = @_;
642 my $id = $$args{itemid};
643 my $authtoken = $$args{authtoken};
646 if( $self->api_name =~ /copy/ ) {
648 return $U->cstorereq(
649 'open-ils.cstore.direct.asset.copy_note.search.atomic',
650 { owning_copy => $id, pub => 't' } );
652 ( $r, $evt ) = $U->checksesperm($authtoken, 'VIEW_COPY_NOTES');
654 return $U->cstorereq(
655 'open-ils.cstore.direct.asset.copy_note.search.atomic', {owning_copy => $id} );
658 } elsif( $self->api_name =~ /call_number/ ) {
660 return $U->cstorereq(
661 'open-ils.cstore.direct.asset.call_number_note.search.atomic',
662 { call_number => $id, pub => 't' } );
664 ( $r, $evt ) = $U->checksesperm($authtoken, 'VIEW_VOLUME_NOTES');
666 return $U->cstorereq(
667 'open-ils.cstore.direct.asset.call_number_note.search.atomic', { call_number => $id } );
670 } elsif( $self->api_name =~ /title/ ) {
672 return $U->cstorereq(
673 'open-ils.cstore.direct.bilbio.record_note.search.atomic',
674 { record => $id, pub => 't' } );
676 ( $r, $evt ) = $U->checksesperm($authtoken, 'VIEW_TITLE_NOTES');
678 return $U->cstorereq(
679 'open-ils.cstore.direct.biblio.record_note.search.atomic', { record => $id } );
686 __PACKAGE__->register_method(
687 method => 'has_notes',
688 api_name => 'open-ils.circ.copy.has_notes');
689 __PACKAGE__->register_method(
690 method => 'has_notes',
691 api_name => 'open-ils.circ.call_number.has_notes');
692 __PACKAGE__->register_method(
693 method => 'has_notes',
694 api_name => 'open-ils.circ.title.has_notes');
698 my( $self, $conn, $authtoken, $id ) = @_;
699 my $editor = OpenILS::Utils::Editor->new(authtoken => $authtoken);
700 return $editor->event unless $editor->checkauth;
702 my $n = $editor->search_asset_copy_note(
703 {owning_copy=>$id}, {idlist=>1}) if $self->api_name =~ /copy/;
705 $n = $editor->search_asset_call_number_note(
706 {call_number=>$id}, {idlist=>1}) if $self->api_name =~ /call_number/;
708 $n = $editor->search_biblio_record_note(
709 {record=>$id}, {idlist=>1}) if $self->api_name =~ /title/;
714 __PACKAGE__->register_method(
715 method => 'create_copy_note',
716 api_name => 'open-ils.circ.copy_note.create',
718 Creates a new copy note
719 @param authtoken The login session key
720 @param note The note object to create
721 @return The id of the new note object
724 sub create_copy_note {
725 my( $self, $connection, $authtoken, $note ) = @_;
726 my( $cnowner, $requestor, $evt );
728 ($cnowner, $evt) = $U->fetch_copy_owner($note->owning_copy);
730 ($requestor, $evt) = $U->checkses($authtoken);
732 $evt = $U->check_perms($requestor->id, $cnowner, 'CREATE_COPY_NOTE');
735 $note->create_date('now');
736 $note->creator($requestor->id);
737 $note->pub( ($U->is_true($note->pub)) ? 1 : 0 );
739 my $id = $U->storagereq(
740 'open-ils.storage.direct.asset.copy_note.create', $note );
741 return $U->DB_UPDATE_FAILED($note) unless $id;
743 $logger->activity("User ".$requestor->id." created a new copy ".
744 "note [$id] for copy ".$note->owning_copy." with text ".$note->value);
749 __PACKAGE__->register_method(
750 method => 'delete_copy_note',
751 api_name => 'open-ils.circ.copy_note.delete',
753 Deletes an existing copy note
754 @param authtoken The login session key
755 @param noteid The id of the note to delete
756 @return 1 on success - Event otherwise.
759 sub delete_copy_note {
760 my( $self, $conn, $authtoken, $noteid ) = @_;
761 my( $requestor, $note, $owner, $evt );
763 ($requestor, $evt) = $U->checkses($authtoken);
766 ($note, $evt) = $U->fetch_copy_note($noteid);
769 if( $note->creator ne $requestor->id ) {
770 ($owner, $evt) = $U->fetch_copy_onwer($note->owning_copy);
772 $evt = $U->check_perms($requestor->id, $owner, 'DELETE_COPY_NOTE');
776 my $stat = $U->storagereq(
777 'open-ils.storage.direct.asset.copy_note.delete', $noteid );
778 return $U->DB_UPDATE_FAILED($noteid) unless $stat;
780 $logger->activity("User ".$requestor->id." deleted copy note $noteid");
785 __PACKAGE__->register_method(
786 method => 'age_hold_rules',
787 api_name => 'open-ils.circ.config.rules.age_hold_protect.retrieve.all',
791 my( $self, $conn ) = @_;
792 return new_editor()->retrieve_all_config_rules_age_hold_protect();
798 __PACKAGE__->register_method(
799 method => 'copy_details',
800 api_name => 'open-ils.circ.copy_details.retrieve',
806 my( $self, $conn, $auth, $copy_id ) = @_;
807 my $e = new_editor(authtoken=>$auth);
808 return $e->event unless $e->checkauth;
810 my $copy = $e->retrieve_asset_copy($copy_id)
813 my $hold = $e->search_action_hold_request(
815 current_copy => $copy_id,
816 capture_time => { "!=" => undef },
817 fulfillment_time => undef,
821 OpenILS::Application::Circ::Holds::flesh_hold_transits([$hold]) if $hold;
823 my $transit = $e->search_action_transit_copy(
824 { target_copy => $copy_id, dest_recv_time => undef } )->[0];
826 # find the latest circ, open or closed
827 my $circ = $e->search_action_circulation(
829 { target_copy => $copy_id },
830 { order_by => { circ => 'xact_start desc' }, limit => 1 }
845 __PACKAGE__->register_method(
846 method => 'mark_item',
847 api_name => 'open-ils.circ.mark_item_damaged',
849 __PACKAGE__->register_method(
850 method => 'mark_item',
851 api_name => 'open-ils.circ.mark_item_missing',
855 my( $self, $conn, $auth, $copy_id ) = @_;
856 my $e = new_editor(authtoken=>$auth, xact =>1);
857 return $e->event unless $e->checkauth;
859 my $perm = 'MARK_ITEM_MISSING';
860 my $stat = OILS_COPY_STATUS_MISSING;
862 if( $self->api_name =~ /damaged/ ) {
863 $perm = 'MARK_ITEM_DAMAGED';
864 $stat = OILS_COPY_STATUS_DAMAGED;
867 my $copy = $e->retrieve_asset_copy($copy_id)
869 $copy->status($stat);
871 $e->update_asset_copy($copy) or return $e->event;
874 my $holds = $e->search_action_hold_request(
876 current_copy => $copy->id,
877 fulfillment_time => undef,
878 cancel_time => undef,
884 $logger->debug("reseting holds that target the marked copy");
885 OpenILS::Application::Circ::Holds->_reset_hold($e->requestor, $_) for @$holds;
895 # ----------------------------------------------------------------------
896 __PACKAGE__->register_method(
897 method => 'magic_fetch',
898 api_name => 'open-ils.agent.fetch'
901 my @FETCH_ALLOWED = qw/ aou aout acp acn bre /;
904 my( $self, $conn, $auth, $args ) = @_;
905 my $e = new_editor( authtoken => $auth );
906 return $e->event unless $e->checkauth;
908 my $hint = $$args{hint};
911 # Is the call allowed to fetch this type of object?
912 return undef unless grep { $_ eq $hint } @FETCH_ALLOWED;
914 # Find the class the iplements the given hint
916 $Fieldmapper::fieldmap->{$_}{hint} eq $hint } Fieldmapper->classes;
918 $class =~ s/Fieldmapper:://og;
920 my $method = "retrieve_$class";
922 my $obj = $e->$method($id) or return $e->event;
925 # ----------------------------------------------------------------------