blib/lib/FedoraCommons/APIM.pm

filter: Statementstmt 5.6% 40 / 703 Branchbran 0.2% 1 / 366 Conditioncond 0.0% 0 / 79 MC/DCmcdc 0.0% 0 / 45 Subroutinesub 23.6% 9 / 38 Podpod 100% 27 / 27 totaltotal 6.1% 77 / 1258 CC 215 SCAR 63.4
CC
215
Cov
4%
createObject
1722.0
addDatastream
870.0
uploadNewDatastream
812.0
CRAP 569.5
↑ Summary
1 # ========================================================================= #
2 #
3 # FedoraCommons::APIM - interface to Fedora's SOAP based API-M
4 #
5 # ========================================================================= #
6 #
7 # Copyright (c) 2011, Cornell University www.cornell.edu (enhancements)
8 # Copyright (c) 2010, Cornell University www.cornell.edu (enhancements)
9 # Copyright (c) 2009, Cornell University www.cornell.edu (enhancements)
10 # Copyright (c) 2007, The Pennsylvania State University, www.psu.edu
11 # Copyright (c) 2006, Technical Knowledge Center of Denmark, www.dtv.dk
12 #
13 # This library is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 2, or (at your option)
16 # any later version.
17 #
18 # See pod documentation for further license and copyright information.
19 #
20 # History: APIM interface was developed at PSU in 2006/2007. This code
21 # was built on top of an existing module which used SOAP (Technical
22 # Knowledge Center of Denmark[2006]).
23 #
24 # Cornell University began using the module for scripts
25 # to import legacy digital collections into a new cloud-based
26 # Archival Repository (2009). During this work the module has been
27 # enhanced with several new methods implemented.
28 #
29 # The module made interacting with a Fedora Commons repository
30 # easy thus the decision to share the module on CPAN.
31 #
32 # Manifest of APIM API methods and APIM Module methods:
33 # POD
34 # Fedora 3.0 APIM API Methods Supported Status Documented
35 # --------------------------- --------- ------ ----------
36 # * Datastream Management
37 # o addDatastream Supported OK Yes
38 # o compareDatastreamChecksum Supported New Yes (C)
39 # o getDatastream Supported OK Yes
40 # o getDatastreamHistory No
41 # o getDatastreams No
42 # o modifyDatastreamByReference Supported OK Yes (PSU)
43 # o modifyDatastreamByValue No
44 # o setDatastreamState No
45 # o setDatastreamVersionable Supported New Yes (C)
46 # o purgeDatastream Supported OK Yes (PSU)
47 # * Relationship Management
48 # o addRelationship Supported New Yes (C)
49 # o getRelationships Development Broken
50 # o purgeRelationship Supported New Yes (C)
51 # * Object Management
52 # o modifyObject
53 # o purgeObject Supported OK Yes
54 # o export
55 # o getNextPID Supported Fixed?? Yes
56 # o getObjectXML
57 # o ingest Supported OK Yes (PSU)
58 # * Miscellaneous Methods
59 # o uploadFile (APIM-Lite api) OK Yes (PSU)
60 # * Non-API Methods
61 # o createObject (not part of API) New Yes (C)
62 # o uploadNewDatastream (not part of API) New Yes (C)
63 #
64 # Allow client to automatically set POLICY datastream
65 # each time a new object is created. (*C)
66 #
67 # o set_policy_url
68 # o get_policy_url
69 # o set_policy_path
70 # o get_policy_path
71 # o set_policy_label
72 # o get_policy_label
73 #
74 # Enhancements/Additions:
75 # *PSU - Implemented by Penn State University
76 # *C - Implemented by Cornell Univeersity
77 #
78 # ========================================================================= #
79 #
80 # $Id: APIM.pm,v 1.2 2007/06/25 15:22:53 dlf2 Exp $
81 #
82 # ========================================================================= #
83 #
84  
85 package FedoraCommons::APIM;
86  
87 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
88 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
89  
90 1 require MIME::Base64;
91 1 require SOAP::Lite;
92 1 ▶use Time::HiRes qw(time);
Subroutine BEGIN: called CC=1 SCAR=0.0
93 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
94 1 ▶use LWP;
Subroutine BEGIN: called CC=1 SCAR=0.0
95 1 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
96 1 ▶use HTML::Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
97  
98 1 require Exporter;
99 1 ▶use AutoLoader qw(AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
100  
101 1 our @ISA = qw(Exporter);
102  
103 # Items to export into callers namespace by default. Note: do not export
104 # names by default without a very good reason. Use EXPORT_OK instead.
105 # Do not simply export all your public functions/methods/constants.
106  
107 # This allows declaration use FedoraCommons::APIM ':all';
108 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
109 # will save memory.
110 1 our %EXPORT_TAGS = ( 'all' => [ qw(
111  
112 ) ] );
113  
114 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
115  
116 1 our @EXPORT = qw(
117  
118 );
119  
120 1 our $VERSION = '0.6';
121  
122  
123 1 our $FEDORA_VERSION = "3.2";
124 1 ▶sub import {
Subroutine import: called CC=4 SCAR=24.2
125 1 my $pkg = shift;
126 1 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 1 1
127 0 my $command = shift;
128 0 my $parameter = shift;
129 0 ▶ if ($command eq 'version') {
Branch: 1 branch
BranchTrueFalseTotal
if ($command eq "version") 0 0 0
130  
131 # Add legal Fedora version numbers as they become available
132 0 ▶ if ($parameter eq "3.2") {
Branch: 1 branch
BranchTrueFalseTotal
if ($parameter eq "3.2") 0 0 0
133 0 $FEDORA_VERSION = $parameter;
134 }
135  
136 }
137 }
138 }
139  
140 1 my $ERROR_MESSAGE;
141  
142 # Preloaded methods go here.
143  
144 # Autoload methods go after =cut, and are processed by the autosplit program.
145  
146  
147  
148 # ========================================================================= #
149 #
150 # Public Methods
151 #
152 # ========================================================================= #
153  
154 1 my $default_foxml = "";
155  
156 # Constructor
157 #
158 # Args in parameter hash:
159 # host : Fedora host
160 # port : Port
161 # usr : Fedora Admin user
162 # pwd : Fedora Admin password
163 # timeout: Allowed timeout
164 #
165 # Return:
166 # The Fedora::APIM object
167 #
168 0 ▶sub new {
Subroutine new: not called CC=19 SCAR=59.4
Pod documented
169 0 my $class = shift;
170 0 my %args = @_;
171 0 my $self = {};
172  
173 0 $self->{'protocol'} = "http";
174  
175 0 foreach my $k (keys %args) {
176 0 ▶ if ($k eq 'usr') {
Branch: 12 branches
BranchTrueFalseTotal
if ($k eq 'usr') { } 0 0 0
elsif ($k eq 'pwd') { } 0 0 0
elsif ($k eq 'host') { } 0 0 0
elsif ($k eq 'port') { } 0 0 0
elsif ($k eq 'timeout') { } 0 0 0
elsif ($k eq 'replace') { } 0 0 0
elsif ($k eq 'reload') { } 0 0 0
elsif ($k eq 'debug') { } 0 0 0
elsif ($k eq 'policy_url') { } 0 0 0
elsif ($k eq 'policy_path') { } 0 0 0
elsif ($k eq 'policy_label') { } 0 0 0
elsif ($k eq 'protocol') { } 0 0 0
177 0 $self->{$k} = $args{$k};
178 } elsif ( $k eq 'pwd') {
179 0 $self->{$k} = $args{$k};
180 } elsif ( $k eq 'host') {
181 0 $self->{$k} = $args{$k};
182 } elsif ( $k eq 'port') {
183 0 $self->{$k} = $args{$k};
184 } elsif ( $k eq 'timeout') {
185 0 $self->{$k} = $args{$k};
186 } elsif ( $k eq 'replace') {
187 0 $self->{$k} = $args{$k};
188 } elsif ( $k eq 'reload') {
189 0 $self->{$k} = $args{$k};
190 } elsif ( $k eq 'debug') {
191 0 $self->{$k} = $args{$k};
192 } elsif ( $k eq 'policy_url') {
193 0 $self->{$k} = $args{$k};
194 0 $self->{'policy_path'} = "";# ensure only one is set
195 } elsif ( $k eq 'policy_path') {
196 0 $self->{$k} = $args{$k};
197 0 $self->{'policy_url'} = ""; # ensure only one is set
198 } elsif ( $k eq 'policy_label') {
199 0 $self->{$k} = $args{$k};
200 } elsif ($k eq 'protocol') {
201 0 $self->{$k} = $args{$k};
202 }
203 }
204  
205 # Check mandatory parameters
206 0 ▶ Carp::croak "Initialization parameter 'host' missing" unless defined($self->{'host'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"host"} 0 0 0
207 0 ▶ Carp::croak "Initialization parameter 'port' missing" unless defined($self->{'port'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"port"} 0 0 0
208 0 ▶ Carp::croak "Initialization parameter 'usr' missing" unless defined($self->{'usr'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"usr"} 0 0 0
209 0 ▶ Carp::croak "Initialization parameter 'pwd' missing" unless defined($self->{'pwd'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"pwd"} 0 0 0
210  
211 # Bless object
212 0 bless $self;
213  
214 # Initialise SOAP class
215 0 my $apim=SOAP::Lite
216 -> uri('http://www.fedora.info/definitions/api/')
217 -> proxy($self->_get_proxy());
218 0 ▶ if (defined($self->{timeout})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"timeout"}) 0 0 0
219 0 $apim->proxy->timeout($self->{timeout});
220 }
221 0 $self->{apim} = $apim;
222 0 $self->{ERROR_MESSAGE} = "";
223  
224 0 return $self;
225 }
226  
227 # Error from most recent operation
228 0 ▶sub error {
Subroutine error: not called CC=1 SCAR=6.9
Pod documented
229 0 my $self = shift;
230 0 return $self->{ERROR_MESSAGE};
231 }
232  
233 # Elapsed time of most recent operation
234 0 ▶sub get_time {
Subroutine get_time: not called CC=1 SCAR=6.9
Pod documented
235 0 my $self = shift;
236 0 return $self->{TIME};
237 }
238  
239 # Statistics
240 0 ▶sub get_stat {
Subroutine get_stat: not called CC=1 SCAR=6.9
Pod documented
241 0 my $self = shift;
242 0 return $self->{STAT};
243 }
244  
245 # Start statistic gathering over
246 0 ▶sub start_stat {
Subroutine start_stat: not called CC=1 SCAR=6.9
Pod documented
247 0 my $self = shift;
248 0 $self->{STAT} = {};
249 0 return;
250 }
251  
252 0 ▶sub get_default_foxml {
Subroutine get_default_foxml: not called CC=1 SCAR=6.9
Pod documented
253 0 return $default_foxml;
254 }
255  
256 0 ▶sub set_policy_url {
Subroutine set_policy_url: not called CC=1 SCAR=6.9
Pod documented
257 0 my $self = shift;
258 0 my $url = shift;
259 0 $self->{'policy_url'} = $url;
260 0 $self->{'policy_path'} = ""; # Allow only one of url/path to be set
261 0 return 1;
262 }
263 0 ▶sub get_policy_url {
Subroutine get_policy_url: not called CC=1 SCAR=6.9
Pod documented
264 0 my $self = shift;
265 0 return $self->{'policy_url'};
266 }
267 0 ▶sub set_policy_path {
Subroutine set_policy_path: not called CC=1 SCAR=6.9
Pod documented
268 0 my $self = shift;
269 0 my $url = shift;
270 0 $self->{'policy_path'} = $url;
271 0 $self->{'policy_url'} = ""; # Allow only one of url/path to be set
272 0 return 1;
273 }
274 0 ▶sub get_policy_path {
Subroutine get_policy_path: not called CC=1 SCAR=6.9
Pod documented
275 0 my $self = shift;
276 0 return $self->{'policy_path'};
277 }
278 0 ▶sub set_policy_label {
Subroutine set_policy_label: not called CC=1 SCAR=6.9
Pod documented
279 0 my $self = shift;
280 0 my $label = shift;
281 0 $self->{'policy_label'} = $label;
282 0 return 1;
283 }
284 0 ▶sub get_policy_label {
Subroutine get_policy_label: not called CC=1 SCAR=6.9
Pod documented
285 0 my $self = shift;
286 0 return $self->{'policy_label'};
287 }
288  
289 # uploadFile
290 #
291 # Args in parameter hash:
292 # filename: File to upload
293 # file_ref Reference to scalar to hold resulting filename
294 #
295 # Return:
296 #
297 # 0 = success
298 # 1 = Error
299 # 2 = Error on remote server
300 #
301 0 ▶sub uploadFile {
Subroutine uploadFile: not called CC=4 SCAR=30.0
Pod documented
302 0 my $self = shift;
303 0 my %args = @_;
304  
305 0 ▶ Carp::croak "Parameter 'filename' missing" unless defined($args{filename});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"filename"} 0 0 0
306 0 ▶ Carp::croak "Parameter 'file_ref' missing" unless defined($args{file_ref});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"file_ref"} 0 0 0
307  
308 my $url = "http://".
309 $self->{usr}.":".$self->{pwd}.
310 0 "\@".$self->{host}.":".$self->{port};
311 0 $url .= "/fedora/management/upload";
312  
313 0 my $agent = new LWP::UserAgent;
314 my $result = $agent->post( $url,
315 Content_Type => 'form-data',
316 0 Content => [ file => [$args{filename}] ] );
317  
318 0 ▶ if (! $result->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($result->is_success) 0 0 0
319 ## $self->{ERROR_MESSAGE} = $result->content;
320 0 return 2;
321 }
322  
323 0 ${$args{file_ref}} = $result->content;
324 0 return 0;
325 }
326  
327  
328 # Ingest
329 #
330 # Args in parameter hash:
331 # XML_ref: Reference to variable holding the foxml record to be ingested
332 # logMessage: Optional log message
333 # pid_ref: Reference to scalar to hold resulting pid
334 #
335 # Return:
336 #
337 # 0 = success
338 # 1 = Error
339 # 2 = Error on remote server
340 #
341 0 ▶sub ingest {
Subroutine ingest: not called CC=18 SCAR=58.3
Pod documented
342 0 my $self = shift;
343 0 my %args = @_;
344  
345 0 $self->{ERROR_MESSAGE}=undef;
346 0 $self->{TIME}=undef;
347  
348 0 ▶ Carp::croak "Parameter 'XML_ref' missing" unless defined($args{XML_ref});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"XML_ref"} 0 0 0
349 0 ▶ Carp::croak "Parameter 'pid_ref' missing" unless defined($args{pid_ref});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"pid_ref"} 0 0 0
350  
351 # Encode FOXML record
352 0 my $foxml_encoded = MIME::Base64::encode_base64(${$args{XML_ref}});
353  
354 # Ingest FOXML record
355 0 my $ingest_result;
356 0 eval {
357 0 my $start=time;
358 $ingest_result = $self->{apim}->ingest(
359 SOAP::Data->value($foxml_encoded)->type('xsd:base64Binary'),
360 "info:fedora/fedora-system:FOXML-1.1", # Format
361 $args{logMessage} # Log message
362 0 );
363 0 my $elapse_time = time - $start;
364 0 $self->{TIME} = $elapse_time;
365 0 $self->{STAT}->{'ingest'}{count}++;
366 0 $self->{STAT}->{'ingest'}{time} += $elapse_time;
367 };
368 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
369 0 $self->{ERROR_MESSAGE}=$self->_handle_exceptions($@);
370 0 return 1;
371 }
372  
373 # New DLF2
374  
375 # We will automatically purge the object and try to recreate the object
376 0 ▶ if ($ingest_result->fault && $self->{replace} &&
Branch: 2 branches
BranchTrueFalseTotal
if ($ingest_result->fault and $self->{'replace'} and $ingest_result->faultstring =~ /already exists in the registry/) { } 0 0 0
elsif ($ingest_result->fault and $self->{'reload'} and $ingest_result->faultstring =~ /already exists in the registry/) { } 0 0 0
Condition0%0/6
$ingest_result->fault and $self->{"replace"} and $ingest_result->faultstring =~ /already exists in the registry/
!ll&&!rl&&r
000
$ingest_result->fault and $self->{"replace"}
!ll&&!rl&&r
000
MC/DC0%0/3
$ingest_result->fault and $self->{"replace"} and $ingest_result->faultstring =~ /already exists in the registry/
$ingest_result->fault $self->{"replace"} $ingest_result->faultstring =~ /already exists in the registry/
Truth table0%0/4
A and B and C
A= $ingest_result->faultB= $self->{"replace"}C= $ingest_result->faultstring =~ /already exists in the registry/
ABCresult
0XX0
10X0
1100
1111
377 $ingest_result->faultstring =~/already exists in the registry/) {
378 0 $ingest_result->faultstring =~/The PID \'([^\']*)\' already/;
379 0 ▶ if ($self->{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 0 0 0
380 0 print "APIM: PID Exists: $1\n";
381 0 print "APIM: Purge Object: $1\n";
382 }
383 0 my $ts;
384 0 ▶ if ($self->purgeObject(pid => $1,
Branch: 1 branch
BranchTrueFalseTotal
if ($self->purgeObject('pid', $1, 'logMessage', 'Purge Object (replace)', 'timestamp_ref', \$ts) == 0) { } 0 0 0
385 logMessage=>"Purge Object (replace)",
386 timestamp_ref =>\$ts) == 0) {
387 0 ▶ if ($self->ingest(XML_ref => $args{XML_ref},
Branch: 1 branch
BranchTrueFalseTotal
if ($self->ingest('XML_ref', $args{'XML_ref'}, 'logMessage', $args{'logMessage'}, 'pid_ref', $args{'pid_ref'}) == 0) { } 0 0 0
388 logMessage=> $args{logMessage},
389 pid_ref => $args{pid_ref}) == 0) {
390 0 ▶ if ($self->{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 0 0 0
391 0 print "APIM: Ingested New Monograph Object(2): $1\n\n";
392 }
393 0 return 0;
394 } else {
395 0 ▶ if ($self->{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 0 0 0
396 print "APIM: Ingest: Object exists: Purge: re-Ingest FAILED: " .
397 0 $self->{ERROR_MESSAGE} . "\n";
398 }
399 }
400 } else {
401 0 ▶ if ($self->{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 0 0 0
402 print "APIM: Ingest: Object exists: Purge FAILED: " .
403 0 $self->{ERROR_MESSAGE} . "\n";
404 }
405 }
406  
407  
408 ▶ } elsif ($ingest_result->fault && $self->{reload} &&
Condition0%0/6
$ingest_result->fault and $self->{"reload"} and $ingest_result->faultstring =~ /already exists in the registry/
!ll&&!rl&&r
000
$ingest_result->fault and $self->{"reload"}
!ll&&!rl&&r
000
MC/DC0%0/3
$ingest_result->fault and $self->{"reload"} and $ingest_result->faultstring =~ /already exists in the registry/
$ingest_result->fault $self->{"reload"} $ingest_result->faultstring =~ /already exists in the registry/
Truth table0%0/4
A and B and C
A= $ingest_result->faultB= $self->{"reload"}C= $ingest_result->faultstring =~ /already exists in the registry/
ABCresult
0XX0
10X0
1100
1111
409 $ingest_result->faultstring =~/already exists in the registry/) {
410 #
411 0 $ingest_result->faultstring =~/The PID \'([^\']*)\' already/;
412 0 ${$args{pid_ref}} = $1;
413 0 ▶ if ($self->{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 0 0 0
414 0 print "APIM: Reload: exists: OKAY\n\n";
415 }
416 0 return 0;
417 }
418  
419 # Handle error from Fedora target
420 0 ▶ if ($ingest_result->fault) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ingest_result->fault) 0 0 0
421 $self->{ERROR_MESSAGE}=
422 0 $ingest_result->faultcode."; ".
423 $ingest_result->faultstring."; ".
424 $ingest_result->faultdetail;
425 0 return 2;
426 }
427  
428 # Handle success
429 0 ${$args{pid_ref}} = $ingest_result->result();
430 0 return 0;
431  
432 }
433  
434 # createObject [NEW] THIS IS NOT A FEDORA APIM REQUEST
435 #
436 # Create a simple Fedora object [empty]
437 #
438 # Args in parameter hash:
439 # XML_ref: Reference to variable holding the foxml record to be
440 # ingested.
441 # XML_file: Reference to foxml path to be munged and ingested
442 # params: Hash reference containing parameters to substitute into
443 # FOXML template. [Use when file
444 # policy_params: Hash reference containing parameters for adding policy
445 # datastream to newly created object. POLICY Datastream
446 # is set according to the arguments you provide.
447 # Datastream label is optional (policy_label).
448 # Client must provide URL that resolves to the
449 # policy (policy_url) or a path to the policy in
450 # the filesystem (policy_path).
451 # logMessage: Optional log message
452 # pid_ref: Reference to scalar to hold resulting pid
453 #
454 # Return:
455 #
456 # 0 = success
457 # 1 = Error
458 # 2 = Error on remote server
459 #
460 0 ▶sub createObject {
Subroutine createObject: not called CC=41 SCAR=74.5
Pod documented
461 0 my $self = shift;
462 0 my %args = @_;
463  
464 0 $self->{ERROR_MESSAGE}=undef;
465 0 $self->{TIME}=undef;
466  
467 # XML_ref object is optional. Will read in default FOXML when missing.
468 0 ▶ if (! defined $args{XML_ref} && ! defined $args{XML_file} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"XML_ref"} or defined $args{"XML_file"}) 0 0 0
Condition0%0/3
defined $args{"XML_ref"} or defined $args{"XML_file"}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $args{"XML_ref"} or defined $args{"XML_file"}
defined $args{"XML_ref"} defined $args{"XML_file"}
Truth table0%0/3
A or B
A= defined $args{"XML_ref"}B= defined $args{"XML_file"}
ABresult
1X1
011
000
469 0 $self->{ERROR_MESSAGE} = "Parameter 'XML_ref' or XML_file missing.";
470 0 return 1;
471 }
472  
473 0 my ($foxml_ref, $foxml_template_file, $pid);
474 0 my (@temp_files) = ();
475  
476 # Use in-line FOXML when defaul FOXML file is not present.
477 0 ▶ if (! $args{XML_ref} && ($args{XML_file} && ! -s $args{XML_file})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $args{"XML_ref"} and ($args{"XML_file"} and not -s $args{"XML_file"})) 0 0 0
Condition0%0/6
not $args{"XML_ref"} and ($args{"XML_file"} and not -s $args{"XML_file"})
!ll&&!rl&&r
000
$args{"XML_file"} and not -s $args{"XML_file"}
!ll&&!rl&&r
000
MC/DC0%0/3
not $args{"XML_ref"} and ($args{"XML_file"} and not -s $args{"XML_file"})
not $args{"XML_ref"} $args{"XML_file"} not -s $args{"XML_file"}
Truth table0%0/4
not(A) and B and not(C)
A= not $args{"XML_ref"}B= $args{"XML_file"}C= not -s $args{"XML_file"}
ABCresult
0XX0
10X0
1100
1111
478 0 $args{XML_ref} = \$default_foxml;
479 }
480  
481 0 ▶ if ($args{XML_ref}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'XML_ref'}) { } 0 0 0
elsif ($args{'XML_file'}) { } 0 0 0
482 0 $foxml_ref = $args{XML_ref};
483 0 my $inputFOXMLfile = POSIX::tmpnam() . 'inputFOXML';
484 0 open my $fh, ">", $inputFOXMLfile;
485 0 binmode $fh, ":utf8";
486 0 ▶ if (defined $fh) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fh) 0 0 0
487 0 print $fh $$foxml_ref;
488 0 $foxml_template_file = $inputFOXMLfile;
489 0 push @temp_files, $inputFOXMLfile;
490 }
491 } elsif ($args{XML_file}) {
492 0 $foxml_template_file = $args{XML_file};
493 } else {
494 0 $foxml_template_file = "./ingesttemplate.xml";
495 }
496  
497 0 ▶ if (! -s $foxml_template_file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-s $foxml_template_file) 0 0 0
498 0 $self->{ERROR_MESSAGE} = "FOXML template file does not exist.";
499 0 return 1;
500 }
501  
502 # Perform template substitutions (when necessary)
503 0 ▶ if ($foxml_template_file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($foxml_template_file) 0 0 0
504  
505 # Manage template operations (Read XML as template, substitute, write out)
506 # Instantiate Template object
507 0 my $template = HTML::Template->new (filename => "$foxml_template_file");
508  
509 0 ▶ if (! defined $template) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $template) 0 0 0
510 0 my $mes = "Failed to instantiate Fedora template.";
511 0 $self->{ERROR_MESSAGE} = "Failed to create FOXML template instance.";
512 0 return 1;
513 }
514  
515 # Create temporary file (to be deleted)
516 0 my $tempFOXMLfile = POSIX::tmpnam() . 'tempFOXML';
517  
518 0 open my $fh, ">", $tempFOXMLfile;
519 0 ▶ if (defined $fh) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fh) { } 0 0 0
520 0 my %params = ();
521  
522 0 ▶ if (defined $args{params}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"params"}) 0 0 0
523 0 %params = %{$args{params}};
524 }
525  
526 0 foreach my $param (keys %params) {
527 0 $template->param($param => $params{$param});
528 }
529  
530 0 print $fh $template->output;
531 0 close $fh;
532 0 push @temp_files, $tempFOXMLfile;
533 } else {
534 # Error creating template file
535 0 $self->{ERROR_MESSAGE} = "Failed to create temp FOXML template file.";
536 0 return 1;
537 }
538 # template written to temp file
539  
540 # Read in FOXML
541 0 open $fh, "<", $tempFOXMLfile;
542 0 binmode $fh, ":utf8";
543  
544 0 ▶ if (defined $fh) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fh) 0 0 0
545 0 my $foxml;
546 0 ▶ while (<$fh>) { $foxml .= $_; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
547 0 close($fh);
548 0 $foxml_ref = \$foxml;
549 }
550 } # end template processing
551  
552 # Proceed if we have successfully created the FOXML
553 0 ▶ if ($foxml_ref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($foxml_ref) { } 0 0 0
554  
555 0 ▶ my $logMessage = $args{logMessage} || "Create New Object";
Condition0%0/2
$args{'logMessage'} || 'Create New Object'
l!l
00
MC/DC0%0/1
$args{'logMessage'} || 'Create New Object'
$args{'logMessage'}
Truth table0%0/2
A
A= $args{'logMessage'}
Aresult
11
00
556  
557 # Now create the object
558 0 ▶ if ($self->ingest(XML_ref => $foxml_ref,
Branch: 1 branch
BranchTrueFalseTotal
if ($self->ingest('XML_ref', $foxml_ref, 'logMessage', "$logMessage", 'pid_ref', \$pid) == 0) { } 0 0 0
559 logMessage => "$logMessage",
560 pid_ref => \$pid) == 0) {
561 0 ▶ if ($self->{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 0 0 0
562 0 print "SUB: Ingested New Monograph Object: $pid\n\n";
563 }
564  
565 # Finished creating new object. Now deal with adding policy
566 # datastream (if specified)
567  
568 # Support setting simple external policy link
569 0 my %policy_params = ();
570  
571 0 my ($path, $url, $label, $cg, $filename);
572 0 $path = "";
573 0 $url = "";
574  
575 # Give arguments to method precidence over instance settings
576 0 ▶ if (defined $args{policy_params}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $args{'policy_params'}) { } 0 0 0
elsif ($self->{'policy_path'} or $self->{'policy_url'}) { } 0 0 0
577 0 %policy_params = %{$args{policy_params}};
578  
579 0 $path = $policy_params{'policy_path'};
580 0 $url = $policy_params{'policy_url'};
581 0 $label = $policy_params{'policy_label'};
582 ▶ } elsif ($self->{'policy_path'} || $self->{'policy_url'}) {
Condition0%0/3
$self->{"policy_path"} or $self->{"policy_url"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"policy_path"} or $self->{"policy_url"}
$self->{"policy_path"} $self->{"policy_url"}
Truth table0%0/3
A or B
A= $self->{"policy_path"}B= $self->{"policy_url"}
ABresult
1X1
011
000
583 0 $path = $self->{'policy_path'};
584 0 $url = $self->{'policy_url'};
585 0 $label = $self->{'policy_label'};
586 }
587  
588 # Can't have both set - return error
589 0 ▶ if ($path && $url) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path and $url) 0 0 0
Condition0%0/3
$path and $url
!ll&&!rl&&r
000
MC/DC0%0/2
$path and $url
$path $url
Truth table0%0/3
A and B
A= $pathB= $url
ABresult
0X0
100
111
590 0 ▶ if ($self->{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 0 0 0
591 0 print "ERROR adding POLICY Datastream FAILED: Set one of \n"
592 . "policy_url or policy_path, not both."
593 . "Object ID: $pid\n";
594 }
595 0 $self->{ERROR_MESSAGE} = "Bad policy arguments. Set only one of ."
596 . "policy_url or policy_path";
597 0 return 1;
598 }
599  
600 # Make sure file exists
601 0 ▶ if ($path && ! -s $path) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path and not -s $path) 0 0 0
Condition0%0/3
$path and not -s $path
!ll&&!rl&&r
000
MC/DC0%0/2
$path and not -s $path
$path not -s $path
Truth table0%0/3
A and not(B)
A= $pathB= not -s $path
ABresult
0X0
100
111
602 0 $self->{ERROR_MESSAGE} = "ERROR: Bad policy path: $path"
603 . " File does not exist.";
604 0 return 1;
605 }
606  
607 # For path we must upload the XACML file first and set url to file ref.
608 # For url (external reference, we are all set)
609 0 ▶ if ($path && -s $path) {
Branch: 2 branches
BranchTrueFalseTotal
if ($path and -s $path) { } 0 0 0
elsif ($url) { } 0 0 0
Condition0%0/3
$path and -s $path
!ll&&!rl&&r
000
MC/DC0%0/2
$path and -s $path
$path -s $path
Truth table0%0/3
A and B
A= $pathB= -s $path
ABresult
0X0
100
111
610 0 $filename = $path;
611 0 ▶ if (! $label) { $label = "Policy Datastream";}
Branch: 1 branch
BranchTrueFalseTotal
unless ($label) 0 0 0
612 0 $cg = 'M';
613 } elsif ($url) {
614 0 ▶ if (! $label) { $label = "External Policy Datastream Reference";}
Branch: 1 branch
BranchTrueFalseTotal
unless ($label) 0 0 0
615 0 $cg = 'E';
616 }
617  
618 # Add policy datastream - this is a new object so we shouldn't need
619 # to worry about existing policy
620 0 ▶ if (defined $url && $url) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $url and $url) 0 0 0
Condition0%0/3
defined $url and $url
!ll&&!rl&&r
000
MC/DC0%0/2
defined $url and $url
defined $url $url
Truth table0%0/3
A and B
A= defined $urlB= $url
ABresult
0X0
100
111
621 0 ▶ if ($self->{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 0 0 0
622 0 print "*** Adding POLICY datastream to object $pid.\n";
623 }
624 0 my $dsID = "POLICY";
625 0 my $altids = '';
626 0 my $v = 'true';
627 0 my $mime = "text/plain";
628 0 my $uri = '';
629 0 my $state = 'A';
630 0 my $msg = "Adding policy to new object.";
631 0 my ($dsid, $ts);
632  
633 0 ▶ if ($self->uploadNewDatastream ( pid => $pid,
Branch: 1 branch
BranchTrueFalseTotal
if ($self->uploadNewDatastream('pid', $pid, 'dsID', $dsID, 'altIDs', $altids, 'dsLabel', $label, 'versionable', $v, 'filename', $filename, 'MIMEType', $mime, 'formatURI', $uri, 'dsLocation', $url, 'controlGroup', $cg, 'dsState', $state, 'logMessage', $msg, 'dsid_ref', \$dsid, 'timestamp_ref', \$ts) == 0) { } 0 0 0
634 dsID => $dsID,
635 altIDs => $altids,
636 dsLabel => $label,
637 versionable => $v,
638 filename => $filename,
639 MIMEType => $mime,
640 formatURI => $uri,
641 dsLocation => $url,
642 controlGroup => $cg,
643 dsState => $state,
644 logMessage => $msg,
645 dsid_ref => \$dsid,
646 timestamp_ref => \$ts, ) == 0) {
647 0 ▶ if ($self->{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 0 0 0
648 0 print "Added POLICY Datastream Reference: $dsid to object: $pid\n";
649 }
650 } else {
651 0 my $error = $self->error();
652 0 ▶ if ($self->{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 0 0 0
653 0 print "Adding POLICY Datastream Reference FAILED: "
654 . "$dsID to object: $pid\n$error\n";
655 }
656 0 $self->{ERROR_MESSAGE} = "Failed to add POLICY datastream. $error";
657 0 return 1;
658 }
659 } # if policy parameters
660  
661 } else {
662 0 ▶ if ($self->{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 0 0 0
663 print "SUB: ERROR: Injesting NEW object FAILED: "
664 . $self->{apim}->error()
665 0 . "\n\n";
666 }
667 $self->{ERROR_MESSAGE} = $self->{ERROR_MESSAGE} .
668 "ERROR: Injesting NEW object FAILED: "
669 0 . $self->{apim}->error();
670  
671 0 return 1;
672 }
673 } else {
674 0 $self->{ERROR_MESSAGE} = "Failed to open FOXML file (internal).";
675 0 return 1;
676 }
677  
678 # Get rid of temporary files
679 0 unlink @temp_files;
680  
681 # Handle success
682 0 ${$args{pid_ref}} = $pid;
683 0 return 0;
684 }
685  
686  
687 # purgeObject
688 #
689 # Args in parameter hash:
690 # pid: PID of object to be purged
691 # logMessage: Optional log message
692 # timestamp_ref: Reference to scalar to hold the timestamp of operation
693 #
694 # Return:
695 #
696 # 0 = success
697 # 1 = Error
698 # 2 = Error on remote server
699 #
700  
701 0 ▶sub purgeObject {
Subroutine purgeObject: not called CC=5 SCAR=34.0
Pod documented
702 0 my $self = shift;
703 0 my %args = @_;
704  
705 0 $self->{ERROR_MESSAGE}=undef;
706 0 $self->{TIME}=undef;
707  
708 0 ▶ Carp::croak "Parameter 'pid' missing" unless defined($args{pid});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"pid"} 0 0 0
709 Carp::croak "Parameter 'timestamp_ref' missing"
710 0 ▶ unless defined($args{timestamp_ref});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"timestamp_ref"} 0 0 0
711  
712 # Set Defaults
713 0 $args{force} = "false"; # To be customizable in future fedora versions
714  
715 #if (!defined($args{force})) {
716 # $args{force} = "false";
717 #}
718  
719 # purge object
720 0 my $purge_result;
721 0 eval {
722 0 my $start=time;
723 $purge_result = $self->{apim}->purgeObject(
724 $args{pid},
725 $args{logMessage},
726 0 SOAP::Data->value($args{force})->type('xsd:boolean'),
727 );
728 0 my $elapse_time = time - $start;
729 0 $self->{TIME} = $elapse_time;
730 0 $self->{STAT}->{'purgeObject'}{count}++;
731 0 $self->{STAT}->{'purgeObject'}{time} += $elapse_time;
732 };
733 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
734 0 $self->{ERROR_MESSAGE}=$self->_handle_exceptions($@);
735 0 return 1;
736 }
737  
738 # Handle error from Fedora target
739 0 ▶ if ($purge_result->fault) {
Branch: 1 branch
BranchTrueFalseTotal
if ($purge_result->fault) 0 0 0
740 $self->{ERROR_MESSAGE}=
741 0 $purge_result->faultcode."; ".
742 $purge_result->faultstring."; ".
743 $purge_result->faultdetail;
744 0 return 2;
745 }
746  
747 # Handle success
748 0 ${$args{timestamp_ref}} = $purge_result->result();
749 0 return 0;
750  
751 }
752  
753  
754 # getNextPID
755 #
756 # Args in parameter hash:
757 # numPids: MNumber of PIDs
758 # pidNamespace: Namespace for PIDs
759 # pidlist_ref: Reference to list to hold resulting pids
760 #
761 # Return:
762 #
763 # 0 = success
764 # 1 = Error
765 # 2 = Error on remote server
766 #
767 0 ▶sub getNextPID {
Subroutine getNextPID: not called CC=7 SCAR=40.3
Pod documented
768 0 my $self = shift;
769 0 my %args = @_;
770  
771 0 $self->{ERROR_MESSAGE}=undef;
772 0 $self->{TIME}=undef;
773  
774 Carp::croak "Parameter 'numPids' missing"
775 0 ▶ unless defined($args{numPids});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"numPids"} 0 0 0
776 Carp::croak "Parameter 'pidNamespace' missing"
777 0 ▶ unless defined($args{pidNamespace});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"pidNamespace"} 0 0 0
778 Carp::croak "Parameter 'pidlist_ref' missing"
779 0 ▶ unless defined($args{pidlist_ref});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"pidlist_ref"} 0 0 0
780  
781 0 my $getnextpid_result;
782 0 eval {
783 0 my $start=time;
784 $getnextpid_result = $self->{apim}->getNextPID(
785 SOAP::Data->value($args{numPids})
786 ->type('xsd:nonNegativeInteger'), # numPids
787 $args{pidNamespace}, # pidNamespace
788 0 );
789 0 my $elapse_time = time - $start;
790 0 $self->{TIME} = $elapse_time;
791 0 $self->{STAT}->{'getNextPID'}{count}++;
792 0 $self->{STAT}->{'getNextPID'}{time} += $elapse_time;
793 };
794 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
795 0 $self->{ERROR_MESSAGE}=$self->_handle_exceptions($@);
796 0 return 1;
797 }
798  
799 # Handle error from Fedora target
800 0 ▶ if ($getnextpid_result->fault) {
Branch: 1 branch
BranchTrueFalseTotal
if ($getnextpid_result->fault) 0 0 0
801 $self->{ERROR_MESSAGE}=
802 0 $getnextpid_result->faultcode."; ".
803 $getnextpid_result->faultstring."; ".
804 $getnextpid_result->faultdetail;
805 0 return 2;
806 }
807  
808 0 my $result_ref = $getnextpid_result->result();
809 0 push @{$args{pidlist_ref}},$result_ref;
810  
811 0 my @pids = $getnextpid_result->paramsout();
812  
813 0 foreach my $p (@pids) {
814 0 push @{$args{pidlist_ref}}, $p;
815 }
816  
817 0 return 0;
818 }
819  
820  
821 # addDatastream
822 #
823 # Args in parameter hash:
824 # pid: PID of the object
825 # dsID: ID of the datastream
826 # altIDs: Alternertive ID's (optional)
827 # dsLabel: Datastream Label
828 # versionable: "true" or "false"
829 # MIMEType: The mimetype of the datastream
830 # formatURI: A URI for the namespace of the record
831 # dsLocation: Location where fedora can retrieve the
832 # content of the datastream
833 # controlGroup: "X", "M", "R", or "E"
834 # dsState: "A", "I" or "D"
835 # checksumType: the checksum algorithm to use in computing
836 # the checksum value
837 # checksum: value of the checksum in hexadecimal string
838 # logMessage: Log message (optional)
839 # dsid_ref: Reference to scalar to hold the resulting datastream id
840 #
841 # Return:
842 #
843 # 0 = success
844 # 1 = Error
845 # 2 = Error on remote server
846 #
847 0 ▶sub addDatastream {
Subroutine addDatastream: not called CC=29 SCAR=67.7
Pod documented
848 0 my $self = shift;
849 0 my %args = @_;
850  
851 0 $self->{ERROR_MESSAGE}=undef;
852 0 $self->{TIME}=undef;
853  
854 0 ▶ Carp::croak "Parameter 'pid' missing" unless defined($args{pid});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"pid"} 0 0 0
855 0 ▶ Carp::croak "Parameter 'dsID' missing" unless defined($args{dsID});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"dsID"} 0 0 0
856 0 ▶ Carp::croak "Parameter 'dsLabel' missing" unless defined($args{dsLabel});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"dsLabel"} 0 0 0
857 0 ▶ Carp::croak "Parameter 'versionable' missing" unless defined($args{versionable});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"versionable"} 0 0 0
858 Carp::croak
859 "Illegal value '".$args{versionable}."' for parameter 'versionable'"
860 0 ▶ unless (($args{versionable} eq "true") || ($args{versionable} eq "false"));
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"versionable"} eq "true" or $args{"versionable"} eq "false" 0 0 0
Condition0%0/3
$args{"versionable"} eq "true" or $args{"versionable"} eq "false"
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"versionable"} eq "true" or $args{"versionable"} eq "false"
$args{"versionable"} eq "true" $args{"versionable"} eq "false"
Truth table0%0/3
A or B
A= $args{"versionable"} eq "true"B= $args{"versionable"} eq "false"
ABresult
1X1
011
000
861 0 ▶ Carp::croak "Parameter 'MIMEType' missing" unless defined($args{MIMEType});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"MIMEType"} 0 0 0
862 0 ▶ Carp::croak "Parameter 'formatURI' missing" unless defined($args{formatURI});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"formatURI"} 0 0 0
863 0 ▶ Carp::croak "Parameter 'dsLocation' missing" unless defined($args{dsLocation});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"dsLocation"} 0 0 0
864 0 ▶ Carp::croak "Parameter 'controlGroup' missing" unless defined($args{controlGroup});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"controlGroup"} 0 0 0
865 Carp::croak
866 "Illegal value '".$args{controlGroup}."' for parameter 'controlGroup'"
867 unless ( ($args{controlGroup} eq "X") ||
868 ($args{controlGroup} eq "M") ||
869 ($args{controlGroup} eq "R") ||
870 0 ▶ ($args{controlGroup} eq "E") );
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"controlGroup"} eq "X" or $args{"controlGroup"} eq "M" or $args{"controlGroup"} eq "R" or $args{"controlGroup"} eq "E" 0 0 0
Condition0%0/9
$args{"controlGroup"} eq "X" or $args{"controlGroup"} eq "M" or $args{"controlGroup"} eq "R" or $args{"controlGroup"} eq "E"
l!l&&r!l&&!r
000
$args{"controlGroup"} eq "X" or $args{"controlGroup"} eq "M" or $args{"controlGroup"} eq "R"
l!l&&r!l&&!r
000
$args{"controlGroup"} eq "X" or $args{"controlGroup"} eq "M"
l!l&&r!l&&!r
000
MC/DC0%0/4
$args{"controlGroup"} eq "X" or $args{"controlGroup"} eq "M" or $args{"controlGroup"} eq "R" or $args{"controlGroup"} eq "E"
$args{"controlGroup"} eq "X" $args{"controlGroup"} eq "M" $args{"controlGroup"} eq "R" $args{"controlGroup"} eq "E"
Truth table0%0/5
A or B or C or D
A= $args{"controlGroup"} eq "X"B= $args{"controlGroup"} eq "M"C= $args{"controlGroup"} eq "R"D= $args{"controlGroup"} eq "E"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
871 0 ▶ Carp::croak "Parameter 'dsState' missing" unless defined($args{dsState});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"dsState"} 0 0 0
872 Carp::croak
873 "Illegal value '".$args{dsState}."' for parameter 'dsState'"
874 unless ( ($args{dsState} eq "A") ||
875 ($args{dsState} eq "I") ||
876 0 ▶ ($args{dsState} eq "D") );
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"dsState"} eq "A" or $args{"dsState"} eq "I" or $args{"dsState"} eq "D" 0 0 0
Condition0%0/6
$args{"dsState"} eq "A" or $args{"dsState"} eq "I" or $args{"dsState"} eq "D"
l!l&&r!l&&!r
000
$args{"dsState"} eq "A" or $args{"dsState"} eq "I"
l!l&&r!l&&!r
000
MC/DC0%0/3
$args{"dsState"} eq "A" or $args{"dsState"} eq "I" or $args{"dsState"} eq "D"
$args{"dsState"} eq "A" $args{"dsState"} eq "I" $args{"dsState"} eq "D"
Truth table0%0/4
A or B or C
A= $args{"dsState"} eq "A"B= $args{"dsState"} eq "I"C= $args{"dsState"} eq "D"
ABCresult
1XX1
01X1
0011
0000
877 0 ▶ Carp::croak "Parameter 'dsid_ref' missing" unless defined($args{dsid_ref});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"dsid_ref"} 0 0 0
878  
879 # Set Defaults
880 0 ▶ if (!defined($args{altIDs})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"altIDs"}) 0 0 0
881 0 $args{altIDs} = "";
882 }
883  
884 # Set Defaults
885 0 ▶ if (! defined($args{checksumType})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"checksumType"}) 0 0 0
886 0 $args{checksumType} = undef;
887 }
888  
889 # Set Defaults
890 0 ▶ if (!defined($args{checksum})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"checksum"}) 0 0 0
891 0 $args{checksum} = undef;
892 }
893  
894 # If replace (datastream) is set we TURN OFF versioning
895 # regardless of user specified argument.
896 0 ▶ if ($self->{replace}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"replace"}) 0 0 0
897 0 $args{versionable} = 'false';
898 }
899  
900  
901 # Since many datastreams were added with the versionable flag set to
902 # false we must change this using the setDatastreamVersionable APIM
903 # request to make this active
904 0 my $ts;
905 0 ▶ if ($self->setDatastreamVersionable
Branch: 1 branch
BranchTrueFalseTotal
if ($self->setDatastreamVersionable('pid', $args{'pid'}, 'dsID', $args{'dsID'}, 'versionable', $args{'versionable'}, 'timestamp_ref', \$ts) == 0) { } 0 0 0
906 ( pid => $args{pid},
907 dsID => $args{dsID},
908 versionable => $args{versionable},
909 timestamp_ref => \$ts,
910 ) == 0) {
911  
912 0 ▶ if ($self->{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 0 0 0
913 0 print "Set Datastream Versionable '$args{versionable}' SUCCEEDED: "
914 . "DSID:$args{dsID} TS:$ts for object: $args{pid}\n"; }
915  
916 } else {
917 0 ▶ if ($self->{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 0 0 0
918 0 print "Set Datastream Versionable FAILED: PID:$args{pid} "
919 . "DSID:$args{dsID}" . $self->error() . "\n";
920 }
921 }
922 # Finished setDatastreamVersionable
923  
924 # Add Datastream
925 0 my $ads_result;
926 0 eval {
927 0 my $start=time;
928 $ads_result = $self->{apim}->addDatastream(
929 $args{pid},
930 $args{dsID},
931 $args{altIDs},
932 $args{dsLabel},
933 SOAP::Data->value($args{versionable})->type('xsd:boolean'),
934 $args{MIMEType},
935 $args{formatURI},
936 SOAP::Data->value($args{dsLocation})->type('xsd:string'),
937 $args{controlGroup},
938 $args{dsState},
939 $args{checksumType},
940 $args{checksum},
941 $args{logMessage},
942 0 );
943 0 my $elapse_time = time - $start;
944 0 $self->{TIME} = $elapse_time;
945 0 $self->{STAT}->{'addDatastream'}{count}++;
946 0 $self->{STAT}->{'addDatastream'}{time} += $elapse_time;
947 };
948 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
949 0 $self->{ERROR_MESSAGE}=$self->_handle_exceptions($@);
950 0 return 1;
951 }
952  
953 # Handle error from Fedora target
954 0 ▶ if ($ads_result->fault) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ads_result->fault) 0 0 0
955 $self->{ERROR_MESSAGE}=
956 0 $ads_result->faultcode."; ".
957 $ads_result->faultstring."; ".
958 $ads_result->faultdetail;
959 0 return 2;
960 }
961  
962 # Handle success
963 0 ${$args{dsid_ref}} = $ads_result->result();
964 0 return 0;
965  
966 }
967  
968 # uploadNewDatastream [NEW] THIS IS NOT A FEDORA APIM REQUEST
969 #
970 # This routine combines the upload operation and the add datastream operation
971 # into one single call. This routine also sets reasonable defaults for many
972 # of the parameters to addDatastream.
973 #
974 # Only addition parameter (on top of addDatastream parameters) is the filename.
975 #
976 # Only required parameters are filename, mime type, pid, and ds_id.
977 #
978 # Args in parameter hash: R - Required
979 # pid: PID of the object R
980 # dsID: ID of the datastream R
981 # altIDs: Alternertive ID's (optional) O
982 # dsLabel: Datastream Label O
983 # versionable: "true" or "false" Default: false
984 # filename: Filename to upload and attach to object R
985 # MIMEType: The mimetype of the datastream R
986 # formatURI: A URI for the namespace of the record [internal]
987 # dsLocation: Location where fedora can retrieve the [internal]
988 # content of the datastream
989 # controlGroup: "X", "M", "R", or "E" Default: M
990 # dsState: "A", "I" or "D" Default: A
991 # checksumType: the checksum algorithm to use in computing the checksum
992 # checksum: value of the checksum in hexadecimal string
993 # logMessage: Log message (optional)
994 # dsid_ref: Reference to scalar to hold the resulting datastream id
995 #
996 # Return:
997 #
998 # 0 = success
999 # 1 = Error
1000 # 2 = Error on remote server
1001 #
1002 # Notes:
1003 # This routine has been modified to add external reference datastreams
1004 # as POLICY datastreams to objects. The 'filename' argument
1005 # is no longer 'require' to allow external reference to be passed in the
1006 # argument 'dsLocation'. 'dsLocation' may contain external link of reference
1007 # to uploaded file.
1008 #
1009 0 ▶sub uploadNewDatastream {
Subroutine uploadNewDatastream: not called CC=28 SCAR=67.0
Pod documented
1010 0 my $self = shift;
1011 0 my %args = @_;
1012  
1013 0 $self->{ERROR_MESSAGE}=undef;
1014 0 $self->{TIME}=undef;
1015  
1016 # Check for required arguments
1017 0 ▶ if (! defined $args{filename} && ! defined $args{dsLocation} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"filename"} or defined $args{"dsLocation"}) 0 0 0
Condition0%0/3
defined $args{"filename"} or defined $args{"dsLocation"}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $args{"filename"} or defined $args{"dsLocation"}
defined $args{"filename"} defined $args{"dsLocation"}
Truth table0%0/3
A or B
A= defined $args{"filename"}B= defined $args{"dsLocation"}
ABresult
1X1
011
000
1018 0 $self->{ERROR_MESSAGE} = "Parameter 'filename' or 'dsLocation' missing.";
1019 0 return 1;
1020 }
1021 0 ▶ if (defined $args{filename} && defined $args{dsLocation} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"filename"} and defined $args{"dsLocation"}) 0 0 0
Condition0%0/3
defined $args{"filename"} and defined $args{"dsLocation"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $args{"filename"} and defined $args{"dsLocation"}
defined $args{"filename"} defined $args{"dsLocation"}
Truth table0%0/3
A and B
A= defined $args{"filename"}B= defined $args{"dsLocation"}
ABresult
0X0
100
111
1022 0 $self->{ERROR_MESSAGE} = "Invalid arguments: Specify only ONE of "
1023 ."either 'filename' or 'dsLocation'.";
1024 0 return 1;
1025 }
1026 0 ▶ if (! defined $args{MIMEType}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"MIMEType"}) 0 0 0
1027 0 $self->{ERROR_MESSAGE} = "Parameter 'MIMEType' missing.";
1028 0 return 1;
1029 }
1030 0 ▶ if (! defined $args{pid}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"pid"}) 0 0 0
1031 0 $self->{ERROR_MESSAGE} = "Parameter 'pid' missing.";
1032 0 return 1;
1033 }
1034 0 ▶ if (! defined $args{dsID}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"dsID"}) 0 0 0
1035 0 $self->{ERROR_MESSAGE} = "Parameter 'dsID' missing.";
1036 0 return 1;
1037 }
1038  
1039 # Fill in optional arguments
1040 0 ▶ if (! defined $args{dsLabel}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"dsLabel"}) 0 0 0
1041 0 $args{dsLabel} = '';
1042 }
1043 0 ▶ if (! defined $args{versionable}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"versionable"}) 0 0 0
1044 ## $args{versionable} = "true";
1045 0 $args{versionable} = "true";
1046 }
1047 0 ▶ if (! defined $args{controlGroup}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"controlGroup"}) 0 0 0
1048 0 $args{controlGroup} = "M";
1049 }
1050 0 ▶ if (! defined $args{dsState}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"dsState"}) 0 0 0
1051 0 $args{dsState} = "A";
1052 }
1053 0 ▶ if (! defined $args{checksumType}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"checksumType"}) 0 0 0
1054 0 $args{checksumType} = "SHA-1";
1055 }
1056 0 ▶ if (! defined $args{logMessage}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"logMessage"}) 0 0 0
1057 0 $args{logMessage} = "Add datastream.";
1058 }
1059  
1060 # Do we need to set other arguments to null?
1061  
1062 # Now upload datastream or reference
1063 # Support uploading filename and external reference (URL)
1064 #
1065 0 my ($file_ref, $dsid, $url, $uri);
1066 0 $uri = '';
1067 0 $url = "";
1068  
1069 0 ▶ if ($args{filename} && -s $args{filename}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"filename"} and -s $args{"filename"}) 0 0 0
Condition0%0/3
$args{"filename"} and -s $args{"filename"}
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"filename"} and -s $args{"filename"}
$args{"filename"} -s $args{"filename"}
Truth table0%0/3
A and B
A= $args{"filename"}B= -s $args{"filename"}
ABresult
0X0
100
111
1070 0 ▶ if ($self->uploadFile(
Branch: 1 branch
BranchTrueFalseTotal
if ($self->uploadFile('filename', $args{'filename'}, 'file_ref', \$file_ref) == 0) { } 0 0 0
1071 filename => $args{filename},
1072 file_ref => \$file_ref
1073 ) == 0 ) {
1074 # mesage file_ref
1075 0 $url = $file_ref;
1076 } else {
1077 0 ▶ if ($self->error()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->error) { } 0 0 0
1078 0 print "ERROR: " . $self->error() . "'$file_ref'\n";
1079 } else {
1080 0 print "ERROR: Unknown error uploadFile().\n";
1081 }
1082 }
1083 }
1084  
1085 0 ▶ if ($args{dsLocation}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"dsLocation"}) 0 0 0
1086 # This value is either an external link or a reference to
1087 # a file that has been already uploaded via the uploadFile
1088 # method. These are both valid values for the argument dsLocation.
1089 0 $url = $args{dsLocation};
1090 }
1091  
1092 # Remove trailing spaces
1093 0 $url =~ s/\s+$//;
1094  
1095 0 ▶ if ($url) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url) { } 0 0 0
1096  
1097 # Add datastream to object
1098 0 ▶ if ($self->addDatastream( pid => $args{pid},
Branch: 1 branch
BranchTrueFalseTotal
if ($self->addDatastream('pid', $args{'pid'}, 'dsID', $args{'dsID'}, 'altIDs', $args{'altIDs'}, 'dsLabel', $args{'dsLabel'}, 'versionable', $args{'versionable'}, 'MIMEType', $args{'MIMEType'}, 'formatURI', $uri, 'dsLocation', $url, 'controlGroup', $args{'controlGroup'}, 'dsState', $args{'dsState'}, 'checksumType', $args{'checksumType'}, 'checksum', undef, 'logMessage', $args{'logMessage'}, 'dsid_ref', \$dsid) == 0) { } 0 0 0
1099 dsID => $args{dsID},
1100 altIDs => $args{altIDs},
1101 dsLabel => $args{dsLabel},
1102 versionable => $args{versionable},
1103 MIMEType => $args{MIMEType},
1104 formatURI => $uri,
1105 dsLocation => $url,
1106 controlGroup => $args{controlGroup},
1107 dsState => $args{dsState},
1108 checksumType => $args{checksumType},
1109 checksum => undef,
1110 logMessage => $args{logMessage},
1111 dsid_ref => \$dsid ) == 0) {
1112  
1113 0 ${$args{dsid_ref}} = $dsid;
1114 0 return 0;
1115 } else {
1116 # addDatastream call failed
1117 0 ▶ if ($self->{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 0 0 0
1118 0 print "Error: Adding datastream: $args{dsLabel}:"
1119 . $self->error() . "\n";
1120 }
1121 0 ▶ if ($self->error() =~ /A datastream already exists with/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->error =~ /A datastream already exists with/) 0 0 0
1122 0 ▶ if ($self->{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 0 0 0
1123 0 print "ERROR: Datastream exists: Will use modify datastream "
1124 . "method\n";
1125 }
1126  
1127 # Modify Datastream
1128 0 my $ts;
1129 0 my $force = "true";
1130 0 my $msg = 'DPubS modifyDatastream';
1131 0 ▶ if ($self->modifyDatastreamByReference
Branch: 1 branch
BranchTrueFalseTotal
if ($self->modifyDatastreamByReference('pid', $args{'pid'}, 'dsID', $args{'dsID'}, 'altIDs', $args{'altIDs'}, 'dsLabel', $args{'dsLabel'}, 'MIMEType', $args{'MIMEType'}, 'formatURI', $uri, 'dsLocation', $url, 'checksumType', $args{'checksumType'}, 'checksum', undef, 'logMessage', $args{'logMessage'}, 'force', $force, 'timestamp_ref', \$ts) == 0) { } 0 0 0
1132 ( pid => $args{pid},
1133 dsID => $args{dsID},
1134 altIDs => $args{altIDs},
1135 dsLabel => $args{dsLabel},
1136 MIMEType => $args{MIMEType},
1137 formatURI => $uri,
1138 dsLocation => $url,
1139 checksumType => $args{checksumType},
1140 checksum => undef,
1141 logMessage => $args{logMessage},
1142 force => $force,
1143 timestamp_ref => \$ts) == 0) {
1144  
1145 0 ▶ if ($self->{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 0 0 0
1146 0 print "Successfully modified datastream: $ts.\n";
1147 }
1148  
1149 0 ${$args{timestamp_ref}} = $ts;
1150 0 return 0;
1151 } else {
1152 # An error occurred in trying to modify datastream
1153 0 ▶ $self->{ERROR_MESSAGE} = ($self->{ERROR_MESSAGE} || "")
Condition0%0/2
$self->{'ERROR_MESSAGE'} || ''
l!l
00
MC/DC0%0/1
$self->{'ERROR_MESSAGE'} || ''
$self->{'ERROR_MESSAGE'}
Truth table0%0/2
A
A= $self->{'ERROR_MESSAGE'}
Aresult
11
00
1154 . "Failed to modify datastream.";
1155 0 return 1;
1156 }
1157 } # end datastream exists code
1158  
1159 # Rely on addDatastream to set error string
1160 0 return 1;
1161 }
1162  
1163 } else { # $url was not set properly, failed to upload or specify link
1164 # Failed to upload file
1165 # Rely on uploadFile to set error string.
1166 0 ▶ $self->{ERROR_MESSAGE} = ($self->{ERROR_MESSAGE} || "")
Condition0%0/2
$self->{'ERROR_MESSAGE'} || ''
l!l
00
MC/DC0%0/1
$self->{'ERROR_MESSAGE'} || ''
$self->{'ERROR_MESSAGE'}
Truth table0%0/2
A
A= $self->{'ERROR_MESSAGE'}
Aresult
11
00
1167 . "Failed to upload datastream file.";
1168 0 return 1;
1169 }
1170 }
1171  
1172 # getDatastream
1173 #
1174 # Args in parameter hash:
1175 # pid: PID of the object
1176 # dsID: Datastream PID
1177 # asOfDateTime:
1178 # ds_ref: Reference to scalar to hold the resulting datastream
1179 #
1180 # Return:
1181 #
1182 # 0 = success
1183 # 1 = Error
1184 # 2 = Error on remote server
1185 #
1186 0 ▶sub getDatastream {
Subroutine getDatastream: not called CC=7 SCAR=40.3
Pod documented
1187 0 my $self = shift;
1188 0 my %args = @_;
1189  
1190 0 $self->{ERROR_MESSAGE}=undef;
1191 0 $self->{TIME}=undef;
1192  
1193 0 ▶ Carp::croak "Parameter 'pid' missing" unless defined($args{pid});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"pid"} 0 0 0
1194 0 ▶ Carp::croak "Parameter 'dsID' missing" unless defined($args{dsID});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"dsID"} 0 0 0
1195 0 ▶ Carp::croak "Parameter 'ds_ref' missing" unless defined($args{ds_ref});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"ds_ref"} 0 0 0
1196  
1197 # Set Defaults
1198 0 ▶ if (!defined($args{asOfDateTime})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"asOfDateTime"}) 0 0 0
1199 0 $args{asOfDateTime} = "undef";
1200 }
1201  
1202 # Add Datastream
1203 0 my $gds_result;
1204 0 eval {
1205 0 my $start=time;
1206 $gds_result = $self->{apim}->getDatastream(
1207 $args{pid},
1208 $args{dsID},
1209 # $args{asOfDateTime},
1210 undef,
1211 0 );
1212 0 my $elapse_time = time - $start;
1213 0 $self->{TIME} = $elapse_time;
1214 0 $self->{STAT}->{'getDatastream'}{count}++;
1215 0 $self->{STAT}->{'getDatastream'}{time} += $elapse_time;
1216 };
1217 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1218 0 $self->{ERROR_MESSAGE}=$self->_handle_exceptions($@);
1219 0 return 1;
1220 }
1221  
1222 # Handle error from Fedora target
1223 0 ▶ if ($gds_result->fault) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gds_result->fault) 0 0 0
1224 $self->{ERROR_MESSAGE}=
1225 0 $gds_result->faultcode."; ".
1226 $gds_result->faultstring."; ".
1227 $gds_result->faultdetail;
1228 0 return 2;
1229 }
1230  
1231 # Handle success
1232 0 ${$args{ds_ref}} = $gds_result->result();
1233 0 return 0;
1234  
1235 }
1236  
1237  
1238 # modifyDatastreamByReference
1239 #
1240 # Args in parameter hash:
1241 # pid: PID of the object
1242 # dsID: Datastream PID
1243 # altIDs: Alternertive ID's (optional)
1244 # dsLabel: Datastream Label
1245 # MIMEType: The mimetype of the datastream
1246 # formatURI: A URI for the namespace of the record
1247 # dsLocation: Location where fedora can retrieve the
1248 # content of the datastream
1249 # logMessage: Log message (optional)
1250 # force: "true" or "false"
1251 # timestamp_ref: Reference to scalar to hold timestamp of the operation
1252 #
1253 # Return:
1254 #
1255 # 0 = success
1256 # 1 = Error
1257 # 2 = Error on remote server
1258 #
1259 0 ▶sub modifyDatastreamByReference{
Subroutine modifyDatastreamByReference: not called CC=16 SCAR=56.1
Pod documented
1260 0 my $self = shift;
1261 0 my %args = @_;
1262  
1263 0 $self->{ERROR_MESSAGE}=undef;
1264 0 $self->{TIME}=undef;
1265  
1266 0 ▶ Carp::croak "Parameter 'pid' missing" unless defined($args{pid});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"pid"} 0 0 0
1267 0 ▶ Carp::croak "Parameter 'dsID' missing" unless defined($args{dsID});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"dsID"} 0 0 0
1268 0 ▶ Carp::croak "Parameter 'dsLabel' missing" unless defined($args{dsLabel});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"dsLabel"} 0 0 0
1269 0 ▶ Carp::croak "Parameter 'MIMEType' missing" unless defined($args{MIMEType});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"MIMEType"} 0 0 0
1270 0 ▶ Carp::croak "Parameter 'formatURI' missing" unless defined($args{formatURI});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"formatURI"} 0 0 0
1271 0 ▶ Carp::croak "Parameter 'dsLocation' missing" unless defined($args{dsLocation});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"dsLocation"} 0 0 0
1272 0 ▶ Carp::croak "Parameter 'force' missing" unless defined($args{force});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"force"} 0 0 0
1273 Carp::croak
1274 "Illegal value '".$args{force}."' for parameter 'force'"
1275 0 ▶ unless (($args{force} eq "true") || ($args{force} eq "false"));
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"force"} eq "true" or $args{"force"} eq "false" 0 0 0
Condition0%0/3
$args{"force"} eq "true" or $args{"force"} eq "false"
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"force"} eq "true" or $args{"force"} eq "false"
$args{"force"} eq "true" $args{"force"} eq "false"
Truth table0%0/3
A or B
A= $args{"force"} eq "true"B= $args{"force"} eq "false"
ABresult
1X1
011
000
1276 Carp::croak "Parameter 'timestamp_ref' missing"
1277 0 ▶ unless defined($args{timestamp_ref});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"timestamp_ref"} 0 0 0
1278  
1279 # Set Defaults
1280 0 ▶ if (!defined($args{altIDs})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"altIDs"}) 0 0 0
1281 0 $args{altIDs} = "";
1282 }
1283  
1284 # Set Defaults
1285 0 ▶ if (!defined($args{checksumType})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"checksumType"}) 0 0 0
1286 0 $args{checksumType} = undef;
1287 }
1288  
1289 # Set Defaults
1290 0 ▶ if (!defined($args{checksum})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"checksum"}) 0 0 0
1291 0 $args{checksum} = undef;
1292 }
1293  
1294 # Modify Datastream By Reference
1295 0 my $mdbr_result;
1296 0 eval {
1297 0 my $start=time;
1298 $mdbr_result = $self->{apim}->modifyDatastreamByReference(
1299 $args{pid},
1300 $args{dsID},
1301 $args{altIDs},
1302 $args{dsLabel},
1303 $args{MIMEType},
1304 $args{formatURI},
1305 SOAP::Data->value($args{dsLocation})->type('xsd:string'),
1306 $args{checksumType},
1307 $args{checksum},
1308 $args{logMessage},
1309 0 SOAP::Data->value($args{force})->type('xsd:boolean'),
1310 );
1311 0 my $elapse_time = time - $start;
1312 0 $self->{TIME} = $elapse_time;
1313 0 $self->{STAT}->{'modifyDatastreambyReference'}{count}++;
1314 0 $self->{STAT}->{'modifyDatastreambyReference'}{time} += $elapse_time;
1315 };
1316 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1317 0 $self->{ERROR_MESSAGE}=$self->_handle_exceptions($@);
1318 0 return 1;
1319 }
1320  
1321 # Handle error from Fedora target
1322 0 ▶ if ($mdbr_result->fault) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mdbr_result->fault) 0 0 0
1323 $self->{ERROR_MESSAGE}=
1324 0 $mdbr_result->faultcode."; ".
1325 $mdbr_result->faultstring."; ".
1326 $mdbr_result->faultdetail;
1327 0 return 2;
1328 }
1329  
1330 # Handle success
1331 0 ${$args{timestamp_ref}} = $mdbr_result->result();
1332 0 return 0;
1333  
1334 }
1335  
1336 # setDatastreamVersionable
1337 #
1338 # Args in parameter hash:
1339 # pid: PID of object
1340 # dsID: ID of the datastream
1341 # versionable: "true" or "false" (boolean)
1342 # logMessage: Log message (optional)
1343 #
1344 # Returns:
1345 # timestamp_ref timestamp
1346 #
1347  
1348 0 ▶sub setDatastreamVersionable {
Subroutine setDatastreamVersionable: not called CC=9 SCAR=45.0
Pod documented
1349 0 my $self = shift;
1350 0 my %args = @_;
1351  
1352 0 ▶ Carp::croak "Parameter 'pid' missing" unless defined($args{pid});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"pid"} 0 0 0
1353 0 ▶ Carp::croak "Parameter 'dsID' missing" unless defined($args{dsID});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"dsID"} 0 0 0
1354 Carp::croak "Parameter 'versionable' missing"
1355 0 ▶ unless defined($args{versionable});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"versionable"} 0 0 0
1356 Carp::croak
1357 "Illegal value '".$args{versionable}."' for parameter 'versionable'"
1358 0 ▶ unless (($args{versionable} eq "true") || ($args{versionable} eq "false"));
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"versionable"} eq "true" or $args{"versionable"} eq "false" 0 0 0
Condition0%0/3
$args{"versionable"} eq "true" or $args{"versionable"} eq "false"
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"versionable"} eq "true" or $args{"versionable"} eq "false"
$args{"versionable"} eq "true" $args{"versionable"} eq "false"
Truth table0%0/3
A or B
A= $args{"versionable"} eq "true"B= $args{"versionable"} eq "false"
ABresult
1X1
011
000
1359  
1360 0 ▶ if (! defined $args{logMessage}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"logMessage"}) 0 0 0
1361 0 $args{logMessage} = "Set datastream versionable attribute.";
1362 }
1363  
1364 0 my $setDV_result;
1365 0 eval {
1366 0 my $start=time;
1367 $setDV_result = $self->{apim}->setDatastreamVersionable
1368 (
1369 $args{pid},
1370 $args{dsID},
1371 SOAP::Data->value($args{versionable})->type('xsd:boolean'),
1372 $args{logMessage},
1373 0 );
1374 0 my $elapse_time = time - $start;
1375 0 $self->{TIME} = $elapse_time;
1376 0 $self->{STAT}->{'setDatastreamVersionable'}{count}++;
1377 0 $self->{STAT}->{'setDatastreamVersionable'}{time} += $elapse_time;
1378 };
1379 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1380 0 $self->{ERROR_MESSAGE}=$self->_handle_exceptions($@);
1381 0 return 1;
1382 }
1383  
1384 # Handle error from Fedora target
1385 0 ▶ if ($setDV_result->fault) {
Branch: 1 branch
BranchTrueFalseTotal
if ($setDV_result->fault) 0 0 0
1386 $self->{ERROR_MESSAGE}=
1387 0 $setDV_result->faultcode."; ".
1388 $setDV_result->faultstring."; ".
1389 $setDV_result->faultdetail;
1390 0 return 2;
1391 }
1392  
1393 # Handle success
1394 0 ${$args{timestamp_ref}} = $setDV_result->result();
1395 0 return 0;
1396  
1397 }
1398  
1399 # purgeDatastream
1400 #
1401 # Args in parameter hash:
1402 # pid: PID of object
1403 # dsID: ID of the datastream
1404 # startDT: Starting date-time stamp of the range
1405 # endDT: Ending date-time stamp of the range
1406 # logMessage: Optional log message
1407 # timestamp_ref: Reference to scalar to hold the timestamp of operation
1408 #
1409 # Return:
1410 #
1411 # 0 = success
1412 # 1 = Error
1413 # 2 = Error on remote server
1414 #
1415  
1416 0 ▶sub purgeDatastream{
Subroutine purgeDatastream: not called CC=8 SCAR=42.8
Pod documented
1417 0 my $self = shift;
1418 0 my %args = @_;
1419  
1420 0 $self->{ERROR_MESSAGE}=undef;
1421 0 $self->{TIME}=undef;
1422  
1423 0 ▶ Carp::croak "Parameter 'pid' missing" unless defined($args{pid});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"pid"} 0 0 0
1424 0 ▶ Carp::croak "Parameter 'dsID' missing" unless defined($args{dsID});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"dsID"} 0 0 0
1425 Carp::croak "Parameter 'timestamp_ref' missing"
1426 0 ▶ unless defined($args{timestamp_ref});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"timestamp_ref"} 0 0 0
1427  
1428 # Set Defaults
1429 0 ▶ if (!defined($args{startDT})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"startDT"}) 0 0 0
1430 0 $args{startDT} = "undef";
1431 }
1432  
1433 # Set Defaults
1434 0 ▶ if (!defined($args{endDT})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"endDT"}) 0 0 0
1435 0 $args{endDT} = "undef";
1436 }
1437  
1438 # Set Defaults
1439 0 $args{force} = "false"; # To be customizable in future fedora versions
1440  
1441 # Purge datastream from an object
1442 0 my $purge_result;
1443 0 eval {
1444 0 my $start=time;
1445 $purge_result = $self->{apim}->purgeDatastream(
1446 $args{pid},
1447 $args{dsID},
1448 $args{startDT},
1449 $args{endDT},
1450 $args{logMessage},
1451 0 SOAP::Data->value($args{force})->type('xsd:boolean'),
1452 );
1453 0 my $elapse_time = time - $start;
1454 0 $self->{TIME} = $elapse_time;
1455 0 $self->{STAT}->{'purgeDatastream'}{count}++;
1456 0 $self->{STAT}->{'purgeDatastream'}{time} += $elapse_time;
1457 };
1458 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1459 0 $self->{ERROR_MESSAGE}=$self->_handle_exceptions($@);
1460 0 return 1;
1461 }
1462  
1463 # Handle error from Fedora target
1464 0 ▶ if ($purge_result->fault) {
Branch: 1 branch
BranchTrueFalseTotal
if ($purge_result->fault) 0 0 0
1465 $self->{ERROR_MESSAGE}=
1466 0 $purge_result->faultcode."; ".
1467 $purge_result->faultstring."; ".
1468 $purge_result->faultdetail;
1469 0 return 2;
1470 }
1471  
1472 # Handle success
1473 0 ${$args{timestamp_ref}} = $purge_result->result();
1474 0 return 0;
1475  
1476 }
1477  
1478  
1479 # compareDatastreamChecksum
1480 #
1481 # Args in parameter hash:
1482 # pid: PID of object to check datastream checksum
1483 # dsID: ID of the datastream
1484 # versionDate: A dateTime indicating the version of the datastream to
1485 # verify. If null, Fedora will use the most recent version.
1486 #
1487 # Return:
1488 #
1489 # 0 = success
1490 # 1 = Error
1491 # 2 = Error on remote server
1492 #
1493 0 ▶sub compareDatastreamChecksum {
Subroutine compareDatastreamChecksum: not called CC=7 SCAR=40.3
Pod documented
1494 0 my $self = shift;
1495 0 my %args = @_;
1496  
1497 0 $self->{ERROR_MESSAGE}=undef;
1498 0 $self->{TIME}=undef;
1499  
1500 Carp::croak "Parameter 'pid' missing"
1501 0 ▶ unless defined($args{pid});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"pid"} 0 0 0
1502 Carp::croak "Parameter 'dsID' missing"
1503 0 ▶ unless defined($args{dsID});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"dsID"} 0 0 0
1504 ## Carp::croak "Parameter 'versionDate' missing"
1505 ## unless defined($args{versionDate});
1506  
1507 # Set Defaults
1508 0 ▶ if (!defined($args{versionDate})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"versionDate"}) 0 0 0
1509 0 $args{versionDate} = "undef";
1510 }
1511  
1512 0 my $compareChecksum_result;
1513 0 eval {
1514 0 my $start=time;
1515 $compareChecksum_result = $self->{apim}->compareDatastreamChecksum (
1516 $args{pid},
1517 $args{dsID},
1518 0 $args{versionDate});
1519 0 my $elapse_time = time - $start;
1520 0 $self->{TIME} = $elapse_time;
1521 0 $self->{STAT}->{'getNextPID'}{count}++;
1522 0 $self->{STAT}->{'getNextPID'}{time} += $elapse_time;
1523 };
1524 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1525 0 $self->{ERROR_MESSAGE}=$self->_handle_exceptions($@);
1526 0 return 1;
1527 }
1528  
1529 # Handle error from Fedora target
1530 0 ▶ if ($compareChecksum_result->fault) {
Branch: 1 branch
BranchTrueFalseTotal
if ($compareChecksum_result->fault) 0 0 0
1531 $self->{ERROR_MESSAGE}=
1532 0 $compareChecksum_result->faultcode."; ".
1533 $compareChecksum_result->faultstring."; ".
1534 $compareChecksum_result->faultdetail;
1535 0 return 2;
1536 }
1537  
1538 0 my $result_ref = $compareChecksum_result->result();
1539  
1540 0 ${$args{checksum_result}} = $result_ref;
1541  
1542 0 ▶ if ($result_ref =~ /Checksum validation error/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result_ref =~ /Checksum validation error/) 0 0 0
1543 0 return 3;
1544 }
1545 0 return 0;
1546 }
1547  
1548 # addRelationship
1549 #
1550 # Args in parameter hash:
1551 # pid: PID of the object
1552 # relationship: The predicate
1553 # object: The object.
1554 # isLiteral: A boolean value indicating whether the object is a literal.
1555 # datatype: The datatype of the literal. Optional.
1556 #
1557 # Return:
1558 #
1559 # 0 = success
1560 # 1 = Error
1561 # 2 = Error on remote server
1562 #
1563 0 ▶sub addRelationship {
Subroutine addRelationship: not called CC=15 SCAR=54.8
Pod documented
1564 0 my $self = shift;
1565 0 my %args = @_;
1566  
1567 0 $self->{ERROR_MESSAGE}=undef; $self->{TIME}=undef;
1568  
1569 0 ▶ Carp::croak "Parameter 'pid' missing" unless defined($args{pid});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"pid"} 0 0 0
1570 0 ▶ Carp::croak "Parameter 'relationship' missing" unless defined($args{relationship});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"relationship"} 0 0 0
1571 0 ▶ Carp::croak "Parameter 'object' missing" unless defined($args{object});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"object"} 0 0 0
1572  
1573 0 ▶ if (! defined($args{isLiteral})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"isLiteral"}) 0 0 0
1574 0 $args{isLiteral} = 'false';
1575 }
1576  
1577 0 ▶ if (! defined($args{datatype})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"datatype"}) 0 0 0
1578 0 $args{datatype} = "";
1579 }
1580  
1581 0 my $arel_result;
1582 0 eval {
1583 0 my $start=time;
1584 $arel_result = $self->{apim}->addRelationship(
1585 $args{pid},
1586 $args{relationship},
1587 $args{object},
1588 SOAP::Data->value($args{isLiteral})->type('xsd:boolean'),
1589 $args{datatype},
1590 0 );
1591 0 my $elapse_time = time - $start;
1592 0 $self->{TIME} = $elapse_time;
1593 0 $self->{STAT}->{'addRelation'}{count}++;
1594 0 $self->{STAT}->{'addRelation'}{time} += $elapse_time;
1595 };
1596 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1597 0 $self->{ERROR_MESSAGE}=$self->_handle_exceptions($@);
1598 0 return 1;
1599 }
1600  
1601 # Handle error from Fedora target
1602 0 ▶ if ($arel_result->fault) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arel_result->fault) 0 0 0
1603 $self->{ERROR_MESSAGE}=
1604 0 $arel_result->faultcode."; ".
1605 $arel_result->faultstring."; ".
1606 $arel_result->faultdetail;
1607 0 return 2;
1608 }
1609  
1610 # Handle success
1611 0 ${$args{result}} = $arel_result->result();
1612  
1613 0 ▶ if ( $arel_result->result() eq 'false') {
Branch: 1 branch
BranchTrueFalseTotal
if ($arel_result->result eq "false") 0 0 0
1614 # Assume that the relation exists already. If we are supporting
1615 # reloads then we must deal with this error even if it indicates
1616 # that the relation already exists.
1617 0 ▶ if ($self->{reload}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'reload'}) { } 0 0 0
1618 # Accept that the relation was loaded previously - but we don't
1619 # know this for certain since the context of addRelationship
1620 # returning 'false' is not defined.
1621 0 my $result;
1622 0 ▶ if ($self->purgeRelationship( pid => $args{pid},
Branch: 1 branch
BranchTrueFalseTotal
if ($self->purgeRelationship('pid', $args{'pid'}, 'relationship', $args{'relationship'}, 'object', $args{'object'}, 'isLiteral', $args{'isLiteral'}, 'datatype', $args{'datatype'}, 'result', \$result) == 0) { } 0 0 0
1623 relationship => $args{relationship},
1624 object => $args{object},
1625 isLiteral => $args{isLiteral},
1626 datatype => $args{datatype},
1627 result => \$result,
1628 ) == 0) {
1629 } else {
1630 0 ▶ my $msg = $self->{ERROR_MESSAGE} || "";
Condition0%0/2
$self->{'ERROR_MESSAGE'} || ''
l!l
00
MC/DC0%0/1
$self->{'ERROR_MESSAGE'} || ''
$self->{'ERROR_MESSAGE'}
Truth table0%0/2
A
A= $self->{'ERROR_MESSAGE'}
Aresult
11
00
1631 0 $self->{ERROR_MESSAGE}="purgeRelationship failed:" . $msg;
1632 0 return 2;
1633 }
1634 # Now add the relationship
1635 0 my $arel_result;
1636 0 eval {
1637 0 my $start=time;
1638 $arel_result = $self->{apim}->addRelationship
1639 (
1640 $args{pid},
1641 $args{relationship},
1642 $args{object},
1643 SOAP::Data->value($args{isLiteral})->type('xsd:boolean'),
1644 $args{datatype},
1645 0 );
1646 0 my $elapse_time = time - $start;
1647 0 $self->{TIME} = $elapse_time;
1648 0 $self->{STAT}->{'addRelation'}{count}++;
1649 0 $self->{STAT}->{'addRelation'}{time} += $elapse_time;
1650 };
1651 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1652 0 $self->{ERROR_MESSAGE}=$self->_handle_exceptions($@);
1653 0 return 1;
1654 }
1655 0 ▶ if ($arel_result->result() eq 'false') {
Branch: 1 branch
BranchTrueFalseTotal
if ($arel_result->result eq 'false') { } 0 0 0
1656 0 return 2;
1657 } else {
1658 0 return 0;
1659 }
1660 } else { # AddRelationship failed and Reload flag not set
1661 0 ▶ my $msg = $self->{ERROR_MESSAGE} || "";
Condition0%0/2
$self->{'ERROR_MESSAGE'} || ''
l!l
00
MC/DC0%0/1
$self->{'ERROR_MESSAGE'} || ''
$self->{'ERROR_MESSAGE'}
Truth table0%0/2
A
A= $self->{'ERROR_MESSAGE'}
Aresult
11
00
1662  
1663 0 $self->{ERROR_MESSAGE}="addRelationship failed (may exist already):"
1664 . $msg;
1665 0 return 2;
1666 }
1667 0 return 2;
1668 }
1669  
1670 0 return 0;
1671 }
1672  
1673 # getRelationships [DOES NOT WORK - FEDORA SERVER RETURNS INTERNAL ERROR]
1674 #
1675 # Args in parameter hash:
1676 # pid: PID of the object
1677 # relationship: The predicate
1678 #
1679 # Return:
1680 #
1681 # 0 = success
1682 # 1 = Error
1683 # 2 = Error on remote server
1684 #
1685 0 ▶sub getRelationships {
Subroutine getRelationships: not called CC=5 SCAR=34.0
Pod documented
1686 0 my $self = shift;
1687 0 my %args = @_;
1688  
1689 0 $self->{ERROR_MESSAGE}=undef;
1690 0 $self->{TIME}=undef;
1691  
1692 0 ▶ Carp::croak "Parameter 'pid' missing" unless defined($args{pid});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"pid"} 0 0 0
1693 0 ▶ Carp::croak "Parameter 'relationship' missing" unless defined($args{relationship});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"relationship"} 0 0 0
1694  
1695 0 my $grel_result;
1696 0 eval {
1697 0 my $start=time;
1698 $grel_result = $self->{apim}->getRelationships
1699 (
1700 $args{pid},
1701 0 "$args{relationship}",
1702 );
1703 0 my $elapse_time = time - $start;
1704 0 $self->{TIME} = $elapse_time;
1705 0 $self->{STAT}->{'addRelation'}{count}++;
1706 0 $self->{STAT}->{'addRelation'}{time} += $elapse_time;
1707 };
1708 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1709 0 $self->{ERROR_MESSAGE}=$self->_handle_exceptions($@);
1710 0 return 1;
1711 }
1712  
1713 # Handle error from Fedora target
1714 0 ▶ if ($grel_result->fault) {
Branch: 1 branch
BranchTrueFalseTotal
if ($grel_result->fault) 0 0 0
1715 $self->{ERROR_MESSAGE}=
1716 0 $grel_result->faultcode."; ".
1717 $grel_result->faultstring."; ".
1718 $grel_result->faultdetail;
1719 0 return 2;
1720 }
1721  
1722 # Handle success
1723 0 ${$args{result_ref}} = $grel_result->result();
1724  
1725 0 return 0;
1726 }
1727  
1728 # purgeRelationship
1729 #
1730 # Args in parameter hash:
1731 # pid: PID of the object
1732 # relationship: The predicate, null matches any predicate.
1733 # object: The object, null matches any object.
1734 # isLiteral: A boolean value indicating whether the object is a literal.
1735 # datatype: The datatype of the literal. Optional.
1736 #
1737 # Return:
1738 #
1739 # 0 = success
1740 # 1 = Error
1741 # 2 = Error on remote server
1742 #
1743 0 ▶sub purgeRelationship {
Subroutine purgeRelationship: not called CC=8 SCAR=42.8
Pod documented
1744 0 my $self = shift;
1745 0 my %args = @_;
1746  
1747 0 $self->{ERROR_MESSAGE}=undef;
1748 0 $self->{TIME}=undef;
1749  
1750 0 ▶ Carp::croak "Parameter 'pid' missing" unless defined($args{pid});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"pid"} 0 0 0
1751 0 ▶ Carp::croak "Parameter 'relationship' missing" unless defined($args{relationship});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"relationship"} 0 0 0
1752 0 ▶ Carp::croak "Parameter 'object' missing" unless defined($args{object});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"object"} 0 0 0
1753  
1754 0 ▶ if (! defined($args{isLiteral})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"isLiteral"}) 0 0 0
1755 0 $args{isLiteral} = 'false';
1756 }
1757 0 ▶ if (! defined($args{datatype})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"datatype"}) 0 0 0
1758 0 $args{datatype} = "";
1759 }
1760  
1761  
1762  
1763 0 my $prel_result;
1764 0 eval {
1765 0 my $start=time;
1766 $prel_result = $self->{apim}->purgeRelationship (
1767 $args{pid},
1768 $args{relationship},
1769 $args{object},
1770 SOAP::Data->value($args{isLiteral})->type('xsd:boolean'),
1771 $args{datatype},
1772 0 );
1773 0 my $elapse_time = time - $start;
1774 0 $self->{TIME} = $elapse_time;
1775 0 $self->{STAT}->{'addRelation'}{count}++;
1776 0 $self->{STAT}->{'addRelation'}{time} += $elapse_time;
1777 };
1778 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1779 0 $self->{ERROR_MESSAGE}=$self->_handle_exceptions($@);
1780 0 return 1;
1781 }
1782  
1783 # Handle error from Fedora target
1784 0 ▶ if ($prel_result->fault) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prel_result->fault) 0 0 0
1785 $self->{ERROR_MESSAGE}=
1786 0 $prel_result->faultcode."; ".
1787 $prel_result->faultstring."; ".
1788 $prel_result->faultdetail;
1789 0 return 2;
1790 }
1791  
1792 # Handle success
1793 0 ${$args{result}} = $prel_result->result();
1794 0 return 0;
1795 }
1796  
1797  
1798 # ========================================================================= #
1799 #
1800 # Private Methods
1801 # ========================================================================= #
1802 #
1803 # Private Methods
1804 #
1805 # ========================================================================= #
1806  
1807  
1808  
1809 # Map die exceptions from SOAP::Lite calls to Fedora::APIM error messages
1810 0 ▶sub _handle_exceptions {
Subroutine _handle_exceptions: not called CC=2 SCAR=17.9
1811 0 my ($self, $exception_text) = @_;
1812 0 ▶ if ($exception_text =~ m{^401 Unauthorized}) { return "401 Unauthorized"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($exception_text =~ /^401 Unauthorized/) 0 0 0
1813 0 return $exception_text;
1814 }
1815  
1816 # Method for constructing proxy URL
1817 0 ▶sub _get_proxy {
Subroutine _get_proxy: not called CC=1 SCAR=6.9
1818 0 my ($self) = @_;
1819 return "$self->{'protocol'}://".
1820 $self->{usr}.":".$self->{pwd}.
1821 "\@".$self->{host}.":".$self->{port}.
1822 0 "/fedora/services/management";
1823 }
1824  
1825 # ========================================================================= #
1826 #
1827 # Store ingest FOXML template in case user doesn't have it.
1828 #
1829 # ========================================================================= #
1830  
1831 1 $default_foxml = <<'DEFAULT_FOXML';
1832 <?xml version="1.0" encoding="UTF-8"?>
1833 <foxml:digitalObject VERSION="1.1" PID="<TMPL_VAR NAME="pid_in">" xmlns:foxml="info:fedora/fedora-system:def/foxml#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="info:fedora/fedora-system:def/foxml# http://www.fedora.info/definitions/1/0/foxml1-1.xsd">
1834 <foxml:objectProperties>
1835 <foxml:property NAME="info:fedora/fedora-system:def/model#state" VALUE="Active"/>
1836 <foxml:property NAME="info:fedora/fedora-system:def/model#label" VALUE="<TMPL_VAR NAME="title_in">"/>
1837 <foxml:property NAME="info:fedora/fedora-system:def/model#ownerId" VALUE="fedoraAdmin"/>
1838 <!-- Note: The value for createdDate is assigned dynamically by the Fedora server at ingest time if the createdDate property is not -->
1839 <!-- present in the object being ingested. Therefore, it is recommended that this property be omitted from the object template so this -->
1840 <!-- date will be assigned dynamically by the Fedora server. If included in the template file, this value will be carried through to the -->
1841 <!-- built objects and will result in the specified static date being used at ingest time by the Fedora server rather than dynamically -->
1842 <!-- assigning createdDate at ingest time. The same is true for object components like datastreams and disseminators. The -->
1843 <!-- datastreamVersion and disseminatorVersion elements contain an optional CREATED attribute that defines a createdDate for -->
1844 <!-- these components. If the CREATED attribute is omitted, a createdDate is assinged dynamically at ingest time. If included in the -->
1845 <!-- template object, the specified values will be carried through to all built objects resulting in the specified static dates being used -->
1846 <!-- rather than than the Fedora server assigning component createdDates. -->
1847 <!-- -->
1848 <!-- Uncomment the next line only if you want all objects built with this template to retain the specified creation date after ingest. -->
1849 <!-- <foxml:property NAME="info:fedora/fedora-system:def/model#createdDate" VALUE="2005-03-15T12:57:07.241Z"/> -->
1850 <foxml:property NAME="info:fedora/fedora-system:def/view#lastModifiedDate" VALUE="2005-03-15T12:57:07.702Z"/>
1851 </foxml:objectProperties>
1852 <foxml:datastream CONTROL_GROUP="X" ID="DC" STATE="A" VERSIONABLE="true">
1853 <!-- Note: The value for createdDate is assigned dynamically by the Fedora server at ingest time if the CREATED attribute is not -->
1854 <!-- present on the component in the object being ingested. Therefore, it is recommended that this attribute be omitted from the -->
1855 <!-- object template so this date will be assigned dynamically by the Fedora server. If included in the template file, this value will be -->
1856 <!-- carried through to the built objects and will result in the specified static date being used at ingest time by the Fedora server -->
1857 <!-- rather than dynamically assigning createdDate at ingest time. -->
1858 <!-- -->
1859 <!-- Uncomment the the following line if you want the DC datastream for all abjects built with this template to retain the specified -->
1860 <!-- createdDate after ingest. -->
1861 <!-- <foxml:datastreamVersion CREATED="2005-03-15T12:57:07.241Z" ID="DC.0" LABEL="template: Dublin Core Record for this object" MIMETYPE="text/xml"> -->
1862 <foxml:datastreamVersion FORMAT_URI="http://www.openarchives.org/OAI/2.0/oai_dc/" ID="DC.0" LABEL="template: Dublin Core Record for this object" MIMETYPE="text/xml">
1863 <foxml:xmlContent>
1864 <oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/">
1865 <dc:title><TMPL_VAR NAME="title_in"></dc:title>
1866 <dc:identifier><TMPL_VAR NAME="pid_in"></dc:identifier>
1867 <dc:relation>dpubs</dc:relation>
1868 <dc:relation><TMPL_VAR NAME="collection_in"></dc:relation>
1869 </oai_dc:dc>
1870 </foxml:xmlContent>
1871 </foxml:datastreamVersion>
1872 </foxml:datastream>
1873 <!--
1874 <foxml:datastream CONTROL_GROUP="X" ID="DESC" STATE="A" VERSIONABLE="true">
1875 <foxml:datastreamVersion ID="DESC.0" LABEL="template: UVA descriptive metadata" MIMETYPE="text/xml">
1876 <foxml:xmlContent>
1877 <dummy/>
1878 </foxml:xmlContent>
1879 </foxml:datastreamVersion>
1880 </foxml:datastream>
1881 -->
1882 </foxml:digitalObject>
1883  
1884 DEFAULT_FOXML
1885  
1886 1 1;
1887  
1888 __END__
↑ Summary