Check that the context has no resources before deleting it.
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/resource-management/resource-manager@164762 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
5a6ae07d22
commit
0bdbd4d6f1
|
@ -3,10 +3,14 @@ package org.gcube.resourcemanagement.manager.webapp.context;
|
|||
import java.util.UUID;
|
||||
|
||||
import org.gcube.informationsystem.model.entity.Context;
|
||||
import org.gcube.informationsystem.model.entity.Resource;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
|
||||
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
|
||||
import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClient;
|
||||
import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClientFactory;
|
||||
|
||||
|
||||
/**
|
||||
* Queries submitted within the context resource.
|
||||
*
|
||||
|
@ -15,19 +19,23 @@ import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryCont
|
|||
*/
|
||||
final class Queries {
|
||||
|
||||
private final ResourceRegistryContextClient client;
|
||||
private final ResourceRegistryContextClient cclient;
|
||||
private final ResourceRegistryClient rclient;
|
||||
|
||||
|
||||
protected Queries() {
|
||||
client = ResourceRegistryContextClientFactory.create();
|
||||
cclient = ResourceRegistryContextClientFactory.create();
|
||||
rclient = ResourceRegistryClientFactory.create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the queries with the given client.
|
||||
*
|
||||
* @param client
|
||||
* @param cclient
|
||||
*/
|
||||
protected Queries(ResourceRegistryContextClient client) {
|
||||
this.client = client;
|
||||
protected Queries(ResourceRegistryContextClient cclient) {
|
||||
this.cclient = cclient;
|
||||
this.rclient = ResourceRegistryClientFactory.create();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -38,7 +46,7 @@ final class Queries {
|
|||
*/
|
||||
protected boolean contextExists(UUID context) {
|
||||
try {
|
||||
return this.client.read(context) != null;
|
||||
return this.cclient.read(context) != null;
|
||||
} catch (ResourceRegistryException e) {
|
||||
return false;
|
||||
}catch (RuntimeException e) {
|
||||
|
@ -55,7 +63,7 @@ final class Queries {
|
|||
*/
|
||||
protected Context fetchContext(UUID context) {
|
||||
try {
|
||||
return this.client.read(context);
|
||||
return this.cclient.read(context);
|
||||
} catch (ResourceRegistryException e) {
|
||||
return null;
|
||||
}
|
||||
|
@ -66,10 +74,14 @@ final class Queries {
|
|||
* Detects if the context has no resources.
|
||||
*
|
||||
* @param context the context to check
|
||||
* @return
|
||||
* @return true if the content is empty.
|
||||
*/
|
||||
protected boolean isContextEmpty(UUID context) {
|
||||
return false;
|
||||
try {
|
||||
return this.rclient.getInstances(Resource.class, true).size() == 0;
|
||||
} catch (ResourceRegistryException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in New Issue