Compare commits
10 Commits
Author | SHA1 | Date |
---|---|---|
Luca Frosini | f932721e5f | |
luca.frosini | 1168cb3bbf | |
luca.frosini | d8cb6081bf | |
luca.frosini | d643e3cfe6 | |
Luca Frosini | 1061c80911 | |
Luca Frosini | 0b6700cd40 | |
Luca Frosini | 1bd0ecfffa | |
Luca Frosini | 12a38af3e8 | |
Luca Frosini | 563024eea5 | |
Luca Frosini | b53f9e9b25 |
|
@ -2,3 +2,5 @@ target
|
|||
.classpath
|
||||
.project
|
||||
.settings
|
||||
/.DS_Store
|
||||
/bin/
|
||||
|
|
10
CHANGELOG.md
10
CHANGELOG.md
|
@ -2,6 +2,16 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||
|
||||
# Changelog for Resource Registry Query Template Client
|
||||
|
||||
## [v1.2.0-SNAPSHOT]
|
||||
|
||||
- Added support for paginated results [#24648]
|
||||
|
||||
|
||||
## [v1.1.1]
|
||||
|
||||
- Migrated code to reorganized E/R format [#24992]
|
||||
|
||||
|
||||
## [v1.1.0]
|
||||
|
||||
- Fixed result of run from List<Entity> to List<ERElement>
|
||||
|
|
10
pom.xml
10
pom.xml
|
@ -10,7 +10,7 @@
|
|||
|
||||
<groupId>org.gcube.information-system</groupId>
|
||||
<artifactId>resource-registry-query-template-client</artifactId>
|
||||
<version>1.1.0</version>
|
||||
<version>1.2.0-SNAPSHOT</version>
|
||||
<name>Resource Registry Query Template Client</name>
|
||||
<description>Resource Registry Query Template Client is a library designed to interact with Resource Registry Query Template APIs</description>
|
||||
|
||||
|
@ -30,7 +30,7 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>gcube-bom</artifactId>
|
||||
<version>2.2.0</version>
|
||||
<version>2.4.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
@ -50,10 +50,6 @@
|
|||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>gxHTTP</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>common-utility-sg3</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
|
@ -78,7 +74,7 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-utils</artifactId>
|
||||
<version>[2.1.0, 3.0.0-SNAPSHOT)</version>
|
||||
<version>[2.2.0, 3.0.0-SNAPSHOT)</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
|
|
@ -8,11 +8,12 @@ import org.gcube.informationsystem.queries.templates.reference.entities.QueryTem
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.templates.QueryTemplateAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.templates.QueryTemplateNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.request.RequestInfo;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public interface ResourceRegistryQueryTemplateClient {
|
||||
public interface ResourceRegistryQueryTemplateClient extends RequestInfo {
|
||||
|
||||
public void addHeader(String name, String value);
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.gcube.informationsystem.resourceregistry.queries.templates;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -18,6 +19,8 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundExcep
|
|||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.templates.QueryTemplateAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.templates.QueryTemplateNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.request.BaseRequestInfo;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.QueryTemplatePath;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPUtility;
|
||||
import org.gcube.informationsystem.serialization.ElementMapper;
|
||||
|
@ -27,7 +30,7 @@ import org.slf4j.LoggerFactory;
|
|||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class ResourceRegistryQueryTemplateClientImpl implements ResourceRegistryQueryTemplateClient {
|
||||
public class ResourceRegistryQueryTemplateClientImpl extends BaseRequestInfo implements ResourceRegistryQueryTemplateClient {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryQueryTemplateClientImpl.class);
|
||||
|
||||
|
@ -38,6 +41,48 @@ public class ResourceRegistryQueryTemplateClientImpl implements ResourceRegistry
|
|||
|
||||
protected Map<String, String> headers;
|
||||
|
||||
private void addOptionalQueryParameters(Map<String,String> queryParams) throws UnsupportedEncodingException {
|
||||
addIncludeMeta(queryParams);
|
||||
addIncludeAllMeta(queryParams);
|
||||
}
|
||||
|
||||
private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest) throws UnsupportedEncodingException{
|
||||
Map<String,String> queryParams = new HashMap<>();
|
||||
return includeAdditionalQueryParameters(gxHTTPStringRequest, queryParams);
|
||||
}
|
||||
|
||||
private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest, Map<String,String> queryParams) throws UnsupportedEncodingException{
|
||||
if(queryParams==null) {
|
||||
queryParams = new HashMap<>();
|
||||
}
|
||||
addOptionalQueryParameters(queryParams);
|
||||
return gxHTTPStringRequest.queryParams(queryParams);
|
||||
}
|
||||
|
||||
private void addIncludeMeta(Map<String,String> queryParams) throws UnsupportedEncodingException{
|
||||
if(includeMeta) {
|
||||
queryParams.put(AccessPath.INCLUDE_META_QUERY_PARAMETER, Boolean.toString(includeMeta));
|
||||
}
|
||||
}
|
||||
|
||||
private void addIncludeAllMeta(Map<String,String> queryParams) throws UnsupportedEncodingException{
|
||||
if(allMeta) {
|
||||
queryParams.put(AccessPath.INCLUDE_META_IN_ALL_INSTANCES_QUERY_PARAMETER, Boolean.toString(allMeta));
|
||||
}
|
||||
}
|
||||
|
||||
private void addOffset(Map<String,String> queryParams) throws UnsupportedEncodingException{
|
||||
if(offset!=null) {
|
||||
queryParams.put(AccessPath.OFFSET_QUERY_PARAMETER, offset.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private void addLimit(Map<String,String> queryParams) throws UnsupportedEncodingException{
|
||||
if(limit!=null) {
|
||||
queryParams.put(AccessPath.LIMIT_QUERY_PARAMETER, limit.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addHeader(String name, String value) {
|
||||
headers.put(name, value);
|
||||
|
@ -55,6 +100,10 @@ public class ResourceRegistryQueryTemplateClientImpl implements ResourceRegistry
|
|||
public ResourceRegistryQueryTemplateClientImpl(String address) {
|
||||
this.address = address;
|
||||
this.headers = new HashMap<>();
|
||||
this.hierarchicalMode = false;
|
||||
this.includeContexts = false;
|
||||
this.includeMeta = false;
|
||||
this.allMeta = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -65,6 +114,13 @@ public class ResourceRegistryQueryTemplateClientImpl implements ResourceRegistry
|
|||
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
|
||||
gxHTTPStringRequest.path(QueryTemplatePath.QUERY_TEMPLATES_PATH_PART);
|
||||
|
||||
Map<String,String> parameters = new HashMap<>();
|
||||
addIncludeMeta(parameters);
|
||||
addIncludeAllMeta(parameters);
|
||||
addOffset(parameters);
|
||||
addLimit(parameters);
|
||||
gxHTTPStringRequest.queryParams(parameters);
|
||||
|
||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
|
||||
String all = HTTPUtility.getResponse(String.class, httpURLConnection);
|
||||
|
||||
|
@ -107,6 +163,11 @@ public class ResourceRegistryQueryTemplateClientImpl implements ResourceRegistry
|
|||
gxHTTPStringRequest.path(QueryTemplatePath.QUERY_TEMPLATES_PATH_PART);
|
||||
gxHTTPStringRequest.path(qt.getName());
|
||||
|
||||
Map<String,String> parameters = new HashMap<>();
|
||||
addIncludeMeta(parameters);
|
||||
addIncludeAllMeta(parameters);
|
||||
gxHTTPStringRequest.queryParams(parameters);
|
||||
|
||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.put(queryTemplate);
|
||||
String c = HTTPUtility.getResponse(String.class, httpURLConnection);
|
||||
|
||||
|
@ -172,6 +233,11 @@ public class ResourceRegistryQueryTemplateClientImpl implements ResourceRegistry
|
|||
gxHTTPStringRequest.path(QueryTemplatePath.QUERY_TEMPLATES_PATH_PART);
|
||||
gxHTTPStringRequest.path(queryTemplateName);
|
||||
|
||||
Map<String,String> parameters = new HashMap<>();
|
||||
addIncludeMeta(parameters);
|
||||
addIncludeAllMeta(parameters);
|
||||
gxHTTPStringRequest.queryParams(parameters);
|
||||
|
||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
|
||||
String c = HTTPUtility.getResponse(String.class, httpURLConnection);
|
||||
|
||||
|
@ -209,6 +275,12 @@ public class ResourceRegistryQueryTemplateClientImpl implements ResourceRegistry
|
|||
gxHTTPStringRequest.path(QueryTemplatePath.QUERY_TEMPLATES_PATH_PART);
|
||||
gxHTTPStringRequest.path(qt.getName());
|
||||
|
||||
Map<String,String> parameters = new HashMap<>();
|
||||
addIncludeMeta(parameters);
|
||||
addIncludeAllMeta(parameters);
|
||||
gxHTTPStringRequest.queryParams(parameters);
|
||||
|
||||
|
||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.put(queryTemplate);
|
||||
String c = HTTPUtility.getResponse(String.class, httpURLConnection);
|
||||
|
||||
|
@ -261,6 +333,8 @@ public class ResourceRegistryQueryTemplateClientImpl implements ResourceRegistry
|
|||
gxHTTPStringRequest.path(QueryTemplatePath.QUERY_TEMPLATES_PATH_PART);
|
||||
gxHTTPStringRequest.path(name);
|
||||
|
||||
includeAdditionalQueryParameters(gxHTTPStringRequest);
|
||||
|
||||
HttpURLConnection httpURLConnection = gxHTTPStringRequest.post(params);
|
||||
String c = HTTPUtility.getResponse(String.class, httpURLConnection);
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ import org.gcube.common.authorization.utils.secret.SecretUtility;
|
|||
import org.gcube.common.keycloak.KeycloakClientFactory;
|
||||
import org.gcube.common.keycloak.model.TokenResponse;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.informationsystem.model.reference.properties.Header;
|
||||
import org.gcube.informationsystem.model.reference.properties.Metadata;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -117,7 +117,7 @@ public class ContextTest {
|
|||
}
|
||||
|
||||
public static String getUser() {
|
||||
String user = Header.UNKNOWN_USER;
|
||||
String user = Metadata.UNKNOWN_USER;
|
||||
try {
|
||||
user = SecretManagerProvider.instance.get().getUser().getUsername();
|
||||
} catch(Exception e) {
|
||||
|
|
|
@ -10,7 +10,7 @@ import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
|||
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.gcube.informationsystem.base.reference.IdentifiableElement;
|
||||
import org.gcube.informationsystem.model.reference.entities.Entity;
|
||||
import org.gcube.informationsystem.model.reference.properties.Header;
|
||||
import org.gcube.informationsystem.model.reference.properties.Metadata;
|
||||
import org.gcube.informationsystem.queries.templates.impl.entities.QueryTemplateImpl;
|
||||
import org.gcube.informationsystem.queries.templates.impl.properties.TemplateVariableImpl;
|
||||
import org.gcube.informationsystem.queries.templates.reference.entities.QueryTemplate;
|
||||
|
@ -45,29 +45,32 @@ public class ResourceRegistryQueryTemplateClientTest extends ContextTest {
|
|||
}
|
||||
}
|
||||
|
||||
public static void checkHeader(IdentifiableElement previous, IdentifiableElement got) {
|
||||
Header gotHeader = got.getHeader();
|
||||
Header previousHeader = previous.getHeader();
|
||||
public static void checkUUIDAndMetadata(IdentifiableElement previous, IdentifiableElement got) {
|
||||
Metadata gotMetadata = got.getMetadata();
|
||||
Metadata previousMetadata = previous.getMetadata();
|
||||
|
||||
Assert.assertTrue(gotHeader != null);
|
||||
Assert.assertTrue(gotHeader.getUUID() != null);
|
||||
Assert.assertTrue(gotMetadata != null);
|
||||
Assert.assertTrue(got.getID() != null);
|
||||
|
||||
String user = ContextTest.getUser();
|
||||
Assert.assertTrue(gotHeader.getLastUpdateBy().compareTo(user) == 0);
|
||||
Assert.assertTrue(gotMetadata.getLastUpdateBy().compareTo(user) == 0);
|
||||
|
||||
if(previousHeader != null) {
|
||||
Assert.assertTrue(gotHeader.getUUID().compareTo(previousHeader.getUUID()) == 0);
|
||||
Assert.assertTrue(gotHeader.getCreatedBy().compareTo(user) == 0);
|
||||
Assert.assertTrue(gotHeader.getCreatedBy().compareTo(previousHeader.getCreatedBy()) == 0);
|
||||
Assert.assertTrue(gotHeader.getCreationTime().compareTo(previousHeader.getCreationTime()) == 0);
|
||||
if(previous.getID()!=null) {
|
||||
Assert.assertTrue(got.getID().compareTo(previous.getID()) == 0);
|
||||
}
|
||||
|
||||
if(previousMetadata != null) {
|
||||
Assert.assertTrue(gotMetadata.getCreatedBy().compareTo(user) == 0);
|
||||
Assert.assertTrue(gotMetadata.getCreatedBy().compareTo(previousMetadata.getCreatedBy()) == 0);
|
||||
Assert.assertTrue(gotMetadata.getCreationTime().compareTo(previousMetadata.getCreationTime()) == 0);
|
||||
}
|
||||
|
||||
Assert.assertFalse(gotHeader.getCreationTime().after(gotHeader.getLastUpdateTime()));
|
||||
Assert.assertFalse(gotMetadata.getCreationTime().after(gotMetadata.getLastUpdateTime()));
|
||||
|
||||
}
|
||||
|
||||
protected void assertions(QueryTemplate expected, QueryTemplate got) {
|
||||
checkHeader(expected, got);
|
||||
checkUUIDAndMetadata(expected, got);
|
||||
Assert.assertTrue(expected.getName().compareTo(got.getName()) == 0);
|
||||
Assert.assertTrue(expected.getDescription().compareTo(got.getDescription()) == 0);
|
||||
// Template and TemplateVariable should be compared
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
{
|
||||
"@class": "EService",
|
||||
"type": "EService",
|
||||
"consistsOf": [
|
||||
{
|
||||
"@class": "ConsistsOf",
|
||||
"type": "ConsistsOf",
|
||||
"propagationConstraint" : {
|
||||
"add": "propagate"
|
||||
},
|
||||
"target": {
|
||||
"@class": "StateFacet",
|
||||
"type": "StateFacet",
|
||||
"value": "$state"
|
||||
}
|
||||
},
|
||||
{
|
||||
"@class": "IsIdentifiedBy",
|
||||
"type": "IsIdentifiedBy",
|
||||
"target": {
|
||||
"@class": "SoftwareFacet",
|
||||
"type": "SoftwareFacet",
|
||||
"name": "$name",
|
||||
"group": "$group"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue