Search in sources :

Example 46 with RestResult

use of com.baidu.hugegraph.rest.RestResult in project incubator-hugegraph-toolchain by apache.

the class TaskAPI method list.

public List<Task> list(List<Long> ids) {
    Map<String, Object> params = new LinkedHashMap<>();
    params.put("ids", ids);
    RestResult result = this.client.get(this.path(), params);
    return result.readList(TASKS, Task.class);
}
Also used : RestResult(com.baidu.hugegraph.rest.RestResult) LinkedHashMap(java.util.LinkedHashMap)

Example 47 with RestResult

use of com.baidu.hugegraph.rest.RestResult in project incubator-hugegraph-toolchain by apache.

the class TaskAPI method cancel.

public Task cancel(long id) {
    Map<String, Object> params = ImmutableMap.of("action", "cancel");
    RestResult result = this.client.put(path(), String.valueOf(id), ImmutableMap.of(), params);
    return result.readObject(Task.class);
}
Also used : RestResult(com.baidu.hugegraph.rest.RestResult)

Example 48 with RestResult

use of com.baidu.hugegraph.rest.RestResult in project incubator-hugegraph-toolchain by apache.

the class AccessAPI method update.

public Access update(Access access) {
    String id = formatRelationId(access.id());
    RestResult result = this.client.put(this.path(), id, access);
    return result.readObject(Access.class);
}
Also used : RestResult(com.baidu.hugegraph.rest.RestResult)

Example 49 with RestResult

use of com.baidu.hugegraph.rest.RestResult in project incubator-hugegraph-toolchain by apache.

the class RestResultTest method testReadIndexLabel.

@Test
public void testReadIndexLabel() {
    String json = "{" + "\"id\": \"4\"," + "\"index_type\": \"SEARCH\"," + "\"base_value\": \"software\"," + "\"name\": \"softwareByPrice\"," + "\"fields\": [\"price\"]," + "\"base_type\": \"VERTEX_LABEL\"" + "}";
    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());
    IndexLabel indexLabel = result.readObject(IndexLabel.class);
    Assert.assertEquals("softwareByPrice", indexLabel.name());
    Assert.assertEquals(HugeType.VERTEX_LABEL, indexLabel.baseType());
    Assert.assertEquals("software", indexLabel.baseValue());
    Assert.assertEquals(IndexType.SEARCH, indexLabel.indexType());
    Assert.assertEquals(ImmutableList.of("price"), indexLabel.indexFields());
}
Also used : RestResult(com.baidu.hugegraph.rest.RestResult) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) Test(org.junit.Test)

Example 50 with RestResult

use of com.baidu.hugegraph.rest.RestResult in project incubator-hugegraph-toolchain by apache.

the class RestResultTest method testReadGremlinPathWithVertexAndEdge.

@Test
public void testReadGremlinPathWithVertexAndEdge() {
    String json = "{" + "\"requestId\": \"238c74ca-18f7-4377-b8e1-2bb3b165e5d6\"," + "\"status\":{" + "\"message\": \"\"," + "\"code\": 200," + "\"attributes\":{}" + "}," + "\"result\":{" + "\"data\":[" + "{" + "\"labels\":[[], []]," + "\"objects\":[" + "{" + "\"id\": \"person:marko\"," + "\"label\": \"person\"," + "\"type\": \"vertex\"," + "\"properties\":{" + "\"city\":\"Beijing\"," + "\"name\":\"marko\"," + "\"age\":29" + "}" + "}," + "{" + "\"id\": \"person:marko>knows>>person:vadas\"," + "\"label\": \"knows\"," + "\"type\": \"edge\"," + "\"inVLabel\": \"person\"," + "\"outVLabel\": \"person\"," + "\"inV\": \"person:vadas\"," + "\"outV\": \"person:marko\"," + "\"properties\":{" + "\"date\": 1452355200000," + "\"weight\": 0.5" + "}" + "}" + "]" + "}" + "]," + "\"meta\":{" + "}" + "}" + "}";
    Mockito.when(this.mockResponse.getStatus()).thenReturn(200);
    Mockito.when(this.mockResponse.getHeaders()).thenReturn(null);
    Mockito.when(this.mockResponse.readEntity(String.class)).thenReturn(json);
    RestResult restResult = new RestResult(this.mockResponse);
    Assert.assertEquals(200, restResult.status());
    Assert.assertNull(restResult.headers());
    Response response = restResult.readObject(Response.class);
    response.graphManager(graph());
    Assert.assertEquals(200, response.status().code());
    Iterator<Result> results = response.result().iterator();
    Assert.assertTrue(results.hasNext());
    Result result = results.next();
    Object object = result.getObject();
    Assert.assertEquals(Path.class, object.getClass());
    Path path = (Path) object;
    Assert.assertEquals(2, path.labels().size());
    Assert.assertEquals(ImmutableList.of(), path.labels().get(0));
    Assert.assertEquals(ImmutableList.of(), path.labels().get(1));
    Vertex vertex = new Vertex("person");
    vertex.id("person:marko");
    vertex.property("name", "marko");
    vertex.property("age", 29);
    vertex.property("city", "Beijing");
    Edge edge = new Edge("knows");
    edge.id("person:marko>knows>>person:vadas");
    edge.sourceId("person:marko");
    edge.sourceLabel("person");
    edge.targetId("person:vadas");
    edge.targetLabel("person");
    edge.property("date", 1452355200000L);
    edge.property("weight", 0.5);
    Assert.assertEquals(2, path.objects().size());
    Utils.assertGraphEqual(ImmutableList.of(vertex), ImmutableList.of(edge), path.objects());
}
Also used : Response(com.baidu.hugegraph.structure.gremlin.Response) Path(com.baidu.hugegraph.structure.graph.Path) Vertex(com.baidu.hugegraph.structure.graph.Vertex) RestResult(com.baidu.hugegraph.rest.RestResult) Edge(com.baidu.hugegraph.structure.graph.Edge) Result(com.baidu.hugegraph.structure.gremlin.Result) RestResult(com.baidu.hugegraph.rest.RestResult) Test(org.junit.Test)

Aggregations

RestResult (com.baidu.hugegraph.rest.RestResult)132 Test (org.junit.Test)44 LinkedHashMap (java.util.LinkedHashMap)23 AbstractRestClient (com.baidu.hugegraph.rest.AbstractRestClient)19 RestClient (com.baidu.hugegraph.rest.RestClient)19 MultivaluedHashMap (jakarta.ws.rs.core.MultivaluedHashMap)12 Response (com.baidu.hugegraph.structure.gremlin.Response)6 Result (com.baidu.hugegraph.structure.gremlin.Result)6 PropertyKey (com.baidu.hugegraph.structure.schema.PropertyKey)6 Edge (com.baidu.hugegraph.structure.graph.Edge)5 Vertex (com.baidu.hugegraph.structure.graph.Vertex)5 Map (java.util.Map)5 IndexLabel (com.baidu.hugegraph.structure.schema.IndexLabel)4 InvalidResponseException (com.baidu.hugegraph.exception.InvalidResponseException)3 NotSupportException (com.baidu.hugegraph.exception.NotSupportException)3 EdgeLabel (com.baidu.hugegraph.structure.schema.EdgeLabel)3 VertexLabel (com.baidu.hugegraph.structure.schema.VertexLabel)3 ArrayList (java.util.ArrayList)3 NotAllCreatedException (com.baidu.hugegraph.exception.NotAllCreatedException)2 Project (com.baidu.hugegraph.structure.auth.Project)2