88 lines
2.1 KiB
Java
88 lines
2.1 KiB
Java
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.
|
|
*
|
|
* @author Manuele Simi (ISTI CNR)
|
|
*
|
|
*/
|
|
final class Queries {
|
|
|
|
private final ResourceRegistryContextClient cclient;
|
|
private final ResourceRegistryClient rclient;
|
|
|
|
|
|
protected Queries() {
|
|
cclient = ResourceRegistryContextClientFactory.create();
|
|
rclient = ResourceRegistryClientFactory.create();
|
|
}
|
|
|
|
/**
|
|
* Makes the queries with the given client.
|
|
*
|
|
* @param cclient
|
|
*/
|
|
protected Queries(ResourceRegistryContextClient cclient) {
|
|
this.cclient = cclient;
|
|
this.rclient = ResourceRegistryClientFactory.create();
|
|
}
|
|
|
|
/**
|
|
* Tests if the given context exists
|
|
*
|
|
* @param uuid
|
|
* @return
|
|
*/
|
|
protected boolean contextExists(UUID context) {
|
|
try {
|
|
return this.cclient.read(context) != null;
|
|
} catch (ResourceRegistryException e) {
|
|
return false;
|
|
}catch (RuntimeException e) {
|
|
e.printStackTrace();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Fetches the resources context.
|
|
*
|
|
* @param context the resource context to fetch
|
|
* @return
|
|
*/
|
|
protected Context fetchContext(UUID context) {
|
|
try {
|
|
return this.cclient.read(context);
|
|
} catch (ResourceRegistryException e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Detects if the context has no resources.
|
|
*
|
|
* @param context the context to check
|
|
* @return true if the content is empty.
|
|
*/
|
|
protected boolean isContextEmpty(UUID context) {
|
|
try {
|
|
return this.rclient.getInstances(Resource.class, true).size() == 0;
|
|
} catch (ResourceRegistryException e) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
}
|