|
Lines 138-144
sub add {
Link Here
|
| 138 |
my $c = shift->openapi->valid_input or return; |
138 |
my $c = shift->openapi->valid_input or return; |
| 139 |
|
139 |
|
| 140 |
try { |
140 |
try { |
| 141 |
my $body = $c->validation->param('Body'); |
141 |
my $headers = $c->req->headers; |
|
|
142 |
my $overrides = $c->stash('koha.overrides'); |
| 142 |
|
143 |
|
| 143 |
my $flavour = |
144 |
my $flavour = |
| 144 |
C4::Context->preference('marcflavour') eq 'UNIMARC' |
145 |
C4::Context->preference('marcflavour') eq 'UNIMARC' |
|
Lines 146-194
sub add {
Link Here
|
| 146 |
: 'MARC21'; |
147 |
: 'MARC21'; |
| 147 |
|
148 |
|
| 148 |
my $record; |
149 |
my $record; |
| 149 |
my $authtypecode; |
|
|
| 150 |
|
150 |
|
| 151 |
if ( $c->req->headers->content_type =~ m/application\/json/ ) { |
151 |
my $authtypecode = $headers->header('x-authority-type'); |
| 152 |
$record = MARC::Record->new_from_xml( $body->{marcxml}, 'UTF-8', $flavour ); |
152 |
my $content_type = $headers->content_type; |
| 153 |
$authtypecode = $body->{authtypecode}; |
153 |
|
|
|
154 |
if ( $content_type =~ m/application\/marcxml\+xml/ ) { |
| 155 |
$record = MARC::Record->new_from_xml( $c->req->body, 'UTF-8', $flavour ); |
| 156 |
} elsif ( $content_type =~ m/application\/marc-in-json/ ) { |
| 157 |
$record = MARC::Record->new_from_mij_structure( $c->req->json ); |
| 158 |
} elsif ( $content_type =~ m/application\/marc/ ) { |
| 159 |
$record = MARC::Record->new_from_usmarc( $c->req->body ); |
| 154 |
} else { |
160 |
} else { |
| 155 |
$authtypecode = $c->validation->param('x-authority-type'); |
161 |
return $c->render( |
| 156 |
if ( $c->req->headers->content_type =~ m/application\/marcxml\+xml/ ) { |
162 |
status => 406, |
| 157 |
$record = MARC::Record->new_from_xml( $body, 'UTF-8', $flavour ); |
163 |
openapi => [ |
| 158 |
} elsif ( $c->req->headers->content_type =~ m/application\/marc-in-json/ ) { |
164 |
"application/marcxml+xml", |
| 159 |
$record = MARC::Record->new_from_mij_structure( $body ); |
165 |
"application/marc-in-json", |
| 160 |
} elsif ( $c->req->headers->content_type =~ m/application\/marc/ ) { |
166 |
"application/marc" |
| 161 |
$record = MARC::Record->new_from_usmarc( $body ); |
167 |
] |
| 162 |
} else { |
168 |
); |
| 163 |
return $c->render( |
|
|
| 164 |
status => 406, |
| 165 |
openapi => [ |
| 166 |
"application/json", |
| 167 |
"application/marcxml+xml", |
| 168 |
"application/marc-in-json", |
| 169 |
"application/marc" |
| 170 |
] |
| 171 |
); |
| 172 |
} |
| 173 |
} |
169 |
} |
| 174 |
|
170 |
|
| 175 |
my ($duplicateauthid,$duplicateauthvalue); |
171 |
unless ( $overrides->{any} || $overrides->{duplicate} ) { |
| 176 |
($duplicateauthid,$duplicateauthvalue) = FindDuplicateAuthority($record,$authtypecode); |
172 |
my ( $duplicateauthid, $duplicateauthvalue ) = FindDuplicateAuthority( $record, $authtypecode ); |
| 177 |
|
|
|
| 178 |
my $confirm_not_duplicate = $c->validation->param('x-confirm-not-duplicate'); |
| 179 |
|
173 |
|
| 180 |
return $c->render( |
174 |
return $c->render( |
| 181 |
status => 400, |
175 |
status => 409, |
| 182 |
openapi => { |
176 |
openapi => { |
| 183 |
error => "Duplicate authority $duplicateauthid" |
177 |
error => "Duplicate record ($duplicateauthid)", |
| 184 |
} |
178 |
error_code => 'duplicate', |
| 185 |
) unless !$duplicateauthid || $confirm_not_duplicate; |
179 |
} |
|
|
180 |
) unless !$duplicateauthid; |
| 181 |
} |
| 186 |
|
182 |
|
| 187 |
my $authid = AddAuthority( $record, undef, $authtypecode ); |
183 |
my $authid = AddAuthority( $record, undef, $authtypecode ); |
| 188 |
|
184 |
|
|
|
185 |
$c->res->headers->location($c->req->url->to_string . '/' . $authid); |
| 189 |
$c->render( |
186 |
$c->render( |
| 190 |
status => 200, |
187 |
status => 201, |
| 191 |
openapi => { id => $authid } |
188 |
openapi => q{}, |
| 192 |
); |
189 |
); |
| 193 |
} |
190 |
} |
| 194 |
catch { |
191 |
catch { |