4 use base 'OpenSRF::Application';
6 use OpenSRF::Utils::Logger;
7 my $log = 'OpenSRF::Utils::Logger';
9 use OpenILS::Application::Storage::CDBI;
10 use OpenILS::Application::Storage::CDBI::actor;
11 use OpenILS::Application::Storage::CDBI::action;
12 use OpenILS::Application::Storage::CDBI::asset;
13 use OpenILS::Application::Storage::CDBI::biblio;
14 use OpenILS::Application::Storage::CDBI::config;
15 use OpenILS::Application::Storage::CDBI::metabib;
16 use OpenILS::Application::Storage::CDBI::money;
17 use OpenILS::Application::Storage::CDBI::container;
19 use vars qw/$fieldmap $VERSION/;
23 sub publish_fieldmapper {
24 my ($self,$client,$class) = @_;
26 return $fieldmap unless (defined $class);
27 return undef unless (exists($$fieldmap{$class}));
28 return {$class => $$fieldmap{$class}};
30 __PACKAGE__->register_method(
31 api_name => 'opensrf.open-ils.system.fieldmapper',
33 method => 'publish_fieldmapper',
37 # To dump the Javascript version of the fieldmapper struct use the command:
39 # PERL5LIB=~/cvs/ILS/OpenSRF/src/perlmods/:~/cvs/ILS/Open-ILS/src/perlmods/ GEN_JS=1 perl -MOpenILS::Utils::Fieldmapper -e 'print "\n";'
41 # ... adjusted for your CVS sandbox, of course.
45 return () unless (defined $fieldmap);
46 return keys %$fieldmap;
50 return if (keys %$fieldmap);
54 'Fieldmapper::container::user_bucket' => { hint => 'cub',
55 proto_fields => { items => 1 } },
56 'Fieldmapper::container::copy_bucket' => { hint => 'ccb',
57 proto_fields => { items => 1 } },
58 'Fieldmapper::container::call_number_bucket' => { hint => 'ccnb',
59 proto_fields => { items => 1 } },
60 'Fieldmapper::container::biblio_record_entry_bucket' => { hint => 'cbreb',
61 proto_fields => { items => 1 } },
63 'Fieldmapper::container::user_bucket_item' => { hint => 'cubi' },
64 'Fieldmapper::container::copy_bucket_item' => { hint => 'ccbi' },
65 'Fieldmapper::container::call_number_bucket_item' => { hint => 'ccnbi' },
66 'Fieldmapper::container::biblio_record_entry_bucket_item' => { hint => 'cbrebi' },
68 'Fieldmapper::action::in_house_use' => { hint => 'aihu' },
69 'Fieldmapper::action::non_cataloged_circulation'=> { hint => 'ancc' },
71 'Fieldmapper::action::survey' => { hint => 'asv',
72 proto_fields => { questions => 1,
74 'Fieldmapper::action::survey_question' => { hint => 'asvq',
75 proto_fields => { answers => 1,
77 'Fieldmapper::action::survey_answer' => { hint => 'asva',
78 proto_fields => { responses => 1 } },
79 'Fieldmapper::action::survey_response' => { hint => 'asvr' },
80 'Fieldmapper::action::circulation' => { hint => 'circ',
83 'Fieldmapper::action::open_circulation' => { hint => 'aoc',
86 'Fieldmapper::actor::user' => { hint => 'au',
87 proto_fields => { cards => 1,
88 survey_responses => 1,
89 stat_cat_entries => 1,
94 standing_penalties => 1,
96 'Fieldmapper::actor::user_setting' => { hint => 'aus' },
97 'Fieldmapper::actor::user_standing_penalty' => { hint => 'ausp' },
98 'Fieldmapper::actor::org_unit_setting' => { hint => 'aous' },
99 'Fieldmapper::actor::user_address' => { hint => 'aua' },
100 'Fieldmapper::actor::org_address' => { hint => 'aoa' },
101 'Fieldmapper::actor::profile' => { hint => 'ap' },
102 'Fieldmapper::actor::card' => { hint => 'ac' },
103 'Fieldmapper::actor::stat_cat' => { hint => 'actsc',
104 proto_fields => { entries => 1 } },
105 'Fieldmapper::actor::stat_cat_entry' => { hint => 'actsce' },
106 'Fieldmapper::actor::stat_cat_entry_user_map' => { hint => 'actscecm' },
107 'Fieldmapper::actor::org_unit' => { hint => 'aou',
108 proto_fields => { children => 1 } },
109 'Fieldmapper::actor::org_unit_type' => { hint => 'aout',
110 proto_fields => { children => 1 } },
112 'Fieldmapper::biblio::record_node' => { hint => 'brn',
114 proto_fields => { children => 1,
125 'Fieldmapper::metabib::virtual_record' => { hint => 'mvr',
127 proto_fields => { title => 1,
136 types_of_resource => 1,
146 'Fieldmapper::authority::record_entry' => { hint => 'are', },
147 'Fieldmapper::authority::record_note' => { hint => 'arn', },
148 'Fieldmapper::biblio::record_entry' => { hint => 'bre',
149 proto_fields => { call_numbers => 1,
150 fixed_fields => 1 } },
151 #'Fieldmapper::biblio::record_marc' => { hint => 'brx' }, # now it's inside record_entry
153 'Fieldmapper::money::payment' => { hint => 'mp',
156 'Fieldmapper::money::cash_payment' => { hint => 'mcp' },
157 'Fieldmapper::money::check_payment' => { hint => 'mckp' },
158 'Fieldmapper::money::credit_payment' => { hint => 'mcrp' },
159 'Fieldmapper::money::credit_card_payment' => { hint => 'mccp' },
160 'Fieldmapper::money::forgive_payment' => { hint => 'mfp' },
161 'Fieldmapper::money::work_payment' => { hint => 'mwp' },
163 'Fieldmapper::money::billing' => { hint => 'mb' },
164 'Fieldmapper::money::billable_transaction' => { hint => 'mbt' },
165 'Fieldmapper::money::grocery' => { hint => 'mg' },
167 'Fieldmapper::money::open_user_summary' => { hint => 'mous',
169 'Fieldmapper::money::user_summary' => { hint => 'mus',
172 'Fieldmapper::money::open_user_circulation_summary' => { hint => 'moucs',
174 'Fieldmapper::money::user_circulation_summary' => { hint => 'mucs',
177 'Fieldmapper::money::open_billable_transaction_summary' => { hint => 'mobts',
179 'Fieldmapper::money::billable_transaction_summary' => { hint => 'mbts',
182 'Fieldmapper::config::identification_type' => { hint => 'cit' },
183 'Fieldmapper::config::bib_source' => { hint => 'cbs' },
184 'Fieldmapper::config::metabib_field' => { hint => 'cmf' },
185 'Fieldmapper::config::rules::recuring_fine' => { hint => 'crrf' },
186 'Fieldmapper::config::rules::circ_duration' => { hint => 'crcd' },
187 'Fieldmapper::config::rules::max_fine' => { hint => 'crmf' },
188 'Fieldmapper::config::non_cataloged_type' => { hint => 'cnct' },
189 'Fieldmapper::config::standing' => { hint => 'cst' },
190 'Fieldmapper::config::copy_status' => { hint => 'ccs' },
192 'Fieldmapper::authority::full_rec' => { hint => 'afr' },
193 'Fieldmapper::authority::record_descriptor' => { hint => 'ard' },
195 'Fieldmapper::metabib::metarecord' => { hint => 'mmr' },
196 'Fieldmapper::metabib::title_field_entry' => { hint => 'mtfe' },
197 'Fieldmapper::metabib::author_field_entry' => { hint => 'mafe' },
198 'Fieldmapper::metabib::subject_field_entry' => { hint => 'msfe' },
199 'Fieldmapper::metabib::keyword_field_entry' => { hint => 'mkfe' },
200 'Fieldmapper::metabib::series_field_entry' => { hint => 'msefe' },
201 'Fieldmapper::metabib::full_rec' => { hint => 'mfr' },
202 'Fieldmapper::metabib::record_descriptor' => { hint => 'mrd' },
203 'Fieldmapper::metabib::metarecord_source_map' => { hint => 'mmrsm'},
205 'Fieldmapper::asset::copy' => { hint => 'acp',
206 proto_fields => { stat_cat_entries => 1 } },
207 'Fieldmapper::asset::stat_cat' => { hint => 'asc',
208 proto_fields => { entries => 1 } },
209 'Fieldmapper::asset::stat_cat_entry' => { hint => 'asce' },
210 'Fieldmapper::asset::stat_cat_entry_copy_map' => { hint => 'ascecm' },
211 'Fieldmapper::asset::copy_note' => { hint => 'acpn' },
212 'Fieldmapper::asset::copy_location' => { hint => 'acpl' },
213 'Fieldmapper::asset::call_number' => { hint => 'acn',
214 proto_fields => { copies => 1 } },
215 'Fieldmapper::asset::call_number_note' => { hint => 'acnn' },
217 'Fieldmapper::permission::perm_list' => { hint => 'ppl' },
218 'Fieldmapper::permission::grp_tree' => { hint => 'pgt', proto_fields => { children => 1 } },
219 'Fieldmapper::permission::usr_grp_map' => { hint => 'pugm' },
220 'Fieldmapper::permission::usr_perm_map' => { hint => 'pupm' },
221 'Fieldmapper::permission::grp_perm_map' => { hint => 'pgpm' },
222 'Fieldmapper::action::hold_request' => { hint => 'ahr', proto_fields => { status => 1 } },
223 'Fieldmapper::action::hold_notification' => { hint => 'ahn' },
224 'Fieldmapper::action::hold_copy_map' => { hint => 'ahcm' },
225 'Fieldmapper::action::hold_transit_copy' => { hint => 'ahtc' },
226 'Fieldmapper::action::transit_copy' => { hint => 'atc' },
227 'Fieldmapper::action::unfulfilled_hold_list' => { hint => 'aufh' },
230 'Fieldmapper::ex' => { hint => 'ex',
238 'Fieldmapper::perm_ex' => { hint => 'perm_ex',
249 #-------------------------------------------------------------------------------
250 # Now comes the evil! Generate classes
252 for my $pkg ( __PACKAGE__->classes ) {
253 (my $cdbi = $pkg) =~ s/^Fieldmapper:://o;
257 use base 'Fieldmapper';
261 for my $vfield ( qw/isnew ischanged isdeleted/ ) {
262 $$fieldmap{$pkg}{fields}{$vfield} = { position => $pos, virtual => 1 };
266 if (exists $$fieldmap{$pkg}{proto_fields}) {
267 for my $pfield ( sort keys %{ $$fieldmap{$pkg}{proto_fields} } ) {
268 $$fieldmap{$pkg}{fields}{$pfield} = { position => $pos, virtual => $$fieldmap{$pkg}{proto_fields}{$pfield} };
273 unless ( $$fieldmap{$pkg}{virtual} ) {
274 $$fieldmap{$pkg}{cdbi} = $cdbi;
275 for my $col ( sort $cdbi->columns('All') ) {
276 $$fieldmap{$pkg}{fields}{$col} = { position => $pos, virtual => 0 };
281 JSON->register_class_hint(
282 hint => $pkg->json_hint,
293 $value = [] unless (defined $value);
294 return bless $value => $self->class_name;
307 (my $field = $AUTOLOAD) =~ s/^.*://o;
308 my $class_name = $obj->class_name;
311 $fpos =~ s/^clear_//og ;
313 my $pos = $$fieldmap{$class_name}{fields}{$fpos}{position};
315 if ($field =~ /^clear_/o) {
317 *{$obj->class_name."::$field"} = sub {
319 $self->[$pos] = undef;
323 return $obj->$field();
326 die "No field by the name $field in $class_name!"
327 unless (exists $$fieldmap{$class_name}{fields}{$field} && defined($pos));
331 *{$obj->class_name."::$field"} = sub {
334 $self->[$pos] = $new_val if (defined $new_val);
335 return $self->[$pos];
338 return $obj->$field($value);
342 my $class_name = shift;
343 return ref($class_name) || $class_name;
348 my $class_name = $self->class_name;
349 my $fields = $$fieldmap{$class_name}{fields};
352 !$$fields{$_}{virtual}
353 } sort {$$fields{$a}{position} <=> $$fields{$b}{position}} keys %$fields;
361 my $class_name = $self->class_name;
362 return 1 if grep { $_ eq $field } keys %{$$fieldmap{$class_name}{fields}};
368 my $class_name = $self->class_name;
369 return keys %{$$fieldmap{$class_name}{fields}};
374 return $self->new( [@$self] );
379 return $fieldmap->{$self->class_name}->{api_level};
384 return $fieldmap->{$self->class_name}->{cdbi};
390 return $fieldmap->{$self->class_name}->{proto_fields}->{$field} if ($field);
391 return $fieldmap->{$self->class_name}->{virtual};
397 return $fieldmap->{$self->class_name}->{readonly};
402 return $fieldmap->{$self->class_name}->{hint};