Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/api/common.py
Show All 21 Lines | from ..config import ( | ||||
ARCHIVE_KEY, METADATA_KEY, RAW_METADATA_KEY, STATE_IRI, | ARCHIVE_KEY, METADATA_KEY, RAW_METADATA_KEY, STATE_IRI, | ||||
DEPOSIT_STATUS_DEPOSITED, DEPOSIT_STATUS_PARTIAL, | DEPOSIT_STATUS_DEPOSITED, DEPOSIT_STATUS_PARTIAL, | ||||
DEPOSIT_STATUS_LOAD_SUCCESS, ARCHIVE_TYPE, METADATA_TYPE | DEPOSIT_STATUS_LOAD_SUCCESS, ARCHIVE_TYPE, METADATA_TYPE | ||||
) | ) | ||||
from ..errors import ( | from ..errors import ( | ||||
MAX_UPLOAD_SIZE_EXCEEDED, BAD_REQUEST, ERROR_CONTENT, | MAX_UPLOAD_SIZE_EXCEEDED, BAD_REQUEST, ERROR_CONTENT, | ||||
CHECKSUM_MISMATCH, make_error_dict, MEDIATION_NOT_ALLOWED, | CHECKSUM_MISMATCH, make_error_dict, MEDIATION_NOT_ALLOWED, | ||||
make_error_response_from_dict, FORBIDDEN, | make_error_response_from_dict, FORBIDDEN, | ||||
NOT_FOUND, make_error_response, METHOD_NOT_ALLOWED | NOT_FOUND, make_error_response, METHOD_NOT_ALLOWED, | ||||
ParserError, PARSING_ERROR | |||||
) | ) | ||||
from ..models import ( | from ..models import ( | ||||
Deposit, DepositRequest, DepositCollection, | Deposit, DepositRequest, DepositCollection, | ||||
DepositClient | DepositClient | ||||
) | ) | ||||
from ..parsers import parse_xml | from ..parsers import parse_xml | ||||
▲ Show 20 Lines • Show All 458 Lines • ▼ Show 20 Lines | def _multipart_upload(self, req, headers, collection_name, | ||||
precondition_status_response = self._check_preconditions_on( | precondition_status_response = self._check_preconditions_on( | ||||
filehandler, | filehandler, | ||||
headers['content-md5sum']) | headers['content-md5sum']) | ||||
if precondition_status_response: | if precondition_status_response: | ||||
return precondition_status_response | return precondition_status_response | ||||
try: | |||||
raw_metadata, metadata = self._read_metadata( | raw_metadata, metadata = self._read_metadata( | ||||
data['application/atom+xml']) | data['application/atom+xml']) | ||||
except ParserError: | |||||
return make_error_dict( | |||||
PARSING_ERROR, | |||||
'Malformed xml metadata', | |||||
"The xml received is malformed. " | |||||
"Please ensure your metadata file is correctly formatted.") | |||||
# actual storage of data | # actual storage of data | ||||
deposit = self._deposit_put(deposit_id=deposit_id, | deposit = self._deposit_put(deposit_id=deposit_id, | ||||
in_progress=headers['in-progress'], | in_progress=headers['in-progress'], | ||||
external_id=external_id) | external_id=external_id) | ||||
deposit_request_data = { | deposit_request_data = { | ||||
ARCHIVE_KEY: filehandler, | ARCHIVE_KEY: filehandler, | ||||
METADATA_KEY: metadata, | METADATA_KEY: metadata, | ||||
Show All 40 Lines | def _atom_entry(self, req, headers, collection_name, | ||||
associated failures, either: | associated failures, either: | ||||
- 400 (bad request) if the request is not providing an external | - 400 (bad request) if the request is not providing an external | ||||
identifier | identifier | ||||
- 400 (bad request) if the request's body is empty | - 400 (bad request) if the request's body is empty | ||||
- 415 (unsupported media type) if a wrong media type is provided | - 415 (unsupported media type) if a wrong media type is provided | ||||
""" | """ | ||||
try: | |||||
raw_metadata, metadata = self._read_metadata(req.data) | raw_metadata, metadata = self._read_metadata(req.data) | ||||
except ParserError: | |||||
return make_error_dict( | |||||
BAD_REQUEST, | |||||
'Malformed xml metadata', | |||||
"The xml received is malformed. " | |||||
"Please ensure your metadata file is correctly formatted.") | |||||
if not metadata: | if not metadata: | ||||
return make_error_dict( | return make_error_dict( | ||||
BAD_REQUEST, | BAD_REQUEST, | ||||
'Empty body request is not supported', | 'Empty body request is not supported', | ||||
'Atom entry deposit is supposed to send for metadata. ' | 'Atom entry deposit is supposed to send for metadata. ' | ||||
'If the body is empty, there is no metadata.') | 'If the body is empty, there is no metadata.') | ||||
external_id = metadata.get('external_identifier', headers['slug']) | external_id = metadata.get('external_identifier', headers['slug']) | ||||
▲ Show 20 Lines • Show All 306 Lines • Show Last 20 Lines |