2017-12-15 05:04:27 +01:00
|
|
|
package org.gcube.resourcemanagement.manager.webapp.context;
|
|
|
|
|
2017-12-17 04:42:14 +01:00
|
|
|
import java.util.Objects;
|
|
|
|
|
2017-12-17 03:44:39 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClient;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClientFactory;
|
2017-12-17 04:42:14 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClientImpl;
|
2017-12-26 13:23:48 +01:00
|
|
|
import org.gcube.resourcemanagement.manager.io.exceptions.CodeException;
|
|
|
|
import org.gcube.resourcemanagement.manager.io.exceptions.RMCode;
|
2017-12-17 03:44:39 +01:00
|
|
|
|
2017-12-15 05:04:27 +01:00
|
|
|
/**
|
|
|
|
* Base request to an operation exposed by the Resource Registry.
|
|
|
|
*
|
|
|
|
* @author Manuele Simi (ISTI-CNR)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public abstract class RequestToResourceRegistry {
|
|
|
|
|
2017-12-17 04:42:14 +01:00
|
|
|
protected ResourceRegistryContextClient resourceRegistryContextClient;
|
2017-12-17 03:44:39 +01:00
|
|
|
|
2017-12-15 05:04:27 +01:00
|
|
|
/**
|
2017-12-16 04:29:16 +01:00
|
|
|
* Forces to use a RR instance at the given url.
|
|
|
|
*
|
2017-12-15 05:04:27 +01:00
|
|
|
* @param forceURL
|
|
|
|
*/
|
|
|
|
public RequestToResourceRegistry forceURL(String forceURL) {
|
2017-12-20 05:12:05 +01:00
|
|
|
this.resourceRegistryContextClient = new ResourceRegistryContextClientImpl(forceURL);
|
2017-12-15 05:04:27 +01:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2017-12-16 04:29:16 +01:00
|
|
|
/**
|
|
|
|
* Validates the request.
|
|
|
|
*
|
|
|
|
* @return the response from the service.
|
|
|
|
*/
|
|
|
|
abstract public RequestToResourceRegistry validate() throws Exception;
|
|
|
|
|
|
|
|
public ResponseFromResourceRegistry submit() {
|
|
|
|
try {
|
|
|
|
this.validate();
|
|
|
|
} catch (Exception e) {
|
2017-12-26 13:23:48 +01:00
|
|
|
ResponseFromResourceRegistry response = ResponseFromResourceRegistry.
|
|
|
|
fromException(new CodeException(RMCode.INVALID_REQUEST));
|
2017-12-16 04:29:16 +01:00
|
|
|
return response;
|
|
|
|
}
|
2017-12-17 04:42:14 +01:00
|
|
|
if (Objects.isNull(this.resourceRegistryContextClient))
|
|
|
|
this.resourceRegistryContextClient = ResourceRegistryContextClientFactory.create();
|
2017-12-19 05:02:42 +01:00
|
|
|
return this.validateResponse(this.send());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gives a chance to sub-classes to validate the response.
|
2017-12-20 05:12:05 +01:00
|
|
|
*
|
2017-12-19 05:02:42 +01:00
|
|
|
* @param response
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
protected ResponseFromResourceRegistry validateResponse(ResponseFromResourceRegistry response) {
|
2017-12-20 05:12:05 +01:00
|
|
|
// by default, returns the response as it is
|
2017-12-19 05:02:42 +01:00
|
|
|
return response;
|
2017-12-16 04:29:16 +01:00
|
|
|
}
|
2017-12-15 05:04:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Submits the request to the RR.
|
2017-12-16 04:29:16 +01:00
|
|
|
*
|
2017-12-15 05:04:27 +01:00
|
|
|
* @return the response from the service.
|
|
|
|
*/
|
2017-12-16 04:29:16 +01:00
|
|
|
abstract protected ResponseFromResourceRegistry send();
|
2017-12-15 05:04:27 +01:00
|
|
|
|
|
|
|
}
|