Ejemplo n.º 1
0
        public Node GetRootNode(ConnectionElement connection)
        {
            string response;
            var    status = Neo4jRestApi.GetRoot(Connection.GetDatabaseEndpoint(connection.DbUrl).Data, out response);

            if (status != HttpStatusCode.OK)
            {
                throw new Exception(string.Format("Error getting root node (http response:{0})", status));
            }

            JObject jo;

            try
            {
                jo = JObject.Parse(response);
            }
            catch (Exception e)
            {
                throw new Exception("Invalid json", e);
            }

            JToken referenceNode;

            if (!jo.TryGetValue("reference_node", out referenceNode))
            {
                throw new NodeNotFoundException("Reference node not found");
            }

            var graphStore = new RestNodeStore(referenceNode.Value <string>());

            return(new Node(graphStore));
        }
        public void SaveProperties(Properties properties)
        {
            var status = Neo4jRestApi.SetPropertiesOnRelationship(DbUrl, Id, properties.ToString());

            if (status != HttpStatusCode.NoContent)
            {
                throw new Exception(string.Format("Error setting properties on relationship (relationship id:{0} http response:{1})", Id, status));
            }
        }
        public HttpStatusCode DeleteRelationship(ConnectionElement connection)
        {
            var status = Neo4jRestApi.DeleteRelationship(connection.DbUrl, Id);

            if (status != HttpStatusCode.NoContent)
            {
                throw new Exception(string.Format("Error deleting relationship (relationship id:{0} http response:{1})", Id, status));
            }

            return(status);
        }
Ejemplo n.º 4
0
        public bool RemoveFromIndex(ConnectionElement connection, Node node, string indexName, string key)
        {
            var status = Neo4jRestApi.RemoveNodeFromIndex(connection.DbUrl, node.Id, indexName, key);

            if (status != HttpStatusCode.NoContent)
            {
                throw new Exception(string.Format("Error remove node from index (node id:{0} index name:{1} key:{2} http response:{3})", node.Id, indexName, key, status));
            }

            return(true);
        }
Ejemplo n.º 5
0
        public HttpStatusCode DeleteNode()
        {
            var status = Neo4jRestApi.DeleteNode(DbUrl, Id);

            if (status != HttpStatusCode.NoContent)
            {
                throw new Exception(string.Format("Error deleting node (node id:{0} http response:{1})", Id, status));
            }

            return(status);
        }
        public bool RemoveFromIndex(ConnectionElement connection, Relationship relationship, string indexName, string key, object value)
        {
            var status = Neo4jRestApi.RemoveRelationshipFromIndex(connection.DbUrl, relationship.Id, indexName, key, value);

            if (status != HttpStatusCode.NoContent)
            {
                throw new Exception(string.Format("Error remove relationship from index (relationship id:{0} index name:{1} key:{2} http response:{3})", relationship.Id, indexName, key, status));
            }

            return(true);
        }
Ejemplo n.º 7
0
        public IEnumerable <Relationship> GetRelationships(RelationshipDirection direction, IEnumerable <string> relationshipTypes)
        {
            string response;
            var    status = Neo4jRestApi.GetRelationshipsOnNode(DbUrl, Id, direction, relationshipTypes, out response);

            if (status != HttpStatusCode.OK)
            {
                throw new Exception(string.Format("Error retrieving relationships on node (node id:{0} http response:{1})", Id, status));
            }

            return(RestRelationshipStore.ParseRelationshipJson(response));
        }
Ejemplo n.º 8
0
        public Node CreateNode(ConnectionElement connection, Properties properties)
        {
            string response;
            var    status = Neo4jRestApi.CreateNode(connection.DbUrl, properties.ToString(), out response);

            if (status != HttpStatusCode.Created)
            {
                throw new Exception(string.Format("Error creating node (http response:{0})", status));
            }

            return(ParseNodeJson(response).First());
        }
Ejemplo n.º 9
0
        public Node GetNode(ConnectionElement connection, long nodeId)
        {
            string response;
            var    status = Neo4jRestApi.GetNode(connection.DbUrl, nodeId, out response);

            if (status == HttpStatusCode.NotFound)
            {
                throw new NodeNotFoundException(string.Format("Node({0})", nodeId));
            }

            return(CreateNodeFromJson(response));
        }
        public IEnumerable <Relationship> GetRelationship(ConnectionElement connection, string indexName, string searchQuery)
        {
            string response;
            var    status = Neo4jRestApi.GetRelationship(connection.DbUrl, indexName, searchQuery, out response);

            if (status != HttpStatusCode.OK)
            {
                throw new Exception(string.Format("Index not found in (index:{0})", indexName));
            }

            return(ParseRelationshipJson(response));
        }
        public Properties GetProperties()
        {
            string response;
            var    status = Neo4jRestApi.GetPropertiesOnRelationship(DbUrl, Id, out response);

            if (status != HttpStatusCode.OK)
            {
                throw new Exception(string.Format("Error retrieving properties on relationship (relationship id:{0} http response:{1})", Id, status));
            }

            return(Properties.ParseJson(response));
        }
        public Relationship GetRelationship(ConnectionElement connection, long relationshipId)
        {
            string response;
            var    status = Neo4jRestApi.GetRelationship(connection.DbUrl, relationshipId, out response);

            if (status == HttpStatusCode.NotFound)
            {
                throw new RelationshipNotFoundException(string.Format("Relationship({0})", relationshipId));
            }

            return(CreateRelationshipFromJson(response));
        }
        public Relationship CreateRelationship(ConnectionElement connection, Node startNode, Node endNode, string name, Properties properties)
        {
            string response;
            var    status = Neo4jRestApi.CreateRelationship(connection.DbUrl, startNode.Id, endNode.Id, name, properties.ToString(), out response);

            if (status != HttpStatusCode.Created)
            {
                throw new Exception(string.Format("Error creating relationship (http response:{0})", status));
            }

            return(ParseRelationshipJson(response).First());
        }
