Ejemplo n.º 1
0
 def create_project(self, label, short_des):
     """ Creates a new project in the Manifest
         and projects tables
     """
     uuid = GenUUID.uuid4()
     man_proj = Manifest()
     man_proj.uuid = uuid
     man_proj.label = label
     man_proj.source_id = "manual"
     man_proj.item_type = "projects"
     man_proj.project_uuid = uuid
     man_proj.des_predicate_uuid = ""
     man_proj.class_uri = ""
     man_proj.views = 0
     man_proj.save()
     pobj = Project()
     pobj.uuid = uuid
     pobj.source_id = "manual"
     pobj.project_uuid = uuid
     pobj.label = label
     pobj.edit_status = 0
     pobj.short_des = short_des
     pobj.content = ""
     pobj.save()
     return uuid
Ejemplo n.º 2
0
 def make_link_tb_media(self, root_tb_uuid, tb_part, im_p_range, imp_file):
     """ makes and links a tb scan media resource """
     tb_scan_label = self.make_tb_scan_media_label(tb_part.label,
                                                   im_p_range)
     exists_tbs = Manifest.objects\
                          .filter(label=tb_scan_label,
                                  item_type='media')[:1]
     if len(exists_tbs) < 1:
         # this item doesn't exist yet, so make it.
         print('New scan label: ' + tb_scan_label)
         scan_uuid = str(GenUUID.uuid4())
         new_man = Manifest()
         new_man.uuid = scan_uuid
         new_man.project_uuid = self.project_uuid
         new_man.source_id = self.source_id
         new_man.item_type = 'media'
         new_man.repo = ''
         new_man.class_uri = self.class_uri
         new_man.label = tb_scan_label
         new_man.des_predicate_uuid = ''
         new_man.views = 0
         new_man.save()
         self.make_media_file(scan_uuid, 'oc-gen:fullfile', 'full',
                              imp_file.record)
         self.make_media_file(scan_uuid, 'oc-gen:preview', 'preview',
                              imp_file.record)
         self.make_media_file(scan_uuid, 'oc-gen:thumbnail', 'preview',
                              imp_file.record)
     else:
         print('Media Image already exists: ' + exists_tbs[0].label)
         scan_uuid = exists_tbs[0].uuid
     self.make_media_links(scan_uuid, root_tb_uuid, tb_part, im_p_range)
Ejemplo n.º 3
0
 def create_person(self, post_data):
     """ creates a person item into a project
     """
     ok = True
     required_params = ['source_id',
                        'item_type',
                        'foaf_type',
                        'combined_name',
                        'given_name',
                        'surname',
                        'mid_init',
                        'initials']
     for r_param in required_params:
         if r_param not in post_data:
             # we're missing some required data
             # don't create the item
             ok = False
             message = 'Missing paramater: ' + r_param + ''
             self.errors.append(message)
     uuid = self.create_or_validate_uuid(post_data)
     if uuid is False:
         ok = False
         note = '; '.join(self.errors)
     if ok:
         label = post_data['combined_name']
         new_pers = Person()
         new_pers.uuid = uuid
         new_pers.project_uuid = self.project_uuid
         new_pers.source_id = post_data['source_id']
         new_pers.foaf_type = post_data['foaf_type']
         new_pers.combined_name = post_data['combined_name']
         new_pers.given_name = post_data['given_name']
         new_pers.surname = post_data['surname']
         new_pers.mid_init = post_data['mid_init']
         new_pers.initials = post_data['initials']
         new_pers.save()
         new_man = Manifest()
         new_man.uuid = uuid
         new_man.project_uuid = self.project_uuid
         new_man.source_id = post_data['source_id']
         new_man.item_type = 'persons'
         new_man.repo = ''
         new_man.class_uri = post_data['foaf_type']
         new_man.label = post_data['combined_name']
         new_man.des_predicate_uuid = ''
         new_man.views = 0
         new_man.save()
         self.created_uuid = uuid
     else:
         label = '[Item not created]'
         uuid = False
     if ok:
         # now clear the cache a change was made
         self.clear_caches()
     self.response = {'action': 'create-item-into',
                      'ok': ok,
                      'change': {'uuid': uuid,
                                 'label': label,
                                 'note': self.add_creation_note(ok)}}
     return self.response
Ejemplo n.º 4
0
 def create_project(self, label, short_des):
     """ Creates a new project in the Manifest
         and projects tables
     """
     uuid = GenUUID.uuid4()
     man_proj = Manifest()
     man_proj.uuid = uuid
     man_proj.label = label
     man_proj.source_id = 'manual'
     man_proj.item_type = 'projects'
     man_proj.project_uuid = uuid
     man_proj.des_predicate_uuid = ''
     man_proj.class_uri = ''
     man_proj.views = 0
     man_proj.save()
     pobj = Project()
     pobj.uuid = uuid
     pobj.source_id = 'manual'
     pobj.project_uuid = uuid
     pobj.label = label
     pobj.edit_status = 0
     pobj.short_des = short_des
     pobj.content = ''
     pobj.save()
     return uuid
