Search in sources :

Example 6 with VertexLabelEntity

use of com.baidu.hugegraph.entity.schema.VertexLabelEntity in project incubator-hugegraph-toolchain by apache.

the class GraphService method buildVertex.

private Vertex buildVertex(int connId, VertexEntity entity) {
    Vertex vertex = new Vertex(entity.getLabel());
    VertexLabelEntity vl = this.vlService.get(entity.getLabel(), connId);
    // Allowed front-end always pass id
    if (vl.getIdStrategy().isCustomize()) {
        Object vid = this.convertVertexId(vl.getIdStrategy(), entity.getId());
        vertex.id(vid);
    }
    this.fillProperties(connId, vl, vertex, entity.getProperties());
    return vertex;
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) VertexLabelEntity(com.baidu.hugegraph.entity.schema.VertexLabelEntity)

Example 7 with VertexLabelEntity

use of com.baidu.hugegraph.entity.schema.VertexLabelEntity in project incubator-hugegraph-toolchain by apache.

the class GraphService method buildEdge.

private EdgeHolder buildEdge(int connId, EdgeEntity entity) {
    HugeClient client = this.client(connId);
    GraphManager graph = client.graph();
    EdgeLabelEntity el = this.elService.get(entity.getLabel(), connId);
    VertexLabelEntity sourceVl = this.vlService.get(el.getSourceLabel(), connId);
    VertexLabelEntity targetVl = this.vlService.get(el.getTargetLabel(), connId);
    Object realSourceId = this.convertVertexId(sourceVl.getIdStrategy(), entity.getSourceId());
    Object realTargetId = this.convertVertexId(targetVl.getIdStrategy(), entity.getTargetId());
    Vertex sourceVertex = graph.getVertex(realSourceId);
    Vertex targetVertex = graph.getVertex(realTargetId);
    Ex.check(el.getSourceLabel().equals(sourceVertex.label()) && el.getTargetLabel().equals(targetVertex.label()), "graph.edge.link-unmatched-vertex", entity.getLabel(), el.getSourceLabel(), el.getTargetLabel(), sourceVertex.label(), targetVertex.label());
    Edge edge = new Edge(entity.getLabel());
    edge.source(sourceVertex);
    edge.target(targetVertex);
    this.fillProperties(connId, el, edge, entity.getProperties());
    return new EdgeHolder(edge, sourceVertex, targetVertex);
}
Also used : EdgeLabelEntity(com.baidu.hugegraph.entity.schema.EdgeLabelEntity) Vertex(com.baidu.hugegraph.structure.graph.Vertex) HugeClient(com.baidu.hugegraph.driver.HugeClient) GraphManager(com.baidu.hugegraph.driver.GraphManager) VertexLabelEntity(com.baidu.hugegraph.entity.schema.VertexLabelEntity) Edge(com.baidu.hugegraph.structure.graph.Edge)

Example 8 with VertexLabelEntity

use of com.baidu.hugegraph.entity.schema.VertexLabelEntity in project incubator-hugegraph-toolchain by apache.

the class GremlinQueryService method getRealVertexId.

private Object getRealVertexId(int connId, AdjacentQuery query) {
    VertexLabelEntity entity = this.vlService.get(query.getVertexLabel(), connId);
    IdStrategy idStrategy = entity.getIdStrategy();
    String rawVertexId = query.getVertexId();
    try {
        if (idStrategy == IdStrategy.AUTOMATIC || idStrategy == IdStrategy.CUSTOMIZE_NUMBER) {
            return Long.parseLong(rawVertexId);
        } else if (idStrategy == IdStrategy.CUSTOMIZE_UUID) {
            return UUID.fromString(rawVertexId);
        }
    } catch (Exception e) {
        throw new ExternalException("gremlin.convert-vertex-id.failed", e, rawVertexId, idStrategy);
    }
    assert idStrategy == IdStrategy.PRIMARY_KEY || idStrategy == IdStrategy.CUSTOMIZE_STRING;
    return rawVertexId;
}
Also used : IdStrategy(com.baidu.hugegraph.structure.constant.IdStrategy) ExternalException(com.baidu.hugegraph.exception.ExternalException) VertexLabelEntity(com.baidu.hugegraph.entity.schema.VertexLabelEntity) ServerException(com.baidu.hugegraph.exception.ServerException) ExternalException(com.baidu.hugegraph.exception.ExternalException) ClientException(com.baidu.hugegraph.rest.ClientException) IllegalGremlinException(com.baidu.hugegraph.exception.IllegalGremlinException) InternalException(com.baidu.hugegraph.exception.InternalException)

Example 9 with VertexLabelEntity

use of com.baidu.hugegraph.entity.schema.VertexLabelEntity in project incubator-hugegraph-toolchain by apache.

the class SchemaController method displayInSchemaView.

