Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/api/private/deposit_read.py
Show All 9 Lines | |||||
from contextlib import contextmanager | from contextlib import contextmanager | ||||
from django.http import FileResponse | from django.http import FileResponse | ||||
from rest_framework import status | from rest_framework import status | ||||
from swh.core import tarball | from swh.core import tarball | ||||
from swh.model import identifiers | from swh.model import identifiers | ||||
from swh.deposit.utils import normalize_date | from swh.deposit.utils import normalize_date | ||||
from swh.deposit import utils | |||||
from . import DepositReadMixin | from . import DepositReadMixin | ||||
from ...config import SWH_PERSON, ARCHIVE_TYPE | from ...config import SWH_PERSON, ARCHIVE_TYPE | ||||
from ..common import SWHGetDepositAPI, SWHPrivateAPIView | from ..common import SWHGetDepositAPI, SWHPrivateAPIView | ||||
from ...models import Deposit | from ...models import Deposit | ||||
@contextmanager | @contextmanager | ||||
▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Lines | ADDITIONAL_CONFIG = { | ||||
}) | }) | ||||
} | } | ||||
def __init__(self): | def __init__(self): | ||||
super().__init__() | super().__init__() | ||||
self.provider = self.config['provider'] | self.provider = self.config['provider'] | ||||
self.tool = self.config['tool'] | self.tool = self.config['tool'] | ||||
def _retrieve_url(self, deposit, metadata): | |||||
client_domain = deposit.client.domain | |||||
for field in metadata: | |||||
if 'url' in field: | |||||
if client_domain in metadata[field]: | |||||
return metadata[field] | |||||
def _normalize_dates(self, deposit, metadata): | def _normalize_dates(self, deposit, metadata): | ||||
"""Normalize the date to use as a tuple of author date, committer date | """Normalize the date to use as a tuple of author date, committer date | ||||
from the incoming metadata. | from the incoming metadata. | ||||
Args: | Args: | ||||
deposit (Deposit): Deposit model representation | deposit (Deposit): Deposit model representation | ||||
metadata (Dict): Metadata dict representation | metadata (Dict): Metadata dict representation | ||||
Show All 25 Lines | def metadata_read(self, deposit): | ||||
Args: | Args: | ||||
deposit (Deposit): Deposit concerned by the data aggregation. | deposit (Deposit): Deposit concerned by the data aggregation. | ||||
Returns: | Returns: | ||||
Dictionary of data representing the deposit to inject in swh. | Dictionary of data representing the deposit to inject in swh. | ||||
""" | """ | ||||
data = {} | |||||
metadata = self._metadata_get(deposit) | metadata = self._metadata_get(deposit) | ||||
# create origin_url from metadata only after deposit_check validates it | |||||
origin_url = self._retrieve_url(deposit, metadata) | |||||
# Read information metadata | # Read information metadata | ||||
data['origin'] = { | data = { | ||||
'origin': { | |||||
'type': 'deposit', | 'type': 'deposit', | ||||
'url': origin_url | 'url': utils.origin_url_from(deposit), | ||||
} | |||||
} | } | ||||
# revision | # revision | ||||
fullname = deposit.client.username | fullname = deposit.client.username | ||||
author_committer = SWH_PERSON | author_committer = SWH_PERSON | ||||
# metadata provider | # metadata provider | ||||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |