Esempio n. 1
0
    def endpointCollection(
            self,
            collection_endpoint,
            entrypoint_node,
            api_doc,
            url):
        """It makes a node for every collection endpoint."""
        print("accessing every collection in entrypoint")
        clas = ClassEndpoints(self.redis_graph, self.class_endpoints)
        for endpoint in collection_endpoint:
            endpoint_method = []
            node_properties = {}
            for support_operation in api_doc.collections[
                    endpoint][
                    "collection"].supportedOperation:
                endpoint_method.append(support_operation.method)
            node_properties["operations"] = str(endpoint_method)
            # all the operations for the collection endpoint is stored in
#            print("supportedOperations",node_properties["operations"])
            node_properties["@id"] = str(collection_endpoint[endpoint])
            node_properties["@type"] = str(endpoint)
            endpoint_collection_node = clas.addNode(
                "collection", endpoint, node_properties)
#            print(endpoint_collection_node)
            clas.addEdge(
                entrypoint_node,
                "has_collection",
                endpoint_collection_node)
    def get_apistructure(self, entrypoint_node, api_doc):
        """ It breaks the endpoint into two parts collection and classes"""
        self.collection_endpoints = {}
        self.class_endpoints = {}
        print(
            "split entrypoint into 2 types of endpoints collection and classes"
        )
        for support_property in api_doc.entrypoint.entrypoint.supportedProperty:
            if isinstance(support_property,
                          hydrus.hydraspec.doc_writer.EntryPointClass):
                self.class_endpoints[
                    support_property.name] = support_property.id_

            if isinstance(support_property,
                          hydrus.hydraspec.doc_writer.EntryPointCollection):
                self.collection_endpoints[
                    support_property.name] = support_property.id_

        if len(self.class_endpoints.keys()) > 0:
            clas = ClassEndpoints(self.redis_graph, self.class_endpoints)
            clas.endpointclasses(entrypoint_node, api_doc, self.url)

        if len(self.collection_endpoints.keys()) > 0:
            coll = CollectionEndpoints(self.redis_graph, self.class_endpoints)
            coll.endpointCollection(self.collection_endpoints, entrypoint_node,
                                    api_doc, self.url)
Esempio n. 3
0
    def __init__(self, api_doc, url, graph):
        self.redis_connection = RedisProxy()
        self.handle_data = HandleData()
        self.connection = self.redis_connection.get_connection()
        self._data = self.handle_data
        self.clas = ClassEndpoints(graph.redis_graph,
                                   graph.class_endpoints)

        self.api_doc = api_doc
        self.url = url
Esempio n. 4
0
class ClassPropertiesValue:
    """
    ClassPropertiesValue is used for geting the values for properties of class
    And once values get from server and then it stored in Redis.
    """

    def __init__(self, api_doc, url, graph):
        self.redis_connection = RedisProxy()
        self.handle_data = HandleData()
        self.connection = self.redis_connection.get_connection()
        self._data = self.handle_data
        self.clas = ClassEndpoints(graph.redis_graph,
                                   graph.class_endpoints)

        self.api_doc = api_doc
        self.url = url

    def data_from_server(self, endpoint):
        """
        Load data from the server for once.
        :param endpoint: endpoint for getting data from the server.
        :return: get data from the Redis memory.
        """
        self.clas.load_from_server(endpoint,
                                   self.api_doc,
                                   self.url,
                                   self.connection)

        get_data = self.connection.execute_command(
            'GRAPH.QUERY',
            'apidoc',
            """MATCH(p:classes)
               WHERE(p.type='{}')
               RETURN p.property_value""".format(
                endpoint))
        return get_data

    def get_property_value(self, query):
        """
        Load data in Redis if data is not in it with help of checklist.
        Checklist have the track on endpoints.
        And access the properties values and show them.
        :param query: get query from the user, Ex:classLocation property_value
        :return: get data from the Redis memory.
        """
        query = query.replace("class", "")
        endpoint = query.replace(" property_value", "")
        if (str.encode("fs:endpoints") in self.connection.keys() and
                str.encode(endpoint) in self.connection.smembers(
                                                   "fs:endpoints")):
            get_data = self.connection.execute_command(
                'GRAPH.QUERY',
                'apidoc',
                """MATCH (p:classes)
                   WHERE (p.type = '{}')
                   RETURN p.property_value""".format(
                    endpoint))
        else:
            self.connection.sadd("fs:endpoints", endpoint)
            print(self.connection.smembers("fs:endpoints"))
            get_data = self.data_from_server(endpoint)

        print(endpoint, "property_value")
        return self._data.show_data(get_data)
