예제 #1
0
	def __list_nodes(self, options):

		data = []

		try:
			rm = GraphModel.objects.get(graphid=options['graph'])
		except GraphModel.DoesNotExist:
			rm = None

		if rm is None:
			self.__error("", "Invalid or missing graph UUID. Use --graph")
		else:
			for node in Node.objects.filter(graph=rm):
				value = {"nodeid": str(node.nodeid), "name": node.name, "datatype": str(node.datatype), "key": (re.sub(r'[^A-Z_]+', '_', node.name.replace(' ', '_').upper().strip('_')))}
				if ((value['datatype'] == 'concept') or (value['datatype'] == 'concept-list')):
					if 'rdmCollection' in node.config:
						conceptid = node.config['rdmCollection']
						if not(conceptid is None):
							values = Concept().get_e55_domain(conceptid)
							value['values'] = []
							for item in values:
								valueobj = get_preflabel_from_valueid(item['id'], 'en')
								valueid = valueobj['id']
								label = get_preflabel_from_valueid(valueid, 'en')
								value['values'].append({'valueid': valueid, 'conceptid': item['conceptid'], 'label': label['value']})
								for child in Concept().get_child_concepts(item['conceptid']):
									value['values'].append({'valueid': child[2], 'conceptid': child[0], 'label': child[1]})
				data.append(value)

		return data
예제 #2
0
def get_related_resources(resourceid, lang, limit=1000, start=0):
    ret = {'resource_relationships': [], 'related_resources': []}
    se = SearchEngineFactory().create()

    query = Query(se, limit=limit, start=start)
    query.add_filter(Terms(field='entityid1', terms=resourceid).dsl,
                     operator='or')
    query.add_filter(Terms(field='entityid2', terms=resourceid).dsl,
                     operator='or')
    resource_relations = query.search(index='resource_relations',
                                      doc_type='all')
    ret['total'] = resource_relations['hits']['total']

    entityids = set()
    for relation in resource_relations['hits']['hits']:
        relation['_source']['preflabel'] = get_preflabel_from_valueid(
            relation['_source']['relationshiptype'], lang)
        ret['resource_relationships'].append(relation['_source'])
        entityids.add(relation['_source']['entityid1'])
        entityids.add(relation['_source']['entityid2'])
    if len(entityids) > 0:
        entityids.remove(resourceid)

    related_resources = se.search(index='entity',
                                  doc_type='_all',
                                  id=list(entityids))
    if related_resources:
        for resource in related_resources['docs']:
            ret['related_resources'].append(resource['_source'])

    return ret
예제 #3
0
파일: resource.py 프로젝트: azerbini/eamena
    def get_related_resources(self, lang='en-US', limit=1000, start=0):
        """
        Returns an object that lists the related resources, the relationship types, and a reference to the current resource

        """

        ret = {
            'resource_instance': self,
            'resource_relationships': [],
            'related_resources': []
        }
        se = SearchEngineFactory().create()
        query = Query(se, limit=limit, start=start)
        bool_filter = Bool()
        bool_filter.should(Terms(field='resourceinstanceidfrom', terms=self.resourceinstanceid))
        bool_filter.should(Terms(field='resourceinstanceidto', terms=self.resourceinstanceid))
        query.add_query(bool_filter)
        resource_relations = query.search(index='resource_relations', doc_type='all')
        ret['total'] = resource_relations['hits']['total']
        instanceids = set()
        for relation in resource_relations['hits']['hits']:
            relation['_source']['preflabel'] = get_preflabel_from_valueid(relation['_source']['relationshiptype'], lang)
            ret['resource_relationships'].append(relation['_source'])
            instanceids.add(relation['_source']['resourceinstanceidto'])
            instanceids.add(relation['_source']['resourceinstanceidfrom'])
        if len(instanceids) > 0:
            instanceids.remove(str(self.resourceinstanceid))

        related_resources = se.search(index='resource', doc_type='_all', id=list(instanceids))
        if related_resources:
            for resource in related_resources['docs']:
                ret['related_resources'].append(resource['_source'])

        return ret
