Exemple #1
0
 def add_predicate(self, predicate_uuid, label, data_type):
     """ adds the predicate """
     if predicate_uuid not in self.predicates:
         self.predicates.append(predicate_uuid)
         pred_exists = self.check_manifest_exists(predicate_uuid)
         if pred_exists is False:
             print('New predicate: ' + label + ' ' + predicate_uuid)
             preds = Predicate.objects\
                              .filter(project_uuid=self.project_uuid)
             sort = len(preds) + 1
             man = Manifest()
             man.uuid = predicate_uuid
             man.label = label
             man.project_uuid = self.project_uuid
             man.source_id = self.source_id
             man.item_type = 'predicates'
             man.class_uri = 'variable'
             man.save()
             pred = Predicate()
             pred.uuid = predicate_uuid
             pred.project_uuid = self.project_uuid
             pred.source_id = self.source_id
             pred.data_type = data_type
             pred.sort = sort
             pred.save()
Exemple #2
0
 def add_predicate(self, predicate_uuid, label, data_type):
     """ adds the predicate """
     if predicate_uuid not in self.predicates:
         self.predicates.append(predicate_uuid)
         pred_exists = self.check_manifest_exists(predicate_uuid)
         if pred_exists is False:
             print('New predicate: ' + label + ' ' + predicate_uuid)
             preds = Predicate.objects\
                              .filter(project_uuid=self.project_uuid)
             sort = len(preds) + 1
             man = Manifest()
             man.uuid = predicate_uuid
             man.label = label
             man.project_uuid = self.project_uuid
             man.source_id = self.source_id
             man.item_type = 'predicates'
             man.class_uri = 'variable'
             man.save()
             pred = Predicate()
             pred.uuid = predicate_uuid
             pred.project_uuid = self.project_uuid
             pred.source_id = self.source_id
             pred.data_type = data_type
             pred.sort = sort
             pred.save()
 def __init__(self, uuid=None, request=None):
     self.id_href = False  # if True, use the local href as the Context's ID,
     self.context_path = '/contexts/projects/'  # path for the ID of the context resource
     self.uuid = uuid
     rp = RootPath()
     self.base_url = rp.get_baseurl()
     self.manifest = False
     self.project_obj = False
     self.edit_status = 0
     self.edit_permitted = False
     self.view_permitted = True
     self.assertion_hashes = False
     self.id = False
     self.href = False
     self.cannonical_href = False
     self.json_ld = False
     self.errors = []
     self.pred_sql_dict_list = None
     self.most_recent_date = None
     self.refresh_cache = False
     self.uuids_for_queries = None
     if uuid is not None:
         if uuid is False or uuid == '0' or uuid == 'open-context':
             self.uuid = '0'
             self.manifest = Manifest()
             self.manifest.uuid = '0'
             self.manifest.project_uuid = '0'
             self.manifest.label = 'Open Context (General)'
             self.manifest.item_type = 'projects'
         else:
             self.dereference_uuid_or_slug(uuid)
             self.set_uri_urls(self.uuid)
             if request is not None:
                 self.check_permissions(request)
Exemple #4
0
def load_context_row(project_uuid, source_id, row):
    """Loads a context record row into the database"""
    parent_man_obj = Manifest.objects.filter(uuid=row['parent_uuid']).first()
    if parent_man_obj is None:
        print('Cannot find parent_uuid {} for uuid {}'.format(
            row['parent_uuid'], row['context_uuid']))
        # Skip the rest.
        return False
    # OK to continue
    man_obj = Manifest.objects.filter(uuid=row['context_uuid']).first()
    if man_obj is None:
        man_obj = Manifest()
    # Set up the new item in the Manifest
    man_obj.uuid = row['context_uuid']
    man_obj.source_id = source_id
    man_obj.label = row['label']
    man_obj.project_uuid = project_uuid
    man_obj.item_type = 'subjects'
    man_obj.class_uri = row['class_uri']
    man_obj.save()
    # Just to be sure, make sure this item does not
    # have any existing parent relations.
    Assertion.objects.filter(
        predicate_uuid=Assertion.PREDICATES_CONTAINS,
        object_uuid=man_obj.uuid,
    ).delete()
    # Now add a context relation to it.
    ass = Assertion()
    ass.uuid = parent_man_obj.uuid
    ass.subject_type = parent_man_obj.item_type
    ass.project_uuid = parent_man_obj.project_uuid
    ass.source_id = source_id
    ass.obs_node = '#contents-{}'.format(DEFAULT_OBS_NUM)
    ass.obs_num = DEFAULT_OBS_NUM
    ass.sort = 1
    ass.visibility = 1
    ass.predicate_uuid = Assertion.PREDICATES_CONTAINS
    ass.object_uuid = man_obj.uuid
    ass.object_type = man_obj.item_type
    ass.save()
    sg = SubjectGeneration()
    sg.generate_save_context_path_from_uuid(man_obj.uuid)
    return True