Ejemplo n.º 5
0
 def create_person(self, post_data):
     """ creates a person item into a project
     """
     ok = True
     required_params = [
         'source_id', 'item_type', 'foaf_type', 'combined_name',
         'given_name', 'surname', 'mid_init', 'initials'
     ]
     for r_param in required_params:
         if r_param not in post_data:
             # we're missing some required data
             # don't create the item
             ok = False
             message = 'Missing paramater: ' + r_param + ''
             self.errors.append(message)
     uuid = self.create_or_validate_uuid(post_data)
     if uuid is False:
         ok = False
         note = '; '.join(self.errors)
     if ok:
         label = post_data['combined_name']
         new_pers = Person()
         new_pers.uuid = uuid
         new_pers.project_uuid = self.project_uuid
         new_pers.source_id = post_data['source_id']
         new_pers.foaf_type = post_data['foaf_type']
         new_pers.combined_name = post_data['combined_name']
         new_pers.given_name = post_data['given_name']
         new_pers.surname = post_data['surname']
         new_pers.mid_init = post_data['mid_init']
         new_pers.initials = post_data['initials']
         new_pers.save()
         new_man = Manifest()
         new_man.uuid = uuid
         new_man.project_uuid = self.project_uuid
         new_man.source_id = post_data['source_id']
         new_man.item_type = 'persons'
         new_man.repo = ''
         new_man.class_uri = post_data['foaf_type']
         new_man.label = post_data['combined_name']
         new_man.des_predicate_uuid = ''
         new_man.views = 0
         new_man.save()
         self.created_uuid = uuid
     else:
         label = '[Item not created]'
         uuid = False
     if ok:
         # now clear the cache a change was made
         self.clear_caches()
     self.response = {
         'action': 'create-item-into',
         'ok': ok,
         'change': {
             'uuid': uuid,
             'label': label,
             'note': self.add_creation_note(ok)
         }
     }
     return self.response
Ejemplo n.º 6
0
 def get_make_predicate(self,
                        predicate_label,
                        predicate_type,
                        data_type=False):
     """
     gets a predicate, filtered by label, predicate_type, and data_type
     """
     self.manifest = False
     self.predicate = False
     if (data_type is not False):
         self.data_type = data_type
     plist = Manifest.objects.filter(label=predicate_label,
                                     item_type='predicates',
                                     project_uuid=self.project_uuid,
                                     class_uri=predicate_type)
     for pitem in plist:
         if (self.manifest is False):
             if (data_type is not False):
                 try:  # try to find the predicate with a given data_type
                     self.predicate = Predicate.objects.get(
                         uuid=pitem.uuid, data_type=data_type)
                     self.manifest = pitem
                 except Predicate.DoesNotExist:
                     self.predicate = False
                     self.manifest = False
             else:
                 try:  # look for the predicate item
                     self.predicate = Predicate.objects.get(uuid=pitem.uuid)
                     self.manifest = pitem
                 except Predicate.DoesNotExist:
                     self.predicate = False
                     self.manifest = False
     if (self.manifest is False and self.predicate is False):
         uuid = GenUUID.uuid4()
         newpred = Predicate()
         newpred.uuid = uuid
         newpred.project_uuid = self.project_uuid
         newpred.source_id = self.source_id
         newpred.data_type = self.data_type
         newpred.sort = self.sort
         newpred.created = datetime.datetime.now()
         newpred.save()
         self.predicate = newpred
         #now make a manifest record for the item
         newman = Manifest()
         newman.uuid = uuid
         newman.project_uuid = self.project_uuid
         newman.source_id = self.source_id
         newman.item_type = 'predicates'
         newman.repo = ''
         newman.class_uri = predicate_type
         newman.label = predicate_label
         newman.des_predicate_uuid = ''
         newman.views = 0
         newman.revised = datetime.datetime.now()
         newman.save()
         self.manifest = newman
     return self.predicate
Ejemplo n.º 7
0
 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)
Ejemplo n.º 8
0
 def create_project(self, post_data):
     """ creates a project item into a project
     """
     ok = True
     required_params = ['source_id', 'label', 'short_des']
     for r_param in required_params:
         if r_param not in post_data:
             # we're missing some required data
             # don't create the item
             ok = False
             message = 'Missing paramater: ' + r_param + ''
             if self.errors['params'] is False:
                 self.errors['params'] = message
             else:
                 self.errors['params'] += '; ' + message
     uuid = self.create_or_validate_uuid(post_data)
     if uuid is False:
         ok = False
         note = self.errors['uuid']
     if ok:
         label = post_data['label']
         if self.oc_root_project:
             project_uuid = uuid
         else:
             project_uuid = self.project_uuid
         new_proj = Project()
         new_proj.uuid = uuid
         new_proj.project_uuid = project_uuid
         new_proj.source_id = post_data['source_id']
         new_proj.edit_status = 0
         new_proj.label = label
         new_proj.short_des = post_data['short_des']
         new_proj.save()
         new_man = Manifest()
         new_man.uuid = uuid
         new_man.project_uuid = project_uuid
         new_man.source_id = post_data['source_id']
         new_man.item_type = 'projects'
         new_man.repo = ''
         new_man.class_uri = ''
         new_man.label = label
         new_man.des_predicate_uuid = ''
         new_man.views = 0
         new_man.save()
     else:
         label = '[Item not created]'
         uuid = False
     self.response = {
         'action': 'create-item-into',
         'ok': ok,
         'change': {
             'uuid': uuid,
             'label': label,
             'note': self.add_creation_note(ok)
         }
     }
     return self.response