예제 #4
0
    def get_related_resources(self, lang='en-US', limit=settings.RELATED_RESOURCES_EXPORT_LIMIT, start=0, page=0):
        """
        Returns an object that lists the related resources, the relationship types, and a reference to the current resource

        """
        graphs = models.GraphModel.objects.all().exclude(
            pk=settings.SYSTEM_SETTINGS_RESOURCE_MODEL_ID).exclude(isresource=False)
        graph_lookup = {str(graph.graphid): {
            'name': graph.name, 'iconclass': graph.iconclass, 'fillColor': graph.color} for graph in graphs}
        ret = {
            'resource_instance': self,
            'resource_relationships': [],
            'related_resources': [],
            'node_config_lookup': graph_lookup
        }
        se = SearchEngineFactory().create()

        if page > 0:
            limit = settings.RELATED_RESOURCES_PER_PAGE
            start = limit*int(page-1)

        def get_relations(resourceinstanceid, start, limit):
            query = Query(se, start=start, limit=limit)
            bool_filter = Bool()
            bool_filter.should(
                Terms(field='resourceinstanceidfrom', terms=resourceinstanceid))
            bool_filter.should(
                Terms(field='resourceinstanceidto', terms=resourceinstanceid))
            query.add_query(bool_filter)
            return query.search(index='resource_relations')

        resource_relations = get_relations(
            self.resourceinstanceid, start, limit)
        ret['total'] = resource_relations['hits']['total']
        instanceids = set()

        for relation in resource_relations['hits']['hits']:
            try:
                preflabel = get_preflabel_from_valueid(
                    relation['_source']['relationshiptype'], lang)
                relation['_source']['relationshiptype_label'] = preflabel['value']
            except:
                relation['_source']['relationshiptype_label'] = relation['_source']['relationshiptype']

            ret['resource_relationships'].append(relation['_source'])
            instanceids.add(relation['_source']['resourceinstanceidto'])
            instanceids.add(relation['_source']['resourceinstanceidfrom'])
        if len(instanceids) > 0:
            instanceids.remove(str(self.resourceinstanceid))

        if len(instanceids) > 0:
            related_resources = se.search(index='resources', id=list(instanceids))
            if related_resources:
                for resource in related_resources['docs']:
                    relations = get_relations(resource['_id'], 0, 0)
                    resource['_source']['total_relations'] = relations['hits']['total']
                    ret['related_resources'].append(resource['_source'])
        return ret
예제 #5
0
    def get_related_resources(
        self, lang="en-US", limit=settings.RELATED_RESOURCES_EXPORT_LIMIT, start=0, page=0,
    ):
        """
        Returns an object that lists the related resources, the relationship types, and a reference to the current resource

        """
        graphs = (
            models.GraphModel.objects.all()
            .exclude(pk=settings.SYSTEM_SETTINGS_RESOURCE_MODEL_ID)
            .exclude(isresource=False)
            .exclude(isactive=False)
        )
        graph_lookup = {
            str(graph.graphid): {"name": graph.name, "iconclass": graph.iconclass, "fillColor": graph.color} for graph in graphs
        }
        ret = {"resource_instance": self, "resource_relationships": [], "related_resources": [], "node_config_lookup": graph_lookup}
        se = SearchEngineFactory().create()

        if page > 0:
            limit = settings.RELATED_RESOURCES_PER_PAGE
            start = limit * int(page - 1)

        def get_relations(resourceinstanceid, start, limit):
            query = Query(se, start=start, limit=limit)
            bool_filter = Bool()
            bool_filter.should(Terms(field="resourceinstanceidfrom", terms=resourceinstanceid))
            bool_filter.should(Terms(field="resourceinstanceidto", terms=resourceinstanceid))
            query.add_query(bool_filter)
            return query.search(index="resource_relations")

        resource_relations = get_relations(self.resourceinstanceid, start, limit)
        ret["total"] = resource_relations["hits"]["total"]
        instanceids = set()

        for relation in resource_relations["hits"]["hits"]:
            try:
                preflabel = get_preflabel_from_valueid(relation["_source"]["relationshiptype"], lang)
                relation["_source"]["relationshiptype_label"] = preflabel["value"]
            except:
                relation["_source"]["relationshiptype_label"] = relation["_source"]["relationshiptype"]

            ret["resource_relationships"].append(relation["_source"])
            instanceids.add(relation["_source"]["resourceinstanceidto"])
            instanceids.add(relation["_source"]["resourceinstanceidfrom"])
        if len(instanceids) > 0:
            instanceids.remove(str(self.resourceinstanceid))

        if len(instanceids) > 0:
            related_resources = se.search(index="resources", id=list(instanceids))
            if related_resources:
                for resource in related_resources["docs"]:
                    relations = get_relations(resource["_id"], 0, 0)
                    resource["_source"]["total_relations"] = relations["hits"]["total"]
                    ret["related_resources"].append(resource["_source"])
        return ret