Exemple #5
0
 def store_records(self, act_table, recs):
     """
     stores records retrieved for a given table
     """
     i = 0
     for record in recs:
         i += 1
         allow_write = self.check_allow_write(act_table, record)
         record = self.prep_update_keep_old(act_table, record)
         if (allow_write is False and self.update_keep_old is False):
             print('\n Not allowed to overwite record.' + str(i))
         else:
             # print('\n Adding record:' + str(record))
             newr = False
             if (act_table == 'link_annotations'):
                 newr = LinkAnnotation(**record)
             elif (act_table == 'link_entities'):
                 newr = LinkEntity(**record)
             elif (act_table == 'oc_assertions'):
                 newr = Assertion(**record)
             elif (act_table == 'oc_manifest'):
                 newr = Manifest(**record)
             elif (act_table == 'oc_subjects'):
                 newr = Subject(**record)
             elif (act_table == 'oc_mediafiles'):
                 newr = Mediafile(**record)
             elif (act_table == 'oc_documents'):
                 newr = OCdocument(**record)
             elif (act_table == 'oc_persons'):
                 newr = Person(**record)
             elif (act_table == 'oc_projects'):
                 newr = Project(**record)
             elif (act_table == 'oc_strings'):
                 newr = OCstring(**record)
             elif (act_table == 'oc_types'):
                 newr = OCtype(**record)
             elif (act_table == 'oc_geospace'):
                 newr = Geospace(**record)
             elif (act_table == 'oc_events'):
                 newr = Event(**record)
             elif (act_table == 'oc_predicates'):
                 newr = Predicate(**record)
             elif (act_table == 'oc_identifiers'):
                 newr = StableIdentifer(**record)
             elif (act_table == 'oc_obsmetadata'):
                 newr = ObsMetadata(**record)
             if (newr is not False):
                 try:
                     newr.save(force_insert=self.force_insert,
                               force_update=self.update_keep_old)
                 except Exception as error:
                     print('Something slipped past in ' + act_table +
                           '...' + str(error))
 def add_predicates_manifest(self):
     """
     adds predicate items to the manifest
     """
     predicates = Predicate.objects.all()
     for predicate in predicates:
         record = {
             "uuid": predicate.uuid,
             "project_uuid": predicate.project_uuid,
             "source_id": predicate.source_id,
             "item_type": "predicates",
             "repo": "",
             "class_uri": predicate.archaeoml_type,
             "label": predicate.label,
             "des_predicate_uuid": "",
             "views": 0,
             "published": predicate.created,
             "revised": predicate.updated,
         }
         newr = Manifest(**record)
         newr.save()
     return len(predicates)
Exemple #7
0
 def add_predicates_manifest(self):
     """
     adds predicate items to the manifest
     """
     predicates = Predicate.objects.all()
     for predicate in predicates:
         record = {
             'uuid': predicate.uuid,
             'project_uuid': predicate.project_uuid,
             'source_id': predicate.source_id,
             'item_type': 'predicates',
             'repo': '',
             'class_uri': predicate.archaeoml_type,
             'label': predicate.label,
             'des_predicate_uuid': '',
             'views': 0,
             'published': predicate.created,
             'revised': predicate.updated
         }
         newr = Manifest(**record)
         newr.save()
     return len(predicates)
Exemple #8
0
 def add_octypes_manifest(self):
     """
     adds octype items to the manifest
     """
     octypes = OCtype.objects.all()
     proj_dates = self.get_manifest_project_dates()
     for octype in octypes:
         record = {
             'uuid': octype.uuid,
             'project_uuid': octype.project_uuid,
             'source_id': octype.source_id,
             'item_type': 'types',
             'repo': '',
             'class_uri': '',
             'label': octype.label,
             'des_predicate_uuid': '',
             'views': 0,
             'published': proj_dates[octype.project_uuid]['earliest'],
             'revised': octype.updated
         }
         newr = Manifest(**record)
         newr.save()
     return len(octypes)
 def add_ocpersons_manifest(self):
     """
     adds ocproject items to the manifest
     """
     ocpersons = Person.objects.all()
     proj_dates = self.get_manifest_project_dates()
     for ocper in ocpersons:
         record = {
             "uuid": ocper.uuid,
             "project_uuid": ocper.project_uuid,
             "source_id": ocper.source_id,
             "item_type": "persons",
             "repo": "",
             "class_uri": "",
             "label": ocper.combined_name,
             "des_predicate_uuid": "",
             "views": 0,
             "published": proj_dates[ocper.project_uuid]["earliest"],
             "revised": ocper.updated,
         }
         newr = Manifest(**record)
         newr.save()
     return len(ocpersons)
