You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.0 KiB
Java
70 lines
2.0 KiB
Java
package org.gcube.resourcemanagement.manager.webapp.context;
|
|
|
|
import java.util.Objects;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClient;
|
|
import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClientFactory;
|
|
import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClientImpl;
|
|
import org.gcube.resourcemanagement.manager.io.exceptions.CodeException;
|
|
import org.gcube.resourcemanagement.manager.io.exceptions.RMCode;
|
|
|
|
/**
|
|
* Base request to an operation exposed by the Resource Registry.
|
|
*
|
|
* @author Manuele Simi (ISTI-CNR)
|
|
*
|
|
*/
|
|
public abstract class RequestToResourceRegistry {
|
|
|
|
protected ResourceRegistryContextClient resourceRegistryContextClient;
|
|
|
|
/**
|
|
* Forces to use a RR instance at the given url.
|
|
*
|
|
* @param forceURL
|
|
*/
|
|
public RequestToResourceRegistry forceURL(String forceURL) {
|
|
this.resourceRegistryContextClient = new ResourceRegistryContextClientImpl(forceURL);
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Validates the request.
|
|
*
|
|
* @return the response from the service.
|
|
*/
|
|
abstract public RequestToResourceRegistry validate() throws Exception;
|
|
|
|
public ResponseFromResourceRegistry submit() {
|
|
try {
|
|
this.validate();
|
|
} catch (Exception e) {
|
|
ResponseFromResourceRegistry response = ResponseFromResourceRegistry.
|
|
fromException(new CodeException(RMCode.INVALID_REQUEST));
|
|
return response;
|
|
}
|
|
if (Objects.isNull(this.resourceRegistryContextClient))
|
|
this.resourceRegistryContextClient = ResourceRegistryContextClientFactory.create();
|
|
return this.validateResponse(this.send());
|
|
}
|
|
|
|
/**
|
|
* Gives a chance to sub-classes to validate the response.
|
|
*
|
|
* @param response
|
|
* @return
|
|
*/
|
|
protected ResponseFromResourceRegistry validateResponse(ResponseFromResourceRegistry response) {
|
|
// by default, returns the response as it is
|
|
return response;
|
|
}
|
|
|
|
/**
|
|
* Submits the request to the RR.
|
|
*
|
|
* @return the response from the service.
|
|
*/
|
|
abstract protected ResponseFromResourceRegistry send();
|
|
|
|
}
|