Search in sources :

Example 1 with InvalidResponseException

use of com.baidu.hugegraph.exception.InvalidResponseException 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 2 with InvalidResponseException

use of com.baidu.hugegraph.exception.InvalidResponseException 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 3 with InvalidResponseException

use of com.baidu.hugegraph.exception.InvalidResponseException 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

InvalidResponseException (com.baidu.hugegraph.exception.InvalidResponseException)3 RestResult (com.baidu.hugegraph.rest.RestResult)3 ImmutableMap (com.google.common.collect.ImmutableMap)1 MultivaluedHashMap (jakarta.ws.rs.core.MultivaluedHashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1