Exemple #10
0
 def add_ocpersons_manifest(self):
     """
     adds ocproject items to the manifest
     """
     ocpersons = Person.objects.all()
     proj_dates = self.get_manifest_project_dates()
     for ocper in ocpersons:
         record = {
             'uuid': ocper.uuid,
             'project_uuid': ocper.project_uuid,
             'source_id': ocper.source_id,
             'item_type': 'persons',
             'repo': '',
             'class_uri': '',
             'label': ocper.combined_name,
             'des_predicate_uuid': '',
             'views': 0,
             'published': proj_dates[ocper.project_uuid]['earliest'],
             'revised': ocper.updated
         }
         newr = Manifest(**record)
         newr.save()
     return len(ocpersons)
Exemple #11
0
 def add_octypes_manifest(self):
     """
     adds octype items to the manifest
     """
     octypes = OCtype.objects.all()
     proj_dates = self.get_manifest_project_dates()
     for octype in octypes:
         record = {
             "uuid": octype.uuid,
             "project_uuid": octype.project_uuid,
             "source_id": octype.source_id,
             "item_type": "types",
             "repo": "",
             "class_uri": "",
             "label": octype.label,
             "des_predicate_uuid": "",
             "views": 0,
             "published": proj_dates[octype.project_uuid]["earliest"],
             "revised": octype.updated,
         }
         newr = Manifest(**record)
         newr.save()
     return len(octypes)
Exemple #12
0
 def update_manifest_objects_by_project(self, project_uuid):
     """ updates the objects in the manifest for
         a given project
     """
     proj_changed = False
     man_proj = self.get_project_manifest_obj(project_uuid)
     if project_uuid == '0':
         man_proj = Manifest()
         man_proj.published = timezone.now()
         man_proj.revised = timezone.now()
     if man_proj is not False:
         print('-------------------------------------------')
         print('UPDATE proj: ' + project_uuid)
         print('-------------------------------------------')
         if man_proj.published is None:
             proj_changed = True
             man_proj.published = timezone.now()
         if man_proj.revised is None:
             proj_changed = True
             man_proj.revised = timezone.now()
         if proj_changed and project_uuid != '0':
             man_proj.save()
         man_list = Manifest.objects\
                            .filter(project_uuid=project_uuid)\
                            .exclude(item_type='projects')\
                            .iterator()
         for man in man_list:
             item_changed = False
             if man.published is None:
                 item_changed = True
                 man.published = man_proj.published
             if man.revised is None:
                 item_changed = True
                 man.revised = man.record_updated
             if item_changed:
                 print('Updating timestamps on ' + str(man.uuid))
                 man.save()
Exemple #13
0
 def check_exists(self, uuid):
     """ checks to see if the input profile exists """
     if self.exists_ok is None:
         self.uuid = uuid
         ok = True
         try:
             self.inp_prof = InputProfile.objects.get(uuid=uuid)
             self.label = self.inp_prof.label
             self.project_uuid = self.inp_prof.project_uuid
         except InputProfile.DoesNotExist:
             self.inp_prof = False
             ok = False
         if ok and self.project_uuid == '0':
             self.project_man = Manifest()
             self.project_man.label = 'Open Context (General Project)'
             self.project = Project()
             self.project.label = self.project_man.label
             self.project.slug = 'oc'
         if ok and self.project_uuid != '0':
             try:
                 self.project_man = Manifest.objects.get(
                     uuid=self.project_uuid, item_type='projects')
             except Manifest.DoesNotExist:
                 self.project_man = False
                 ok = False
         if ok and self.project_uuid != '0':
             try:
                 self.project = Project.objects.get(uuid=self.project_uuid)
                 self.project.label = self.project_man.label
                 self.project.slug = self.project_man.slug
             except Project.DoesNotExist:
                 self.project = False
                 ok = False
         self.exists_ok = ok
     else:
         ok = self.exists_ok
     return ok
