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;
}
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);
}
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;
}
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);
}
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);
}
Aggregations