Ejemplo n.º 9
0
 def get_make_predicate(self, predicate_label, predicate_type, data_type=False):
     """
     gets a predicate, filtered by label, predicate_type, and data_type
     """
     self.manifest = False
     self.predicate = False
     if(data_type is not False):
         self.data_type = data_type
     plist = Manifest.objects.filter(label=predicate_label,
                                     item_type='predicates',
                                     project_uuid=self.project_uuid,
                                     class_uri=predicate_type)
     for pitem in plist:
         if(self.manifest is False):
             if(data_type is not False):
                 try:  # try to find the predicate with a given data_type
                     self.predicate = Predicate.objects.get(uuid=pitem.uuid,
                                                            data_type=data_type)
                     self.manifest = pitem
                 except Predicate.DoesNotExist:
                     self.predicate = False
                     self.manifest = False
             else:
                 try:  # look for the predicate item
                     self.predicate = Predicate.objects.get(uuid=pitem.uuid)
                     self.manifest = pitem
                 except Predicate.DoesNotExist:
                     self.predicate = False
                     self.manifest = False
     if(self.manifest is False and self.predicate is False):
         uuid = GenUUID.uuid4()
         newpred = Predicate()
         newpred.uuid = uuid
         newpred.project_uuid = self.project_uuid
         newpred.source_id = self.source_id
         newpred.data_type = self.data_type
         newpred.sort = self.sort
         newpred.created = datetime.datetime.now()
         newpred.save()
         self.predicate = newpred
         #now make a manifest record for the item
         newman = Manifest()
         newman.uuid = uuid
         newman.project_uuid = self.project_uuid
         newman.source_id = self.source_id
         newman.item_type = 'predicates'
         newman.repo = ''
         newman.class_uri = predicate_type
         newman.label = predicate_label
         newman.des_predicate_uuid = ''
         newman.views = 0
         newman.revised = datetime.datetime.now()
         newman.save()
         self.manifest = newman
     return self.predicate
Ejemplo n.º 10
0
 def create_project(self, post_data):
     """ creates a project item into a project
     """
     ok = True
     required_params = ['source_id',
                        'label',
                        'short_des']
     for r_param in required_params:
         if r_param not in post_data:
             # we're missing some required data
             # don't create the item
             ok = False
             message = 'Missing paramater: ' + r_param + ''
             if self.errors['params'] is False:
                 self.errors['params'] = message
             else:
                 self.errors['params'] += '; ' + message
     uuid = self.create_or_validate_uuid(post_data)
     if uuid is False:
         ok = False
         note = self.errors['uuid']
     if ok:
         label = post_data['label']
         if self.oc_root_project:
             project_uuid = uuid
         else:
             project_uuid = self.project_uuid
         new_proj = Project()
         new_proj.uuid = uuid
         new_proj.project_uuid = project_uuid
         new_proj.source_id = post_data['source_id']
         new_proj.edit_status = 0
         new_proj.label = label
         new_proj.short_des = post_data['short_des']
         new_proj.save()
         new_man = Manifest()
         new_man.uuid = uuid
         new_man.project_uuid = project_uuid
         new_man.source_id = post_data['source_id']
         new_man.item_type = 'projects'
         new_man.repo = ''
         new_man.class_uri = ''
         new_man.label = label
         new_man.des_predicate_uuid = ''
         new_man.views = 0
         new_man.save()
     else:
         label = '[Item not created]'
         uuid = False
     self.response = {'action': 'create-item-into',
                      'ok': ok,
                      'change': {'uuid': uuid,
                                 'label': label,
                                 'note': self.add_creation_note(ok)}}
     return self.response
Ejemplo n.º 11
0
 def create_media_item(self):
     """ Create and save a new subject object"""
     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 = 'media'
     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()
Ejemplo n.º 12
0
 def create_media_item(self):
     """ Create and save a new subject object"""
     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 = 'media'
     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()
Ejemplo n.º 13
0
 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)
Ejemplo n.º 14
0
 def create_media_item(self, sup_metadata=None):
     """ Create and save a new subject object"""
     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 = 'media'
     new_man.repo = ''
     new_man.class_uri = self.class_uri
     new_man.label = self.label
     new_man.des_predicate_uuid = ''
     new_man.views = 0
     if isinstance(sup_metadata, dict):
         new_man.sup_json = sup_metadata
     new_man.save()
Ejemplo n.º 15
0
 def create_media_item(self, sup_metadata=None):
     """ Create and save a new subject object"""
     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 = 'media'
     new_man.repo = ''
     new_man.class_uri = self.class_uri
     new_man.label = self.label
     new_man.des_predicate_uuid = ''
     new_man.views = 0
     if isinstance(sup_metadata, dict):
         new_man.sup_json = sup_metadata
     new_man.save()
Ejemplo n.º 16
0
 def create_item(self, required_make_data):
     """ creates an item based on required data """
     if self.create_ok:
         # we've got the required data to make the item
         label = False
         context_uuid = False
         content = False
         class_uri = ''
         subject_uuid = False
         for req_field in required_make_data:
             if req_field['predicate_uuid'] == 'oc-gen:label':
                 label = req_field['value']
             elif req_field['predicate_uuid'] == 'oc-gen:content':
                 content = req_field['value']
             elif req_field['predicate_uuid'] == 'oc-gen:contained-in':
                 context_uuid = req_field['value']
             elif req_field['predicate_uuid'] == 'oc-gen:class_uri':
                 class_uri = req_field['value']
             elif req_field['predicate_uuid'] == 'oc-gen:subjects-link':
                 subject_uuid = req_field['value']
     if self.create_ok:
         item_man = Manifest()
         item_man.uuid = self.edit_uuid
         item_man.project_uuid = self.project_uuid
         item_man.source_id = self.make_source_id()
         item_man.item_type = self.item_type
         item_man.repo = ''
         item_man.class_uri = class_uri
         item_man.label = label
         item_man.des_predicate_uuid = ''
         item_man.views = 0
         item_man.save()
         if context_uuid is not False \
            and self.item_type == 'subjects':
             self.save_contained_subject(context_uuid, item_man)
         if subject_uuid is not False:
             self.save_subject_link(subject_uuid, item_man)
         if content is not False \
            and self.item_type == 'documents':
             doc = OCdocument()
             doc.uuid = item_man.uuid
             doc.project_uuid = item_man.project_uuid
             doc.source_id = item_man.source_id
             doc.content = content
             doc.save()
     else:
         item_man = False
     return item_man
Ejemplo n.º 17
0
 def create_item(self, required_make_data):
     """ creates an item based on required data """
     if self.create_ok:
         # we've got the required data to make the item
         label = False
         context_uuid = False
         content = False
         class_uri = ''
         subject_uuid = False
         for req_field in required_make_data:
             if req_field['predicate_uuid'] == 'oc-gen:label':
                 label = req_field['value']
             elif req_field['predicate_uuid'] == 'oc-gen:content':
                 content = req_field['value']
             elif req_field['predicate_uuid'] == 'oc-gen:contained-in':
                 context_uuid = req_field['value']
             elif req_field['predicate_uuid'] == 'oc-gen:class_uri':
                 class_uri = req_field['value']
             elif req_field['predicate_uuid'] == 'oc-gen:subjects-link':
                 subject_uuid = req_field['value']
     if self.create_ok:
         item_man = Manifest()
         item_man.uuid = self.edit_uuid
         item_man.project_uuid = self.project_uuid
         item_man.source_id = self.make_source_id()
         item_man.item_type = self.item_type
         item_man.repo = ''
         item_man.class_uri = class_uri
         item_man.label = label
         item_man.des_predicate_uuid = ''
         item_man.views = 0
         item_man.save()
         if context_uuid is not False \
            and self.item_type == 'subjects':
             self.save_contained_subject(context_uuid, item_man)
         if subject_uuid is not False:
             self.save_subject_link(subject_uuid, item_man)
         if content is not False \
            and self.item_type == 'documents':
             doc = OCdocument()
             doc.uuid = item_man.uuid
             doc.project_uuid = item_man.project_uuid
             doc.source_id = item_man.source_id
             doc.content = content
             doc.save()
     else:
         item_man = False
     return item_man
Ejemplo n.º 18
0
 def get_make_type_pred_uuid_content_uuid(self, predicate_uuid,
                                          content_uuid):
     """
     gets a type, filtered by a given predicate_uuid and content string
     if a type does not exist, this function creates it, then returns the type
     """
     found = self.check_exists_pred_uuid_content_uuid(
         predicate_uuid, content_uuid)
     if found is False:
         if self.content is False:
             try:
                 oc_string = OCstring.objects.get(uuid=content_uuid)
                 self.content = oc_string.content
             except OCstring.DoesNotExist:
                 self.content = False
         # print('Content: ' + str(self.content))
         if self.content is not False:
             # make a new oc_type object!
             if self.suggested_uuid is not False:
                 uuid = self.suggested_uuid
             else:
                 # string is new to the project so make it.
                 uuid = GenUUID.uuid4()
             newtype = OCtype()
             newtype.uuid = uuid
             newtype.project_uuid = self.project_uuid
             newtype.source_id = self.source_id
             newtype.predicate_uuid = predicate_uuid
             newtype.content_uuid = content_uuid
             newtype.rank = 0
             newtype.save()
             self.oc_type = newtype
             #now make a manifest record for the item
             newman = Manifest()
             newman.uuid = uuid
             newman.project_uuid = self.project_uuid
             newman.source_id = self.source_id
             newman.item_type = 'types'
             newman.repo = ''
             newman.class_uri = ''
             newman.label = self.content
             newman.des_predicate_uuid = ''
             newman.views = 0
             newman.sup_json = self.sup_dict
             newman.revised = datetime.datetime.now()
             newman.save()
     return self.oc_type
