def get_parents_context_metadata(self, uuid): """ get all parents from memory or by DB lookups """ if len(self.parents) >= 5000: self.parents = {} par_res = Assertion.objects\ .filter(object_uuid=uuid, predicate_uuid=Assertion.PREDICATES_CONTAINS)[:1] if len(par_res) > 0: # item has a parent parent_uuid = par_res[0].uuid if parent_uuid not in self.parents: # we don't have a context path parent list for this parent in memory yet # so let's go and make it p_list = [] act_contain = Containment() raw_parents = act_contain.get_parents_by_child_uuid(parent_uuid) if raw_parents is not False: if len(raw_parents) > 0: for tree_node, r_parents in raw_parents.items(): p_list = r_parents break p_list.insert(0, parent_uuid) # add the 1st parent to the start of the list context_metadata = {'p_list': p_list} self.parents[parent_uuid] = context_metadata else: context_metadata = self.parents[parent_uuid] else: parent_uuid = False # now get geo and chrono metadata context_metadata = self.get_geo_chrono_metadata(uuid, parent_uuid, context_metadata) return context_metadata
def delete_by_uuid(self, delete_uuid): """ Deletes an item by uuid, returns dictionary object with information about deletion """ self.delete_uuid = delete_uuid output = {} output['done'] = False ok_delete = self.prep_delete_uuid(delete_uuid) if ok_delete: if self.delete_manifest_obj.item_type == 'subjects': cont = Containment() self.delete_children = cont.get_children_by_parent_uuid(delete_uuid, True) cont = Containment() parents = cont.get_parents_by_child_uuid(delete_uuid, False) if len(cont.contexts_list) > 0: parent_uuid = cont.contexts_list[0] # use the deleted item's parent as the new parent for it's child items output['containment'] = self.alter_assertions_by_role('subjects', delete_uuid, parent_uuid, Assertion.PREDICATES_CONTAINS) if ok_delete: output['assertions'] = self.alter_assertions(delete_uuid, False) output['annotations'] = self.alter_annotations(delete_uuid, False) output['altered_children'] = self.update_children_subjects(self.delete_children) output['message'] = 'Deleted item: ' + self.delete_manifest_obj.label + '(' + delete_uuid + ')' self.delete_manifest_obj.delete() # deletes object from the manifest self.delete_type_records(delete_uuid, delete_manifest_obj.item_type) output['done'] = True return output
def generate_context_path(self, uuid, include_self=True, delim='/'): """ generates a context path for a subject with a given uuid """ path = False act_contain = Containment() act_contain.redis_ok = False contexts = [] r_contexts = act_contain.get_parents_by_child_uuid(uuid) for tree_node, r_parents in r_contexts.items(): # now reverse the list of parent contexts, so top most parent context is first, # followed by children contexts contexts = r_parents[::-1] if (include_self): contexts.append(uuid) if (len(contexts) > 0): path_items = [] for p_uuid in contexts: try: act_p = Manifest.objects.get(uuid=p_uuid) path_items.append(act_p.label) except Manifest.DoesNotExist: return False path = delim.join(path_items) return path
def generate_context_path(self, uuid, include_self=True, delim='/'): """ generates a context path for a subject with a given uuid """ path = False act_contain = Containment() act_contain.redis_ok = False contexts = [] r_contexts = act_contain.get_parents_by_child_uuid(uuid) for tree_node, r_parents in r_contexts.items(): # now reverse the list of parent contexts, so top most parent context is first, # followed by children contexts contexts = r_parents[::-1] if(include_self): contexts.append(uuid) if(len(contexts) > 0): path_items = [] for p_uuid in contexts: try: act_p = Manifest.objects.get(uuid=p_uuid) path_items.append(act_p.label) except Manifest.DoesNotExist: return False path = delim.join(path_items) return path
def get_parents_context_metadata(self, uuid): """ get all parents from memory or by DB lookups """ if len(self.parents) >= 5000: self.parents = {} par_res = Assertion.objects\ .filter(object_uuid=uuid, predicate_uuid=Assertion.PREDICATES_CONTAINS)[:1] if len(par_res) > 0: # item has a parent parent_uuid = par_res[0].uuid if parent_uuid not in self.parents: # we don't have a context path parent list for this parent in memory yet # so let's go and make it p_list = [] act_contain = Containment() raw_parents = act_contain.get_parents_by_child_uuid( parent_uuid) if raw_parents is not False: if len(raw_parents) > 0: for tree_node, r_parents in raw_parents.items(): p_list = r_parents break p_list.insert( 0, parent_uuid) # add the 1st parent to the start of the list context_metadata = {'p_list': p_list} self.parents[parent_uuid] = context_metadata else: context_metadata = self.parents[parent_uuid] else: parent_uuid = False # now get geo and chrono metadata context_metadata = self.get_geo_chrono_metadata( uuid, parent_uuid, context_metadata) return context_metadata
def get_spatial_temporal_context(self): """ gets the item spatial context """ act_contain = Containment() if self.manifest.item_type == 'subjects': # get item geospatial and chronological metadata if subject item # will do it differently if not a subject item parents = act_contain.get_parents_by_child_uuid(self.manifest.uuid) self.contexts = parents # prepare a list of contexts (including the current item) to check for # geospatial and event / chronology metadata subject_list = act_contain.contexts_list subject_list.insert(0, self.manifest.uuid) self.geo_meta = act_contain.get_geochron_from_subject_list( subject_list, 'geo') self.temporal_meta = act_contain.get_geochron_from_subject_list( subject_list, 'temporal') self.event_meta = act_contain.get_geochron_from_subject_list( subject_list, 'event') # now get any children items, contained in this "subjects" item act_contain = Containment() self.contents = act_contain.get_children_by_parent_uuid( self.manifest.uuid) else: parents = act_contain.get_related_context(self.manifest.uuid) self.contexts = False self.linked_contexts = parents if self.manifest.item_type == 'projects': # get project metadata objects directly pm = ProjectMeta() project = self.item_gen_cache.get_project_model_object( self.manifest.uuid) sub_projects = self.item_gen_cache.get_project_subprojects( self.manifest.uuid) if project is not None: if isinstance(project.meta_json, dict): if Project.META_KEY_GEO_SPECIFICITY in project.meta_json: # the project has some default geographic specificity noted # use this value when making geo_meta pm.project_specificity = project.meta_json[ Project.META_KEY_GEO_SPECIFICITY] self.geo_meta = pm.get_project_geo_from_db(self.manifest.uuid) if self.geo_meta is False: # make geospatial metadata for the project, and sub-projects if they exist pm.make_geo_meta(self.manifest.uuid, sub_projects) self.geo_meta = pm.geo_objs act_contain = Containment() if self.geo_meta is False: self.geo_meta = act_contain.get_related_geochron( self.manifest.uuid, self.manifest.item_type, 'geo') if self.temporal_meta is False: self.temporal_meta = act_contain.get_related_geochron( self.manifest.uuid, self.manifest.item_type, 'temporal') if self.temporal_meta is False: # now look in the project for temporal metadata self.temporal_meta = act_contain.get_temporal_from_project( self.manifest.project_uuid) if self.event_meta is False: self.event_meta = act_contain.get_related_geochron( self.manifest.uuid, self.manifest.item_type, 'event')
def get_geo_event_metadata(self): """ gets geospatial and event metadata for the item """ if self.is_valid: act_contain = Containment() if self.manifest.item_type == 'subjects': parents = act_contain.get_parents_by_child_uuid( self.manifest.uuid) subject_list = act_contain.contexts_list subject_list.insert(0, self.manifest.uuid) self.geo_meta = act_contain.get_geochron_from_subject_list( subject_list, 'geo') self.event_meta = act_contain.get_geochron_from_subject_list( subject_list, 'event') else: self.geo_meta = act_contain.get_related_geochron( self.manifest.uuid, self.manifest.item_type, 'geo') self.event_meta = act_contain.get_related_geochron( self.manifest.uuid, self.manifest.item_type, 'event') if self.event_meta is not False and self.event_meta is not None: start = None stop = None for event in self.event_meta: if start is None: start = event.start if stop is None: stop = event.stop if start < event.start: start = event.start if stop > event.stop: stop = event.stop if stop is None: stop = start if start is not None: if stop < start: stop_temp = start start = stop stop = stop_temp # we have a start year, so make a temporal value in ISON 8601 format self.temporal = ISOyears().make_iso_from_float(start) if stop != start: # stop year different from start, so add a / sep and the stop # year in ISO 8601 format self.temporal += '/' + ISOyears().make_iso_from_float( stop) if self.temporal is None and self.manifest.item_type == 'projects': # get project teporal metadata via solr # now query Solr for temporal data cq = CompleteQuery() payload = {'proj': self.manifest.slug} ass_metadata = cq.get_json_query(payload, None) if 'dc-terms:temporal' in ass_metadata: self.temporal = ass_metadata['dc-terms:temporal']
def get_geo_event_metadata(self): """ gets geospatial and event metadata for the item """ if self.is_valid: act_contain = Containment() if self.manifest.item_type == 'subjects': parents = act_contain.get_parents_by_child_uuid(self.manifest.uuid) subject_list = act_contain.contexts_list subject_list.insert(0, self.manifest.uuid) self.geo_meta = act_contain.get_geochron_from_subject_list(subject_list, 'geo') self.event_meta = act_contain.get_geochron_from_subject_list(subject_list, 'event') else: self.geo_meta = act_contain.get_related_geochron(self.manifest.uuid, self.manifest.item_type, 'geo') self.event_meta = act_contain.get_related_geochron(self.manifest.uuid, self.manifest.item_type, 'event') if self.event_meta is not False and self.event_meta is not None: start = None stop = None for event in self.event_meta: if start is None: start = event.start if stop is None: stop = event.stop if start < event.start: start = event.start if stop > event.stop: stop = event.stop if stop is None: stop = start if start is not None: if stop < start: stop_temp = start start = stop stop = stop_temp # we have a start year, so make a temporal value in ISON 8601 format self.temporal = ISOyears().make_iso_from_float(start) if stop != start: # stop year different from start, so add a / sep and the stop # year in ISO 8601 format self.temporal += '/' + ISOyears().make_iso_from_float(stop) if self.temporal is None and self.manifest.item_type == 'projects': # get project teporal metadata via solr # now query Solr for temporal data cq = CompleteQuery() payload = {'proj': self.manifest.slug} ass_metadata = cq.get_json_query(payload, None) if 'dc-terms:temporal' in ass_metadata: self.temporal = ass_metadata['dc-terms:temporal']
def get_geo_event_metadata(self): """ gets geospatial and event metadata for the item """ if self.is_valid: act_contain = Containment() if self.manifest.item_type == 'subjects': parents = act_contain.get_parents_by_child_uuid(self.manifest.uuid) subject_list = act_contain.contexts_list subject_list.insert(0, self.manifest.uuid) self.geo_meta = act_contain.get_geochron_from_subject_list(subject_list, 'geo') self.event_meta = act_contain.get_geochron_from_subject_list(subject_list, 'event') if self.event_meta is not False and self.event_meta is not None: start = None stop = None for event in self.event_meta: if start is None: start = event.start if stop is None: stop = event.stop if start < event.start: start = event.start if stop > event.stop: stop = event.stop if stop is None: stop = start if start is not None: if stop < start: stop_temp = start start = stop stop = stop_temp # we have a start year, so make a temporal value in ISON 8601 format self.temporal = ISOyears().make_iso_from_float(start) if stop != start: # stop year different from start, so add a / sep and the stop # year in ISO 8601 format self.temporal += '/' + ISOyears().make_iso_from_float(stop)