@GetMapping("graphview")
public SchemaView displayInSchemaView(@PathVariable("connId") int connId) {
    List<PropertyKeyEntity> propertyKeys = this.pkService.list(connId);
    List<VertexLabelEntity> vertexLabels = this.vlService.list(connId);
    List<EdgeLabelEntity> edgeLabels = this.elService.list(connId);
    List<Map<String, Object>> vertices = new ArrayList<>(vertexLabels.size());
    for (VertexLabelEntity entity : vertexLabels) {
        Map<String, Object> vertex = new LinkedHashMap<>();
        vertex.put("id", entity.getName());
        vertex.put("label", entity.getName());
        if (entity.getIdStrategy() == IdStrategy.PRIMARY_KEY) {
            vertex.put("primary_keys", entity.getPrimaryKeys());
        } else {
            vertex.put("primary_keys", new ArrayList<>());
        }
        Map<String, String> properties = new LinkedHashMap<>();
        this.fillProperties(properties, entity, propertyKeys);
        vertex.put("properties", properties);
        vertex.put("~style", entity.getStyle());
        vertices.add(vertex);
    }
    List<Map<String, Object>> edges = new ArrayList<>(edgeLabels.size());
    for (EdgeLabelEntity entity : edgeLabels) {
        Map<String, Object> edge = new LinkedHashMap<>();
        String edgeId = String.format("%s-%s->%s", entity.getSourceLabel(), entity.getName(), entity.getTargetLabel());
        edge.put("id", edgeId);
        edge.put("label", entity.getName());
        edge.put("source", entity.getSourceLabel());
        edge.put("target", entity.getTargetLabel());
        if (entity.isLinkMultiTimes()) {
            edge.put("sort_keys", entity.getSortKeys());
        } else {
            edge.put("sort_keys", new ArrayList<>());
        }
        Map<String, String> properties = new LinkedHashMap<>();
        this.fillProperties(properties, entity, propertyKeys);
        edge.put("properties", properties);
        edge.put("~style", entity.getStyle());
        edges.add(edge);
    }
    return new SchemaView(vertices, edges);
}
Also used : EdgeLabelEntity(com.baidu.hugegraph.entity.schema.EdgeLabelEntity) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) VertexLabelEntity(com.baidu.hugegraph.entity.schema.VertexLabelEntity) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) PropertyKeyEntity(com.baidu.hugegraph.entity.schema.PropertyKeyEntity) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 10 with VertexLabelEntity

use of com.baidu.hugegraph.entity.schema.VertexLabelEntity in project incubator-hugegraph-toolchain by apache.

the class EdgeLabelController method checkConflict.

@PostMapping("check_conflict")
public ConflictDetail checkConflict(@PathVariable("connId") int connId, @RequestParam("reused_conn_id") int reusedConnId, @RequestBody ConflictCheckEntity entity) {
    Ex.check(!CollectionUtils.isEmpty(entity.getElEntities()), "common.param.cannot-be-empty", "edgelabels");
    Ex.check(CollectionUtils.isEmpty(entity.getPkEntities()), "common.param.must-be-null", "propertykeys");
    Ex.check(CollectionUtils.isEmpty(entity.getPiEntities()), "common.param.must-be-null", "propertyindexes");
    Ex.check(CollectionUtils.isEmpty(entity.getVlEntities()), "common.param.must-be-null", "vertexlabels");
    Ex.check(connId != reusedConnId, "schema.conn.cannot-reuse-self");
    Set<String> pkNames = new HashSet<>();
    Set<String> piNames = new HashSet<>();
    Set<String> vlNames = new HashSet<>();
    for (EdgeLabelEntity e : entity.getElEntities()) {
        pkNames.addAll(e.getPropNames());
        piNames.addAll(e.getIndexProps());
        vlNames.addAll(e.getLinkLabels());
    }
    List<VertexLabelEntity> vlEntities;
    vlEntities = this.vlService.list(vlNames, reusedConnId, false);
    for (VertexLabelEntity e : vlEntities) {
        pkNames.addAll(e.getPropNames());
        piNames.addAll(e.getIndexProps());
    }
    entity.setPkEntities(this.pkService.list(pkNames, reusedConnId, false));
    entity.setPiEntities(this.piService.list(piNames, reusedConnId, false));
    entity.setVlEntities(vlEntities);
    return this.elService.checkConflict(entity, connId, false);
}
Also used : EdgeLabelEntity(com.baidu.hugegraph.entity.schema.EdgeLabelEntity) VertexLabelEntity(com.baidu.hugegraph.entity.schema.VertexLabelEntity) HashSet(java.util.HashSet) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

VertexLabelEntity (com.baidu.hugegraph.entity.schema.VertexLabelEntity)13 EdgeLabelEntity (com.baidu.hugegraph.entity.schema.EdgeLabelEntity)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 HugeClient (com.baidu.hugegraph.driver.HugeClient)2 FileSetting (com.baidu.hugegraph.entity.load.FileSetting)2 IdStrategy (com.baidu.hugegraph.structure.constant.IdStrategy)2 Vertex (com.baidu.hugegraph.structure.graph.Vertex)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 GraphManager (com.baidu.hugegraph.driver.GraphManager)1 EdgeMapping (com.baidu.hugegraph.entity.load.EdgeMapping)1 VertexMapping (com.baidu.hugegraph.entity.load.VertexMapping)1 ConflictStatus (com.baidu.hugegraph.entity.schema.ConflictStatus)1 PropertyKeyEntity (com.baidu.hugegraph.entity.schema.PropertyKeyEntity)1 ExternalException (com.baidu.hugegraph.exception.ExternalException)1 IllegalGremlinException (com.baidu.hugegraph.exception.IllegalGremlinException)1 InternalException (com.baidu.hugegraph.exception.InternalException)1 ServerException (com.baidu.hugegraph.exception.ServerException)1 ClientException (com.baidu.hugegraph.rest.ClientException)1 Edge (com.baidu.hugegraph.structure.graph.Edge)1