Lines 137-158
sub getPrefixes {
Link Here
|
137 |
return $values; |
137 |
return $values; |
138 |
} |
138 |
} |
139 |
|
139 |
|
140 |
=head3 getLibraryPrivileges |
|
|
141 |
|
142 |
my $privileges= $config->getLibraryPrivileges; |
143 |
|
144 |
Return the LibraryPrivilege definitions defined by our config. |
145 |
|
146 |
=cut |
147 |
|
148 |
sub getLibraryPrivileges { |
149 |
my ( $self ) = @_; |
150 |
my $values= $self->{configuration}->{library_privileges}->{branch} || {}; |
151 |
$values->{default} = |
152 |
$self->{configuration}->{library_privileges}->{default}; |
153 |
return $values; |
154 |
} |
155 |
|
156 |
=head3 getLimitRules |
140 |
=head3 getLimitRules |
157 |
|
141 |
|
158 |
my $rules = $config->getLimitRules('brw_cat' | 'branch') |
142 |
my $rules = $config->getLimitRules('brw_cat' | 'branch') |
Lines 186-237
sub getDigitalRecipients {
Link Here
|
186 |
return $values; |
170 |
return $values; |
187 |
} |
171 |
} |
188 |
|
172 |
|
189 |
=head3 getDefaultFormats |
|
|
190 |
|
191 |
my $defaultFormat = $config->getLimitRules('brw_cat' | 'branch') |
192 |
|
193 |
Return the hash of ILL default formats defined by our config. |
194 |
|
195 |
=cut |
196 |
|
197 |
sub getDefaultFormats { |
198 |
my ( $self, $type ) = @_; |
199 |
die "Unexpected type." unless ( $type eq 'brw_cat' || $type eq 'branch' ); |
200 |
my $values = $self->{configuration}->{default_formats}->{$type}; |
201 |
$values->{default} = $self->{configuration}->{default_formats}->{default}; |
202 |
return $values; |
203 |
} |
204 |
|
205 |
=head3 getCredentials |
206 |
|
207 |
my $credentials = $config->getCredentials($branchCode); |
208 |
|
209 |
Fetch the best-fit credentials: if we have credentials for $branchCode, use |
210 |
those; otherwise fall back on default credentials. If neither can be found, |
211 |
simply populate application details, and populate key details with 0. |
212 |
|
213 |
=cut |
214 |
|
215 |
sub getCredentials { |
216 |
my ( $self, $branchCode ) = @_; |
217 |
my $creds = $self->{configuration}->{credentials} |
218 |
|| die "We have no credentials defined. Please check koha-conf.xml."; |
219 |
|
220 |
my $exact = { api_key => 0, api_auth => 0 }; |
221 |
if ( $branchCode && $creds->{api_keys}->{$branchCode} ) { |
222 |
$exact = $creds->{api_keys}->{$branchCode} |
223 |
} elsif ( $creds->{api_keys}->{default} ) { |
224 |
$exact = $creds->{api_keys}->{default}; |
225 |
} |
226 |
|
227 |
return { |
228 |
api_key => $exact->{api_key}, |
229 |
api_key_auth => $exact->{api_auth}, |
230 |
api_application => $creds->{api_application}->{key}, |
231 |
api_application_auth => $creds->{api_application}->{auth}, |
232 |
}; |
233 |
} |
234 |
|
235 |
=head3 censorship |
173 |
=head3 censorship |
236 |
|
174 |
|
237 |
my $censoredValues = $config->censorship($hash); |
175 |
my $censoredValues = $config->censorship($hash); |
Lines 251-283
sub censorship {
Link Here
|
251 |
return $self->{configuration}->{censorship}; |
189 |
return $self->{configuration}->{censorship}; |
252 |
} |
190 |
} |
253 |
|
191 |
|
254 |
=head3 getApiUrl |
|
|
255 |
|
256 |
my $api_url = $config->getApiUrl; |
257 |
|
258 |
Return the url for the api configured by koha-conf.xml, or the fall-back url. |
259 |
|
260 |
=cut |
261 |
|
262 |
sub getApiUrl { |
263 |
my ( $self ) = @_; |
264 |
return $self->{configuration}->{api_url}; |
265 |
} |
266 |
|
267 |
=head3 getApiSpecFile |
268 |
|
269 |
my $api_spec_file = $config->getApiSpecFile; |
270 |
|
271 |
Return the path pointing to the API specfile, if it indeed exists, from by |
272 |
koha-conf.xml, or 0. |
273 |
|
274 |
=cut |
275 |
|
276 |
sub getApiSpecFile { |
277 |
my ( $self ) = @_; |
278 |
return $self->{configuration}->{spec_file} || 0; |
279 |
} |
280 |
|
281 |
=head3 _load_configuration |
192 |
=head3 _load_configuration |
282 |
|
193 |
|
283 |
my $configuration = $config->_load_configuration($config_from_xml); |
194 |
my $configuration = $config->_load_configuration($config_from_xml); |
Lines 292-323
file to ensure we have only valid input there.
Link Here
|
292 |
|
203 |
|
293 |
sub _load_configuration { |
204 |
sub _load_configuration { |
294 |
my ( $from_xml, $unmediated ) = @_; |
205 |
my ( $from_xml, $unmediated ) = @_; |
295 |
my $xml_config = $from_xml->{configuration}; |
|
|
296 |
my $xml_api_url = $from_xml->{api_url}; |
297 |
my $xml_backend_dir = $from_xml->{backend_directory}; |
206 |
my $xml_backend_dir = $from_xml->{backend_directory}; |
298 |
|
207 |
my $xml_config = $from_xml->{configuration} || {}; |
299 |
# Input validation |
|
|
300 |
die "CONFIGURATION has not been defined in koha-conf.xml." |
301 |
unless ( ref($xml_config) eq "HASH" ); |
302 |
die "APPLICATION has not been defined in koha-conf.xml." |
303 |
unless ( ref($from_xml->{application}) eq "HASH" ); |
304 |
|
208 |
|
305 |
# Default data structure to be returned |
209 |
# Default data structure to be returned |
306 |
my $configuration = { |
210 |
my $configuration = { |
307 |
backend_directory => $xml_backend_dir, |
211 |
backend_directory => $xml_backend_dir, |
308 |
api_url => $xml_api_url || 'http://apitest.bldss.bl.uk', |
|
|
309 |
spec_file => $from_xml->{api_specification}, |
310 |
censorship => { |
212 |
censorship => { |
311 |
censor_notes_staff => 0, |
213 |
censor_notes_staff => 0, |
312 |
censor_reply_date => 0, |
214 |
censor_reply_date => 0, |
313 |
}, |
215 |
}, |
314 |
credentials => { |
|
|
315 |
api_application => {}, |
316 |
api_keys => {}, |
317 |
}, |
318 |
library_privileges => {}, |
319 |
limits => {}, |
216 |
limits => {}, |
320 |
default_formats => {}, |
|
|
321 |
digital_recipients => {}, |
217 |
digital_recipients => {}, |
322 |
prefixes => {}, |
218 |
prefixes => {}, |
323 |
}; |
219 |
}; |
Lines 373-384
sub _load_configuration {
Link Here
|
373 |
config => $configuration |
269 |
config => $configuration |
374 |
}); |
270 |
}); |
375 |
|
271 |
|
376 |
# Application key & auth |
|
|
377 |
$configuration->{credentials}->{api_application} = { |
378 |
key => $from_xml->{application}->{key}, |
379 |
auth => $from_xml->{application}->{auth}, |
380 |
}; |
381 |
|
382 |
# Censorship |
272 |
# Censorship |
383 |
my $staff_comments = $from_xml->{staff_request_comments}; |
273 |
my $staff_comments = $from_xml->{staff_request_comments}; |
384 |
$configuration->{censorship}->{censor_notes_staff} = 1 |
274 |
$configuration->{censorship}->{censor_notes_staff} = 1 |
Lines 448-467
sub _load_unit_config {
Link Here
|
448 |
} |
338 |
} |
449 |
} |
339 |
} |
450 |
|
340 |
|
451 |
# Add library_privilege rules (only per branch). |
|
|
452 |
# LIBRARY_PRIVILEGE := 1 || 0 |
453 |
unless ( $type && 'brw_cat' eq $type ) { |
454 |
if ( $unit->{library_privilege} ) { |
455 |
if ( 'default' eq $id ) { |
456 |
$config->{library_privileges}->{$id} = |
457 |
$unit->{library_privilege}; |
458 |
} else { |
459 |
$config->{library_privileges}->{branch}->{$id} = |
460 |
$unit->{library_privilege}; |
461 |
} |
462 |
} |
463 |
} |
464 |
|
465 |
# Add prefix rules. |
341 |
# Add prefix rules. |
466 |
# PREFIX := string |
342 |
# PREFIX := string |
467 |
if ( $unit->{prefix} ) { |
343 |
if ( $unit->{prefix} ) { |
Lines 483-509
sub _load_unit_config {
Link Here
|
483 |
} |
359 |
} |
484 |
} |
360 |
} |
485 |
|
361 |
|
486 |
# Add default_formats types. |
|
|
487 |
# FORMAT && QUALITY && QUANTITY && SERVICE && SPEED := x >= 0 |
488 |
if ( ref $unit->{default_formats} eq 'HASH' ) { |
489 |
my @fields = qw(format quality quantity service speed); |
490 |
if ( 'default' eq $id ) { |
491 |
for ( @fields ) { |
492 |
my $val = $unit->{default_formats}->{$_}; |
493 |
die "Invalid default_formats: '$_' missing" |
494 |
unless $val; |
495 |
$config->{default_formats}->{$id}->{$_} = $val; |
496 |
} |
497 |
} else { |
498 |
for ( @fields ) { |
499 |
my $val = $unit->{default_formats}->{$_}; |
500 |
die "Invalid default_formats: '$_' missing" |
501 |
unless $val; |
502 |
$config->{default_formats}->{$type}->{$id}->{$_} = $val; |
503 |
} |
504 |
} |
505 |
} |
506 |
|
507 |
return $config; |
362 |
return $config; |
508 |
} |
363 |
} |
509 |
|
364 |
|
510 |
- |
|
|