예제 #6
0
파일: resource.py 프로젝트: u5673710/arches
    def get_related_resources(self, lang='en-US', limit=1000, start=0):
        """
        Returns an object that lists the related resources, the relationship types, and a reference to the current resource

        """

        ret = {
            'resource_instance': self,
            'resource_relationships': [],
            'related_resources': []
        }
        se = SearchEngineFactory().create()

        def get_relations(resourceinstanceid, start, limit):
            query = Query(se, limit=limit, start=start)
            bool_filter = Bool()
            bool_filter.should(
                Terms(field='resourceinstanceidfrom',
                      terms=resourceinstanceid))
            bool_filter.should(
                Terms(field='resourceinstanceidto', terms=resourceinstanceid))
            query.add_query(bool_filter)
            return query.search(index='resource_relations', doc_type='all')

        resource_relations = get_relations(self.resourceinstanceid, start,
                                           limit)
        ret['total'] = resource_relations['hits']['total']
        instanceids = set()

        for relation in resource_relations['hits']['hits']:
            try:
                preflabel = get_preflabel_from_valueid(
                    relation['_source']['relationshiptype'], lang)
                relation['_source']['relationshiptype_label'] = preflabel[
                    'value']
            except:
                relation['_source']['relationshiptype_label'] = relation[
                    '_source']['relationshiptype']

            ret['resource_relationships'].append(relation['_source'])
            instanceids.add(relation['_source']['resourceinstanceidto'])
            instanceids.add(relation['_source']['resourceinstanceidfrom'])
        if len(instanceids) > 0:
            instanceids.remove(str(self.resourceinstanceid))

        related_resources = se.search(index='resource',
                                      doc_type='_all',
                                      id=list(instanceids))
        if related_resources:
            for resource in related_resources['docs']:
                relations = get_relations(resource['_id'], 0, 0)
                resource['_source']['total_relations'] = relations['hits'][
                    'total']
                ret['related_resources'].append(resource['_source'])
        return ret
예제 #7
0
 def get_pref_label(self, nodevalue, lang='en-US'):
     return get_preflabel_from_valueid(nodevalue, lang)['value']
예제 #8
0
    def get_related_resources(
        self,
        lang="en-US",
        limit=settings.RELATED_RESOURCES_EXPORT_LIMIT,
        start=0,
        page=0,
        user=None,
        resourceinstance_graphid=None,
    ):
        """
        Returns an object that lists the related resources, the relationship types, and a reference to the current resource

        """
        graphs = (models.GraphModel.objects.all().exclude(
            pk=settings.SYSTEM_SETTINGS_RESOURCE_MODEL_ID).exclude(
                isresource=False).exclude(isactive=False))

        graph_lookup = {
            str(graph.graphid): {
                "name": graph.name,
                "iconclass": graph.iconclass,
                "fillColor": graph.color
            }
            for graph in graphs
        }

        ret = {
            "resource_instance": self,
            "resource_relationships": [],
            "related_resources": [],
            "node_config_lookup": graph_lookup
        }

        if page > 0:
            limit = settings.RELATED_RESOURCES_PER_PAGE
            start = limit * int(page - 1)

        def get_relations(resourceinstanceid,
                          start,
                          limit,
                          resourceinstance_graphid=None):
            query = Query(se, start=start, limit=limit)
            bool_filter = Bool()
            bool_filter.should(
                Terms(field="resourceinstanceidfrom",
                      terms=resourceinstanceid))
            bool_filter.should(
                Terms(field="resourceinstanceidto", terms=resourceinstanceid))

            if resourceinstance_graphid:
                graph_filter = Bool()
                to_graph_id_filter = Bool()
                to_graph_id_filter.filter(
                    Terms(field="resourceinstancefrom_graphid",
                          terms=str(self.graph_id)))
                to_graph_id_filter.filter(
                    Terms(field="resourceinstanceto_graphid",
                          terms=resourceinstance_graphid))
                graph_filter.should(to_graph_id_filter)

                from_graph_id_filter = Bool()
                from_graph_id_filter.filter(
                    Terms(field="resourceinstancefrom_graphid",
                          terms=resourceinstance_graphid))
                from_graph_id_filter.filter(
                    Terms(field="resourceinstanceto_graphid",
                          terms=str(self.graph_id)))
                graph_filter.should(from_graph_id_filter)
                bool_filter.must(graph_filter)

            query.add_query(bool_filter)

            return query.search(index=RESOURCE_RELATIONS_INDEX)

        resource_relations = get_relations(
            resourceinstanceid=self.resourceinstanceid,
            start=start,
            limit=limit,
            resourceinstance_graphid=resourceinstance_graphid,
        )

        ret["total"] = resource_relations["hits"]["total"]
        instanceids = set()

        restricted_instances = get_restricted_instances(
            user, se) if user is not None else []
        for relation in resource_relations["hits"]["hits"]:
            try:
                preflabel = get_preflabel_from_valueid(
                    relation["_source"]["relationshiptype"], lang)
                relation["_source"][
                    "relationshiptype_label"] = preflabel["value"] or ""
            except:
                relation["_source"]["relationshiptype_label"] = relation[
                    "_source"]["relationshiptype"] or ""

            resourceid_to = relation["_source"]["resourceinstanceidto"]
            resourceid_from = relation["_source"]["resourceinstanceidfrom"]
            if resourceid_to not in restricted_instances and resourceid_from not in restricted_instances:
                ret["resource_relationships"].append(relation["_source"])
                instanceids.add(resourceid_to)
                instanceids.add(resourceid_from)
            else:
                ret["total"]["value"] -= 1

        if str(self.resourceinstanceid) in instanceids:
            instanceids.remove(str(self.resourceinstanceid))

        if len(instanceids) > 0:
            related_resources = se.search(index=RESOURCES_INDEX,
                                          id=list(instanceids))
            if related_resources:
                for resource in related_resources["docs"]:
                    relations = get_relations(
                        resourceinstanceid=resource["_id"],
                        start=0,
                        limit=0,
                    )
                    if resource["found"]:
                        resource["_source"]["total_relations"] = relations[
                            "hits"]["total"]
                        ret["related_resources"].append(resource["_source"])

        return ret
