use of com.baidu.hugegraph.api.filter.StatusFilter.Status in project incubator-hugegraph by apache.
the class EdgeAPI method create.
@POST
@Timed(name = "batch-create")
@Decompress
@Path("batch")
@Status(Status.CREATED)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({ "admin", "$owner=$graph $action=edge_write" })
public String create(@Context HugeConfig config, @Context GraphManager manager, @PathParam("graph") String graph, @QueryParam("check_vertex") @DefaultValue("true") boolean checkVertex, List<JsonEdge> jsonEdges) {
LOG.debug("Graph [{}] create edges: {}", graph, jsonEdges);
checkCreatingBody(jsonEdges);
checkBatchSize(config, jsonEdges);
HugeGraph g = graph(manager, graph);
TriFunction<HugeGraph, Object, String, Vertex> getVertex = checkVertex ? EdgeAPI::getVertex : EdgeAPI::newVertex;
return this.commit(config, g, jsonEdges.size(), () -> {
List<Id> ids = new ArrayList<>(jsonEdges.size());
for (JsonEdge jsonEdge : jsonEdges) {
/*
* NOTE: If the query param 'checkVertex' is false,
* then the label is correct and not matched id,
* it will be allowed currently
*/
Vertex srcVertex = getVertex.apply(g, jsonEdge.source, jsonEdge.sourceLabel);
Vertex tgtVertex = getVertex.apply(g, jsonEdge.target, jsonEdge.targetLabel);
Edge edge = srcVertex.addEdge(jsonEdge.label, tgtVertex, jsonEdge.properties());
ids.add((Id) edge.id());
}
return manager.serializer(g).writeIds(ids);
});
}
use of com.baidu.hugegraph.api.filter.StatusFilter.Status in project incubator-hugegraph by apache.
the class EdgeAPI method create.
@POST
@Timed(name = "single-create")
@Status(Status.CREATED)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({ "admin", "$owner=$graph $action=edge_write" })
public String create(@Context GraphManager manager, @PathParam("graph") String graph, JsonEdge jsonEdge) {
LOG.debug("Graph [{}] create edge: {}", graph, jsonEdge);
checkCreatingBody(jsonEdge);
HugeGraph g = graph(manager, graph);
if (jsonEdge.sourceLabel != null && jsonEdge.targetLabel != null) {
/*
* NOTE: If the vertex id is correct but label not match with id,
* we allow to create it here
*/
vertexLabel(g, jsonEdge.sourceLabel, "Invalid source vertex label '%s'");
vertexLabel(g, jsonEdge.targetLabel, "Invalid target vertex label '%s'");
}
Vertex srcVertex = getVertex(g, jsonEdge.source, jsonEdge.sourceLabel);
Vertex tgtVertex = getVertex(g, jsonEdge.target, jsonEdge.targetLabel);
Edge edge = commit(g, () -> {
return srcVertex.addEdge(jsonEdge.label, tgtVertex, jsonEdge.properties());
});
return manager.serializer(g).writeEdge(edge);
}
use of com.baidu.hugegraph.api.filter.StatusFilter.Status in project incubator-hugegraph by apache.
the class VertexAPI method create.
@POST
@Timed(name = "batch-create")
@Decompress
@Path("batch")
@Status(Status.CREATED)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({ "admin", "$owner=$graph $action=vertex_write" })
public String create(@Context HugeConfig config, @Context GraphManager manager, @PathParam("graph") String graph, List<JsonVertex> jsonVertices) {
LOG.debug("Graph [{}] create vertices: {}", graph, jsonVertices);
checkCreatingBody(jsonVertices);
checkBatchSize(config, jsonVertices);
HugeGraph g = graph(manager, graph);
return this.commit(config, g, jsonVertices.size(), () -> {
List<Id> ids = new ArrayList<>(jsonVertices.size());
for (JsonVertex vertex : jsonVertices) {
ids.add((Id) g.addVertex(vertex.properties()).id());
}
return manager.serializer(g).writeIds(ids);
});
}
use of com.baidu.hugegraph.api.filter.StatusFilter.Status in project incubator-hugegraph by apache.
the class RaftAPI method addPeer.
@POST
@Timed
@Status(Status.OK)
@Path("add_peer")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({ "admin" })
public Map<String, String> addPeer(@Context GraphManager manager, @PathParam("graph") String graph, @QueryParam("group") @DefaultValue("default") String group, @QueryParam("endpoint") String endpoint) {
LOG.debug("Graph [{}] prepare to add peer: {}", graph, endpoint);
HugeGraph g = graph(manager, graph);
RaftGroupManager raftManager = raftGroupManager(g, group, "add_peer");
String peerId = raftManager.addPeer(endpoint);
return ImmutableMap.of(raftManager.group(), peerId);
}
use of com.baidu.hugegraph.api.filter.StatusFilter.Status in project incubator-hugegraph by apache.
the class IndexLabelAPI method create.
@POST
@Timed
@Status(Status.ACCEPTED)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({ "admin", "$owner=$graph $action=index_label_write" })
public String create(@Context GraphManager manager, @PathParam("graph") String graph, JsonIndexLabel jsonIndexLabel) {
LOG.debug("Graph [{}] create index label: {}", graph, jsonIndexLabel);
checkCreatingBody(jsonIndexLabel);
HugeGraph g = graph(manager, graph);
IndexLabel.Builder builder = jsonIndexLabel.convert2Builder(g);
SchemaElement.TaskWithSchema il = builder.createWithTask();
il.indexLabel(mapIndexLabel(il.indexLabel()));
return manager.serializer(g).writeTaskWithSchema(il);
}
Aggregations