Search in sources :

Example 6 with EdgeLabel

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

the class VertexLabelService method getLinkEdgeLabels.

public List<String> getLinkEdgeLabels(String name, int connId) {
    HugeClient client = this.client(connId);
    List<EdgeLabel> edgeLabels = client.schema().getEdgeLabels();
    List<String> results = new ArrayList<>();
    for (EdgeLabel edgeLabel : edgeLabels) {
        if (edgeLabel.linkedVertexLabel(name)) {
            results.add(edgeLabel.name());
        }
    }
    return results;
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) ArrayList(java.util.ArrayList)

Example 7 with EdgeLabel

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

the class RestResultTest method testReadEdgeLabels.

@Test
public void testReadEdgeLabels() {
    String json = "{\"edgelabels\": [" + "{" + "\"id\": 2," + "\"source_label\": \"person\"," + "\"index_labels\": [\"createdByDate\"]," + "\"name\": \"created\"," + "\"target_label\": \"software\"," + "\"sort_keys\": []," + "\"properties\": [\"date\"]," + "\"frequency\": \"SINGLE\"" + "}," + "{\"id\": 3," + "\"source_label\": \"person\"," + "\"index_labels\": []," + "\"name\": \"knows\"," + "\"target_label\": \"person\"," + "\"sort_keys\": []," + "\"properties\": [\"date\", \"city\"]," + "\"frequency\": \"SINGLE\"" + "}" + "]}";
    Mockito.when(this.mockResponse.getStatus()).thenReturn(200);
    Mockito.when(this.mockResponse.getHeaders()).thenReturn(null);
    Mockito.when(this.mockResponse.readEntity(String.class)).thenReturn(json);
    RestResult result = new RestResult(this.mockResponse);
    Assert.assertEquals(200, result.status());
    Assert.assertNull(result.headers());
    List<EdgeLabel> edgeLabels = result.readList("edgelabels", EdgeLabel.class);
    Assert.assertEquals(2, edgeLabels.size());
    EdgeLabel edgeLabel1 = edgeLabels.get(0);
    EdgeLabel edgeLabel2 = edgeLabels.get(1);
    Assert.assertEquals("created", edgeLabel1.name());
    Assert.assertEquals("person", edgeLabel1.sourceLabel());
    Assert.assertEquals("software", edgeLabel1.targetLabel());
    Assert.assertEquals(Frequency.SINGLE, edgeLabel1.frequency());
    Assert.assertEquals(Collections.emptyList(), edgeLabel1.sortKeys());
    Assert.assertEquals(ImmutableSet.of("date"), edgeLabel1.properties());
    Assert.assertEquals("knows", edgeLabel2.name());
    Assert.assertEquals("person", edgeLabel2.sourceLabel());
    Assert.assertEquals("person", edgeLabel2.targetLabel());
    Assert.assertEquals(Frequency.SINGLE, edgeLabel2.frequency());
    Assert.assertEquals(Collections.emptyList(), edgeLabel2.sortKeys());
    Assert.assertEquals(ImmutableSet.of("date", "city"), edgeLabel2.properties());
}
Also used : RestResult(com.baidu.hugegraph.rest.RestResult) EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) Test(org.junit.Test)

Example 8 with EdgeLabel

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

the class RestResultTest method testReadEdgeLabel.

@Test
public void testReadEdgeLabel() {
    String json = "{" + "\"id\": 2," + "\"source_label\": \"person\"," + "\"index_labels\": [\"createdByDate\"]," + "\"name\": \"created\"," + "\"target_label\": \"software\"," + "\"sort_keys\": []," + "\"properties\": [\"date\"]," + "\"frequency\": \"SINGLE\"" + "}";
    Mockito.when(this.mockResponse.getStatus()).thenReturn(200);
    Mockito.when(this.mockResponse.getHeaders()).thenReturn(null);
    Mockito.when(this.mockResponse.readEntity(String.class)).thenReturn(json);
    RestResult result = new RestResult(this.mockResponse);
    Assert.assertEquals(200, result.status());
    Assert.assertNull(result.headers());
    EdgeLabel edgeLabel = result.readObject(EdgeLabel.class);
    Assert.assertEquals("created", edgeLabel.name());
    Assert.assertEquals("person", edgeLabel.sourceLabel());
    Assert.assertEquals("software", edgeLabel.targetLabel());
    Assert.assertEquals(Frequency.SINGLE, edgeLabel.frequency());
    Assert.assertEquals(Collections.emptyList(), edgeLabel.sortKeys());
    Assert.assertEquals(ImmutableSet.of("date"), edgeLabel.properties());
}
Also used : RestResult(com.baidu.hugegraph.rest.RestResult) EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) Test(org.junit.Test)

Example 9 with EdgeLabel

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

the class EdgeLabelTest method testRemoveEdgeLabelAsync.

@Test
public void testRemoveEdgeLabelAsync() {
    SchemaManager schema = schema();
    EdgeLabel write = schema.edgeLabel("write").link("person", "book").properties("date", "weight").userdata("multiplicity", "one-to-many").userdata("icon", "picture2").create();
    Assert.assertNotNull(write);
    // Remove edge label async and wait
    long taskId = schema.removeEdgeLabelAsync("write");
    Task task = task().waitUntilTaskCompleted(taskId, 10);
    Assert.assertTrue(task.completed());
}
Also used : Task(com.baidu.hugegraph.structure.Task) EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Test(org.junit.Test)

Example 10 with EdgeLabel

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

the class EdgeLabelTest method testEliminateEdgeLabelWithUserData.

@Test
public void testEliminateEdgeLabelWithUserData() {
    SchemaManager schema = schema();
    EdgeLabel write = schema.edgeLabel("write").link("person", "book").properties("date", "weight").userdata("multiplicity", "one-to-many").userdata("icon", "picture2").create();
    Assert.assertEquals(3, write.userdata().size());
    Assert.assertEquals("one-to-many", write.userdata().get("multiplicity"));
    Assert.assertEquals("picture2", write.userdata().get("icon"));
    String time = (String) write.userdata().get("~create_time");
    Date createTime = DateUtil.parse(time);
    Assert.assertTrue(createTime.before(DateUtil.now()));
    write = schema.edgeLabel("write").userdata("icon", "").eliminate();
    Assert.assertEquals(2, write.userdata().size());
    Assert.assertEquals("one-to-many", write.userdata().get("multiplicity"));
    time = (String) write.userdata().get("~create_time");
    Assert.assertEquals(createTime, DateUtil.parse(time));
}
Also used : EdgeLabel(com.baidu.hugegraph.structure.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Date(java.util.Date) Test(org.junit.Test)

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