예제 #1
0
 def create(id='', value=''):
     entity = Entity()
     entity.entityid = id
     entity.entitytypeid = 'TEST.E1'
     entity.property = 'P1'
     entity.value = value
     entity.child_entities = []
     return entity
예제 #2
0
 def create(id='', value=''):
     entity = Entity()
     entity.entityid = id
     entity.entitytypeid = 'TEST.E1'
     entity.property = 'P1'
     entity.value = value
     entity.child_entities = []
     return entity
예제 #3
0
    def prepare_documents_for_report_index(self, geom_entities=[]):
        """
        Generates a list of specialized resource based documents to support resource reports

        """

        geojson_geom = None
        if len(geom_entities) > 0:
            geojson_geom = {
                'type': 'GeometryCollection',
                'geometries': [geom_entity['value'] for geom_entity in geom_entities]
            }

        entity_dict = Entity()
        entity_dict.property = self.property
        entity_dict.entitytypeid = self.entitytypeid
        entity_dict.entityid = self.entityid
        entity_dict.primaryname = self.get_primary_name()
        entity_dict.geometry = geojson_geom
        
        entity_dict.graph = self.dictify(keys=['label', 'value'])
        return [JSONSerializer().serializeToPython(entity_dict)]
예제 #4
0
    def prepare_documents_for_search_index(self):
        """
        Generates a list of specialized resource based documents to support resource search

        """

        document = Entity()
        document.property = self.property
        document.entitytypeid = self.entitytypeid
        document.entityid = self.entityid
        document.value = self.value
        document.label = self.label
        document.businesstablename = self.businesstablename
        document.primaryname = self.get_primary_name()
        document.child_entities = []
        document.dates = []
        document.domains = []
        document.geometries = []
        document.numbers = []

        for entity in self.flatten():
            if entity.entityid != self.entityid:
                if entity.businesstablename == 'domains':
                    value = archesmodels.Values.objects.get(pk=entity.value)
                    entity_copy = entity.copy()
                    entity_copy.conceptid = value.conceptid_id
                    document.domains.append(entity_copy)
                elif entity.businesstablename == 'dates':
                    document.dates.append(entity)
                elif entity.businesstablename == 'numbers':
                    document.numbers.append(entity)
                elif entity.businesstablename == 'geometries':
                    entity.value = JSONDeserializer().deserialize(
                        fromstr(entity.value).json)
                    document.geometries.append(entity)
                else:
                    document.child_entities.append(entity)

        return [JSONSerializer().serializeToPython(document)]
예제 #5
0
    def prepare_documents_for_search_index(self):
        """
        Generates a list of specialized resource based documents to support resource search

        """

        document = Entity()
        document.property = self.property
        document.entitytypeid = self.entitytypeid
        document.entityid = self.entityid
        document.value = self.value
        document.label = self.label
        document.businesstablename = self.businesstablename
        document.primaryname = self.get_primary_name()
        document.child_entities = []
        document.dates = []
        document.domains = []
        document.geometries = []
        document.numbers = []

        for entity in self.flatten():
            if entity.entityid != self.entityid:
                if entity.businesstablename == 'domains':
                    value = archesmodels.Values.objects.get(pk=entity.value)
                    entity_copy = entity.copy()
                    entity_copy.conceptid = value.conceptid_id
                    document.domains.append(entity_copy)
                elif entity.businesstablename == 'dates':
                    document.dates.append(entity)
                elif entity.businesstablename == 'numbers':
                    document.numbers.append(entity)
                elif entity.businesstablename == 'geometries':
                    entity.value = JSONDeserializer().deserialize(fromstr(entity.value).json)
                    document.geometries.append(entity)
                else:
                    document.child_entities.append(entity)

        return [JSONSerializer().serializeToPython(document)]
예제 #6
0
    def prepare_documents_for_report_index(self, geom_entities=[]):
        """
        Generates a list of specialized resource based documents to support resource reports

        """

        geojson_geom = None
        if len(geom_entities) > 0:
            geojson_geom = {
                'type':
                'GeometryCollection',
                'geometries':
                [geom_entity['value'] for geom_entity in geom_entities]
            }

        entity_dict = Entity()
        entity_dict.property = self.property
        entity_dict.entitytypeid = self.entitytypeid
        entity_dict.entityid = self.entityid
        entity_dict.primaryname = self.get_primary_name()
        entity_dict.geometry = geojson_geom

        entity_dict.graph = self.dictify(keys=['label', 'value'])
        return [JSONSerializer().serializeToPython(entity_dict)]
예제 #7
0
    def prepare_documents_for_search_index(self):
        """
        Generates a list of specialized resource based documents to support resource search

        """
        
        document = Entity()
        document.property = self.property
        document.entitytypeid = self.entitytypeid
        document.entityid = self.entityid
        document.value = self.value
        document.label = self.label
        document.businesstablename = self.businesstablename
        document.primaryname = self.get_primary_name()
        document.child_entities = []
        document.dates = []
        document.extendeddates = []
        document.domains = []
        document.geometries = []
        document.numbers = []

        for entity in self.flatten():
            if entity.entityid != self.entityid:
                if entity.businesstablename == 'domains':
                    value = archesmodels.Values.objects.get(pk=entity.value)
                    entity_copy = entity.copy()
                    entity_copy.conceptid = value.conceptid_id
                    document.domains.append(entity_copy)
                elif entity.businesstablename == 'dates':
                    document.dates.append(entity)
                    document.extendeddates.append(entity)
                elif entity.businesstablename == 'numbers':
                    document.numbers.append(entity)
                elif entity.businesstablename == 'geometries':
                    entity.value = JSONDeserializer().deserialize(fromstr(entity.value).json)
                    document.geometries.append(entity)
                else:
                    document.child_entities.append(entity)

                if entity.entitytypeid in settings.EXTENDED_DATE_NODES:
                    document.extendeddates.append(entity)

        doc = JSONSerializer().serializeToPython(document)

        # documents = super(Resource, self).prepare_documents_for_search_index()
        # for doc in documents:
        
        ## index dates to extended date mapping
        for entity in doc['extendeddates']:
            date = date_to_int(entity['value'])
            entity['value'] = date
        
        ## index dates groups to extended date groups mapping
        doc['extendeddategroups'] = []
        for branch,labels in settings.INDEXED_DATE_BRANCH_FORMATIONS.iteritems():
            for nodes in self.get_nodes(branch,keys=['value']):
                doc['extendeddategroups'].append({
                    'value': date_to_int(nodes[labels[0]]),
                    'conceptid': nodes[labels[1]]
                })
    
        return [doc]