Exemple #14
0
 def update_manifest_objects_by_project(self, project_uuid):
     """ updates the objects in the manifest for
         a given project
     """
     proj_changed = False
     man_proj = self.get_project_manifest_obj(project_uuid)
     if project_uuid == '0':
         man_proj = Manifest()
         man_proj.published = timezone.now()
         man_proj.revised = timezone.now()
     if man_proj is not False:
         print('-------------------------------------------')
         print('UPDATE proj: ' + project_uuid)
         print('-------------------------------------------')
         if man_proj.published is None:
             proj_changed = True
             man_proj.published = timezone.now()
         if man_proj.revised is None:
             proj_changed = True
             man_proj.revised = timezone.now()
         if proj_changed and project_uuid != '0':
             man_proj.save()
         man_list = Manifest.objects\
                            .filter(project_uuid=project_uuid)\
                            .exclude(item_type='projects')\
                            .iterator()
         for man in man_list:
             item_changed = False
             if man.published is None:
                 item_changed = True
                 man.published = man_proj.published
             if man.revised is None:
                 item_changed = True
                 man.revised = man.record_updated
             if item_changed:
                 print('Updating timestamps on ' + str(man.uuid))
                 man.save()
Exemple #15
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)
Exemple #16
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)
Exemple #17
0
 def save_table_manifest_record(self, table_id):
     """ saves a table (public-id) record
         to the manifest
     """
     ex_id = ExpTableIdentifiers()
     ex_id.make_all_identifiers(table_id)
     tab_obj = False
     try:
         tab_obj = ExpTable.objects.get(table_id=ex_id.table_id)
     except Manifest.DoesNotExist:
         tab_obj = False
     if tab_obj is not False:
         man_list = Manifest.objects\
                            .filter(uuid=ex_id.public_table_id)[:1]
         if len(man_list) < 1:
             project_uuid = '0'  # default to all projects
             proj_uuid_counts = self.get_table_project_uuid_counts(ex_id.table_id)
             if len(proj_uuid_counts) == 1:
                 project_uuid = proj_uuid_counts[0]['project_uuid']
             man_obj = Manifest()
             man_obj.uuid = ex_id.public_table_id
             man_obj.project_uuid = project_uuid
             man_obj.source_id = 'exp-tables-management'
             man_obj.item_type = 'tables'
             man_obj.class_uri = ''
             man_obj.label = tab_obj.label
             man_obj.save()
             print('Manifest saved table: ' + str(unidecode(man_obj.label)))
         else:
             man_obj = man_list[0]
             if man_obj.label != tab_obj.label:
                 man_obj.label = tab_obj.label
                 man_obj.save()
                 print('Manifest updated for table: ' + str(unidecode(man_obj.label)))
             else:
                 print('Manifest all ready current for table: ' + str(unidecode(man_obj.label)))
 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
Exemple #19
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
Exemple #20
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 + ''
             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['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()
     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
 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
Exemple #22
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
         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.revised = datetime.datetime.now()
             newman.save()
     return self.oc_type
Exemple #23
0
 def save_table_manifest_record(self, table_id):
     """ saves a table (public-id) record
         to the manifest
     """
     ex_id = ExpTableIdentifiers()
     ex_id.make_all_identifiers(table_id)
     tab_obj = False
     try:
         tab_obj = ExpTable.objects.get(table_id=ex_id.table_id)
     except Manifest.DoesNotExist:
         tab_obj = False
     if tab_obj is not False:
         man_list = Manifest.objects\
                            .filter(uuid=ex_id.public_table_id)[:1]
         if len(man_list) < 1:
             project_uuid = '0'  # default to all projects
             proj_uuid_counts = self.get_table_project_uuid_counts(
                 ex_id.table_id)
             if len(proj_uuid_counts) == 1:
                 project_uuid = proj_uuid_counts[0]['project_uuid']
             man_obj = Manifest()
             man_obj.uuid = ex_id.public_table_id
             man_obj.project_uuid = project_uuid
             man_obj.source_id = 'exp-tables-management'
             man_obj.item_type = 'tables'
             man_obj.class_uri = ''
             man_obj.label = tab_obj.label
             man_obj.save()
             print('Manifest saved table: ' + str(unidecode(man_obj.label)))
         else:
             man_obj = man_list[0]
             if man_obj.label != tab_obj.label:
                 man_obj.label = tab_obj.label
                 man_obj.save()
                 print('Manifest updated for table: ' +
                       str(unidecode(man_obj.label)))
             else:
                 print('Manifest all ready current for table: ' +
                       str(unidecode(man_obj.label)))
Exemple #24
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
Exemple #25
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()
Exemple #26
0
 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()
Exemple #27
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 = ''
         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']
     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 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
Exemple #28
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()
 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 + ''
             self.errors.append(message)
     uuid = self.create_or_validate_uuid(post_data)
     if uuid is False:
         ok = False
         note = '; '.join(self.errors)
     short_id = self.validate_project_short_id(post_data)
     if short_id is False:
         ok = False
         note = '; '.join(self.errors)
     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.short_id = short_id
         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()
         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
Exemple #30
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)
 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
 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()