예제 #9
0
파일: resource.py 프로젝트: fargeo/arches
    def get_related_resources(self, lang='en-US', limit=settings.RELATED_RESOURCES_EXPORT_LIMIT, start=0, page=0):
        """
        Returns an object that lists the related resources, the relationship types, and a reference to the current resource

        """
        root_nodes = models.Node.objects.filter(istopnode=True)
        node_config_lookup = {}
        graphs = models.GraphModel.objects.all().exclude(pk=settings.SYSTEM_SETTINGS_RESOURCE_MODEL_ID).exclude(isresource=False)
        graph_lookup = {str(graph.graphid): {'name':graph.name, 'iconclass': graph.iconclass} for graph in graphs}
        for node in root_nodes:
            graph_id = unicode(node.graph_id)
            if node.config != None and graph_id in graph_lookup:
                node_config_lookup[graph_id] = node.config
                node_config_lookup[graph_id]['iconclass'] = graph_lookup[graph_id]['iconclass']
                node_config_lookup[graph_id]['name'] = graph_lookup[graph_id]['name']

        ret = {
            'resource_instance': self,
            'resource_relationships': [],
            'related_resources': [],
            'node_config_lookup': node_config_lookup
        }
        se = SearchEngineFactory().create()

        if page > 0:
            limit = settings.RELATED_RESOURCES_PER_PAGE
            start = limit*int(page-1)

        def get_relations(resourceinstanceid, start, limit):
            query = Query(se, start=start, limit=limit)
            bool_filter = Bool()
            bool_filter.should(Terms(field='resourceinstanceidfrom', terms=resourceinstanceid))
            bool_filter.should(Terms(field='resourceinstanceidto', terms=resourceinstanceid))
            query.add_query(bool_filter)
            return query.search(index='resource_relations', doc_type='all')

        resource_relations = get_relations(self.resourceinstanceid, start, limit)
        ret['total'] = resource_relations['hits']['total']
        instanceids = set()

        for relation in resource_relations['hits']['hits']:
            try:
                preflabel = get_preflabel_from_valueid(relation['_source']['relationshiptype'], lang)
                relation['_source']['relationshiptype_label'] = preflabel['value']
            except:
                relation['_source']['relationshiptype_label'] = relation['_source']['relationshiptype']

            ret['resource_relationships'].append(relation['_source'])
            instanceids.add(relation['_source']['resourceinstanceidto'])
            instanceids.add(relation['_source']['resourceinstanceidfrom'])
        if len(instanceids) > 0:
            instanceids.remove(str(self.resourceinstanceid))

        if len(instanceids) > 0:
            related_resources = se.search(index='resource', doc_type='_all', id=list(instanceids))
            if related_resources:
                for resource in related_resources['docs']:
                    relations = get_relations(resource['_id'], 0, 0)
                    resource['_source']['total_relations'] = relations['hits']['total']
                    ret['related_resources'].append(resource['_source'])
        return ret
