]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Circ/NonCat.pm
5f9e663966efec305f0e9f703a1ac6ff75e1d3a8
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Circ / NonCat.pm
1 package OpenILS::Application::Circ::NonCat;
2 use base 'OpenSRF::Application';
3 use strict; use warnings;
4 use OpenSRF::EX qw(:try);
5 use Data::Dumper;
6 use OpenSRF::Utils::Logger qw(:logger);
7 use OpenILS::Application::AppUtils;
8 use OpenILS::Utils::Fieldmapper;
9 $Data::Dumper::Indent = 0;
10
11 my $U = "OpenILS::Application::AppUtils";
12
13
14 __PACKAGE__->register_method(
15         method  => "create_noncat_type",
16         api_name        => "open-ils.circ.non_cat_type.create",
17         notes           => q/
18                 Creates a new non cataloged item type
19                 @param authtoken The login session key
20                 @param name The name of the new type
21                 @param orgId The location where the type will live
22                 @return The type object on success and the corresponding
23                 event on failure
24         /);
25
26 sub create_noncat_type {
27         my( $self, $client, $authtoken, $name, $orgId ) = @_;
28         my( $staff, $evt ) = $U->checkses($authtoken);
29         return $evt if $evt;
30
31         my $type;
32
33         # first, see if the exact type already exists  XXX this needs to be ranged
34         ($type, $evt) = $U->fetch_non_cat_type_by_name_and_org($name, $orgId);
35         return OpenILS::Event->new('NON_CAT_TYPE_EXISTS') if $type;
36
37         $evt = $U->check_perms( $staff->id, $orgId, 'CREATE_NON_CAT_TYPE' );
38         return $evt if $evt;
39
40         $type = Fieldmapper::config::non_cataloged_type->new;
41         $type->name($name);
42         $type->owning_lib($orgId);
43
44         my $id = $U->simplereq(
45                 'open-ils.storage',
46                 'open-ils.storage.direct.config.non_cataloged_type.create', $type );
47
48         return $U->DB_UPDATE_FAILED($type) unless $id;
49         $type->id($id);
50         return $type;
51 }
52
53 __PACKAGE__->register_method(
54         method  => "update_noncat_type",
55         api_name        => "open-ils.circ.non_cat_type.update",
56         notes           => q/
57                 Updates a non-cataloged type object
58                 @param authtoken The login session key
59                 @param type The updated type object
60                 @return The result of the DB update call unless a preceeding event occurs, 
61                         in which case the event will be returned
62         /);
63
64 sub update_noncat_type {
65         my( $self, $client, $authtoken, $type ) = @_;
66         my( $staff, $evt ) = $U->checkses($authtoken);
67         return $evt if $evt;
68
69         my $otype;
70         ($otype, $evt) = $U->fetch_non_cat_type($type->id);
71         return $evt if $evt;
72
73         $type->owning_lib($otype->owning_lib); # do not allow them to "move" the object
74
75         $evt = $U->check_perms( $staff->id, $type->owning_lib, 'UPDATE_NON_CAT_TYPE' );
76         return $evt if $evt;
77
78         return $U->simplereq(
79                 'open-ils.storage',
80                 'open-ils.storage.direct.config.non_cataloged_type.update', $type );
81 }
82
83 __PACKAGE__->register_method(
84         method  => "retrieve_noncat_types_all",
85         api_name        => "open-ils.circ.non_cat_types.retrieve.all",
86         notes           => q/
87                 Retrieves the non-cat types at the requested location as well
88                 as those above and below the requested location in the org tree
89                 @param orgId The base location at which to retrieve the type objects
90                 @return An array of non cat type objects or an event if an error occurs
91         /);
92
93 sub retrieve_noncat_types_all {
94         my( $self, $client, $orgId ) = @_;
95         return $U->simplereq(
96                 'open-ils.storage', # XXX Needs to be a ranged call
97                 'open-ils.storage.direct.config.non_cataloged_type.search_where.atomic', 
98                 { owning_lib => $orgId } );
99 }
100
101
102
103 1;