Search in sources :

Example 1 with UniEdge

use of org.unipop.structure.UniEdge in project unipop by unipop-graph.

the class NestedEdgeSchema method fromFields.

@Override
public Collection<Edge> fromFields(Map<String, Object> fields) {
    Object pathValue = fields.get(this.path);
    if (pathValue == null)
        return null;
    Vertex parentVertex = parentVertexSchema.createElement(fields);
    if (parentVertex == null)
        return null;
    if (pathValue instanceof Collection) {
        List<Edge> edges = new ArrayList<>(((Collection) pathValue).size());
        Collection<Map<String, Object>> edgesFields = (Collection<Map<String, Object>>) pathValue;
        for (Map<String, Object> edgeFields : edgesFields) {
            UniEdge edge = createEdge(parentVertex, edgeFields);
            if (edge == null)
                continue;
            edges.add(edge);
        }
        return edges;
    } else if (pathValue instanceof Map) {
        Map<String, Object> edgeFields = (Map<String, Object>) pathValue;
        UniEdge edge = createEdge(parentVertex, edgeFields);
        return Collections.singleton(edge);
    }
    return null;
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) UniEdge(org.unipop.structure.UniEdge) JSONObject(org.json.JSONObject) UniEdge(org.unipop.structure.UniEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge)

Example 2 with UniEdge

use of org.unipop.structure.UniEdge in project unipop by unipop-graph.

the class NestedEdgeSchema method createEdge.

private UniEdge createEdge(Vertex parentVertex, Map<String, Object> edgeFields) {
    Map<String, Object> edgeProperties = getProperties(edgeFields);
    if (edgeProperties == null)
        return null;
    Vertex childVertex = childVertexSchema.createElement(edgeFields);
    if (childVertex == null)
        return null;
    UniEdge edge = new UniEdge(edgeProperties, parentDirection.equals(Direction.OUT) ? parentVertex : childVertex, parentDirection.equals(Direction.IN) ? parentVertex : childVertex, graph);
    return edge;
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) UniEdge(org.unipop.structure.UniEdge) JSONObject(org.json.JSONObject)

Example 3 with UniEdge

use of org.unipop.structure.UniEdge in project unipop by unipop-graph.

the class RestController method addEdge.

@Override
public Edge addEdge(AddEdgeQuery uniQuery) {
    UniEdge edge = new UniEdge(uniQuery.getProperties(), uniQuery.getOutVertex(), uniQuery.getInVertex(), graph);
    for (RestEdgeSchema edgeSchema : edgeSchemas) {
        try {
            BaseRequest baseRequest = edgeSchema.addElement(edge);
            if (baseRequest == null)
                return edge;
            baseRequest.asJson();
        } catch (UnirestException e) {
            e.printStackTrace();
        } catch (NoSuchElementException e) {
            continue;
        }
    }
    return edge;
}
Also used : UniEdge(org.unipop.structure.UniEdge) BaseRequest(com.mashape.unirest.request.BaseRequest) UnirestException(com.mashape.unirest.http.exceptions.UnirestException)

Example 4 with UniEdge

use of org.unipop.structure.UniEdge in project unipop by unipop-graph.

the class DocEdgeSchema method fromFields.

@Override
public Collection<Edge> fromFields(Map<String, Object> fields) {
    Map<String, Object> edgeProperties = getProperties(fields);
    if (edgeProperties == null)
        return null;
    Vertex outVertex = outVertexSchema.createElement(fields);
    if (outVertex == null)
        return null;
    Vertex inVertex = inVertexSchema.createElement(fields);
    if (inVertex == null)
        return null;
    UniEdge uniEdge = new UniEdge(edgeProperties, outVertex, inVertex, graph);
    return Collections.singleton(uniEdge);
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) UniEdge(org.unipop.structure.UniEdge) JSONObject(org.json.JSONObject)

Example 5 with UniEdge

use of org.unipop.structure.UniEdge in project unipop by unipop-graph.

the class RowEdgeSchema method fromFields.

@Override
public Collection<Edge> fromFields(Map<String, Object> fields) {
    Map<String, Object> edgeProperties = getProperties(fields);
    if (edgeProperties == null)
        return null;
    Vertex outVertex = outVertexSchema.createElement(fields);
    if (outVertex == null)
        return null;
    Vertex inVertex = inVertexSchema.createElement(fields);
    if (inVertex == null)
        return null;
    UniEdge uniEdge = new UniEdge(edgeProperties, outVertex, inVertex, graph);
    return Collections.singleton(uniEdge);
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) UniEdge(org.unipop.structure.UniEdge) JSONObject(org.json.JSONObject)

Aggregations

UniEdge (org.unipop.structure.UniEdge)5 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)4 JSONObject (org.json.JSONObject)4 UnirestException (com.mashape.unirest.http.exceptions.UnirestException)1 BaseRequest (com.mashape.unirest.request.BaseRequest)1 Edge (org.apache.tinkerpop.gremlin.structure.Edge)1