Ejemplo n.º 19
0
 def get_make_type_pred_uuid_content_uuid(self, predicate_uuid, content_uuid):
     """
     gets a type, filtered by a given predicate_uuid and content string
     if a type does not exist, this function creates it, then returns the type
     """
     found = self.check_exists_pred_uuid_content_uuid(predicate_uuid, content_uuid)
     if found is False:
         if self.content is False:
             try:
                 oc_string = OCstring.objects.get(uuid=content_uuid)
                 self.content = oc_string.content
             except OCstring.DoesNotExist:
                 self.content = False
         # print('Content: ' + str(self.content))
         if self.content is not False:
             # make a new oc_type object!
             if self.suggested_uuid is not False:
                 uuid = self.suggested_uuid
             else:
                 # string is new to the project so make it.
                 uuid = GenUUID.uuid4()
             newtype = OCtype()
             newtype.uuid = uuid
             newtype.project_uuid = self.project_uuid
             newtype.source_id = self.source_id
             newtype.predicate_uuid = predicate_uuid
             newtype.content_uuid = content_uuid
             newtype.rank = 0
             newtype.save()
             self.oc_type = newtype
             #now make a manifest record for the item
             newman = Manifest()
             newman.uuid = uuid
             newman.project_uuid = self.project_uuid
             newman.source_id = self.source_id
             newman.item_type = 'types'
             newman.repo = ''
             newman.class_uri = ''
             newman.label = self.content
             newman.des_predicate_uuid = ''
             newman.views = 0
             newman.sup_json = self.sup_dict
             newman.revised = datetime.datetime.now()
             newman.save()
     return self.oc_type
Ejemplo n.º 20
0
 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()
Ejemplo n.º 21
0
 def make_link_tb_media(self, root_tb_uuid, tb_part, im_p_range, imp_file):
     """ makes and links a tb scan media resource """
     tb_scan_label = self.make_tb_scan_media_label(tb_part.label,
                                                   im_p_range)
     exists_tbs = Manifest.objects\
                          .filter(label=tb_scan_label,
                                  item_type='media')[:1]
     if len(exists_tbs) < 1:
         # this item doesn't exist yet, so make it.
         print('New scan label: ' + tb_scan_label)
         scan_uuid = str(GenUUID.uuid4())
         new_man = Manifest()
         new_man.uuid = scan_uuid
         new_man.project_uuid = self.project_uuid
         new_man.source_id = self.source_id
         new_man.item_type = 'media'
         new_man.repo = ''
         new_man.class_uri = self.class_uri
         new_man.label = tb_scan_label
         new_man.des_predicate_uuid = ''
         new_man.views = 0
         new_man.save()
         self.make_media_file(scan_uuid,
                              'oc-gen:fullfile',
                              'full',
                              imp_file.record)
         self.make_media_file(scan_uuid,
                              'oc-gen:preview',
                              'preview',
                              imp_file.record)
         self.make_media_file(scan_uuid,
                              'oc-gen:thumbnail',
                              'preview',
                              imp_file.record)
     else:
         print('Media Image already exists: ' + exists_tbs[0].label )
         scan_uuid = exists_tbs[0].uuid
     self.make_media_links(scan_uuid,
                           root_tb_uuid,
                           tb_part,
                           im_p_range)
Ejemplo n.º 22
0
 def create_document_item(self, sup_metadata=None):
     """ Create and save a new subject object"""
     new_doc = OCdocument()
     new_doc.uuid = self.uuid  # use the previously assigned temporary UUID
     new_doc.project_uuid = self.project_uuid
     new_doc.source_id = self.source_id
     new_doc.content = self.content
     new_doc.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 = 'documents'
     new_man.repo = ''
     new_man.class_uri = ''
     new_man.label = self.label
     new_man.des_predicate_uuid = ''
     new_man.views = 0
     if isinstance(sup_metadata, dict):
         new_man.sup_json = sup_metadata
     new_man.save()
Ejemplo n.º 23
0
 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()
Ejemplo n.º 24
0
 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()
Ejemplo n.º 25
0
 def create_media_and_links(self, subj_uuid, id_str, filename):
     """ create database records for the image, associate
         with the subject
     """
     file_label = self.make_image_label(id_str, filename)
     med_man_objs = Manifest.objects\
                            .filter(label=file_label,
                                    source_id=self.source_id,
                                    item_type='media')[:1]
     filename = filename.replace(' ', '-')
     filename = filename.replace('_', '-')
     med_files = Mediafile.objects\
                          .filter(file_uri__icontains=filename)[:1]
     # med_man_objs = [1, 2, 3]
     if len(med_man_objs) < 1 and len(med_files) < 1:
         # now make another media item
         media_uuid = str(GenUUID.uuid4())
         print('Making on: ' + file_label + ' (' + media_uuid +')')
         new_man = Manifest()
         new_man.uuid = media_uuid
         new_man.project_uuid = self.project_uuid
         new_man.source_id = self.source_id
         new_man.item_type = 'media'
         new_man.repo = ''
         new_man.class_uri = 'oc-gen:image'
         new_man.label = file_label
         new_man.des_predicate_uuid = ''
         new_man.views = 0
         new_man.save()
         self.make_media_file_obj(media_uuid,
                                  'oc-gen:fullfile',
                                  (self.full_uri_prefix + filename))
         self.make_media_file_obj(media_uuid,
                                  'oc-gen:preview',
                                  (self.prev_uri_prefix + filename))
         self.make_media_file_obj(media_uuid,
                                  'oc-gen:thumbnail',
                                  (self.thumb_uri_prefix + filename))
         self.add_media_assertions(subj_uuid, media_uuid)
