| 1 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | package DAIA::Response; | ||||||||||||||||||||||||||||
| 4 | #ABSTRACT: DAIA information root element | ||||||||||||||||||||||||||||
| 5 | 11 | our $VERSION = '0.43'; #VERSION | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use base 'DAIA::Object'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use POSIX qw(strftime); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 11 | ▶ | use Carp::Clan; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | our %PROPERTIES = ( | ||||||||||||||||||||||||||||
| 13 | version => { | ||||||||||||||||||||||||||||
| 14 | default => '0.5', | ||||||||||||||||||||||||||||
| 15 | 8 | ▶ | filter => sub { '0.5' } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | }, | ||||||||||||||||||||||||||||
| 17 | timestamp => { | ||||||||||||||||||||||||||||
| 18 | 4 | ▶ | default => sub { strftime("%Y-%m-%dT%H:%M:%SZ", gmtime); }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 8 | ▶ | filter => sub { $_[0] }, # TODO: check format | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | }, | ||||||||||||||||||||||||||||
| 21 | message => $DAIA::Object::COMMON_PROPERTIES{message}, | ||||||||||||||||||||||||||||
| 22 | 11 | institution => { | |||||||||||||||||||||||||||
| 23 | type => 'DAIA::Institution', | ||||||||||||||||||||||||||||
| 24 | }, | ||||||||||||||||||||||||||||
| 25 | document => { | ||||||||||||||||||||||||||||
| 26 | type => 'DAIA::Document', | ||||||||||||||||||||||||||||
| 27 | repeatable => 1 | ||||||||||||||||||||||||||||
| 28 | }, | ||||||||||||||||||||||||||||
| 29 | item => { | ||||||||||||||||||||||||||||
| 30 | type => 'DAIA::Item', | ||||||||||||||||||||||||||||
| 31 | repeatable => 1 | ||||||||||||||||||||||||||||
| 32 | }, | ||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 14 | ▶ | sub item { | ||||||||||||||||||||||||||
|
Subroutine
item: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | 14 | my $self = shift; | |||||||||||||||||||||||||||
| 37 | 14 | ▶ | croak "DAIA response cannot have both, documents and item" if @_ and $self->{document}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ and $self->{"document"}
MC/DC0%0/2
@_ and $self->{"document"}
@_
$self->{"document"}
Truth table66%2/3
A and B
A= @_B= $self->{"document"}
| |||||||||||||||||||||||||||||
| 38 | 14 | $DAIA::Object::AUTOLOAD = 'DAIA::Response::item'; | |||||||||||||||||||||||||||
| 39 | 14 | return $self->AUTOLOAD(@_); | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 16 | ▶ | sub document { | ||||||||||||||||||||||||||
|
Subroutine
document: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | 16 | my $self = shift; | |||||||||||||||||||||||||||
| 44 | 16 | ▶ | croak "DAIA response cannot have both, documents and item" if @_ and $self->{item}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ and $self->{"item"}
MC/DC0%0/2
@_ and $self->{"item"}
@_
$self->{"item"}
Truth table66%2/3
A and B
A= @_B= $self->{"item"}
| |||||||||||||||||||||||||||||
| 45 | 16 | $DAIA::Object::AUTOLOAD = 'DAIA::Response::document'; | |||||||||||||||||||||||||||
| 46 | 16 | return $self->AUTOLOAD(@_); | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 1 | ▶ | sub rdfhash { | ||||||||||||||||||||||||||
|
Subroutine
rdfhash: called CC=14 SCAR=36.9
Pod
documented
| |||||||||||||||||||||||||||||
| 50 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 1 | my $me = { | |||||||||||||||||||||||||||
| 53 | 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' => [{ | ||||||||||||||||||||||||||||
| 54 | type => 'uri', value => 'http://purl.org/ontology/daia/Response' | ||||||||||||||||||||||||||||
| 55 | }] | ||||||||||||||||||||||||||||
| 56 | }; | ||||||||||||||||||||||||||||
| 57 | $me->{'http://purl.org/ontology/daia/timestamp'} = [{ | ||||||||||||||||||||||||||||
| 58 | type => 'literal', value => $self->{timestamp}, | ||||||||||||||||||||||||||||
| 59 | 1 | datatype => 'http://www.w3c.org/2001/XMLSchema#dateTime' | |||||||||||||||||||||||||||
| 60 | }];# if $self->{timestamp}; | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | $me->{'http://purl.org/dc/terms/description'} = [ | ||||||||||||||||||||||||||||
| 63 | 0 | map { $_->rdfhash } @{$self->{message}} | |||||||||||||||||||||||||||
| 64 | 1 | ▶ | ] if $self->{message}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 1 | my $rdf = { $self->rdfuri => $me }; | |||||||||||||||||||||||||||
| 67 | 1 | my $inst = $self->{institution}; | |||||||||||||||||||||||||||
| 68 | 1 | ▶ | my @doc = @{$self->{document}} if $self->{document}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 1 | my @see = grep { defined $_ } $inst, @doc; | |||||||||||||||||||||||||||
| 71 | 1 | foreach my $s (@see) { | |||||||||||||||||||||||||||
| 72 | 1 | my $r = $s->rdfhash; # TODO: pass (institution => $inst->rdfuri) | |||||||||||||||||||||||||||
| 73 | 1 | $rdf->{$_} = $r->{$_} for keys %$r; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | $me->{'http://www.w3.org/2000/01/rdf-schema#seeAlso'} = [ | ||||||||||||||||||||||||||||
| 77 | 1 | ▶ | map { { type => 'uri', value => $_->rdfuri } } @see | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | ] if @see; | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 1 | ▶ | if ($inst) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 0 | foreach my $doc (@doc) { | |||||||||||||||||||||||||||
| 82 | 0 | $rdf->{ $doc->rdfuri }->{'http://purl.org/ontology/daia/collectedBy'} = [{ | |||||||||||||||||||||||||||
| 83 | type => "uri", value => $inst->rdfuri | ||||||||||||||||||||||||||||
| 84 | }]; | ||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | # TODO: add connections | ||||||||||||||||||||||||||||
| 89 | # department <- subOrgOf / parOf institution | ||||||||||||||||||||||||||||
| 90 | # service <- providedBy institution | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | # # item <- heldBy | ||||||||||||||||||||||||||||
| 93 | # TODO: if no inst given, try to use department instead | ||||||||||||||||||||||||||||
| 94 | 1 | ▶ | if ($self->document and $self->institution) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->document and $self->institution
MC/DC0%0/2
$self->document and $self->institution
$self->document
$self->institution
Truth table33%1/3
A and B
A= $self->documentB= $self->institution
| |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | my @items = map { $_->item ? @{$_->{item}} : () } @{$self->{document}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 0 | my $by = $self->{institution}->rdfuri; | |||||||||||||||||||||||||||
| 97 | 0 | ▶ | $by = { value => $by, type => ($by =~ /^_:/) ? 'bnode' : 'uri' }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 0 | foreach my $item (@items) { | |||||||||||||||||||||||||||
| 99 | 0 | ▶ | $rdf->{ $item->rdfuri }->{'http://purl.org/ontology/daia/heldBy'} ||= [$by]; | ||||||||||||||||||||||||||
|
Condition0%0/2
$$rdf{$item->rdfuri}{"http://purl.org/ontology/daia/heldBy"} ||= [$by]
MC/DC0%0/1
$$rdf{$item->rdfuri}{"http://purl.org/ontology/daia/heldBy"} ||= [$by]
$$rdf{$item->rdfuri}{"http://purl.org/ontology/daia/heldBy"}
Truth table0%0/2
A
A= $$rdf{$item->rdfuri}{"http://purl.org/ontology/daia/heldBy"}
| |||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | # delete $rdf->{ $self->rdfuri }; | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 1 | return $rdf; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | sub check_valid_id { | ||||||||||||||||||||||||||
|
Subroutine
check_valid_id: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 109 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 110 | 0 | my $id = shift; # TODO: take from CGI object, if not given | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | ▶ | if ( ! defined $id ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 113 | 0 | $self->addMessage( "en" => "please provide a document id!", errno => 1 ); | |||||||||||||||||||||||||||
| 114 | } elsif ( ! DAIA::is_uri( $id ) ) { | ||||||||||||||||||||||||||||
| 115 | 0 | $id = " $id"; | |||||||||||||||||||||||||||
| 116 | 0 | ▶ | $id = (substr($id,0,32) . '...') if (length($id) > 32); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 0 | $self->addMessage( "en" => "document id$id is no valid URI!", errno => 2 ); | |||||||||||||||||||||||||||
| 118 | } else { | ||||||||||||||||||||||||||||
| 119 | 0 | return $id; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | return undef; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 11 | 1; | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | __END__ | ||||||||||||||||||||||||||||