Backported changes from version 2.0.0

This commit is contained in:
Luca Frosini 2026-02-10 11:49:47 +01:00
parent 88ca964023
commit 50a3767fb7
5 changed files with 1375 additions and 5 deletions

View File

@ -2,9 +2,10 @@ 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]
## [v1.2.0]
- Added support for paginated results [#24648]
- Backported changes from version 2.0.0
## [v1.1.1]

View File

@ -10,7 +10,7 @@
<groupId>org.gcube.information-system</groupId>
<artifactId>resource-registry-query-template-client</artifactId>
<version>1.2.0-SNAPSHOT</version>
<version>1.2.0</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.4.0</version>
<version>2.4.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>

View File

@ -12,22 +12,44 @@ public class ResourceRegistryQueryTemplateClientFactory {
private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryQueryTemplateClientFactory.class);
/**
* Gets the Resource Registry service URL using the current context.
*
* @return The complete URL for the Resource Registry service
*/
public static String getResourceRegistryURL() {
String address = String.format("%s/%s", ServiceInstance.getServiceURL(),Constants.SERVICE_NAME);
String address = "%s/%s".formatted(ServiceInstance.getServiceURL(), Constants.SERVICE_NAME);
return address;
}
/**
* Gets the Resource Registry service URL for a specific context.
*
* @param context The context to use for determining the service URL
* @return The complete URL for the Resource Registry service in the specified context
*/
public static String getResourceRegistryURL(String context) {
String address = String.format("%s/%s", ServiceInstance.getServiceURL(context),Constants.SERVICE_NAME);
String address = "%s/%s".formatted(ServiceInstance.getServiceURL(context), Constants.SERVICE_NAME);
return address;
}
/**
* Creates a new ResourceRegistryQueryTemplateClient instance using the current context.
*
* @return A new ResourceRegistryQueryTemplateClient instance configured for the current context
*/
public static ResourceRegistryQueryTemplateClient create() {
String address = getResourceRegistryURL();
logger.trace("The {} will be contacted at {}", Constants.SERVICE_NAME, address);
return new ResourceRegistryQueryTemplateClientImpl(address);
}
/**
* Creates a new ResourceRegistryQueryTemplateClient instance for a specific context.
*
* @param context The context to use for the ResourceRegistryQueryTemplateClient instance
* @return A new ResourceRegistryQueryTemplateClient instance configured for the specified context
*/
public static ResourceRegistryQueryTemplateClient create(String context) {
String address = getResourceRegistryURL(context);
logger.trace("The {} will be contacted at {}", Constants.SERVICE_NAME, address);

View File

@ -37,8 +37,10 @@ public class ResourceRegistryQueryTemplateClientImpl extends BaseRequestInfo imp
private static final String ACCEPT_HTTP_HEADER_KEY = "Accept";
private static final String CONTENT_TYPE_HTTP_HEADER_KEY = "Content-Type";
/** The base address of the Resource Registry Query Template service */
protected final String address;
/** Additional HTTP headers to be included in requests */
protected Map<String, String> headers;
private void addOptionalQueryParameters(Map<String,String> queryParams) throws UnsupportedEncodingException {
@ -83,11 +85,27 @@ public class ResourceRegistryQueryTemplateClientImpl extends BaseRequestInfo imp
}
}
/**
* {@inheritDoc}
*/
@Override
public void addHeader(String name, String value) {
headers.put(name, value);
}
/**
* {@inheritDoc}
*/
@Override
public void addHeader(String name, boolean value) {
addHeader(name, Boolean.toString(value));
}
/**
* Creates and configures a new HTTP request with authorization headers and custom headers.
*
* @return A configured GXHTTPStringRequest instance ready for use
*/
protected GXHTTPStringRequest getGXHTTPStringRequest() {
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPUtility.getGXHTTPStringRequest(address);
gxHTTPStringRequest.from(this.getClass().getSimpleName());
@ -97,6 +115,11 @@ public class ResourceRegistryQueryTemplateClientImpl extends BaseRequestInfo imp
return gxHTTPStringRequest;
}
/**
* Creates a new ResourceRegistryQueryTemplateClientImpl instance.
*
* @param address The base address of the Resource Registry Query Template service
*/
public ResourceRegistryQueryTemplateClientImpl(String address) {
this.address = address;
this.headers = new HashMap<>();
@ -106,6 +129,9 @@ public class ResourceRegistryQueryTemplateClientImpl extends BaseRequestInfo imp
this.allMeta = false;
}
/**
* {@inheritDoc}
*/
@Override
public List<QueryTemplate> all() throws ResourceRegistryException {
try {
@ -138,6 +164,11 @@ public class ResourceRegistryQueryTemplateClientImpl extends BaseRequestInfo imp
}
}
/**
* {@inheritDoc}
*
* This method is a type-safe wrapper that delegates to {@link #create(String)} for implementation details.
*/
@Override
public QueryTemplate create(QueryTemplate queryTemplate) throws QueryTemplateAlreadyPresentException, ResourceRegistryException {
try {
@ -151,6 +182,9 @@ public class ResourceRegistryQueryTemplateClientImpl extends BaseRequestInfo imp
}
}
/**
* {@inheritDoc}
*/
@Override
public String create(String queryTemplate) throws QueryTemplateAlreadyPresentException, ResourceRegistryException {
try {
@ -181,6 +215,9 @@ public class ResourceRegistryQueryTemplateClientImpl extends BaseRequestInfo imp
}
}
/**
* {@inheritDoc}
*/
@Override
public boolean exist(String queryTemplateName) throws ResourceRegistryException {
try {
@ -202,16 +239,31 @@ public class ResourceRegistryQueryTemplateClientImpl extends BaseRequestInfo imp
}
}
/**
* {@inheritDoc}
*
* This method is a type-safe wrapper that delegates to {@link #exist(String)} for implementation details.
*/
@Override
public boolean exist(QueryTemplate queryTemplate) throws ResourceRegistryException {
return exist(queryTemplate.getName());
}
/**
* {@inheritDoc}
*
* This method is a type-safe wrapper that delegates to {@link #read(String)} for implementation details.
*/
@Override
public QueryTemplate read(QueryTemplate queryTemplate) throws QueryTemplateNotFoundException, ResourceRegistryException {
return read(queryTemplate.getName());
}
/**
* {@inheritDoc}
*
* This method is a type-safe wrapper that delegates to {@link #readAsString(String)} for implementation details.
*/
@Override
public QueryTemplate read(String queryTemplateName) throws QueryTemplateNotFoundException, ResourceRegistryException {
try {
@ -224,6 +276,9 @@ public class ResourceRegistryQueryTemplateClientImpl extends BaseRequestInfo imp
}
}
/**
* {@inheritDoc}
*/
@Override
public String readAsString(String queryTemplateName) throws QueryTemplateNotFoundException, ResourceRegistryException {
try {
@ -250,6 +305,11 @@ public class ResourceRegistryQueryTemplateClientImpl extends BaseRequestInfo imp
}
}
/**
* {@inheritDoc}
*
* This method is a type-safe wrapper that delegates to {@link #update(String)} for implementation details.
*/
@Override
public QueryTemplate update(QueryTemplate queryTemplate) throws QueryTemplateNotFoundException, ResourceRegistryException {
try {
@ -263,6 +323,9 @@ public class ResourceRegistryQueryTemplateClientImpl extends BaseRequestInfo imp
}
}
/**
* {@inheritDoc}
*/
@Override
public String update(String queryTemplate) throws QueryTemplateNotFoundException, ResourceRegistryException {
try {
@ -294,11 +357,21 @@ public class ResourceRegistryQueryTemplateClientImpl extends BaseRequestInfo imp
}
}
/**
* {@inheritDoc}
*
* This method is a convenience wrapper that delegates to {@link #run(String, String)} with empty parameters for implementation details.
*/
@Override
public String runGetString(String name) throws QueryTemplateNotFoundException, ResourceRegistryException {
return run(name, "");
}
/**
* {@inheritDoc}
*
* This method is a type-safe wrapper that delegates to {@link #runGetString(String)} for implementation details.
*/
@Override
public <E extends ERElement> List<E> run(String name) throws QueryTemplateNotFoundException, ResourceRegistryException {
try {
@ -312,11 +385,19 @@ public class ResourceRegistryQueryTemplateClientImpl extends BaseRequestInfo imp
}
}
/**
* {@inheritDoc}
*
* This method is a type-safe wrapper that delegates to {@link #run(String)} for implementation details.
*/
@Override
public <E extends ERElement> List<E> run(QueryTemplate queryTemplate) throws QueryTemplateNotFoundException, ResourceRegistryException {
return run(queryTemplate.getName());
}
/**
* {@inheritDoc}
*/
@Override
public String run(String name, String params) throws QueryTemplateNotFoundException, ResourceRegistryException {
try {
@ -347,6 +428,11 @@ public class ResourceRegistryQueryTemplateClientImpl extends BaseRequestInfo imp
}
}
/**
* {@inheritDoc}
*
* This method is a type-safe wrapper that delegates to {@link #run(String, String)} for implementation details.
*/
@Override
public <E extends ERElement> List<E> run(String name, JsonNode jsonNode) throws QueryTemplateNotFoundException, ResourceRegistryException {
try {
@ -361,16 +447,29 @@ public class ResourceRegistryQueryTemplateClientImpl extends BaseRequestInfo imp
}
}
/**
* {@inheritDoc}
*
* This method is a type-safe wrapper that delegates to {@link #run(String, JsonNode)} for implementation details.
*/
@Override
public <E extends ERElement> List<E> run(QueryTemplate queryTemplate, JsonNode jsonNode) throws QueryTemplateNotFoundException, ResourceRegistryException {
return run(queryTemplate.getName(), jsonNode);
}
/**
* {@inheritDoc}
*
* This method is a type-safe wrapper that delegates to {@link #delete(String)} for implementation details.
*/
@Override
public boolean delete(QueryTemplate queryTemplate) throws QueryTemplateNotFoundException, ResourceRegistryException {
return delete(queryTemplate.getName());
}
/**
* {@inheritDoc}
*/
@Override
public boolean delete(String queryTemplateName) throws QueryTemplateNotFoundException, ResourceRegistryException {
try {