|
|
|
@ -26,6 +26,7 @@ import org.gcube.common.resources.gcore.Resource;
|
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
|
import org.gcube.common.scope.impl.ScopeBean;
|
|
|
|
|
import org.gcube.common.scope.impl.ScopeBean.Type;
|
|
|
|
|
import org.gcube.informationsystem.publisher.AdvancedPublisher;
|
|
|
|
|
import org.gcube.informationsystem.publisher.RegistryPublisher;
|
|
|
|
|
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
|
|
|
|
|
import org.gcube.resourcemanagement.support.server.exceptions.AbstractResourceException;
|
|
|
|
@ -175,7 +176,7 @@ public abstract class AbstractResourceManager {
|
|
|
|
|
* @throws ResourceParameterException if the parameters are invalid
|
|
|
|
|
*/
|
|
|
|
|
public final RMBinderLibrary getResourceManager(String scope) throws AbstractResourceException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ScopeBean bscope = new ScopeBean(scope);
|
|
|
|
|
if (bscope.is(Type.VRE)) {
|
|
|
|
|
scope = bscope.enclosingScope().toString();
|
|
|
|
@ -202,7 +203,7 @@ public abstract class AbstractResourceManager {
|
|
|
|
|
scope = bscope.enclosingScope().toString();
|
|
|
|
|
}
|
|
|
|
|
ScopeProvider.instance.set(scope);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ServerConsole.info(LOG_PREFIX, "Getting Resource Manager in scope [" + scope.toString() + "]");
|
|
|
|
|
RMReportingLibrary rml = Proxies.reportingService().build();
|
|
|
|
|
if (rml == null) { // no managers found
|
|
|
|
@ -232,7 +233,7 @@ public abstract class AbstractResourceManager {
|
|
|
|
|
targetScope.toString() + "]");
|
|
|
|
|
String curr = ScopeProvider.instance.get();
|
|
|
|
|
ScopeProvider.instance.set(targetScope.toString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AddResourcesParameters addParam = new AddResourcesParameters();
|
|
|
|
|
ResourceItem toAdd = new ResourceItem();
|
|
|
|
|
toAdd.setId(this.getID());
|
|
|
|
@ -261,7 +262,7 @@ public abstract class AbstractResourceManager {
|
|
|
|
|
targetScope.toString() + "]... reportID: " + reportID);
|
|
|
|
|
|
|
|
|
|
RMReportingLibrary pt = this.getReportResourceManager(scope.toString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String toReturn = pt.getReport(reportID);
|
|
|
|
|
ScopeProvider.instance.set(curr);
|
|
|
|
|
return toReturn;
|
|
|
|
@ -286,7 +287,7 @@ public abstract class AbstractResourceManager {
|
|
|
|
|
checker.validate(sourceScope != null, new ResourceParameterException("Invalid parameter sourceScope. null not allowed."));
|
|
|
|
|
checker.validate(targetScope != null, new ResourceParameterException("Invalid parameter targetScope. null not allowed."));
|
|
|
|
|
checker.validate(this.getID() != null, new ResourceOperationException("Invalid resource ID. null not allowed."));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String curr = ScopeProvider.instance.get();
|
|
|
|
|
ScopeProvider.instance.set(sourceScope.toString());
|
|
|
|
|
ReportBuilder report = new ReportBuilder();
|
|
|
|
@ -319,7 +320,7 @@ public abstract class AbstractResourceManager {
|
|
|
|
|
targetScope.toString() + " the remote report ID is: " +
|
|
|
|
|
this.bindToScope(targetScope.toString()), true));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String toReturn = report.getXML();
|
|
|
|
|
ScopeProvider.instance.set(curr);
|
|
|
|
|
return toReturn;
|
|
|
|
@ -407,9 +408,9 @@ public abstract class AbstractResourceManager {
|
|
|
|
|
protected final String getXMLDescription(final ScopeBean scope) throws AbstractResourceException {
|
|
|
|
|
Assertion<AbstractResourceException> checker = new Assertion<AbstractResourceException>();
|
|
|
|
|
checker.validate(this.getID() != null, new ResourceAccessException("Cannot execute on resources with no ID."));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ScopeProvider.instance.set(scope.toString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Phase 1. retrieve the resource to copy
|
|
|
|
|
Query query = new QueryBox("for $resource in collection('/db/Profiles/" + this.getType().name() + "')//Resource " +
|
|
|
|
|
"where ( $resource/ID/string() eq '" +
|
|
|
|
@ -423,7 +424,7 @@ public abstract class AbstractResourceManager {
|
|
|
|
|
if (results == null || results.isEmpty())
|
|
|
|
|
throw new ResourceAccessException("Cannot retrieve the IS profile for resource: " + this.getID() +
|
|
|
|
|
" in scope: " + scope.toString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return results.get(0).toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -475,10 +476,10 @@ public abstract class AbstractResourceManager {
|
|
|
|
|
Assertion<AbstractResourceException> checker = new Assertion<AbstractResourceException>();
|
|
|
|
|
checker.validate(scope != null, new ResourceParameterException("Invalid parameter scope. null not allowed."));
|
|
|
|
|
checker.validate(this.getID() != null, new ResourceOperationException("Invalid ID. null not allowed."));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ScopeProvider.instance.set(scope.toString());
|
|
|
|
|
String retval = this.basicRemoveFromScope(scope);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -503,14 +504,20 @@ public abstract class AbstractResourceManager {
|
|
|
|
|
* @param scope where the resource is bound
|
|
|
|
|
* @throws AbstractResourceException
|
|
|
|
|
*/
|
|
|
|
|
public final void forceDelete(final ScopeBean scope) throws AbstractResourceException {
|
|
|
|
|
ServerConsole.trace(LOG_PREFIX, "[DELETE] [DELETE-BRANCH] deleting resource since no more scopes remained");
|
|
|
|
|
Resource resStub = this.getResource(scope);
|
|
|
|
|
try {
|
|
|
|
|
this.getRegistryPublisher().remove(resStub);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
ServerConsole.error(LOG_PREFIX, e);
|
|
|
|
|
}
|
|
|
|
|
public final void forceDelete(ScopeBean scope) throws AbstractResourceException {
|
|
|
|
|
ServerConsole.trace(LOG_PREFIX, "[FORCE DELETE] [DELETE-BRANCH] deleting resource from scope " + scope);
|
|
|
|
|
String currScope = ScopeProvider.instance.get();
|
|
|
|
|
|
|
|
|
|
Resource toDelete = this.getResource(scope);
|
|
|
|
|
|
|
|
|
|
while (scope.enclosingScope() != null)
|
|
|
|
|
scope = scope.enclosingScope();
|
|
|
|
|
|
|
|
|
|
ScopeProvider.instance.set(scope.toString());
|
|
|
|
|
AdvancedPublisher advancedPublisher = new AdvancedPublisher(this.getRegistryPublisher());
|
|
|
|
|
advancedPublisher.forceRemove(toDelete);
|
|
|
|
|
ServerConsole.trace(LOG_PREFIX, "[FORCE DELETE] [DELETE-BRANCH] deleted resource from scope " + scope);
|
|
|
|
|
ScopeProvider.instance.set(currScope);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -528,8 +535,8 @@ public abstract class AbstractResourceManager {
|
|
|
|
|
checker.validate(this.getID() != null, new ResourceOperationException("Invalid ID. null not allowed."));
|
|
|
|
|
|
|
|
|
|
System.out.println("DELETING TYPE: "+ this.getType());
|
|
|
|
|
ScopeProvider.instance.set(scope.toString());
|
|
|
|
|
|
|
|
|
|
String currScope = ScopeProvider.instance.get();
|
|
|
|
|
ScopeProvider.instance.set(scope.toString());
|
|
|
|
|
Resource resStub = this.getResource(scope);
|
|
|
|
|
|
|
|
|
|
List<ScopeBean> boundedScopes = this.validateScopes(resStub.scopes().toArray(new String[0]));
|
|
|
|
@ -545,8 +552,9 @@ public abstract class AbstractResourceManager {
|
|
|
|
|
try {
|
|
|
|
|
this.getRegistryPublisher().remove(resStub);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
|
|
ScopeProvider.instance.set(currScope);
|
|
|
|
|
}
|
|
|
|
|
ScopeProvider.instance.set(currScope);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|