diff --git a/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/Queries.java b/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/Queries.java index e19f912..c146ee6 100644 --- a/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/Queries.java +++ b/webapp/src/main/java/org/gcube/resourcemanagement/manager/webapp/context/Queries.java @@ -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; + } } }