| 1 | package Hetula::Client; | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | 2 | our $VERSION = '0.007'; | |||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||
| 5 | # ABSTRACT: Interface with Hetula | ||||||||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||||||||
| 7 | # Copyright 2018 National Library of Finland | ||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | =encoding utf8 | ||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||
| 13 | Hetula::Client - Perl client implementation to communicate with Hetula. | ||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | Perl client implementation to communicate with Hetula, the Patron data store | ||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||
| 19 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||
| 21 | my $hc = Hetula::Client->new({baseURL => 'https://hetula.example.com'}); | ||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||
| 23 | my $loginResponse = $hc->login({username => 'master', password => 'blaster', organization => 'Administratoria'}); | ||||||||||||||||||||||||||||||||||
| 24 | die($loginResponse->{error}) if ($loginResponse->{error}); | ||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||
| 26 | my $loginActiveResp = $hc->loginActive(); | ||||||||||||||||||||||||||||||||||
| 27 | ok(! $loginActiveResp->{error}, "Login active"); | ||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||
| 29 | my $ssnAddResp = $hc->ssnAdd({ssn => 'bad-ssn'}); | ||||||||||||||||||||||||||||||||||
| 30 | ok($ssnAddResp->{error}, "SSN add failed - Bad SSN '$ssnAddResp->{error}'"); | ||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||
| 32 | my $ssnGetResp = $hc->ssnGet({id => 1}); | ||||||||||||||||||||||||||||||||||
| 33 | ok(! $ssnGetResp->{error}, "SSN got"); | ||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||
| 35 | my $ssnsBatchAddResp = $hc->ssnsBatchAdd(['101010-101A', '101010-102B']); | ||||||||||||||||||||||||||||||||||
| 36 | is(@$ssnsBatchAddResp, 2, "SSNs batch add"); | ||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||
| 38 | =cut | ||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||
| 40 | ##Pragmas | ||||||||||||||||||||||||||||||||||
| 41 | 2 | ▶ | use Modern::Perl; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 42 | 2 | ▶ | use feature qw(signatures); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 43 | 2 | ▶ | no warnings qw(experimental::signatures); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 44 | 2 | ▶ | use Carp::Always; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 45 | 2 | ▶ | use autodie; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 46 | 2 | ▶ | use English; #Use verbose alternatives for perl's strange $0 and $\ etc. | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||
| 48 | ##External modules | ||||||||||||||||||||||||||||||||||
| 49 | 2 | ▶ | use Mojo::UserAgent; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 50 | 2 | ▶ | use Storable; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 51 | 2 | ▶ | use Regexp::Common; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 52 | 2 | ▶ | use Data::Printer; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||
| 54 | =head3 new | ||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||
| 56 | @param1 {HASHRef} baseURL => https://hetula.example.com | ||||||||||||||||||||||||||||||||||
| 57 | credentials => filepath, Where to load the credentials file. | ||||||||||||||||||||||||||||||||||
| 58 | see slurpCredentials() for more info. | ||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||
| 60 | =cut | ||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||
| 62 | ▶ | sub new($class, $params) { | |||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=17.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 63 | 1 | ▶ | slurpCredentials($params->{credentials}, $params) if ($params->{credentials}); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 64 | 1 | _detectKohaEnvironment($params); | |||||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | die("Hetula::Client::BadParam - parameter 'baseURL' is missing") unless $params->{baseURL}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 66 | 1 | ▶ | die("Hetula::Client::BadParam - parameter 'baseURL' '$params->{baseURL}' is not a valid URI") unless $params->{baseURL} =~ /$RE{URI}{HTTP}{-scheme=>qr!https?!}/; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||
| 68 | 1 | my $s = bless(Storable::dclone($params), $class); | |||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||
| 70 | 1 | ▶ | $s->{ua} = Mojo::UserAgent->new() unless $s->{ua}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 71 | 1 | return $s; | |||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||
| 74 | =head2 API Access methods | ||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||
| 76 | =head3 login | ||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||
| 78 | See Hetula API doc for endpoint POST /api/v1/auth | ||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||
| 80 | @param1 {HASHRef} username => String || undef if given via credentials during construction, | ||||||||||||||||||||||||||||||||||
| 81 | password => String || undef if given via credentials during construction, | ||||||||||||||||||||||||||||||||||
| 82 | organization => String || undef if given via credentials during construction, | ||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||
| 84 | =cut | ||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||
| 86 | 1 | ▶ | sub login($s, $params={}) { | ||||||||||||||||||||||||||||||||
|
Subroutine
login: called CC=6 SCAR=26.5
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 87 | 1 | ▶ | $params->{username} = $s->{username} unless $params->{username}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 88 | 1 | ▶ | $params->{password} = $s->{password} unless $params->{password}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 89 | 1 | ▶ | $params->{organization} = $s->{organization} unless $params->{organization}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||
| 91 | 1 | my $tx = $s->ua->post( $s->baseURL().'/api/v1/auth', {Accept => '*/*'}, json => $params ); | |||||||||||||||||||||||||||||||||
| 92 | 1 | my $json = _handleResponse($tx); | |||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | return $json if $json->{error}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||
| 95 | 0 | my $cookies = $tx->res->cookies; | |||||||||||||||||||||||||||||||||
| 96 | 0 | my $sessionCookie = $cookies->[0]; | |||||||||||||||||||||||||||||||||
| 97 | 0 | $s->ua->cookie_jar->add($sessionCookie); | |||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||
| 99 | 0 | my $csrfHeader = $tx->res->headers->header('X-CSRF-Token'); | |||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||
| 101 | $s->ua->on(start => sub { | ||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | my ($ua, $tx) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 103 | 0 | $tx->req->headers->header('X-CSRF-Token' => $csrfHeader); | |||||||||||||||||||||||||||||||||
| 104 | 0 | }); | |||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||
| 106 | 0 | return $json; | |||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||
| 109 | =head3 loginActive | ||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||
| 111 | =cut | ||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||
| 113 | ▶ | sub loginActive($s) { | |||||||||||||||||||||||||||||||||
|
Subroutine
loginActive: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 114 | 0 | my $tx = $s->ua->get( $s->baseURL().'/api/v1/auth' ); | |||||||||||||||||||||||||||||||||
| 115 | 0 | return _handleResponse($tx); | |||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||
| 118 | =head3 ssnAdd | ||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||
| 120 | See Hetula API doc for endpoint POST /api/v1/ssns | ||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||
| 122 | =cut | ||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||
| 124 | ▶ | sub ssnAdd($s, $params) { | |||||||||||||||||||||||||||||||||
|
Subroutine
ssnAdd: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 125 | 0 | my $tx = $s->ua->post( $s->baseURL().'/api/v1/ssns', {Accept => '*/*'}, json => $params ); | |||||||||||||||||||||||||||||||||
| 126 | 0 | return _handleResponse($tx); | |||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||
| 129 | =head3 ssnGet | ||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||
| 131 | See Hetula API doc for endpoint GET /api/v1/users/<id> | ||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||
| 133 | @param1 {HASHRef} id => ssn id to get | ||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||
| 135 | =cut | ||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||
| 137 | ▶ | sub ssnGet($s, $params) { | |||||||||||||||||||||||||||||||||
|
Subroutine
ssnGet: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | die("Hetula::Client::BadParameter - parameter 'id' is not an integer") unless $params->{id} =~ /$RE{num}{int}/; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 139 | 0 | my $tx = $s->ua->get( $s->baseURL().'/api/v1/ssns/'.$params->{id} ); | |||||||||||||||||||||||||||||||||
| 140 | 0 | return _handleResponse($tx); | |||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||
| 143 | =head3 ssnsBatchAdd | ||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||
| 145 | See Hetula API doc for endpoint GET /api/v1/ssns/batch | ||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||
| 147 | @param1 {ARRAYRef} of ssns | ||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||
| 149 | =cut | ||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||
| 151 | ▶ | sub ssnsBatchAdd($s, $ssnArray) { | |||||||||||||||||||||||||||||||||
|
Subroutine
ssnsBatchAdd: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 152 | 0 | my $tx = $s->ua->post( $s->baseURL().'/api/v1/ssns/batch', {Accept => '*/*'}, json => $ssnArray ); | |||||||||||||||||||||||||||||||||
| 153 | 0 | return _handleResponse($tx); | |||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||
| 156 | =head2 ssnsBatchAddChunked | ||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||
| 158 | Invokes the ssnsBatchAdd()-method repeatedly in small chunks. Useful for | ||||||||||||||||||||||||||||||||||
| 159 | importing an inconveniently large amount of ssns that would otherwise timeout | ||||||||||||||||||||||||||||||||||
| 160 | the Hetula-server. | ||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||
| 162 | @param1 {sub} Receives a feeder callback, which sends ssn-lists to the | ||||||||||||||||||||||||||||||||||
| 163 | ssnsBatchAdd()-method. | ||||||||||||||||||||||||||||||||||
| 164 | for ex. | ||||||||||||||||||||||||||||||||||
| 165 | sub { | ||||||||||||||||||||||||||||||||||
| 166 | #Keep sending ssns while there are ssns to send | ||||||||||||||||||||||||||||||||||
| 167 | return ['ssn1','ssn2','ssn3'] if @ssns; | ||||||||||||||||||||||||||||||||||
| 168 | #When ssns run out, return false to signal the end of transmission | ||||||||||||||||||||||||||||||||||
| 169 | return undef || []; | ||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||
| 172 | @param2 {sub} Receives a digester callback, which receives the ssnsBatchAdd()-methods | ||||||||||||||||||||||||||||||||||
| 173 | response|return value. | ||||||||||||||||||||||||||||||||||
| 174 | for ex. | ||||||||||||||||||||||||||||||||||
| 175 | sub { | ||||||||||||||||||||||||||||||||||
| 176 | my ($ssnReportsFromHetula) = @_; | ||||||||||||||||||||||||||||||||||
| 177 | print $FH_OUT "$_->{ssn}->{id},$_->{ssn}->{ssn},$_->{error}\n" for @$ssnReportsFromHetula; | ||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||
| 180 | =cut | ||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||
| 182 | ▶ | sub ssnsBatchAddChunked($s, $feederCallback, $digesterCallback) { | |||||||||||||||||||||||||||||||||
|
Subroutine
ssnsBatchAddChunked: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | while (my $ssns = $feederCallback->()) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | last unless($ssns && @$ssns); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ssns and @$ssns
MC/DC0%0/2
$ssns and @$ssns
$ssns
@$ssns
Truth table0%0/3
A and B
A= $ssnsB= @$ssns
| |||||||||||||||||||||||||||||||||||
| 185 | 0 | $digesterCallback->($s->ssnsBatchAdd($ssns)) | |||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||
| 189 | =head2 ssnsBatchAddFromFile | ||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||
| 191 | Wrapper for ssnsBatchAddChunked(), where this manages the file IO as well. | ||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||
| 193 | @param1 {filepath} Where to read ssns from. | ||||||||||||||||||||||||||||||||||
| 194 | This can be a simple .csv-file, in this case the last (or only) | ||||||||||||||||||||||||||||||||||
| 195 | column is expected to be one containing the ssn that is | ||||||||||||||||||||||||||||||||||
| 196 | intended to be migrated to Hetula. | ||||||||||||||||||||||||||||||||||
| 197 | If there are any extra columns, they are appended to the | ||||||||||||||||||||||||||||||||||
| 198 | ssn report/result .csv-file as ssn report context. | ||||||||||||||||||||||||||||||||||
| 199 | @param2 {filepath} Where to write the ssn migration results/reports | ||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||
| 201 | =cut | ||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | sub ssnsBatchAddFromFile($s, $filenameIn, $filenameOut, $batchSize=500) { | ||||||||||||||||||||||||||||||||
|
Subroutine
ssnsBatchAddFromFile: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | open(my $FH_IN, "<:encoding(UTF-8)", $filenameIn) or die("Hetula::Client::File - Opening the given file '$filenameIn' for reading ssns failed: $!\n"); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | open(my $FH_OUT, ">:encoding(UTF-8)", $filenameOut) or die("Hetula::Client::File - Opening the given file '$filenameOut' for writing ssns results failed: $!\n"); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||
| 207 | 0 | print $FH_OUT "ssnId,ssn,error,context\n"; | |||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||
| 209 | 0 | my $i = 0; #Keep track of how many ssns are processed. | |||||||||||||||||||||||||||||||||
| 210 | 0 | my $retry = 0; | |||||||||||||||||||||||||||||||||
| 211 | 0 | my @ssns; | |||||||||||||||||||||||||||||||||
| 212 | my @context; | ||||||||||||||||||||||||||||||||||
| 213 | my $feeder = sub { #Feeds ssns to the batch grinder | ||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | if ($retry == 0) { #Do not reset the input if retrying | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 215 | 0 | @ssns = (); | |||||||||||||||||||||||||||||||||
| 216 | 0 | @context = (); | |||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | while (<$FH_IN>) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 218 | 0 | $i++; | |||||||||||||||||||||||||||||||||
| 219 | 0 | chomp; | |||||||||||||||||||||||||||||||||
| 220 | 0 | my @cols = split(',', $_); | |||||||||||||||||||||||||||||||||
| 221 | 0 | push(@ssns, pop(@cols)); #The last value is expected to be the ssn | |||||||||||||||||||||||||||||||||
| 222 | 0 | push(@context, \@cols); #always push the context, even if cols is empty. This makes sure the order of contexts is preserved! | |||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | last if @ssns >= $batchSize; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | if (@ssns) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 227 | 0 | print __PACKAGE__."::ssnsBatchAddFromFile() :> '$i' ssns fed.\n"; | |||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||
| 229 | else { | ||||||||||||||||||||||||||||||||||
| 230 | 0 | print __PACKAGE__."::ssnsBatchAddFromFile() :> All '$i' ssns fed.\n"; | |||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||
| 233 | 0 | return \@ssns; | |||||||||||||||||||||||||||||||||
| 234 | 0 | }; | |||||||||||||||||||||||||||||||||
| 235 | my $digester = sub { #digests ssn reports from Hetula | ||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | my ($ssnReports) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | if (ref($ssnReports) ne 'ARRAY') { #There is something wrong! | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 239 | 0 | Data::Printer::p($ssnReports); | |||||||||||||||||||||||||||||||||
| 240 | 0 | $retry++; | |||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | sleep($ENV{MOCK_BAD_CONNECTION}||10); #Wait a bit, maybe the pipi goes away. | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$ENV{'MOCK_BAD_CONNECTION'} || 10
MC/DC0%0/1
$ENV{'MOCK_BAD_CONNECTION'} || 10
$ENV{'MOCK_BAD_CONNECTION'}
Truth table0%0/2
A
A= $ENV{'MOCK_BAD_CONNECTION'}
| |||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | $ENV{MOCK_BAD_CONNECTION_RETRIES} = $retry if $ENV{MOCK_BAD_CONNECTION}; #Awkwardly mix test hooks here, sorry about that. | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | return if $retry <= 3; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 246 | 0 | die("Hetula::Client::Connection - Retried '".($retry-1)."' times, but still cannot succeed. Sorry... Exception from Hetula: ".Data::Printer::np($ssnReports)); | |||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||
| 248 | 0 | $retry = 0; #Presumably we have succeeded in something here. | |||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | for (my $i=0 ; $i<@$ssnReports ; $i++) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 251 | 0 | my $res = $ssnReports->[$i]; | |||||||||||||||||||||||||||||||||
| 252 | 0 | my $ssn = $ssns[$i]; | |||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | die("Hetula::Client::SSN - Local ssns and Hetula ssns are out of sync at batch file row='$i', local ssn='$ssn', Hetula ssn='$res->{ssn}->{ssn}'?") unless ($res->{ssn}->{ssn} eq $ssn); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||
| 256 | print $FH_OUT join(",", $res->{ssn}->{id}//'', $ssn, $res->{error}//'', | ||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | @{$context[$i]} #Add what is left of the given file columns as a context for the ssn report file. This makes it easier for possible next processing steps in the migration pipeline. | ||||||||||||||||||||||||||||||||
|
Condition0%0/4
$res->{"ssn"}{"id"} // ""
$res->{"error"} // ""
MC/DC0%0/1
$res->{"ssn"}{"id"} // ""
$res->{"ssn"}{"id"}
MC/DC0%0/1
$res->{"error"} // ""
$res->{"error"}
Truth table0%0/2
A
A= $res->{"ssn"}{"id"}
Truth table0%0/2
A
A= $res->{"error"}
| |||||||||||||||||||||||||||||||||||
| 258 | )."\n"; | ||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||
| 260 | 0 | print __PACKAGE__."::ssnsBatchAddFromFile() :> '$i' reports digested.\n"; | |||||||||||||||||||||||||||||||||
| 261 | 0 | }; | |||||||||||||||||||||||||||||||||
| 262 | 0 | $s->ssnsBatchAddChunked($feeder, $digester); | |||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||
| 265 | =head3 userAdd | ||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||
| 267 | See Hetula API doc for endpoint POST /api/v1/users | ||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||
| 269 | =cut | ||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||
| 271 | ▶ | sub userAdd($s, $params) { | |||||||||||||||||||||||||||||||||
|
Subroutine
userAdd: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 272 | 0 | my $tx = $s->ua->post( $s->baseURL().'/api/v1/users', {Accept => '*/*'}, json => $params ); | |||||||||||||||||||||||||||||||||
| 273 | 0 | return _handleResponse($tx); | |||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||
| 276 | =head3 userBasicAdd | ||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||
| 278 | Adds a user with only the most minimum permisions needed to push records into Hetula. | ||||||||||||||||||||||||||||||||||
| 279 | Organization the user belongs to is implied from the currently logged in organization. | ||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||
| 281 | @param {HASHRef} username => 'MattiM', | ||||||||||||||||||||||||||||||||||
| 282 | password => 'Secret', | ||||||||||||||||||||||||||||||||||
| 283 | realname => 'Matti Meikäläinen', | ||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||
| 285 | =cut | ||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||
| 287 | ▶ | sub userBasicAdd($s, $params) { | |||||||||||||||||||||||||||||||||
|
Subroutine
userBasicAdd: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 288 | $params->{permissions} = [ | ||||||||||||||||||||||||||||||||||
| 289 | 0 | 'ssns-post', | |||||||||||||||||||||||||||||||||
| 290 | 'auth-get', | ||||||||||||||||||||||||||||||||||
| 291 | ]; | ||||||||||||||||||||||||||||||||||
| 292 | 0 | return $s->userAdd($params); | |||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||
| 295 | =head3 userReadAdd | ||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||
| 297 | Adds a user with read access to Hetula. | ||||||||||||||||||||||||||||||||||
| 298 | Organization the user belongs to is implied from the currently logged in organization. | ||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||
| 300 | @param {HASHRef} username => 'MattiM', | ||||||||||||||||||||||||||||||||||
| 301 | password => 'Secret', | ||||||||||||||||||||||||||||||||||
| 302 | realname => 'Matti Meikäläinen', | ||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||
| 304 | =cut | ||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||
| 306 | ▶ | sub userReadAdd($s, $params) { | |||||||||||||||||||||||||||||||||
|
Subroutine
userReadAdd: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 307 | $params->{permissions} = [ | ||||||||||||||||||||||||||||||||||
| 308 | 0 | 'ssns-post', | |||||||||||||||||||||||||||||||||
| 309 | 'ssns-id-get', | ||||||||||||||||||||||||||||||||||
| 310 | 'auth-get', | ||||||||||||||||||||||||||||||||||
| 311 | ]; | ||||||||||||||||||||||||||||||||||
| 312 | 0 | return $s->userAdd($params); | |||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||
| 315 | =head3 userMod | ||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||
| 317 | See Hetula API doc for endpoint PUT /api/v1/users/<id> | ||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||
| 319 | @param {HASHRef} username or id => mandatory, | ||||||||||||||||||||||||||||||||||
| 320 | other patron attributes => and values, | ||||||||||||||||||||||||||||||||||
| 321 | ... | ||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||
| 323 | =cut | ||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||
| 325 | ▶ | sub userMod($s, $params) { | |||||||||||||||||||||||||||||||||
|
Subroutine
userMod: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | my $id = $params->{id} || $params->{username}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$params->{'id'} || $params->{'username'}
MC/DC0%0/2
$params->{'id'} || $params->{'username'}
$params->{'id'}
$params->{'username'}
Truth table0%0/3
A || B
A= $params->{'id'}B= $params->{'username'}
| |||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | die("Hetula::Client::BadParameter - parameter 'id' or 'username' is missing") unless ($id); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 328 | 0 | my $tx = $s->ua->put( $s->baseURL()."/api/v1/users/$id", {Accept => '*/*'}, json => $params ); | |||||||||||||||||||||||||||||||||
| 329 | 0 | return _handleResponse($tx); | |||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||
| 332 | =head3 userChangePassword | ||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||
| 334 | @param {HASHRef} username or id => mandatory, | ||||||||||||||||||||||||||||||||||
| 335 | password => mandatory - the new password, | ||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||
| 337 | =cut | ||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||
| 339 | ▶ | sub userChangePassword($s, $params) { | |||||||||||||||||||||||||||||||||
|
Subroutine
userChangePassword: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | my $id = $params->{id} || $params->{username}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$params->{'id'} || $params->{'username'}
MC/DC0%0/2
$params->{'id'} || $params->{'username'}
$params->{'id'}
$params->{'username'}
Truth table0%0/3
A || B
A= $params->{'id'}B= $params->{'username'}
| |||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | die("Hetula::Client::BadParameter - parameter 'id' or 'username' is missing") unless ($id); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | die("Hetula::Client::BadParameter - parameter 'password' is missing") unless $params->{password}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 343 | 0 | my $tx = $s->ua->put( $s->baseURL()."/api/v1/users/$id/password", {Accept => '*/*'}, json => $params ); | |||||||||||||||||||||||||||||||||
| 344 | 0 | return _handleResponse($tx); | |||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||
| 347 | =head3 userDisableAccount | ||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||
| 349 | To recover from a disabled account, change the password | ||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||
| 351 | @param {String} username or id | ||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||
| 353 | =cut | ||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||
| 355 | ▶ | sub userDisableAccount($s, $params) { | |||||||||||||||||||||||||||||||||
|
Subroutine
userDisableAccount: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | my $id = $params->{id} || $params->{username}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$params->{'id'} || $params->{'username'}
MC/DC0%0/2
$params->{'id'} || $params->{'username'}
$params->{'id'}
$params->{'username'}
Truth table0%0/3
A || B
A= $params->{'id'}B= $params->{'username'}
| |||||||||||||||||||||||||||||||||||
| 357 | 0 | ▶ | die("Hetula::Client::BadParameter - parameter 'id' or 'username' is missing") unless ($id); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 358 | 0 | my $tx = $s->ua->delete( $s->baseURL()."/api/v1/users/$id/password", {Accept => '*/*'} ); | |||||||||||||||||||||||||||||||||
| 359 | 0 | return _handleResponse($tx); | |||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||
| 362 | =head2 HELPERS | ||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||
| 364 | =head3 slurpCredentials | ||||||||||||||||||||||||||||||||||
| 365 | @static | ||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||
| 367 | Reads the contents of a credentials file. | ||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||
| 369 | The credentials file must consist of up to 4 lines, with each line | ||||||||||||||||||||||||||||||||||
| 370 | specifying the following commandline argument replacements: | ||||||||||||||||||||||||||||||||||
| 371 | username | ||||||||||||||||||||||||||||||||||
| 372 | password | ||||||||||||||||||||||||||||||||||
| 373 | organization | ||||||||||||||||||||||||||||||||||
| 374 | url | ||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||
| 376 | @param1 {String} Path to the credentials file | ||||||||||||||||||||||||||||||||||
| 377 | @param2 {HASHRef} Optional, HASHRef where to inject the found credentials | ||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||
| 379 | =cut | ||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | sub slurpCredentials($credentialsFile, $injectHere=undef) { | ||||||||||||||||||||||||||||||||
|
Subroutine
slurpCredentials: not called CC=15 SCAR=54.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 382 | 0 | ▶ | open(my $FH, '<:encoding(UTF-8)', $credentialsFile) or die("Couldn't read '$credentialsFile': $!"); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | my $username = <$FH>; if ($username) { chomp($username); $injectHere->{username} = $username if $username && $injectHere; } | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$username and $injectHere
MC/DC0%0/2
$username and $injectHere
$username
$injectHere
Truth table0%0/3
A and B
A= $usernameB= $injectHere
| |||||||||||||||||||||||||||||||||||
| 384 | 0 | ▶ | my $password = <$FH>; if ($password) { chomp($password); $injectHere->{password} = $password if $password && $injectHere; } | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$password and $injectHere
MC/DC0%0/2
$password and $injectHere
$password
$injectHere
Truth table0%0/3
A and B
A= $passwordB= $injectHere
| |||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | my $organization = <$FH>; if ($organization) { chomp($organization); $injectHere->{organization} = $organization if $organization && $injectHere; } | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$organization and $injectHere
MC/DC0%0/2
$organization and $injectHere
$organization
$injectHere
Truth table0%0/3
A and B
A= $organizationB= $injectHere
| |||||||||||||||||||||||||||||||||||
| 386 | 0 | ▶ | my $baseURL = <$FH>; if ($baseURL) { chomp($baseURL); $injectHere->{baseURL} = $baseURL if $baseURL && $injectHere; } | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$baseURL and $injectHere
MC/DC0%0/2
$baseURL and $injectHere
$baseURL
$injectHere
Truth table0%0/3
A and B
A= $baseURLB= $injectHere
| |||||||||||||||||||||||||||||||||||
| 387 | 0 | return ($username, $password, $organization, $baseURL); | |||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||
| 390 | =head2 ATTRIBUTES | ||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||
| 392 | =head3 ua | ||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||
| 394 | =cut | ||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||
| 396 | 3 | ▶ | sub ua { return $_[0]->{ua} } | ||||||||||||||||||||||||||||||||
|
Subroutine
ua: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||
| 398 | =head3 baseURL | ||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||
| 400 | =cut | ||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||
| 402 | 1 | ▶ | sub baseURL { return $_[0]->{baseURL} } | ||||||||||||||||||||||||||||||||
|
Subroutine
baseURL: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||
| 404 | ################ | ||||||||||||||||||||||||||||||||||
| 405 | ####################### | ||||||||||||||||||||||||||||||||||
| 406 | ### Private methods ### | ||||||||||||||||||||||||||||||||||
| 407 | #################### | ||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||
| 409 | ▶ | sub _handleResponse($tx) { | |||||||||||||||||||||||||||||||||
|
Subroutine
_handleResponse: called CC=7 SCAR=39.2
| |||||||||||||||||||||||||||||||||||
| 410 | 1 | ▶ | if (my $res = $tx->success) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 411 | 0 | ▶ | if ($ENV{HETULA_DEBUG}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 412 | 0 | print "Request success:\n"; | |||||||||||||||||||||||||||||||||
| 413 | 0 | Data::Printer::p($res->json); | |||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | return $res->json || { OK => $tx->res->code }; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$res->json || {'OK', $tx->res->code}
MC/DC0%0/1
$res->json || {'OK', $tx->res->code}
$res->json
Truth table0%0/2
A
A= $res->json
| |||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||
| 417 | else { | ||||||||||||||||||||||||||||||||||
| 418 | 0 | my $error = $tx->error; | |||||||||||||||||||||||||||||||||
| 419 | 0 | ▶ | $error->{error} = $tx->res->body || $error->{message} || $error->{code}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
$tx->res->body || $error->{'message'} || $error->{'code'}
$tx->res->body or $error->{"message"}
MC/DC0%0/3
$tx->res->body || $error->{'message'} || $error->{'code'}
$tx->res->body
$error->{"message"}
$error->{'code'}
Truth table0%0/4
A or B || C
A= $tx->res->bodyB= $error->{"message"}C= $error->{'code'}
| |||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | if ($ENV{HETULA_DEBUG}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 421 | 0 | print "Request error:\n"; | |||||||||||||||||||||||||||||||||
| 422 | 0 | Data::Printer::p($error); | |||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||
| 424 | 0 | return $error; | |||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||
| 428 | ## @static | ||||||||||||||||||||||||||||||||||
| 429 | ## If you are using https://koha-community.org/ | ||||||||||||||||||||||||||||||||||
| 430 | ## Hetula::Client tries to pick configurations from there automatically. | ||||||||||||||||||||||||||||||||||
| 431 | ## | ||||||||||||||||||||||||||||||||||
| 432 | ▶ | sub _detectKohaEnvironment($params) { | |||||||||||||||||||||||||||||||||
|
Subroutine
_detectKohaEnvironment: called CC=8 SCAR=39.1
| |||||||||||||||||||||||||||||||||||
| 433 | 1 | ▶ | eval "use C4::Context;"; #This way the Dist::Zilla ::Plugin::AutoPrereqs doesn't think this is a mandatory requirement | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||
| 434 | 1 | ▶ | unless ($@) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 435 | 0 | print "Koha detected. "; | |||||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | if (my $hetulaConfig = C4::Context->config('hetula')) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 437 | 0 | ▶ | if (my $url = $hetulaConfig->{url}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 438 | 0 | ▶ | $params->{baseURL} = $url unless $params->{baseURL}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 439 | 0 | print "Hetula baseURL found '$url'. "; | |||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||
| 441 | else { | ||||||||||||||||||||||||||||||||||
| 442 | 0 | ▶ | die "KOHA_CONF: hetula->url is missing!" unless $url; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||
| 445 | 0 | ▶ | if (my $org = $hetulaConfig->{organization}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | $params->{organization} = $org unless $params->{organization}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 447 | 0 | print "Hetula organization found '$org'.\n"; | |||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||
| 449 | else { | ||||||||||||||||||||||||||||||||||
| 450 | 0 | die "KOHA_CONF: hetula->organization is missing!"; | |||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||
| 453 | else { | ||||||||||||||||||||||||||||||||||
| 454 | 0 | die("Koha detected, but 'hetula' is not configured in the \$KOHA_CONF='$ENV{KOHA_CONF}'"); | |||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||
| 456 | }; | ||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||
| 459 | 2 | 1; | |||||||||||||||||||||||||||||||||