]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Circ/NonCat.pm
checking all non-cat types in my orgs for an existing type
[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         # grab all of "my" non-cat types and see if one with 
32         # the requested name already exists
33         my $types = $self->retrieve_noncat_types_all($client, $orgId);
34         if(ref($types)) {
35                 for(@$types) {
36                         return OpenILS::Event->new('NON_CAT_TYPE_EXISTS') if $_->name eq $name;
37                 }
38         }
39
40         $evt = $U->check_perms( $staff->id, $orgId, 'CREATE_NON_CAT_TYPE' );
41         return $evt if $evt;
42
43         my $type = Fieldmapper::config::non_cataloged_type->new;
44         $type->name($name);
45         $type->owning_lib($orgId);
46
47         my $id = $U->simplereq(
48                 'open-ils.storage',
49                 'open-ils.storage.direct.config.non_cataloged_type.create', $type );
50
51         return $U->DB_UPDATE_FAILED($type) unless $id;
52         $type->id($id);
53         return $type;
54 }
55
56 __PACKAGE__->register_method(
57         method  => "update_noncat_type",
58         api_name        => "open-ils.circ.non_cat_type.update",
59         notes           => q/
60                 Updates a non-cataloged type object
61                 @param authtoken The login session key
62                 @param type The updated type object
63                 @return The result of the DB update call unless a preceeding event occurs, 
64                         in which case the event will be returned
65         /);
66
67 sub update_noncat_type {
68         my( $self, $client, $authtoken, $type ) = @_;
69         my( $staff, $evt ) = $U->checkses($authtoken);
70         return $evt if $evt;
71
72         my $otype;
73         ($otype, $evt) = $U->fetch_non_cat_type($type->id);
74         return $evt if $evt;
75
76         $type->owning_lib($otype->owning_lib); # do not allow them to "move" the object
77
78         $evt = $U->check_perms( $staff->id, $type->owning_lib, 'UPDATE_NON_CAT_TYPE' );
79         return $evt if $evt;
80
81         return $U->simplereq(
82                 'open-ils.storage',
83                 'open-ils.storage.direct.config.non_cataloged_type.update', $type );
84 }
85
86 __PACKAGE__->register_method(
87         method  => "retrieve_noncat_types_all",
88         api_name        => "open-ils.circ.non_cat_types.retrieve.all",
89         notes           => q/
90                 Retrieves the non-cat types at the requested location as well
91                 as those above and below the requested location in the org tree
92                 @param orgId The base location at which to retrieve the type objects
93                 @param depth Optional parameter to limit the depth of the tree
94                 @return An array of non cat type objects or an event if an error occurs
95         /);
96
97 sub retrieve_noncat_types_all {
98         my( $self, $client, $orgId, $depth ) = @_;
99         my $meth = 'open-ils.storage.ranged.config.non_cataloged_type.retrieve.atomic';
100         my $svc = 'open-ils.storage';
101         return $U->simplereq($svc, $meth, $orgId, $depth) if defined($depth);
102         return $U->simplereq($svc, $meth, $orgId);
103 }
104
105
106
107 1;