76 lines
1.6 KiB
Java
76 lines
1.6 KiB
Java
package org.gcube.resourcemanagement.manager.webapp.context;
|
|
|
|
import java.util.UUID;
|
|
|
|
import org.gcube.informationsystem.model.entity.Context;
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
|
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 client;
|
|
|
|
protected Queries() {
|
|
client = ResourceRegistryContextClientFactory.create();
|
|
}
|
|
|
|
/**
|
|
* Makes the queries with the given client.
|
|
*
|
|
* @param client
|
|
*/
|
|
protected Queries(ResourceRegistryContextClient client) {
|
|
this.client = client;
|
|
}
|
|
|
|
/**
|
|
* Tests if the given context exists
|
|
*
|
|
* @param uuid
|
|
* @return
|
|
*/
|
|
protected boolean contextExists(UUID context) {
|
|
try {
|
|
return this.client.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.client.read(context);
|
|
} catch (ResourceRegistryException e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Detects if the context has no resources.
|
|
*
|
|
* @param context the context to check
|
|
* @return
|
|
*/
|
|
protected boolean isContextEmpty(UUID context) {
|
|
return false;
|
|
}
|
|
|
|
}
|