Exemple #33
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
Exemple #34
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()
Exemple #35
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()
Exemple #36
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
Exemple #37
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()
Exemple #38
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
Exemple #39
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()
Exemple #40
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
Exemple #41
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)
 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
Exemple #43
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()
Exemple #44
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
         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.revised = datetime.datetime.now()
             newman.save()
     return self.oc_type
Exemple #45
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()
Exemple #46
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()
Exemple #47
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
Exemple #48
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
Exemple #49
0
 def add_subjects_from_table(self, source_id, old_table):
     """ adds subjects from a table """
     proj_mappings = {
         'Petra Great Temple Excavations': 'A5DDBEA2-B3C8-43F9-8151-33343CBDC857',
         'Hazor: Zooarchaeology': 'HazorZooPRJ0000000010',
         'San Diego Archaeological Center': '3FAAA477-5572-4B05-8DC1-CA264FE1FC10'
     }
     class_mappings = {
         'Small Find': 'oc-gen:cat-object',
         'Arch. Element': 'oc-gen:cat-arch-element',
         'Locus': 'oc-gen:cat-locus',
         'Non Diag. Bone': 'oc-gen:cat-non-diag-bone'
     }
     filename = old_table + '.csv'
     tab_obj = self.load_csv_file(self.table_dir, filename)
     missing_parents = {}
     if tab_obj is not False:
         i = -1
         context_cells_indexes = []
         label_index = False
         category_index = False
         for row in tab_obj:
             i += 1
             if i == 0:
                 cc = 0
                 for cell in row:
                     if 'Context (' in cell:
                         context_cells_indexes.append(cc)
                     if 'Item name' == cell:
                         label_index = cc
                     if 'Category' == cell:
                         category_index = cc
                     cc += 1
             elif i > 0 and label_index is not False \
                 and category_index is not False:
                 # OK to generate a new item
                 uuid = row[0]
                 label = row[label_index]
                 tab_source = row[1]
                 if row[3] in proj_mappings \
                    and row[category_index] in class_mappings:
                     class_uri = class_mappings[row[category_index]]
                     project_uuid = proj_mappings[row[3]]
                     parent_contexts = []
                     for context_cell_index in context_cells_indexes:
                         parent_contexts.append(row[context_cell_index])
                     parent_context = '/'.join(parent_contexts)
                     par_sub = Subject.objects\
                                      .filter(project_uuid=project_uuid,
                                              context=parent_context)[:1]
                     if len(par_sub) < 1:
                         print('Cannot find parent: ' + parent_context)
                     else:
                         print('Found parent: ' + parent_context)
                         parent_uuid = par_sub[0].uuid
                         try:
                             parent_ok = Manifest.objects.get(uuid=parent_uuid)
                         except Manifest.DoesNotExist:
                             parent_ok = False
                         if parent_ok is not False:
                             # we have a parent, so make the bone
                             man = Manifest()
                             m_ass = ManageAssertions()
                             m_ass.source_id = source_id
                             su_gen = SubjectGeneration()
                             man.uuid = uuid
                             man.label = label
                             man.source_id = source_id
                             man.item_type = 'subjects'
                             man.class_uri = class_uri
                             man.project_uuid = project_uuid
                             man.save()
                             m_ass.add_containment_assertion(parent_uuid, man.uuid)
                             su_gen.generate_save_context_path_from_manifest_obj(man)
                             print('Added: ' + uuid + ' from ' + tab_source)
                         else:
                             missing_parents[parent_uuid] = {'label': parent_label, 'tab': tab_source}
             else:
                 if i > 0:
                     print('Strange problems...')
                     raise('Check: ' + str(row))
         print('Missing parents: ' + str(missing_parents))
Exemple #50
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)