Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TASK-4967 - ArrayOutOfBounds using cellbase client #664

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public class ParentRestClient<T> {
protected static final String META = "meta";
protected static final String WEBSERVICES = "webservices";
protected static final String REST = "rest";

private String apiKeyParam;
private String serverVersion;

@Deprecated
ParentRestClient(ClientConfiguration configuration) {
Expand Down Expand Up @@ -234,6 +235,8 @@ protected <U> CellBaseDataResponse<U> execute(List<String> idList, String resour
return new CellBaseDataResponse<>();
}

lazyInit();

// If the list contain less than REST_CALL_BATCH_SIZE variants then we can make a normal REST call.
if (idList.size() <= REST_CALL_BATCH_SIZE) {
return fetchData(idList, resource, options, clazz, post);
Expand Down Expand Up @@ -445,13 +448,6 @@ private <U> CellBaseDataResponse<U> restCall(List<String> hosts, String version,
// Add the last URL part, the 'action' or 'resource'
callUrl = callUrl.path(resource);

// Attention: parameter 'token' was renamed to 'apiKey' in CelBase v5.7
String apiKeyParam = null;
if (VersionUtils.isMinVersion("v5.7", configuration.getVersion())) {
apiKeyParam = API_KEY_PARAM;
} else if (VersionUtils.isMinVersion("v5.4", configuration.getVersion())) {
apiKeyParam = TOKEN_PARAM;
}

if (queryOptions != null) {
for (String s : queryOptions.keySet()) {
Expand All @@ -463,7 +459,7 @@ private <U> CellBaseDataResponse<U> restCall(List<String> hosts, String version,
if (dataRelease != null && StringUtils.isEmpty(queryOptions.getString(DATA_RELEASE_PARAM))) {
callUrl = callUrl.queryParam(DATA_RELEASE_PARAM, dataRelease);
}
if (apiKeyParam != null && apiKey != null && StringUtils.isEmpty(queryOptions.getString(API_KEY_PARAM))) {
if (apiKeyParam != null && apiKey != null && StringUtils.isEmpty(queryOptions.getString(apiKeyParam))) {
callUrl = callUrl.queryParam(apiKeyParam, apiKey);
}
} else {
Expand All @@ -490,6 +486,39 @@ private <U> CellBaseDataResponse<U> restCall(List<String> hosts, String version,
return parseResult(jsonString, clazz);
}

private void lazyInit() throws IOException {
// Lazy init other variables.
if (apiKey != null) {
String serverVersion = getServerVersion();

// Attention: parameter 'token' was renamed to 'apiKey' in CelBase v5.7
if (VersionUtils.isMinVersion("5.7.0", serverVersion)) {
apiKeyParam = API_KEY_PARAM;
} else if (VersionUtils.isMinVersion("5.4.0", serverVersion)) {
apiKeyParam = TOKEN_PARAM;
} // else { throw exception, api key not supported } ???
}
}

/**
* Get CellBase server version.
* @return CellBase full version
* @throws IOException on IOException
*/
public String getServerVersion() throws IOException {
if (serverVersion == null) {
initServerVersion();
}
return serverVersion;
}

private synchronized void initServerVersion() throws IOException {
if (serverVersion == null) {
ObjectMap about = new MetaClient(species, assembly, dataRelease, null, configuration).about().firstResult();
serverVersion = about.getString("Version");
}
}

protected WebTarget getBaseUrl(List<String> hosts, String version) {
return client
.target(URI.create(hosts.get(0)))
Expand Down
Loading