Search in sources :

Example 81 with RestResult

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

the class RestResultTest method testReadIndexLabels.

@Test
public void testReadIndexLabels() {
    String json = "{\"indexlabels\": [" + "{" + "\"id\": \"4\"," + "\"index_type\": \"SEARCH\"," + "\"base_value\": \"software\"," + "\"name\": \"softwareByPrice\"," + "\"fields\": [\"price\"]," + "\"base_type\": \"VERTEX_LABEL\"" + "}," + "{" + "\"id\": \"4\"," + "\"index_type\": \"SECONDARY\"," + "\"base_value\": \"person\"," + "\"name\": \"personByName\"," + "\"fields\": [\"name\"]," + "\"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());
    List<IndexLabel> indexLabels = result.readList("indexlabels", IndexLabel.class);
    Assert.assertEquals(2, indexLabels.size());
    IndexLabel indexLabel1 = indexLabels.get(0);
    IndexLabel indexLabel2 = indexLabels.get(1);
    Assert.assertEquals("softwareByPrice", indexLabel1.name());
    Assert.assertEquals(HugeType.VERTEX_LABEL, indexLabel1.baseType());
    Assert.assertEquals("software", indexLabel1.baseValue());
    Assert.assertEquals(IndexType.SEARCH, indexLabel1.indexType());
    Assert.assertEquals(ImmutableList.of("price"), indexLabel1.indexFields());
    Assert.assertEquals("personByName", indexLabel2.name());
    Assert.assertEquals(HugeType.VERTEX_LABEL, indexLabel2.baseType());
    Assert.assertEquals("person", indexLabel2.baseValue());
    Assert.assertEquals(IndexType.SECONDARY, indexLabel2.indexType());
    Assert.assertEquals(ImmutableList.of("name"), indexLabel2.indexFields());
}
Also used : RestResult(com.baidu.hugegraph.rest.RestResult) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) Test(org.junit.Test)

Example 82 with RestResult

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

the class GraphsAPI method mode.

public GraphMode mode(String graph) {
    RestResult result = this.client.get(joinPath(this.path(), graph), MODE);
    @SuppressWarnings("unchecked") Map<String, String> mode = result.readObject(Map.class);
    String value = mode.get(MODE);
    if (value == null) {
        throw new InvalidResponseException("Invalid response, expect 'mode' in response");
    }
    try {
        return GraphMode.valueOf(value);
    } catch (IllegalArgumentException e) {
        throw new InvalidResponseException("Invalid GraphMode value '%s'", value);
    }
}
Also used : RestResult(com.baidu.hugegraph.rest.RestResult) InvalidResponseException(com.baidu.hugegraph.exception.InvalidResponseException)

Example 83 with RestResult

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

the class GraphsAPI method readMode.

public GraphReadMode readMode(String graph) {
    this.client.checkApiVersion("0.59", "graph read mode");
    RestResult result = this.client.get(joinPath(this.path(), graph), GRAPH_READ_MODE);
    @SuppressWarnings("unchecked") Map<String, String> readMode = result.readObject(Map.class);
    String value = readMode.get(GRAPH_READ_MODE);
    if (value == null) {
        throw new InvalidResponseException("Invalid response, expect 'graph_read_mode' in response");
    }
    try {
        return GraphReadMode.valueOf(value);
    } catch (IllegalArgumentException e) {
        throw new InvalidResponseException("Invalid GraphReadMode value '%s'", value);
    }
}
Also used : RestResult(com.baidu.hugegraph.rest.RestResult) InvalidResponseException(com.baidu.hugegraph.exception.InvalidResponseException)

Example 84 with RestResult

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

the class EdgeAPI method append.

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

Example 85 with RestResult

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

the class VertexAPI method append.

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

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