Ejemplo n.º 14
0
        public IEnumerable <Node> GetNode(ConnectionElement connection, string indexName, string key, object value)
        {
            string response;
            var    status = Neo4jRestApi.GetNode(connection.DbUrl, indexName, key, value, out response);

            if (status == HttpStatusCode.OK)
            {
                return(ParseNodeJson(response));
            }

            if (status == HttpStatusCode.NotFound)
            {
                return(new List <Node>());
            }

            throw new Exception(string.Format("Index not found in (index:{0})", indexName));
        }
Ejemplo n.º 15
0
        public Relationship CreateRelationship(Node startNode, Node endNode, string relationshipType, Properties properties)
        {
            string response;
            var    status = Neo4jRestApi.CreateRelationship(DbUrl,
                                                            startNode.Id,
                                                            endNode.Id,
                                                            relationshipType,
                                                            properties == null ? null : properties.ToString(),
                                                            out response);

            if (status != HttpStatusCode.Created)
            {
                throw new Exception(string.Format("Error creationg relationship on node (node id:{0} http response:{1})", Id, status));
            }

            return(RestRelationshipStore.ParseRelationshipJson(response).First());
        }
        public Relationship AddToIndex(ConnectionElement connection, Relationship relationship, string indexName, string key, object value)
        {
            string response;
            var    status = Neo4jRestApi.AddRelationshipToIndex(connection.DbUrl, relationship.Id, indexName, key, value, out response);

            if (status == HttpStatusCode.Created || status == HttpStatusCode.OK)
            {
                return(ParseRelationshipJson(response).First());
            }

            //// Add a relationship to an index but mapping already exists
            //if (unique && status == HttpStatusCode.OK)
            //{
            //	return null;
            //}

            throw new Exception(string.Format("Error adding relationship to index (http response:{0})", status));
        }
        public Relationship CreateUniqueRelationship(ConnectionElement connection, Node startNode, Node endNode, string name, Properties properties, string indexName, string key, object value, IndexUniqueness uniqueness)
        {
            string response;
            var    status = Neo4jRestApi.CreateUniqueRelationship(connection.DbUrl, startNode.Id, endNode.Id, name, properties.ToString(), indexName, key, value, uniqueness, out response);

            if (status == HttpStatusCode.Created)
            {
                return(ParseRelationshipJson(response).First());
            }

            // Create unique relationship but index mapping already exists
            if (status == HttpStatusCode.OK)
            {
                return(null);
            }

            throw new Exception(string.Format("Error creating relationship (http response:{0})", status));
        }
Ejemplo n.º 18
0
        public static DatabaseEndpoint GetDatabaseEndpoint(string dbUrl)
        {
            DatabaseEndpoint endpoint;

            if (!DatabaseEndpoints.TryGetValue(dbUrl, out endpoint))
            {
                string response;

                if (Neo4jRestApi.GetRoot(dbUrl, out response) == HttpStatusCode.OK)
                {
                    endpoint = JsonConvert.DeserializeObject <DatabaseEndpoint>(response);
                    DatabaseEndpoints.TryAdd(dbUrl, endpoint);
                }
                else
                {
                    throw new DatabaseEndpointNotFound();
                }
            }

            return(endpoint);
        }
Ejemplo n.º 19
0
        public static ServiceRoot GetServiceRoot(string dbUrl)
        {
            ServiceRoot serviceRoot;

            if (!ServiceRoots.TryGetValue(dbUrl, out serviceRoot))
            {
                string response;

                if (Neo4jRestApi.GetRoot(GetDatabaseEndpoint(dbUrl).Data, out response) == HttpStatusCode.OK)
                {
                    serviceRoot = JsonConvert.DeserializeObject <ServiceRoot>(response);
                    ServiceRoots.TryAdd(dbUrl, serviceRoot);
                }
                else
                {
                    throw new ServiceRootNotFound();
                }
            }

            return(serviceRoot);
        }