def link_entities(self, entity_map: EntityMap, submission: Submission): progress = 0 for entity in entity_map.get_entities(): for link in entity.direct_links: to_entity = entity_map.get_entity(link['entity'], link['id']) try: self.link_entity(entity, to_entity, relationship=link['relationship'], is_collection=link.get('is_collection', True)) progress = progress + 1 expected_links = int(submission.manifest.get('expectedLinks', 0)) if progress % self.PROGRESS_CTR == 0 or (progress == expected_links): manifest_url = self.ingest_api.get_link_from_resource(submission.manifest, 'self') self.ingest_api.patch(manifest_url, {'actualLinks': progress}) self.logger.info(f"links progress: {progress}/ {submission.manifest.get('expectedLinks')}") except Exception as link_error: error_message = f'''The {entity.type} with id {entity.id} could not be linked to {to_entity.type} \ with id {to_entity.id}.''' self.logger.error(error_message) self.logger.error(f'{str(link_error)}') raise
def update_entities(self, entity_map: EntityMap): updated_entities = [self.update_entity(e) for e in entity_map.get_entities() if e.is_reference] return updated_entities