Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/api/private/deposit_check.py
Show All 13 Lines | |||||
from rest_framework.request import Request | from rest_framework.request import Request | ||||
from swh.scheduler.utils import create_oneshot_task_dict | from swh.scheduler.utils import create_oneshot_task_dict | ||||
from . import APIPrivateView, DepositReadMixin | from . import APIPrivateView, DepositReadMixin | ||||
from ...config import ARCHIVE_TYPE, DEPOSIT_STATUS_REJECTED, DEPOSIT_STATUS_VERIFIED | from ...config import ARCHIVE_TYPE, DEPOSIT_STATUS_REJECTED, DEPOSIT_STATUS_VERIFIED | ||||
from ...models import Deposit, DepositRequest | from ...models import Deposit, DepositRequest | ||||
from ..checks import check_metadata | from ..checks import check_metadata | ||||
from ..common import APIGet | from ..common import APIGet, get_deposit_by_id | ||||
MANDATORY_ARCHIVE_UNREADABLE = ( | MANDATORY_ARCHIVE_UNREADABLE = ( | ||||
"At least one of its associated archives is not readable" # noqa | "At least one of its associated archives is not readable" # noqa | ||||
) | ) | ||||
MANDATORY_ARCHIVE_INVALID = ( | MANDATORY_ARCHIVE_INVALID = ( | ||||
"Mandatory archive is invalid (i.e contains only one archive)" # noqa | "Mandatory archive is invalid (i.e contains only one archive)" # noqa | ||||
) | ) | ||||
MANDATORY_ARCHIVE_UNSUPPORTED = "Mandatory archive type is not supported" | MANDATORY_ARCHIVE_UNSUPPORTED = "Mandatory archive type is not supported" | ||||
▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | ) -> Tuple[int, Dict, str]: | ||||
req: Client request | req: Client request | ||||
collection_name: Collection owning the deposit | collection_name: Collection owning the deposit | ||||
deposit_id: Deposit concerned by the reading | deposit_id: Deposit concerned by the reading | ||||
Returns: | Returns: | ||||
Tuple status, stream of content, content-type | Tuple status, stream of content, content-type | ||||
""" | """ | ||||
deposit = Deposit.objects.get(pk=deposit_id) | deposit = get_deposit_by_id(deposit_id) | ||||
metadata, _ = self._metadata_get(deposit) | metadata, _ = self._metadata_get(deposit) | ||||
problems: Dict = {} | problems: Dict = {} | ||||
# will check each deposit's associated request (both of type | # will check each deposit's associated request (both of type | ||||
# archive and metadata) for errors | # archive and metadata) for errors | ||||
archives_status, error_detail = self._check_deposit_archives(deposit) | archives_status, error_detail = self._check_deposit_archives(deposit) | ||||
if not archives_status: | if not archives_status: | ||||
assert error_detail is not None | assert error_detail is not None | ||||
problems.update(error_detail) | problems.update(error_detail) | ||||
Show All 32 Lines |