Esempio n. 5
0
    def collectionobjects(
            self,
            endpoint_collection_node,
            endpoint_list,
            new_url,
            api_doc,
            url,
            redis_connection):
        """Creating nodes for all objects stored in collection.
        :param endpoint_collection_node: parent/collection endpoint node.
        :param endpoint_list: Members/objects of any collection.
        :param new_url: parent url for members/objects
        :param api_doc: Apidocumentation for particular url.
        :param url: Base url given by user.
        :param redis_connection: connection of Redis memory.
        """
        print("accesing the collection object like events or drones")
        if endpoint_list:
            clas = ClassEndpoints(self.redis_graph, self.class_endpoints)
            for endpoint in endpoint_list:
                node_properties = {}
                no_endpoint_list = []
                endpoint_method = []
                member = {}
                endpoint_property_list = []
                supported_property_list = []
                no_endpoint_property = {}
                match_obj = re.match(
                    r'/(.*)/(.*)/(.*)?', endpoint["@id"], re.M | re.I)
                base_url = "/{0}/{1}/".format(match_obj.group(1),
                                              match_obj.group(2))
                entrypoint_member = endpoint["@type"].lower(
                ) + match_obj.group(3)
#                print(base_url, entrypoint_member,endpoint["@type"])
                member_alias = entrypoint_member
                # key for the object node is memeber_alias
                member_id = match_obj.group(3)
                member_url = new_url + "/" + member_id
                # object data retrieving from the server
                new_file = self.fetch_data(member_url)
                if isinstance (new_file, RequestError):
                    return None
                for support_operation in api_doc.parsed_classes[
                    endpoint["@type"]
                ]["class"
                  ].supportedOperation:
                    endpoint_method.append(support_operation.method)
                # all the operations for the object is stored in method
                node_properties["operations"] = str(endpoint_method)
                # endpoint_property_list store all properties which is class/object and also an endpoint.
                # supported_property_list store all the properties.
                # no_endpoint_list store all properties which is class/object
                # but not endpoint.
                for support_property in api_doc.parsed_classes[
                    endpoint["@type"]
                ]["class"
                  ].supportedProperty:
                    supported_property_list.append(support_property.title)
                    if support_property.title in self.class_endpoints:
                        endpoint_property_list.append(
                            str(support_property.title))
                    elif support_property.title in api_doc.parsed_classes:
                        no_endpoint_list.append(support_property.title)

                    # members contain all the property with value.
                    # it contains null value for the property which not have value in server.
                    # no_endpoint_properrty store value for no_endpoint_list.
                    if support_property.title in new_file:
                        if isinstance(new_file[support_property.title], str):
                            member[support_property.title] = str(
                                new_file[
                                    support_property.title].replace(" ", ""))
                        else:
                            no_endpoint_property[
                                support_property.title] = new_file[
                                support_property.title]
                    else:
                        member[support_property.title] = "null"

                node_properties["@id"] = str(endpoint["@id"])
                node_properties["@type"] = str(endpoint["@type"])
                member[endpoint["@type"]] = str(endpoint["@id"])
                node_properties["property_value"] = str(member)
                member["type"] = str(endpoint["@type"])
                redis_connection.set((endpoint["@id"]), (member))
                self.faceted_indexing(
                    endpoint["@id"], redis_connection, member)
                node_properties["properties"] = str(supported_property_list)
                # add object as a node in redis
                collection_object_node = clas.addNode(
                    str("objects" + str(endpoint["@type"])),
                    str(member_alias.capitalize()),
                    node_properties)
                # set an edge between the collection and its object
                clas.addEdge(endpoint_collection_node,
                             "has_" + str(endpoint["@type"]),
                             collection_object_node)

                if endpoint_property_list:
                    for endpoint_property in endpoint_property_list:
                        for nodes in self.redis_graph.nodes.values():
                            if endpoint_property == nodes.alias:
                                clas.addEdge(
                                    collection_object_node,
                                    "hasendpointproperty",
                                    nodes)
                if no_endpoint_list:
                    clas.objects_property(
                        collection_object_node,
                        no_endpoint_list,
                        no_endpoint_property,
                        api_doc)

        else:
            print("NO MEMBERS")