diff --git a/src/azul/indexer/transform.py b/src/azul/indexer/transform.py index ab648a624e..be8ccf17ef 100644 --- a/src/azul/indexer/transform.py +++ b/src/azul/indexer/transform.py @@ -54,15 +54,18 @@ def entity_type(cls) -> EntityType: """ raise NotImplementedError - @abstractmethod - def _replicate(self, entity: EntityReference) -> tuple[str, JSON]: + def _replica_type(self, entity: EntityReference) -> str: """ - A tuple consisting of: - - 1. The name of the type of replica emitted by this transformer for a - given entity. See :py:attr:`Replica.replica_type`. + The name of the type of replica emitted by this transformer for a given + entity. See :py:attr:`Replica.replica_type`. + """ + return entity.entity_type - 2. The contents of the replica for that entity. + @abstractmethod + def _replica_contents(self, entity: EntityReference) -> JSON: + """ + The contents of the replica emitted by this transformer for a given + entity. """ raise NotImplementedError @@ -136,7 +139,8 @@ def _replica(self, root_hub: EntityID, file_hub: EntityID | None, ) -> Replica: - replica_type, contents = self._replicate(entity) + replica_type = self._replica_type(entity) + contents = self._replica_contents(entity) coordinates = ReplicaCoordinates(content_hash=json_hash(contents).hexdigest(), entity=entity) return Replica(coordinates=coordinates, diff --git a/src/azul/plugins/metadata/anvil/indexer/transform.py b/src/azul/plugins/metadata/anvil/indexer/transform.py index 9acff0a931..5ff292ffaa 100644 --- a/src/azul/plugins/metadata/anvil/indexer/transform.py +++ b/src/azul/plugins/metadata/anvil/indexer/transform.py @@ -192,9 +192,8 @@ def _transform(self, ) -> Iterable[Contribution | Replica]: raise NotImplementedError - def _replicate(self, entity: EntityReference) -> tuple[str, JSON]: - content = ChainMap(self.bundle.entities, self.bundle.orphans)[entity] - return entity.entity_type, content + def _replica_contents(self, entity: EntityReference) -> JSON: + return ChainMap(self.bundle.entities, self.bundle.orphans)[entity] def _convert_entity_type(self, entity_type: str) -> str: assert entity_type == 'bundle' or entity_type.startswith('anvil_'), entity_type @@ -428,9 +427,6 @@ def _activity_polymorphic_types(self) -> AbstractSet[str]: if table['name'].endswith('activity') } - def _is_duos(self, dataset: JSON) -> bool: - return 'duos_id' in dataset - @classmethod def inner_entity_id(cls, entity_type: EntityType, entity: JSON) -> EntityID: return entity['document_id'] @@ -509,8 +505,11 @@ def _duos_types(cls) -> FieldTypes: def _duos(self, dataset: EntityReference) -> MutableJSON: return self._entity(dataset, self._duos_types()) + def _is_duos(self, dataset: EntityReference) -> bool: + return 'duos_id' in self.bundle.entities[dataset] + def _dataset(self, dataset: EntityReference) -> MutableJSON: - if self._is_duos(self.bundle.entities[dataset]): + if self._is_duos(dataset): return self._duos(dataset) else: return super()._dataset(dataset) diff --git a/src/azul/plugins/metadata/hca/indexer/transform.py b/src/azul/plugins/metadata/hca/indexer/transform.py index 9d989d6ea6..e757be97ab 100644 --- a/src/azul/plugins/metadata/hca/indexer/transform.py +++ b/src/azul/plugins/metadata/hca/indexer/transform.py @@ -497,13 +497,12 @@ def aggregator(cls, entity_type: EntityType) -> EntityAggregator | None: agg_cls = SimpleAggregator return agg_cls(entity_type) - def _replicate(self, entity: EntityReference) -> tuple[str, JSON]: + def _replica_contents(self, entity: EntityReference) -> JSON: if entity == self.api_bundle.ref: - content = self.bundle.links + return self.bundle.links else: api_entity = self.api_bundle.entities[UUID(entity.entity_id)] - content = api_entity.json - return entity.entity_type, content + return api_entity.json def _find_ancestor_samples(self, entity: api.LinkedEntity,