Added support to request contexts uuids in instances header #20012

This commit is contained in:
Luca Frosini 2020-11-09 15:48:06 +01:00
parent 23b6a531db
commit 1f37bf6400
3 changed files with 39 additions and 7 deletions

View File

@ -48,7 +48,6 @@
<dependency>
<groupId>org.gcube.information-system</groupId>
<artifactId>resource-registry-api</artifactId>
<version>[4.1.0-SNAPSHOT, 5.0.0-SNAPSHOT]</version>
</dependency>
<dependency>
<groupId>org.gcube.information-system</groupId>

View File

@ -28,10 +28,28 @@ public class ResourceRegistryPublisherFactory {
return ResourceRegistryPublisherFactory.HIERARCHICAL_MODE;
}
/**
* The affected methods are {@link ResourceRegistryPublisher} safe methods i.e. read* and exists*
* @param hierarchicalMode
*/
public static void setHierarchicalMode(boolean hierarchicalMode) {
ResourceRegistryPublisherFactory.HIERARCHICAL_MODE = hierarchicalMode;
}
protected static boolean INCLUDE_CONTEXTS_IN_INSTANCES_HEADER;
protected static boolean includeContextsInInstanceHeader() {
return ResourceRegistryPublisherFactory.INCLUDE_CONTEXTS_IN_INSTANCES_HEADER;
}
/**
* The affected methods are {@link ResourceRegistryClient} instances safe methods i.e. read* and exists*
* @param hierarchicalMode
*/
public static void includeContextsInInstanceHeader(boolean includeContextsInInstancesHeader) {
ResourceRegistryPublisherFactory.INCLUDE_CONTEXTS_IN_INSTANCES_HEADER = includeContextsInInstancesHeader;
}
protected static List<String> addresses;
static {

View File

@ -44,18 +44,33 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
protected final String address;
private void checkHierarchicalMode(GXHTTPStringRequest gxHTTPStringRequest) throws UnsupportedEncodingException{
checkHierarchicalMode(gxHTTPStringRequest, null);
private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest) throws UnsupportedEncodingException{
return includeAdditionalQueryParameters(gxHTTPStringRequest, null);
}
private void checkHierarchicalMode(GXHTTPStringRequest gxHTTPStringRequest, Map<String,String> queryParams) throws UnsupportedEncodingException{
private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest, Map<String,String> queryParams) throws UnsupportedEncodingException{
gxHTTPStringRequest = checkHierarchicalMode(gxHTTPStringRequest, queryParams);
return checkIncludeContextsInInstanceHeader(gxHTTPStringRequest, queryParams);
}
private GXHTTPStringRequest checkHierarchicalMode(GXHTTPStringRequest gxHTTPStringRequest, Map<String,String> queryParams) throws UnsupportedEncodingException{
if(ResourceRegistryPublisherFactory.isHierarchicalMode()) {
if(queryParams==null) {
queryParams = new HashMap<>();
}
queryParams.put(AccessPath.HIERARCHICAL_MODE_PARAM, Boolean.toString(true));
}
gxHTTPStringRequest.queryParams(queryParams);
return gxHTTPStringRequest.queryParams(queryParams);
}
private GXHTTPStringRequest checkIncludeContextsInInstanceHeader(GXHTTPStringRequest gxHTTPStringRequest, Map<String,String> queryParams) throws UnsupportedEncodingException{
if(ResourceRegistryPublisherFactory.includeContextsInInstanceHeader()) {
if(queryParams==null) {
queryParams = new HashMap<>();
}
queryParams.put(AccessPath.INCLUDE_CONTEXTS_IN_HEADER_PARAM, Boolean.toString(true));
}
return gxHTTPStringRequest.queryParams(queryParams);
}
protected ContextCacheRenewal contextCacheRenewal = new ContextCacheRenewal() {
@ -286,7 +301,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
gxHTTPStringRequest.path(type);
gxHTTPStringRequest.path(uuid.toString());
checkHierarchicalMode(gxHTTPStringRequest);
includeAdditionalQueryParameters(gxHTTPStringRequest);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.head();
HTTPUtility.getResponse(String.class, httpURLConnection);
@ -332,7 +347,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
gxHTTPStringRequest.path(identifiableElementTypeName);
gxHTTPStringRequest.path(uuid.toString());
checkHierarchicalMode(gxHTTPStringRequest);
includeAdditionalQueryParameters(gxHTTPStringRequest);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
String ret = HTTPUtility.getResponse(String.class, httpURLConnection);