Search in sources :

Example 86 with RestResult

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

the class VertexAPI method list.

public Vertices list(String label, Map<String, Object> properties, boolean keepP, int offset, String page, int limit) {
    checkOffset(offset);
    checkLimit(limit, "Limit");
    String props = GraphAPI.formatProperties(properties);
    Map<String, Object> params = new LinkedHashMap<>();
    params.put("label", label);
    params.put("properties", props);
    params.put("keep_start_p", keepP);
    params.put("offset", offset);
    params.put("limit", limit);
    params.put("page", page);
    RestResult result = this.client.get(this.path(), params);
    return result.readObject(Vertices.class);
}
Also used : RestResult(com.baidu.hugegraph.rest.RestResult) LinkedHashMap(java.util.LinkedHashMap)

Example 87 with RestResult

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

the class VertexAPI method update.

public List<Vertex> update(BatchVertexRequest request) {
    this.client.checkApiVersion("0.45", "batch property update");
    MultivaluedHashMap<String, Object> headers = new MultivaluedHashMap<>();
    headers.putSingle("Content-Encoding", BATCH_ENCODING);
    RestResult result = this.client.put(this.batchPath(), null, request, headers);
    return result.readList(this.type(), Vertex.class);
}
Also used : MultivaluedHashMap(jakarta.ws.rs.core.MultivaluedHashMap) RestResult(com.baidu.hugegraph.rest.RestResult)

Example 88 with RestResult

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

the class VertexAPI method eliminate.

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

Example 89 with RestResult

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

the class VertexAPI method create.

public List<Object> create(List<Vertex> vertices) {
    MultivaluedHashMap<String, Object> headers = new MultivaluedHashMap<>();
    headers.putSingle("Content-Encoding", BATCH_ENCODING);
    RestResult result = this.client.post(this.batchPath(), vertices, headers);
    List<Object> ids = result.readList(Object.class);
    if (vertices.size() != ids.size()) {
        throw new NotAllCreatedException("Not all vertices are successfully created, " + "expect '%s', the actual is '%s'", ids, vertices.size(), ids.size());
    }
    return ids;
}
Also used : MultivaluedHashMap(jakarta.ws.rs.core.MultivaluedHashMap) RestResult(com.baidu.hugegraph.rest.RestResult) NotAllCreatedException(com.baidu.hugegraph.exception.NotAllCreatedException)

Example 90 with RestResult

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

the class VertexAPI method update.

public int update(BatchOlapPropertyRequest request) {
    this.client.checkApiVersion("0.59", "olap property batch update");
    MultivaluedHashMap<String, Object> headers = new MultivaluedHashMap<>();
    headers.putSingle("Content-Encoding", BATCH_ENCODING);
    String path = String.join("/", this.path(), "olap/batch");
    RestResult result = this.client.put(path, null, request, headers);
    Object size = result.readObject(Map.class).get("size");
    if (!(size instanceof Integer)) {
        throw new InvalidResponseException("The 'size' in response must be int, but got: %s(%s)", size, size.getClass());
    }
    return (int) size;
}
Also used : MultivaluedHashMap(jakarta.ws.rs.core.MultivaluedHashMap) RestResult(com.baidu.hugegraph.rest.RestResult) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedHashMap(java.util.LinkedHashMap) MultivaluedHashMap(jakarta.ws.rs.core.MultivaluedHashMap) Map(java.util.Map) InvalidResponseException(com.baidu.hugegraph.exception.InvalidResponseException)

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