예제 #10
0
def get_pref_label(request):
    valueid = request.GET.get('valueid')
    label = get_preflabel_from_valueid(valueid, settings.LANGUAGE_CODE)
    return JSONResponse(label)
예제 #11
0
 def get_pref_label(self, nodevalue, lang="en-US"):
     return get_preflabel_from_valueid(nodevalue, lang)["value"]
예제 #12
0
파일: concept.py 프로젝트: legiongis/arches
def get_pref_label(request):
    valueid = request.GET.get("valueid")
    label = get_preflabel_from_valueid(valueid, request.LANGUAGE_CODE)
    return JSONResponse(label)
예제 #13
0
 def get_pref_label(self, nodevalue, lang='en-US'):
     return get_preflabel_from_valueid(nodevalue, lang)['value']
예제 #14
0
파일: concept.py 프로젝트: fargeo/arches
def get_pref_label(request):
    valueid = request.GET.get('valueid')
    label = get_preflabel_from_valueid(valueid, settings.LANGUAGE_CODE)
    return JSONResponse(label)
예제 #15
0
    def get_related_resources(self,
                              lang='en-US',
                              limit=settings.RELATED_RESOURCES_EXPORT_LIMIT,
                              start=0,
                              page=0):
        """
        Returns an object that lists the related resources, the relationship types, and a reference to the current resource

        """
        root_nodes = models.Node.objects.filter(istopnode=True)
        node_config_lookup = {}

        for node in root_nodes:
            graph_id = unicode(node.graph_id)
            if node.config != None:
                node_config_lookup[graph_id] = node.config
                node_config_lookup[graph_id][
                    'iconclass'] = node.graph.iconclass
                node_config_lookup[graph_id]['name'] = node.graph.name

        ret = {
            'resource_instance':
            self,
            'resource_relationships': [],
            'related_resources': [],
            'root_node_config':
            models.Node.objects.filter(graph_id=self.graph.graphid).filter(
                istopnode=True)[0].config,
            'node_config_lookup':
            node_config_lookup
        }
        se = SearchEngineFactory().create()

        if page > 0:
            limit = settings.RELATED_RESOURCES_PER_PAGE
            start = limit * int(page - 1)

        def get_relations(resourceinstanceid, start, limit):
            query = Query(se, start=start, limit=limit)
            bool_filter = Bool()
            bool_filter.should(
                Terms(field='resourceinstanceidfrom',
                      terms=resourceinstanceid))
            bool_filter.should(
                Terms(field='resourceinstanceidto', terms=resourceinstanceid))
            query.add_query(bool_filter)
            return query.search(index='resource_relations', doc_type='all')

        resource_relations = get_relations(self.resourceinstanceid, start,
                                           limit)
        ret['total'] = resource_relations['hits']['total']
        instanceids = set()

        for relation in resource_relations['hits']['hits']:
            try:
                preflabel = get_preflabel_from_valueid(
                    relation['_source']['relationshiptype'], lang)
                relation['_source']['relationshiptype_label'] = preflabel[
                    'value']
            except:
                relation['_source']['relationshiptype_label'] = relation[
                    '_source']['relationshiptype']

            ret['resource_relationships'].append(relation['_source'])
            instanceids.add(relation['_source']['resourceinstanceidto'])
            instanceids.add(relation['_source']['resourceinstanceidfrom'])
        if len(instanceids) > 0:
            instanceids.remove(str(self.resourceinstanceid))

        if len(instanceids) > 0:
            related_resources = se.search(index='resource',
                                          doc_type='_all',
                                          id=list(instanceids))
            if related_resources:
                for resource in related_resources['docs']:
                    relations = get_relations(resource['_id'], 0, 0)
                    resource['_source']['total_relations'] = relations['hits'][
                        'total']
                    ret['related_resources'].append(resource['_source'])
        return ret