Extended BaseRequestInfo to get new query parameters management for free
This commit is contained in:
parent
dbfa2901c0
commit
3670c234a4
|
@ -51,9 +51,20 @@ public interface ResourceRegistryPublisher extends RequestInfo {
|
|||
|
||||
public void addHeader(String name, String value);
|
||||
|
||||
|
||||
/**
|
||||
* Use {@link #getContexts()} instead
|
||||
* @return an array containing all contexts definition
|
||||
* @throws ResourceRegistryException if fails
|
||||
*/
|
||||
@Deprecated
|
||||
public List<Context> getAllContext() throws ResourceRegistryException;
|
||||
|
||||
/**
|
||||
* @return an array containing all contexts definition
|
||||
* @throws ResourceRegistryException if fails
|
||||
*/
|
||||
public List<Context> getContexts() throws ResourceRegistryException;
|
||||
|
||||
public Context getContext(UUID uuid) throws ContextNotFoundException, ResourceRegistryException;
|
||||
|
||||
public Context getCurrentContext() throws ContextNotFoundException, ResourceRegistryException;
|
||||
|
|
|
@ -10,12 +10,10 @@ import java.util.UUID;
|
|||
import org.gcube.common.gxhttp.reference.GXConnection;
|
||||
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
|
||||
import org.gcube.common.http.GXHTTPUtility;
|
||||
import org.gcube.informationsystem.base.reference.IdentifiableElement;
|
||||
import org.gcube.informationsystem.contexts.reference.entities.Context;
|
||||
import org.gcube.informationsystem.model.reference.ERElement;
|
||||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||
import org.gcube.informationsystem.model.reference.properties.Metadata;
|
||||
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
||||
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
||||
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
|
||||
|
@ -39,6 +37,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.isr
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.isrelatedto.IsRelatedToAvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.isrelatedto.IsRelatedToNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.request.BaseRequestInfo;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.InstancePath;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath;
|
||||
|
@ -51,7 +50,7 @@ import org.gcube.informationsystem.utils.UUIDUtility;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher {
|
||||
public class ResourceRegistryPublisherImpl extends BaseRequestInfo implements ResourceRegistryPublisher {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryPublisherImpl.class);
|
||||
|
||||
|
@ -61,27 +60,6 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
protected final String address;
|
||||
|
||||
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;
|
||||
|
||||
|
@ -107,32 +85,6 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
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 {
|
||||
addHierarchicalMode(queryParams);
|
||||
addIncludeContexts(queryParams);
|
||||
|
@ -181,7 +133,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
|
||||
@Override
|
||||
public List<Context> renew() throws ResourceRegistryException {
|
||||
return getAllContextFromServer();
|
||||
return getContextsFromServer();
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -205,12 +157,9 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
}
|
||||
|
||||
public ResourceRegistryPublisherImpl(String address, boolean sharedContextCache) {
|
||||
super();
|
||||
this.address = address;
|
||||
this.headers = new HashMap<>();
|
||||
this.hierarchicalMode = false;
|
||||
this.includeContexts = false;
|
||||
this.includeMeta = false;
|
||||
this.allMeta = false;
|
||||
if(sharedContextCache) {
|
||||
contextCache = ContextCache.getInstance();
|
||||
}else {
|
||||
|
@ -225,7 +174,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
* @return All Contexts read from server
|
||||
* @throws ResourceRegistryException
|
||||
*/
|
||||
public List<Context> getAllContextFromServer() throws ResourceRegistryException {
|
||||
public List<Context> getContextsFromServer() throws ResourceRegistryException {
|
||||
try {
|
||||
logger.info("Going to read all {}s", Context.NAME);
|
||||
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
|
||||
|
@ -255,9 +204,15 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public List<Context> getAllContext() throws ResourceRegistryException {
|
||||
return getContexts();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Context> getContexts() throws ResourceRegistryException {
|
||||
return contextCache.getContexts();
|
||||
}
|
||||
|
||||
|
|
|
@ -224,8 +224,8 @@ public class MultiContextTest extends ContextTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllContexts() throws Exception {
|
||||
List<Context> contexts = resourceRegistryPublisher.getAllContext();
|
||||
public void testGetContexts() throws Exception {
|
||||
List<Context> contexts = resourceRegistryPublisher.getContexts();
|
||||
logger.debug("{}", contexts);
|
||||
|
||||
ContextCache contextCache = ContextCache.getInstance();
|
||||
|
|
Loading…
Reference in New Issue