Search in sources :

Example 26 with EdgeLabel

use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.

the class EdgeAPI method update.

@PUT
@Timed(name = "single-update")
@Path("{id}")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({ "admin", "$owner=$graph $action=edge_write" })
public String update(@Context GraphManager manager, @PathParam("graph") String graph, @PathParam("id") String id, @QueryParam("action") String action, JsonEdge jsonEdge) {
    LOG.debug("Graph [{}] update edge: {}", graph, jsonEdge);
    checkUpdatingBody(jsonEdge);
    if (jsonEdge.id != null) {
        E.checkArgument(id.equals(jsonEdge.id), "The ids are different between url and " + "request body ('%s' != '%s')", id, jsonEdge.id);
    }
    // Parse action param
    boolean append = checkAndParseAction(action);
    HugeGraph g = graph(manager, graph);
    HugeEdge edge = (HugeEdge) g.edge(id);
    EdgeLabel edgeLabel = edge.schemaLabel();
    for (String key : jsonEdge.properties.keySet()) {
        PropertyKey pkey = g.propertyKey(key);
        E.checkArgument(edgeLabel.properties().contains(pkey.id()), "Can't update property for edge '%s' because " + "there is no property key '%s' in its edge label", id, key);
    }
    commit(g, () -> updateProperties(edge, jsonEdge, append));
    return manager.serializer(g).writeEdge(edge);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) Path(jakarta.ws.rs.Path) RolesAllowed(jakarta.annotation.security.RolesAllowed) Consumes(jakarta.ws.rs.Consumes) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) PUT(jakarta.ws.rs.PUT)

Example 27 with EdgeLabel

use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.

the class EdgeLabelAPI method create.

@POST
@Timed
@Status(Status.CREATED)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({ "admin", "$owner=$graph $action=edge_label_write" })
public String create(@Context GraphManager manager, @PathParam("graph") String graph, JsonEdgeLabel jsonEdgeLabel) {
    LOG.debug("Graph [{}] create edge label: {}", graph, jsonEdgeLabel);
    checkCreatingBody(jsonEdgeLabel);
    HugeGraph g = graph(manager, graph);
    EdgeLabel.Builder builder = jsonEdgeLabel.convert2Builder(g);
    EdgeLabel edgeLabel = builder.create();
    return manager.serializer(g).writeEdgeLabel(edgeLabel);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) Status(com.baidu.hugegraph.api.filter.StatusFilter.Status) RolesAllowed(jakarta.annotation.security.RolesAllowed) POST(jakarta.ws.rs.POST) Consumes(jakarta.ws.rs.Consumes) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed)

Example 28 with EdgeLabel

use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.

the class HugeGraphAuthProxy method removeEdgeLabel.

@Override
public Id removeEdgeLabel(Id id) {
    EdgeLabel label = this.hugegraph.edgeLabel(id);
    verifySchemaPermission(HugePermission.DELETE, label);
    return this.hugegraph.removeEdgeLabel(id);
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel)

Example 29 with EdgeLabel

use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.

the class StandardHugeGraph method edgeLabel.

@Override
public EdgeLabel edgeLabel(Id id) {
    EdgeLabel el = this.schemaTransaction().getEdgeLabel(id);
    E.checkArgument(el != null, "Undefined edge label with id: '%s'", id);
    return el;
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel)

Example 30 with EdgeLabel

use of com.baidu.hugegraph.schema.EdgeLabel in project incubator-hugegraph by apache.

the class StandardHugeGraph method removeEdge.

@Override
public void removeEdge(String label, Object id) {
    if (label != null) {
        EdgeLabel el = this.edgeLabel(label);
        if (!el.existsIndexLabel()) {
            // Improve perf by removeEdge(id)
            Id idValue = HugeEdge.getIdValue(id, false);
            HugeEdge edge = new HugeEdge(this, idValue, el);
            this.removeEdge(edge);
            return;
        }
    }
    this.edge(id).remove();
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Id(com.baidu.hugegraph.backend.id.Id)

Aggregations

EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)58 Test (org.junit.Test)22 SchemaManager (com.baidu.hugegraph.schema.SchemaManager)19 Id (com.baidu.hugegraph.backend.id.Id)16 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)12 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)11 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)11 HugeGraph (com.baidu.hugegraph.HugeGraph)10 Edge (org.apache.tinkerpop.gremlin.structure.Edge)10 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)8 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)7 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)6 Timed (com.codahale.metrics.annotation.Timed)5 RolesAllowed (jakarta.annotation.security.RolesAllowed)5 Produces (jakarta.ws.rs.Produces)5 Date (java.util.Date)4 GraphTransaction (com.baidu.hugegraph.backend.tx.GraphTransaction)3 SchemaTransaction (com.baidu.hugegraph.backend.tx.SchemaTransaction)3 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)3 SchemaStatus (com.baidu.hugegraph.type.define.SchemaStatus)3