Ejemplo n.º 26
0
 def create_person_item(self):
     """ Create and save a new subject object"""
     new_pers = Person()
     new_pers.uuid = self.uuid  # use the previously assigned temporary UUID
     new_pers.project_uuid = self.project_uuid
     new_pers.source_id = self.source_id
     new_pers.foaf_type = self.foaf_type
     new_pers.combined_name = self.combined_name
     new_pers.given_name = self.given_name
     new_pers.surname = self.surname
     new_pers.mid_init = self.mid_init
     new_pers.initials = self.initials
     new_pers.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 = 'persons'
     new_man.repo = ''
     new_man.class_uri = self.foaf_type
     new_man.label = self.label
     new_man.des_predicate_uuid = ''
     new_man.views = 0
     new_man.save()
Ejemplo n.º 27
0
 def create_person_item(self):
     """ Create and save a new subject object"""
     new_pers = Person()
     new_pers.uuid = self.uuid  # use the previously assigned temporary UUID
     new_pers.project_uuid = self.project_uuid
     new_pers.source_id = self.source_id
     new_pers.foaf_type = self.foaf_type
     new_pers.combined_name = self.combined_name
     new_pers.given_name = self.given_name
     new_pers.surname = self.surname
     new_pers.mid_init = self.mid_init
     new_pers.initials = self.initials
     new_pers.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 = 'persons'
     new_man.repo = ''
     new_man.class_uri = self.foaf_type
     new_man.label = self.label
     new_man.des_predicate_uuid = ''
     new_man.views = 0
     new_man.save()
Ejemplo n.º 28
0
 def create_media(self, post_data):
     """ creates a type item into a project
     """
     ok = True
     label = None
     required_params = [
         'source_id', 'item_type', 'label', 'project_uuid', 'source_id',
         'full_uri', 'preview_uri', 'thumbs_uri'
     ]
     for r_param in required_params:
         if r_param not in post_data:
             # we're missing some required data
             # don't create the item
             ok = False
             message = 'Missing paramater: ' + r_param + ''
             self.errors.append(message)
     uuid = self.create_or_validate_uuid(post_data)
     if uuid is False:
         ok = False
         note = '; '.join(self.errors)
     if ok:
         # now check to see if this already exists
         class_uri = ''
         if 'class_uri' in post_data:
             class_uri = post_data['class_uri'].strip()
         note = ''
         item_type = 'media'
         source_id = post_data['source_id'].strip()
         label = post_data['label'].strip()
         if len(label) < 1:
             ok = False
             message = 'The label cannot be blank.'
             self.errors.append(message)
             note = '; '.join(self.errors)
         else:
             exist_uuid = self.get_uuid_manifest_label(label, item_type)
             if exist_uuid is not False:
                 ok = False
                 message = 'Cannot create a media item called "' + label + '"'
                 message += ', becuase it already exists with UUID: ' + uuid
                 self.errors.append(message)
                 note = '; '.join(self.errors)
     if ok:
         note = 'Media item "' + label + '" created with UUID:' + uuid
         # now save to the manifest
         new_man = Manifest()
         new_man.uuid = uuid
         new_man.project_uuid = self.project_uuid
         new_man.source_id = source_id
         new_man.item_type = 'media'
         new_man.repo = ''
         new_man.class_uri = ''
         new_man.label = label
         new_man.des_predicate_uuid = ''
         new_man.views = 0
         new_man.save()
         self.created_uuid = uuid
         self.save_media_file(uuid, source_id, 'oc-gen:fullfile',
                              post_data['full_uri'])
         self.save_media_file(uuid, source_id, 'oc-gen:preview',
                              post_data['preview_uri'])
         self.save_media_file(uuid, source_id, 'oc-gen:thumbnail',
                              post_data['thumbs_uri'])
     if ok:
         # now clear the cache a change was made
         self.clear_caches()
     self.response = {
         'action': 'create-item-into',
         'ok': ok,
         'change': {
             'uuid': uuid,
             'label': label,
             'note': self.add_creation_note(ok)
         }
     }
     return self.response
