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:
Manuele Simi 2018-03-07 04:24:01 +00:00
parent 5a6ae07d22
commit 0bdbd4d6f1
1 changed files with 21 additions and 9 deletions

View File

@ -3,10 +3,14 @@ package org.gcube.resourcemanagement.manager.webapp.context;
import java.util.UUID; import java.util.UUID;
import org.gcube.informationsystem.model.entity.Context; 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.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.ResourceRegistryContextClient;
import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClientFactory; import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClientFactory;
/** /**
* Queries submitted within the context resource. * Queries submitted within the context resource.
* *
@ -15,19 +19,23 @@ import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryCont
*/ */
final class Queries { final class Queries {
private final ResourceRegistryContextClient client; private final ResourceRegistryContextClient cclient;
private final ResourceRegistryClient rclient;
protected Queries() { protected Queries() {
client = ResourceRegistryContextClientFactory.create(); cclient = ResourceRegistryContextClientFactory.create();
rclient = ResourceRegistryClientFactory.create();
} }
/** /**
* Makes the queries with the given client. * Makes the queries with the given client.
* *
* @param client * @param cclient
*/ */
protected Queries(ResourceRegistryContextClient client) { protected Queries(ResourceRegistryContextClient cclient) {
this.client = client; this.cclient = cclient;
this.rclient = ResourceRegistryClientFactory.create();
} }
/** /**
@ -38,7 +46,7 @@ final class Queries {
*/ */
protected boolean contextExists(UUID context) { protected boolean contextExists(UUID context) {
try { try {
return this.client.read(context) != null; return this.cclient.read(context) != null;
} catch (ResourceRegistryException e) { } catch (ResourceRegistryException e) {
return false; return false;
}catch (RuntimeException e) { }catch (RuntimeException e) {
@ -55,7 +63,7 @@ final class Queries {
*/ */
protected Context fetchContext(UUID context) { protected Context fetchContext(UUID context) {
try { try {
return this.client.read(context); return this.cclient.read(context);
} catch (ResourceRegistryException e) { } catch (ResourceRegistryException e) {
return null; return null;
} }
@ -66,10 +74,14 @@ final class Queries {
* Detects if the context has no resources. * Detects if the context has no resources.
* *
* @param context the context to check * @param context the context to check
* @return * @return true if the content is empty.
*/ */
protected boolean isContextEmpty(UUID context) { protected boolean isContextEmpty(UUID context) {
return false; try {
return this.rclient.getInstances(Resource.class, true).size() == 0;
} catch (ResourceRegistryException e) {
return false;
}
} }
} }