Added support to request contexts uuids in instances header #20012
This commit is contained in:
parent
23b6a531db
commit
1f37bf6400
1
pom.xml
1
pom.xml
|
@ -48,7 +48,6 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.information-system</groupId>
|
<groupId>org.gcube.information-system</groupId>
|
||||||
<artifactId>resource-registry-api</artifactId>
|
<artifactId>resource-registry-api</artifactId>
|
||||||
<version>[4.1.0-SNAPSHOT, 5.0.0-SNAPSHOT]</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.information-system</groupId>
|
<groupId>org.gcube.information-system</groupId>
|
||||||
|
|
|
@ -28,10 +28,28 @@ public class ResourceRegistryPublisherFactory {
|
||||||
return ResourceRegistryPublisherFactory.HIERARCHICAL_MODE;
|
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) {
|
public static void setHierarchicalMode(boolean hierarchicalMode) {
|
||||||
ResourceRegistryPublisherFactory.HIERARCHICAL_MODE = 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;
|
protected static List<String> addresses;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
|
|
@ -44,18 +44,33 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
||||||
|
|
||||||
protected final String address;
|
protected final String address;
|
||||||
|
|
||||||
private void checkHierarchicalMode(GXHTTPStringRequest gxHTTPStringRequest) throws UnsupportedEncodingException{
|
private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest) throws UnsupportedEncodingException{
|
||||||
checkHierarchicalMode(gxHTTPStringRequest, null);
|
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(ResourceRegistryPublisherFactory.isHierarchicalMode()) {
|
||||||
if(queryParams==null) {
|
if(queryParams==null) {
|
||||||
queryParams = new HashMap<>();
|
queryParams = new HashMap<>();
|
||||||
}
|
}
|
||||||
queryParams.put(AccessPath.HIERARCHICAL_MODE_PARAM, Boolean.toString(true));
|
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() {
|
protected ContextCacheRenewal contextCacheRenewal = new ContextCacheRenewal() {
|
||||||
|
@ -286,7 +301,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
||||||
gxHTTPStringRequest.path(type);
|
gxHTTPStringRequest.path(type);
|
||||||
gxHTTPStringRequest.path(uuid.toString());
|
gxHTTPStringRequest.path(uuid.toString());
|
||||||
|
|
||||||
checkHierarchicalMode(gxHTTPStringRequest);
|
includeAdditionalQueryParameters(gxHTTPStringRequest);
|
||||||
|
|
||||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.head();
|
HttpURLConnection httpURLConnection = gxHTTPStringRequest.head();
|
||||||
HTTPUtility.getResponse(String.class, httpURLConnection);
|
HTTPUtility.getResponse(String.class, httpURLConnection);
|
||||||
|
@ -332,7 +347,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
||||||
gxHTTPStringRequest.path(identifiableElementTypeName);
|
gxHTTPStringRequest.path(identifiableElementTypeName);
|
||||||
gxHTTPStringRequest.path(uuid.toString());
|
gxHTTPStringRequest.path(uuid.toString());
|
||||||
|
|
||||||
checkHierarchicalMode(gxHTTPStringRequest);
|
includeAdditionalQueryParameters(gxHTTPStringRequest);
|
||||||
|
|
||||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
|
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
|
||||||
String ret = HTTPUtility.getResponse(String.class, httpURLConnection);
|
String ret = HTTPUtility.getResponse(String.class, httpURLConnection);
|
||||||
|
|
Loading…
Reference in New Issue