Ejemplo n.º 29
0
 def create_predicate(self, post_data):
     """ creates a type item into a project
     """
     ok = True
     required_params = [
         'source_id', 'item_type', 'label', 'note', 'class_uri', 'data_type'
     ]
     for r_param in required_params:
         if r_param not in post_data:
             # we're missing some required data
             # don't create the item
             ok = False
             message = 'Missing paramater: ' + r_param + ''
             if self.errors['params'] is False:
                 self.errors['params'] = message
             else:
                 self.errors['params'] += '; ' + message
     uuid = self.create_or_validate_uuid(post_data)
     if uuid is False:
         ok = False
         note = self.errors['uuid']
     if ok:
         # now check to see if this already exists
         note = ''
         item_type = 'predicates'
         source_id = post_data['source_id'].strip()
         label = post_data['label'].strip()
         if len(label) < 1:
             ok = False
             self.errors['label'] = 'The label cannot be blank.'
             note += self.errors['label'] + ' '
         else:
             exist_uuid = self.get_uuid_manifest_label(label, item_type)
             if exist_uuid is not False:
                 ok = False
                 self.errors[
                     'uuid'] = 'Cannot create a category called "' + label + '"'
                 self.errors[
                     'uuid'] += ', becuase it already exists with UUID: ' + uuid
                 note += self.errors['uuid'] + ' '
         pred_note = post_data['note'].strip()
         class_uri = post_data['class_uri'].strip()
         if class_uri not in Predicate.CLASS_TYPES:
             ok = False
             self.errors[
                 'class_uri'] = class_uri + ' is not a valid Predicate class.'
             note += self.errors['class_uri'] + ' '
         data_type = post_data['data_type'].strip()
         if data_type not in Predicate.DATA_TYPES_HUMAN:
             ok = False
             self.errors[
                 'data_type'] = data_type + ' is not a valid Predicate data-type.'
             note += self.errors['data_type'] + ' '
     if ok:
         note = 'Predicate "' + label + '" created with UUID:' + uuid
         # everything checked out OK, so make the predicate
         new_pred = Predicate()
         new_pred.uuid = uuid
         new_pred.project_uuid = self.project_uuid
         new_pred.source_id = source_id
         new_pred.data_type = data_type
         new_pred.sort = 1
         new_pred.save()
         # now save to the manifest
         new_man = Manifest()
         new_man.uuid = uuid
         new_man.project_uuid = self.project_uuid
         new_man.source_id = source_id
         new_man.item_type = 'predicates'
         new_man.repo = ''
         new_man.class_uri = class_uri
         new_man.label = label
         new_man.des_predicate_uuid = ''
         new_man.views = 0
         new_man.save()
         # now add the note if not empty
         self.add_description_note(uuid, 'predicates', source_id, pred_note)
     self.response = {
         'action': 'create-item-into',
         'ok': ok,
         'change': {
             'uuid': uuid,
             'label': label,
             'note': self.add_creation_note(ok)
         }
     }
     return self.response
Ejemplo n.º 30
0
 def get_make_predicate(self, predicate_label, predicate_type, data_type=False):
     """
     gets a predicate, filtered by label, predicate_type, and data_type
     """
     self.manifest = False
     self.predicate = False
     if data_type is not False:
         self.data_type = data_type
     plist = Manifest.objects.filter(label=predicate_label,
                                     item_type='predicates',
                                     project_uuid=self.project_uuid,
                                     class_uri=predicate_type)
     for pitem in plist:
         if self.sup_reconcile_key is not None and\
            self.sup_reconcile_value is not None:
             # checks to see if the supplemental JSON has a matching key, value pair
             # this lets us further constrain reconciliation, say with FAIMS predicates
             sup_key_ok = pitem.check_sup_json_key_value(self.sup_reconcile_key,
                                                         self.sup_reconcile_value)
         else:
             sup_key_ok = True # default to true, only false if the key does NOT match
         if self.manifest is False and sup_key_ok:
             if data_type is not False:
                 try:  # try to find the predicate with a given data_type
                     self.predicate = Predicate.objects.get(uuid=pitem.uuid,
                                                            data_type=data_type)
                     self.manifest = pitem
                 except Predicate.DoesNotExist:
                     self.predicate = False
                     self.manifest = False
             else:
                 try:  # look for the predicate item
                     self.predicate = Predicate.objects.get(uuid=pitem.uuid)
                     self.manifest = pitem
                 except Predicate.DoesNotExist:
                     self.predicate = False
                     self.manifest = False
     if self.manifest is False and self.predicate is False:
         uuid = GenUUID.uuid4()
         newpred = Predicate()
         newpred.uuid = uuid
         newpred.project_uuid = self.project_uuid
         newpred.source_id = self.source_id
         newpred.data_type = self.data_type
         newpred.sort = self.sort
         newpred.created = datetime.datetime.now()
         newpred.save()
         self.predicate = newpred
         #now make a manifest record for the item
         newman = Manifest()
         newman.uuid = uuid
         newman.project_uuid = self.project_uuid
         newman.source_id = self.source_id
         newman.item_type = 'predicates'
         newman.repo = ''
         newman.class_uri = predicate_type
         newman.label = predicate_label
         newman.des_predicate_uuid = ''
         newman.views = 0
         newman.revised = datetime.datetime.now()
         newman.sup_json = self.sup_dict
         newman.save()
         self.manifest = newman
     return self.predicate
