def generate_save_context_path_from_manifest_obj(self, man_obj): """ Generates a context path for a manifest object, then saves it to the Subjects """ output = False new_context = True act_context = self.generate_context_path(man_obj.uuid) if act_context is not False: try: sub_obj = Subject.objects.get(uuid=man_obj.uuid) if sub_obj.context == act_context: new_context = False except Subject.DoesNotExist: sub_obj = False if sub_obj is False: sub_obj = Subject() sub_obj.uuid = man_obj.uuid sub_obj.project_uuid = man_obj.project_uuid sub_obj.source_id = man_obj.source_id sub_obj.context = act_context if new_context: try: sub_obj.save() output = sub_obj self.changes += 1 except IntegrityError as e: self.error_uuids[sub_obj.uuid] = { 'context': act_context, 'error': e } else: self.error_uuids[man_obj.uuid] = { 'context': act_context, 'error': 'bad path' } return output
def generate_save_context_path_from_manifest_obj(self, man_obj): """ Generates a context path for a manifest object, then saves it to the Subjects """ output = False new_context = True act_context = self.generate_context_path(man_obj.uuid) if act_context is not False: print('Saving Path (' + str(man_obj.uuid) + '): ' + str(unidecode(act_context))) try: sub_obj = Subject.objects.get(uuid=man_obj.uuid) if sub_obj.context == act_context: new_context = False except Subject.DoesNotExist: sub_obj = False if sub_obj is False: sub_obj = Subject() sub_obj.uuid = man_obj.uuid sub_obj.project_uuid = man_obj.project_uuid sub_obj.source_id = man_obj.source_id sub_obj.context = act_context if new_context: try: sub_obj.save() output = sub_obj self.changes += 1 except IntegrityError as e: self.error_uuids[sub_obj.uuid] = {'context': act_context, 'error': e} else: self.error_uuids[man_obj.uuid] = {'context': act_context, 'error': 'bad path'} return output
def db_create_initial_subject_item(self, act_dir, ent_dict, faims_item_id, item_label): """ reconciles or makes a new subject item (manifest, subject, initial containment assertion) """ if faims_item_id not in self.entities: # a new item, not seen before man_obj = self.check_get_faims_manifest_object(faims_item_id, item_label, ent_dict['item_type'], ent_dict['class_uri']) if man_obj is False: # we did not find it, so make a new one # first, make the supplemental dict object to help associate the faims_item_id # with the manifest object. This makes reconcilation precise. sup_dict = {} sup_dict[self.reconcile_key] = faims_item_id sup_dict['faims_label'] = item_label # now, make sure the item label is unique item_label = self.check_make_manifest_label_unique(item_label, ent_dict['item_type'], ent_dict['class_uri']) # make the intial context, based on the root context's path context = self.root_subject_context + '/' + item_label uuid = GenUUID.uuid4() uuid = str(uuid) new_sub = Subject() new_sub.uuid = uuid new_sub.project_uuid = self.project_uuid new_sub.source_id = self.source_id new_sub.context = context new_sub.save() man_obj = Manifest() man_obj.uuid = uuid man_obj.project_uuid = self.project_uuid man_obj.source_id = self.source_id man_obj.item_type = 'subjects' man_obj.repo = '' man_obj.class_uri = ent_dict['class_uri'] man_obj.label = item_label man_obj.des_predicate_uuid = '' man_obj.views = 0 man_obj.sup_json = sup_dict man_obj.save() # now add the initial containment relationship self.add_change_containment_assertion(self.root_subject_uuid, man_obj.uuid) # now save the open context uuid for the entity in the entities dict self.entities[faims_item_id] = LastUpdatedOrderedDict() self.entities[faims_item_id]['uuid'] = man_obj.uuid self.entities[faims_item_id]['item_type'] = man_obj.item_type self.fm.save_serialized_json(self.oc_config_entities, act_dir, self.entities)
def db_create_initial_subject_item(self, act_dir, ent_dict, faims_item_id, item_label): """ reconciles or makes a new subject item (manifest, subject, initial containment assertion) """ if faims_item_id not in self.entities: # a new item, not seen before man_obj = self.check_get_faims_manifest_object( faims_item_id, item_label, ent_dict['item_type'], ent_dict['class_uri']) if man_obj is False: # we did not find it, so make a new one # first, make the supplemental dict object to help associate the faims_item_id # with the manifest object. This makes reconcilation precise. sup_dict = {} sup_dict[self.reconcile_key] = faims_item_id sup_dict['faims_label'] = item_label # now, make sure the item label is unique item_label = self.check_make_manifest_label_unique( item_label, ent_dict['item_type'], ent_dict['class_uri']) # make the intial context, based on the root context's path context = self.root_subject_context + '/' + item_label uuid = GenUUID.uuid4() uuid = str(uuid) new_sub = Subject() new_sub.uuid = uuid new_sub.project_uuid = self.project_uuid new_sub.source_id = self.source_id new_sub.context = context new_sub.save() man_obj = Manifest() man_obj.uuid = uuid man_obj.project_uuid = self.project_uuid man_obj.source_id = self.source_id man_obj.item_type = 'subjects' man_obj.repo = '' man_obj.class_uri = ent_dict['class_uri'] man_obj.label = item_label man_obj.des_predicate_uuid = '' man_obj.views = 0 man_obj.sup_json = sup_dict man_obj.save() # now add the initial containment relationship self.add_change_containment_assertion(self.root_subject_uuid, man_obj.uuid) # now save the open context uuid for the entity in the entities dict self.entities[faims_item_id] = LastUpdatedOrderedDict() self.entities[faims_item_id]['uuid'] = man_obj.uuid self.entities[faims_item_id]['item_type'] = man_obj.item_type self.fm.save_serialized_json(self.oc_config_entities, act_dir, self.entities)
def create_subject_item(self): """ Create and save a new subject object""" new_sub = Subject() new_sub.uuid = self.uuid # use the previously assigned temporary UUID new_sub.project_uuid = self.project_uuid new_sub.source_id = self.source_id new_sub.context = self.context new_sub.save() new_man = Manifest() new_man.uuid = self.uuid new_man.project_uuid = self.project_uuid new_man.source_id = self.source_id new_man.item_type = 'subjects' new_man.repo = '' new_man.class_uri = self.class_uri new_man.label = self.label new_man.des_predicate_uuid = '' new_man.views = 0 new_man.save()
def db_create_temporary_root_subject(self): """ makes a temporary root subject for the whole import makes it easier to move subjects into hiearchies later """ if not isinstance(self.root_subject_label, str): self.root_subject_label = self.source_id + '-root' if not isinstance(self.root_subject_context, str): self.root_subject_context = self.root_subject_label if not isinstance(self.root_subject_uuid, str): man_objs = Manifest.objects\ .filter(label=self.root_subject_label, class_uri=self.root_subject_class, project_uuid=self.project_uuid)[:1] if len(man_objs) > 0: self.root_subject_uuid = man_objs[0].uuid else: # did not find a root subject, so make one sup_dict = {} sup_dict[self.reconcile_key] = self.root_subject_sup_id root_uuid = GenUUID.uuid4() root_uuid = str(root_uuid) self.root_subject_uuid = root_uuid new_sub = Subject() new_sub.uuid = self.root_subject_uuid new_sub.project_uuid = self.project_uuid new_sub.source_id = self.source_id new_sub.context = self.root_subject_context new_sub.save() new_man = Manifest() new_man.uuid = self.root_subject_uuid new_man.project_uuid = self.project_uuid new_man.source_id = self.source_id new_man.item_type = 'subjects' new_man.repo = '' new_man.class_uri = self.root_subject_class new_man.label = self.root_subject_label new_man.des_predicate_uuid = '' new_man.views = 0 new_man.sup_json = sup_dict new_man.save()
def create_missing_parent(self, orphan_uuid, prev_parent, subjects_path, parent): """ Makes records for a missing parent in manifest, oc_assertions, and oc_subjects """ orphan_man = False try: orphan_man = Manifest.objects.get(uuid=orphan_uuid) except Manifest.DoesNotExist: orphan_man = False if orphan_man is not False: # first check to see we didn't create this yet if parent['uuid'] not in self.done_parents: # now save the subject label_path_dict = {'label': parent['label'], 'context': subjects_path} label_path_dict = self.context_path_validate(label_path_dict) parent['label'] = label_path_dict['label'] subjects_path = label_path_dict['context'] par_sub = Subject() par_sub.uuid = parent['uuid'] par_sub.project_uuid = orphan_man.project_uuid par_sub.source_id = 'child-xml-ref' par_sub.context = subjects_path par_sub.save() # first make a manifest object for this item parent_man = Manifest() parent_man.uuid = parent['uuid'] parent_man.project_uuid = orphan_man.project_uuid parent_man.source_id = 'child-xml-ref' parent_man.item_type = 'subjects' parent_man.class_uri = parent['class_uri'] parent_man.label = parent['label'] parent_man.save() # now save an assertion of containment if prev_parent is not False: par_ass = Assertion() par_ass.uuid = prev_parent par_ass.subject_type = 'subjects' par_ass.project_uuid = orphan_man.project_uuid par_ass.source_id = 'child-xml-ref' par_ass.obs_node = '#contents-1' par_ass.obs_num = 1 par_ass.sort = 1 par_ass.visibility = 1 par_ass.predicate_uuid = Assertion.PREDICATES_CONTAINS par_ass.object_uuid = parent['uuid'] par_ass.object_type = 'subjects' par_ass.save() # note we've made this parent, so we don't have to make it self.done_parents.append(parent['uuid']) # now check the orphan has a subject record orphan_sub = False try: orphan_sub = Subject.objects.get(uuid=orphan_uuid) except Subject.DoesNotExist: orphan_sub = False if orphan_sub is False: orphan_sub = Subject() orphan_sub.uuid = orphan_uuid orphan_sub.project_uuid = orphan_man.project_uuid orphan_sub.source_id = 'child-xml-ref' orphan_sub.context = subjects_path + '/' + orphan_man.label orphan_sub.save()