61 lines
1.6 KiB
Java
61 lines
1.6 KiB
Java
package org.gcube.resourcemanagement.manager.webapp.context;
|
|
|
|
import java.util.Objects;
|
|
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 localRegistryClient = ResourceRegistryContextClientFactory.create();
|
|
|
|
/**
|
|
* Tests if the given context exists
|
|
*
|
|
* @param uuid
|
|
* @param registryClient
|
|
* @return
|
|
*/
|
|
protected boolean contextExists(UUID uuid, ResourceRegistryContextClient ... registryClient) {
|
|
try {
|
|
return client(registryClient).read(uuid) != null;
|
|
} catch (ResourceRegistryException e) {
|
|
return false;
|
|
}catch (RuntimeException e) {
|
|
e.printStackTrace();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Fetches the context.
|
|
*
|
|
* @param uuid
|
|
* @param registryClient
|
|
* @return
|
|
*/
|
|
protected Context fetchContext(UUID uuid, ResourceRegistryContextClient ... registryClient) {
|
|
try {
|
|
return client(registryClient).read(uuid);
|
|
} catch (ResourceRegistryException e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private ResourceRegistryContextClient client(ResourceRegistryContextClient ... registryClient) {
|
|
if (registryClient.length > 0 && Objects.nonNull(registryClient[0]))
|
|
return registryClient[0];
|
|
else
|
|
return this.localRegistryClient;
|
|
}
|
|
}
|