Extended BaseRequestInfo to get new query parameters management for free

This commit is contained in:
luca.frosini 2023-09-13 18:42:25 +02:00
parent de47918497
commit 164be53064
1 changed files with 3 additions and 63 deletions

View File

@ -36,6 +36,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.Cont
import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.templates.QueryTemplateNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.templates.QueryTemplateNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.request.BaseRequestInfo;
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath; import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
import org.gcube.informationsystem.resourceregistry.api.rest.ContextPath; import org.gcube.informationsystem.resourceregistry.api.rest.ContextPath;
import org.gcube.informationsystem.resourceregistry.api.rest.InstancePath; import org.gcube.informationsystem.resourceregistry.api.rest.InstancePath;
@ -52,7 +53,7 @@ import org.slf4j.LoggerFactory;
/** /**
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
*/ */
public class ResourceRegistryClientImpl implements ResourceRegistryClient { public class ResourceRegistryClientImpl extends BaseRequestInfo implements ResourceRegistryClient {
private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryClientImpl.class); private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryClientImpl.class);
@ -63,39 +64,8 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
protected Map<String, String> headers; protected Map<String, String> headers;
/**
* Track if the client must request the hierarchicalMode
*/
protected boolean hierarchicalMode;
/**
* Track if the client must request to include contexts
*/
protected boolean includeContexts;
/**
* Track if the client must request to include {@link Metadata}
*/
protected boolean includeMeta;
/**
* Track if the client must request to include {@link Metadata} in all
* {@link IdentifiableElement} or just in the root instance
*/
protected boolean allMeta;
protected ContextCache contextCache; protected ContextCache contextCache;
@Override
public boolean isHierarchicalMode() {
return hierarchicalMode;
}
@Override
public void setHierarchicalMode(boolean hierarchicalMode) {
this.hierarchicalMode = hierarchicalMode;
}
@Deprecated @Deprecated
@Override @Override
public boolean isIncludeContextsInHeader() { public boolean isIncludeContextsInHeader() {
@ -108,33 +78,6 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
setIncludeContexts(includeContexts); setIncludeContexts(includeContexts);
} }
@Override
public boolean includeContexts() {
return includeContexts;
}
@Override
public void setIncludeContexts(boolean includeContexts) {
this.includeContexts = includeContexts;
}
public boolean includeMeta() {
return includeMeta;
}
public void setIncludeMeta(boolean includeMeta) {
this.includeMeta = includeMeta;
}
public boolean allMeta() {
return allMeta;
}
public void setAllMeta(boolean allMeta) {
this.allMeta = allMeta;
}
private void addOptionalQueryParameters(Map<String,String> queryParams) throws UnsupportedEncodingException { private void addOptionalQueryParameters(Map<String,String> queryParams) throws UnsupportedEncodingException {
addHierarchicalMode(queryParams); addHierarchicalMode(queryParams);
addIncludeContexts(queryParams); addIncludeContexts(queryParams);
@ -207,11 +150,8 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
} }
public ResourceRegistryClientImpl(String address, boolean sharedContextCache) { public ResourceRegistryClientImpl(String address, boolean sharedContextCache) {
super();
this.address = address; this.address = address;
this.hierarchicalMode = false;
this.includeContexts = false;
this.includeMeta = false;
this.allMeta = false;
this.headers = new HashMap<>(); this.headers = new HashMap<>();
if(sharedContextCache) { if(sharedContextCache) {
contextCache = ContextCache.getInstance(); contextCache = ContextCache.getInstance();