Search in sources :

Example 21 with EdgeLabel

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

the class EdgeLabelApiTest method testDelete.

@Test
public void testDelete() {
    EdgeLabel edgeLabel = schema().edgeLabel("created").sourceLabel("person").targetLabel("software").singleTime().properties("date", "city").build();
    edgeLabelAPI.create(edgeLabel);
    long taskId = edgeLabelAPI.delete("created");
    waitUntilTaskCompleted(taskId);
    Utils.assertResponseError(404, () -> {
        edgeLabelAPI.get("created");
    });
}
Also used : EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) Test(org.junit.Test)

Example 22 with EdgeLabel

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

the class EdgeLabelApiTest method testCreateWithUndefinedVertexLabel.

@Test
public void testCreateWithUndefinedVertexLabel() {
    EdgeLabel edgeLabel = schema().edgeLabel("created").sourceLabel("programmer").targetLabel("software").singleTime().properties("date", "city").build();
    Utils.assertResponseError(400, () -> {
        edgeLabelAPI.create(edgeLabel);
    });
}
Also used : EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) Test(org.junit.Test)

Example 23 with EdgeLabel

use of com.baidu.hugegraph.structure.schema.EdgeLabel in project hugegraph-computer by hugegraph.

the class FileEdgeFetcher method buildElement.

@Override
protected List<Edge> buildElement(Line line, ElementBuilder<Edge> builder) {
    List<Edge> edges = super.buildElement(line, builder);
    for (Edge edge : edges) {
        // generate edgeId
        EdgeLabel edgeLabel = (EdgeLabel) builder.schemaLabel();
        String edgeId = IdUtil.assignEdgeId(edge, edgeLabel);
        edge.id(edgeId);
    }
    return edges;
}
Also used : EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) Edge(com.baidu.hugegraph.structure.graph.Edge)

Example 24 with EdgeLabel

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

the class EdgeLabelService method convert.

private static EdgeLabel convert(EdgeLabelUpdateEntity entity, HugeClient client) {
    if (entity == null) {
        return null;
    }
    Set<String> properties = new HashSet<>();
    if (entity.getAppendProperties() != null) {
        entity.getAppendProperties().forEach(p -> {
            properties.add(p.getName());
        });
    }
    EdgeLabel.Builder builder;
    builder = client.schema().edgeLabel(entity.getName()).properties(toStringArray(properties)).nullableKeys(toStringArray(properties));
    EdgeLabel edgeLabel = builder.build();
    Map<String, Object> userdata = edgeLabel.userdata();
    EdgeLabelStyle style = entity.getStyle();
    if (style != null) {
        userdata.put(USER_KEY_STYLE, JsonUtil.toJson(style));
    }
    return edgeLabel;
}
Also used : EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) EdgeLabelStyle(com.baidu.hugegraph.entity.schema.EdgeLabelStyle) HashSet(java.util.HashSet)

Example 25 with EdgeLabel

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

the class EdgeLabelService method get.

public EdgeLabelEntity get(String name, int connId) {
    HugeClient client = this.client(connId);
    try {
        EdgeLabel edgeLabel = client.schema().getEdgeLabel(name);
        List<IndexLabel> indexLabels = client.schema().getIndexLabels();
        return convert(edgeLabel, indexLabels);
    } catch (ServerException e) {
        if (e.status() == Constant.STATUS_NOT_FOUND) {
            throw new ExternalException("schema.edgelabel.not-exist", e, name);
        }
        throw new ExternalException("schema.edgelabel.get.failed", e, name);
    }
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) ServerException(com.baidu.hugegraph.exception.ServerException) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) ExternalException(com.baidu.hugegraph.exception.ExternalException)

Aggregations

EdgeLabel (com.baidu.hugegraph.structure.schema.EdgeLabel)44 Test (org.junit.Test)31 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)9 HugeClient (com.baidu.hugegraph.driver.HugeClient)8 IndexLabel (com.baidu.hugegraph.structure.schema.IndexLabel)6 ExternalException (com.baidu.hugegraph.exception.ExternalException)4 ServerException (com.baidu.hugegraph.exception.ServerException)4 Date (java.util.Date)4 RestResult (com.baidu.hugegraph.rest.RestResult)3 VertexLabel (com.baidu.hugegraph.structure.schema.VertexLabel)3 ArrayList (java.util.ArrayList)3 Task (com.baidu.hugegraph.structure.Task)2 BaseApiTest (com.baidu.hugegraph.api.BaseApiTest)1 EdgeLabelEntity (com.baidu.hugegraph.entity.schema.EdgeLabelEntity)1 EdgeLabelStyle (com.baidu.hugegraph.entity.schema.EdgeLabelStyle)1 Edge (com.baidu.hugegraph.structure.graph.Edge)1 PropertyKey (com.baidu.hugegraph.structure.schema.PropertyKey)1 HashSet (java.util.HashSet)1