Skip to content

Commit

Permalink
basic support gs filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Thespica committed Nov 9, 2024
1 parent 5ecbae6 commit 7bd6bc3
Showing 1 changed file with 67 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@

package org.apache.hugegraph.client;

import java.util.Map;

import org.apache.hugegraph.exception.ServerException;
import org.apache.hugegraph.rest.AbstractRestClient;
import org.apache.hugegraph.rest.ClientException;
import org.apache.hugegraph.rest.RestClientConfig;
import org.apache.hugegraph.rest.RestHeaders;
import org.apache.hugegraph.rest.RestResult;
import org.apache.hugegraph.serializer.PathDeserializer;
import org.apache.hugegraph.structure.graph.Path;
Expand All @@ -34,14 +37,16 @@ public class RestClient extends AbstractRestClient {

private static final int SECOND = 1000;

private Version apiVersion = null;
private static boolean filter = false;

static {
SimpleModule module = new SimpleModule();
module.addDeserializer(Path.class, new PathDeserializer());
RestResult.registerModule(module);
}

private Version apiVersion = null;

public RestClient(String url, String username, String password, int timeout) {
super(url, username, password, timeout * SECOND);
}
Expand All @@ -58,6 +63,11 @@ public RestClient(String url, RestClientConfig config) {
super(url, config);
}

private static String removeDefaultGsPrefix(String path) {
final String DEFAULT_GS_PATH_PREFIX = "graphspaces/DEFAULT/";
return path.replaceFirst(DEFAULT_GS_PATH_PREFIX, "");
}

public void apiVersion(Version version) {
E.checkNotNull(version, "api version");
this.apiVersion = version;
Expand All @@ -80,9 +90,64 @@ public boolean apiVersionLt(String minVersion) {
return apiVersion != null && !VersionUtil.gte(apiVersion, minVersion);
}

@Override
public RestResult post(String path, Object object) {
return super.post(filter ? path : removeDefaultGsPrefix(path), object);
}

@Override
public RestResult get(String path, String id) {
return super.get(filter ? path : removeDefaultGsPrefix(path), id);
}

@Override
public RestResult delete(String path, Map<String, Object> params) {
return super.delete(filter ? path : removeDefaultGsPrefix(path), params);
}

@Override
public RestResult delete(String path, String id) {
return super.delete(filter ? path : removeDefaultGsPrefix(path), id);
}

@Override
public RestResult post(String path, Object object, RestHeaders headers) {
return super.post(filter ? path : removeDefaultGsPrefix(path), object, headers, null);
}

@Override
public RestResult post(String path, Object object, Map<String, Object> params) {
return super.post(filter ? path : removeDefaultGsPrefix(path), object, null, params);
}

@Override
public RestResult put(String path, String id, Object object) {
return super.put(filter ? path : removeDefaultGsPrefix(path), id, object, null, null);
}

@Override
public RestResult put(String path, String id, Object object, RestHeaders headers) {
return super.put(filter ? path : removeDefaultGsPrefix(path), id, object, headers, null);
}

@Override
public RestResult put(String path, String id, Object object, Map<String, Object> params) {
return super.put(filter ? path : removeDefaultGsPrefix(path), id, object, null, params);
}

@Override
public RestResult get(String path) {
return super.get(filter ? path : removeDefaultGsPrefix(path));
}

@Override
public RestResult get(String path, Map<String, Object> params) {
return super.get(filter ? path : removeDefaultGsPrefix(path), params);
}

@Override
protected void checkStatus(okhttp3.Response response, int... statuses) {
boolean match = false;
boolean match = filter;
for (int status : statuses) {
if (status == response.code()) {
match = true;
Expand Down

0 comments on commit 7bd6bc3

Please sign in to comment.