@ -1,6 +1,5 @@
package org.gcube.resourcemanagement.manager.webapp.context ;
import java.util.Objects ;
import java.util.UUID ;
import org.gcube.informationsystem.model.entity.Context ;
@ -16,18 +15,30 @@ import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryCont
* /
final class Queries {
private final ResourceRegistryContextClient lo calRegistryC lient = ResourceRegistryContextClientFactory . create ( ) ;
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
* @param registryClient
* @return
* /
protected boolean contextExists ( UUID uuid , ResourceRegistryContextClient . . . registryClient ) {
protected boolean contextExists ( UUID context) {
try {
return client ( registryClient ) . read ( uuid ) ! = null ;
return this . client . read ( context ) ! = null ;
} catch ( ResourceRegistryException e ) {
return false ;
} catch ( RuntimeException e ) {
@ -37,24 +48,28 @@ final class Queries {
}
/ * *
* Fetches the context.
* Fetches the resources context.
*
* @param uuid
* @param registryClient
* @param context the resource context to fetch
* @return
* /
protected Context fetchContext ( UUID uuid, Resour ceRegistryC ontextClient . . . registryClien t) {
protected Context fetchContext ( UUID context) {
try {
return client ( registryClient ) . read ( uuid ) ;
return this . client . read ( context ) ;
} 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 ;
/ * *
* Detects if the context has no resources .
*
* @param context the context to check
* @return
* /
protected boolean isContextEmpty ( UUID context ) {
return false ;
}
}