Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/api/private/deposit_read.py
Show First 20 Lines • Show All 129 Lines • ▼ Show 20 Lines | def _normalize_dates(self, deposit, metadata): | ||||
author_date = deposit.complete_date | author_date = deposit.complete_date | ||||
commit_date = deposit.complete_date | commit_date = deposit.complete_date | ||||
return (normalize_date(author_date), normalize_date(commit_date)) | return (normalize_date(author_date), normalize_date(commit_date)) | ||||
def metadata_read(self, deposit: Deposit) -> Dict[str, Any]: | def metadata_read(self, deposit: Deposit) -> Dict[str, Any]: | ||||
"""Read and aggregate multiple deposit information into one unified dictionary. | """Read and aggregate multiple deposit information into one unified dictionary. | ||||
Args: | Args: | ||||
deposit: Deposit concerned by the data aggregation. | deposit: Deposit to retrieve information from | ||||
Returns: | Returns: | ||||
Dictionary of deposit information read by the deposit loader, with the | Dictionary of deposit information read by the deposit loader, with the | ||||
following keys: | following keys: | ||||
**origin** (Dict): Information about the origin | **origin** (Dict): Information about the origin | ||||
anlambert: `(as)` should be removed I think | |||||
Done Inline Actionsright ;) ardumont: right ;) | |||||
**origin_metadata (Dict): Metadata about the origin to load | |||||
**metadata_raw** (List[str]): List of raw metadata received for the | **metadata_raw** (List[str]): List of raw metadata received for the | ||||
deposit | deposit | ||||
**metadata_dict** (Dict): Deposit aggregated metadata into one dict | **metadata_dict** (Dict): Deposit aggregated metadata into one dict | ||||
**provider** (Dict): the metadata provider information about the | **provider** (Dict): the metadata provider information about the | ||||
deposit client | deposit client | ||||
**tool** (Dict): the deposit information | **tool** (Dict): the deposit information | ||||
**deposit** (Dict): deposit information relevant to build the revision | **deposit** (Dict): deposit information relevant to build the revision | ||||
(author_date, committer_date, etc...) | (author_date, committer_date, etc...) | ||||
""" | """ | ||||
metadata, raw_metadata = self._metadata_get(deposit) | metadata, raw_metadata = self._metadata_get(deposit) | ||||
# Read information metadata | |||||
data = {"origin": {"type": "deposit", "url": deposit.origin_url,}} | |||||
author_date, commit_date = self._normalize_dates(deposit, metadata) | author_date, commit_date = self._normalize_dates(deposit, metadata) | ||||
if deposit.parent: | if deposit.parent: | ||||
parent_swhid = deposit.parent.swhid | parent_swhid = deposit.parent.swhid | ||||
assert parent_swhid is not None | assert parent_swhid is not None | ||||
swhid = identifiers.parse_swhid(parent_swhid) | swhid = identifiers.parse_swhid(parent_swhid) | ||||
parent_revision = swhid.object_id | parent_revision = swhid.object_id | ||||
parents = [parent_revision] | parents = [parent_revision] | ||||
else: | else: | ||||
parents = [] | parents = [] | ||||
data["origin_metadata"] = { | return { | ||||
# metadata provider | "origin": {"type": "deposit", "url": deposit.origin_url}, | ||||
"provider": { | "provider": { | ||||
"provider_name": deposit.client.last_name, | "provider_name": deposit.client.last_name, | ||||
"provider_url": deposit.client.provider_url, | "provider_url": deposit.client.provider_url, | ||||
"provider_type": MetadataAuthorityType.DEPOSIT_CLIENT.value, | "provider_type": MetadataAuthorityType.DEPOSIT_CLIENT.value, | ||||
"metadata": {}, | "metadata": {}, | ||||
}, | }, | ||||
"tool": self.tool, | "tool": self.tool, | ||||
"metadata_raw": raw_metadata, | "metadata_raw": raw_metadata, | ||||
"metadata_dict": metadata, | "metadata_dict": metadata, | ||||
} | "deposit": { | ||||
data["deposit"] = { | |||||
"id": deposit.id, | "id": deposit.id, | ||||
"client": deposit.client.username, | "client": deposit.client.username, | ||||
"collection": deposit.collection.name, | "collection": deposit.collection.name, | ||||
"author": SWH_PERSON, | "author": SWH_PERSON, | ||||
"author_date": author_date, | "author_date": author_date, | ||||
"committer": SWH_PERSON, | "committer": SWH_PERSON, | ||||
"committer_date": commit_date, | "committer_date": commit_date, | ||||
"revision_parents": parents, | "revision_parents": parents, | ||||
}, | |||||
} | } | ||||
return data | |||||
def process_get( | def process_get( | ||||
self, request, collection_name: str, deposit_id: int | self, request, collection_name: str, deposit_id: int | ||||
) -> Tuple[int, Dict, str]: | ) -> Tuple[int, Dict, str]: | ||||
deposit = Deposit.objects.get(pk=deposit_id) | deposit = Deposit.objects.get(pk=deposit_id) | ||||
data = self.metadata_read(deposit) | data = self.metadata_read(deposit) | ||||
return status.HTTP_200_OK, data if data else {}, "application/json" | return status.HTTP_200_OK, data if data else {}, "application/json" |
(as) should be removed I think