Ejemplo n.º 31
0
 def create_media(self, post_data):
     """ creates a type item into a project
     """
     ok = True
     required_params = ['source_id',
                        'item_type',
                        'label',
                        'project_uuid',
                        'source_id',
                        'full_uri',
                        'preview_uri',
                        'thumbs_uri']
     for r_param in required_params:
         if r_param not in post_data:
             # we're missing some required data
             # don't create the item
             ok = False
             message = 'Missing paramater: ' + r_param + ''
             self.errors.append(message)
     uuid = self.create_or_validate_uuid(post_data)
     if uuid is False:
         ok = False
         note = '; '.join(self.errors)
     if ok:
         # now check to see if this already exists
         class_uri = ''
         if 'class_uri' in post_data:
             class_uri = post_data['class_uri'].strip()
         note = ''
         item_type = 'media'
         source_id = post_data['source_id'].strip()
         label = post_data['label'].strip()
         if len(label) < 1:
             ok = False
             message = 'The label cannot be blank.'
             self.errors.append(message)
             note = '; '.join(self.errors)
         else:
             exist_uuid = self.get_uuid_manifest_label(label,
                                                       item_type)
             if exist_uuid is not False:
                 ok = False
                 message = 'Cannot create a media item called "' + label + '"'
                 message += ', becuase it already exists with UUID: ' + uuid
                 self.errors.append(message)
                 note = '; '.join(self.errors)
     if ok:
         note = 'Media item "' + label + '" created with UUID:' + uuid
         # now save to the manifest
         new_man = Manifest()
         new_man.uuid = uuid
         new_man.project_uuid = self.project_uuid
         new_man.source_id = source_id
         new_man.item_type = 'media'
         new_man.repo = ''
         new_man.class_uri = ''
         new_man.label = label
         new_man.des_predicate_uuid = ''
         new_man.views = 0
         new_man.save()
         self.created_uuid = uuid
         self.save_media_file(uuid,
                              source_id,
                              'oc-gen:fullfile',
                              post_data['full_uri'])
         self.save_media_file(uuid,
                              source_id,
                              'oc-gen:preview',
                              post_data['preview_uri'])
         self.save_media_file(uuid,
                              source_id,
                              'oc-gen:thumbnail',
                              post_data['thumbs_uri'])
     if ok:
         # now clear the cache a change was made
         self.clear_caches()
     self.response = {'action': 'create-item-into',
                      'ok': ok,
                      'change': {'uuid': uuid,
                                 'label': label,
                                 'note': self.add_creation_note(ok)}}
     return self.response
Ejemplo n.º 32
0
 def create_predicate(self, post_data):
     """ creates a predicate item into a project
     """
     ok = True
     required_params = ['source_id',
                        'item_type',
                        'label',
                        'note',
                        'class_uri',
                        'data_type']
     for r_param in required_params:
         if r_param not in post_data:
             # we're missing some required data
             # don't create the item
             ok = False
             message = 'Missing paramater: ' + r_param + ''
             self.errors.append(message)
     uuid = self.create_or_validate_uuid(post_data)
     if uuid is False:
         ok = False
         note = '; '.join(self.errors)
     if ok:
         # now check to see if this already exists
         note = ''
         item_type = 'predicates'
         source_id = post_data['source_id'].strip()
         label = post_data['label'].strip()
         if len(label) < 1:
             ok = False
             message = 'The label cannot be blank.'
             self.errors.append(message)
             note = '; '.join(self.errors)
         else:
             exist_uuid = self.get_uuid_manifest_label(label,
                                                       item_type)
             if exist_uuid is not False:
                 ok = False
                 message = 'Cannot create a predicated called "' + label + '"'
                 message += ', becuase it already exists with UUID: ' + uuid
                 note += self.errors['uuid'] + ' '
         pred_note = post_data['note'].strip()
         class_uri = post_data['class_uri'].strip()
         if class_uri not in Predicate.CLASS_TYPES:
             ok = False
             message = class_uri + ' is not a valid Predicate class.'
             self.errors.append(message)
             note = '; '.join(self.errors)
         data_type = post_data['data_type'].strip()
         if data_type not in Predicate.DATA_TYPES_HUMAN:
             ok = False
             message = data_type + ' is not a valid Predicate data-type.'
             self.errors.append(message)
             note = '; '.join(self.errors)
     if ok:
         note = 'Predicate "' + label + '" created with UUID:' + uuid
         # everything checked out OK, so make the predicate
         new_pred = Predicate()
         new_pred.uuid = uuid
         new_pred.project_uuid = self.project_uuid
         new_pred.source_id = source_id
         new_pred.data_type = data_type
         new_pred.sort = 1
         new_pred.save()
         # now save to the manifest
         new_man = Manifest()
         new_man.uuid = uuid
         new_man.project_uuid = self.project_uuid
         new_man.source_id = source_id
         new_man.item_type = 'predicates'
         new_man.repo = ''
         new_man.class_uri = class_uri
         new_man.label = label
         new_man.des_predicate_uuid = ''
         new_man.views = 0
         new_man.save()
         self.created_uuid = uuid
         # now add the note if not empty
         self.add_description_note(uuid,
                                   'predicates',
                                   source_id,
                                   pred_note)
     if ok:
         # now clear the cache a change was made
         self.clear_caches()
     self.response = {'action': 'create-item-into',
                      'ok': ok,
                      'change': {'uuid': uuid,
                                 'label': label,
                                 'note': self.add_creation_note(ok)}}
     return self.response