Involved methods thrown SchemaViolationExc. refs #7355 #18216 #20531

This commit is contained in:
Luca Frosini 2021-02-16 17:00:46 +01:00
parent 32f02d057f
commit 54715a0783
2 changed files with 441 additions and 406 deletions

View File

@ -19,6 +19,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceAlreadyPresentException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceAlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
/** /**
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
@ -26,10 +27,10 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resour
public interface ResourceRegistryPublisher { public interface ResourceRegistryPublisher {
public <IE extends IdentifiableElement> IE create(IE er) public <IE extends IdentifiableElement> IE create(IE er)
throws AlreadyPresentException, ResourceRegistryException; throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException;
public String create(String json) throws AlreadyPresentException, ResourceRegistryException;
public String create(String json)
throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException;
public <IE extends IdentifiableElement> boolean exists(Class<IE> clazz, UUID uuid) public <IE extends IdentifiableElement> boolean exists(Class<IE> clazz, UUID uuid)
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException; throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
@ -40,162 +41,152 @@ public interface ResourceRegistryPublisher {
public boolean exists(String type, UUID uuid) public boolean exists(String type, UUID uuid)
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException; throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
public <IE extends IdentifiableElement> IE read(IE identifiableElement)
public <IE extends IdentifiableElement> IE read(IE identifiableElement) throws NotFoundException, ResourceRegistryException; throws NotFoundException, ResourceRegistryException;
public String read(String type, UUID uuid) throws NotFoundException, ResourceRegistryException; public String read(String type, UUID uuid) throws NotFoundException, ResourceRegistryException;
public <IE extends IdentifiableElement> IE update(IE identifiableElement) public <IE extends IdentifiableElement> IE update(IE identifiableElement)
throws NotFoundException, ResourceRegistryException; throws SchemaViolationException, NotFoundException, ResourceRegistryException;
public String update(String type, String json) throws NotFoundException, ResourceRegistryException; public String update(String type, String json)
throws SchemaViolationException, NotFoundException, ResourceRegistryException;
public String update(String json) throws NotFoundException, ResourceRegistryException; public String update(String json) throws SchemaViolationException, NotFoundException, ResourceRegistryException;
public <IE extends IdentifiableElement> boolean delete(IE identifiableElement)
throws SchemaViolationException, NotFoundException, ResourceRegistryException;
public <IE extends IdentifiableElement> boolean delete(IE identifiableElement) throws NotFoundException, ResourceRegistryException; public boolean delete(String type, UUID uuid)
throws SchemaViolationException, NotFoundException, ResourceRegistryException;
public boolean delete(String type, UUID uuid) throws NotFoundException, ResourceRegistryException;
/* ----- */ /* ----- */
public <F extends Facet> F createFacet(F facet) public <F extends Facet> F createFacet(F facet)
throws FacetAlreadyPresentException, ResourceRegistryException; throws SchemaViolationException, FacetAlreadyPresentException, ResourceRegistryException;
public String createFacet(String facet) throws FacetAlreadyPresentException, ResourceRegistryException;
public String createFacet(String facet)
throws SchemaViolationException, FacetAlreadyPresentException, ResourceRegistryException;
public <F extends Facet> F readFacet(F facet) throws FacetNotFoundException, ResourceRegistryException; public <F extends Facet> F readFacet(F facet) throws FacetNotFoundException, ResourceRegistryException;
public String readFacet(String facetType, UUID uuid) throws FacetNotFoundException, ResourceRegistryException; public String readFacet(String facetType, UUID uuid) throws FacetNotFoundException, ResourceRegistryException;
public <F extends Facet> F updateFacet(F facet) public <F extends Facet> F updateFacet(F facet)
throws FacetNotFoundException, ResourceRegistryException; throws SchemaViolationException, FacetNotFoundException, ResourceRegistryException;
public String updateFacet(String facet) throws FacetNotFoundException, ResourceRegistryException; public String updateFacet(String facet)
throws SchemaViolationException, FacetNotFoundException, ResourceRegistryException;
public <F extends Facet> boolean deleteFacet(F facet)
throws SchemaViolationException, FacetNotFoundException, ResourceRegistryException;
public <F extends Facet> boolean deleteFacet(F facet) throws FacetNotFoundException, ResourceRegistryException; public boolean deleteFacet(String facetType, UUID uuid)
throws SchemaViolationException, FacetNotFoundException, ResourceRegistryException;
public boolean deleteFacet(String facetType, UUID uuid) throws FacetNotFoundException, ResourceRegistryException;
/* ----- */ /* ----- */
public <R extends Resource> R createResource(R resource) public <R extends Resource> R createResource(R resource)
throws ResourceAlreadyPresentException, ResourceRegistryException; throws SchemaViolationException, ResourceAlreadyPresentException, ResourceRegistryException;
public String createResource(String resource) throws ResourceAlreadyPresentException, ResourceRegistryException; public String createResource(String resource)
throws SchemaViolationException, ResourceAlreadyPresentException, ResourceRegistryException;
public <R extends Resource> R readResource(R resource) throws ResourceNotFoundException, ResourceRegistryException;
public <R extends Resource> R readResource(R resource) public String readResource(String resourceType, UUID uuid)
throws ResourceNotFoundException, ResourceRegistryException; throws ResourceNotFoundException, ResourceRegistryException;
public String readResource(String resourceType, UUID uuid) throws ResourceNotFoundException, ResourceRegistryException;
public <R extends Resource> R updateResource(R resource) public <R extends Resource> R updateResource(R resource)
throws ResourceNotFoundException, ResourceRegistryException; throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException;
public String updateResource(String resource) public String updateResource(String resource)
throws ResourceNotFoundException, ResourceRegistryException; throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException;
public <R extends Resource> boolean deleteResource(R resource) public <R extends Resource> boolean deleteResource(R resource)
throws ResourceNotFoundException, ResourceRegistryException; throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException;
public boolean deleteResource(String resourceType, UUID uuid) throws ResourceNotFoundException, ResourceRegistryException;
public boolean deleteResource(String resourceType, UUID uuid)
throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException;
/* ----- */ /* ----- */
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> C createConsistsOf(C consistsOf)
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> C createConsistsOf( throws SchemaViolationException, NotFoundException, ResourceRegistryException;
C consistsOf) throws NotFoundException, ResourceRegistryException;
public String createConsistsOf(String consistsOf) public String createConsistsOf(String consistsOf)
throws SchemaViolationException, NotFoundException, ResourceRegistryException;
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> C readConsistsOf(C consistsOf)
throws NotFoundException, ResourceRegistryException; throws NotFoundException, ResourceRegistryException;
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> C readConsistsOf(
C consistsOf) throws NotFoundException, ResourceRegistryException;
public String readConsistsOf(String consistsOfType, UUID uuid) throws NotFoundException, ResourceRegistryException; public String readConsistsOf(String consistsOfType, UUID uuid) throws NotFoundException, ResourceRegistryException;
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> C updateConsistsOf(C consistsOf) public <C extends ConsistsOf<? extends Resource, ? extends Facet>> C updateConsistsOf(C consistsOf)
throws NotFoundException, ResourceRegistryException; throws SchemaViolationException, NotFoundException, ResourceRegistryException;
public String updateConsistsOf(String consistsOf) public String updateConsistsOf(String consistsOf)
throws NotFoundException, ResourceRegistryException; throws SchemaViolationException, NotFoundException, ResourceRegistryException;
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> boolean deleteConsistsOf(C consistsOf) public <C extends ConsistsOf<? extends Resource, ? extends Facet>> boolean deleteConsistsOf(C consistsOf)
throws ResourceRegistryException; throws SchemaViolationException, ResourceRegistryException;
public boolean deleteConsistsOf(String consistsOfType, UUID uuid) throws ResourceRegistryException;
public boolean deleteConsistsOf(String consistsOfType, UUID uuid)
throws SchemaViolationException, ResourceRegistryException;
/* ----- */ /* ----- */
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> I createIsRelatedTo(I isRelatedTo)
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> I createIsRelatedTo( throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException;
I isRelatedTo) throws ResourceNotFoundException, ResourceRegistryException;
public String createIsRelatedTo(String isRelatedTo) public String createIsRelatedTo(String isRelatedTo)
throws ResourceNotFoundException, ResourceRegistryException; throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException;
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> I readIsRelatedTo(I isRelatedTo)
throws NotFoundException, ResourceRegistryException;
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> I readIsRelatedTo( public String readIsRelatedTo(String isRelatedToType, UUID uuid)
I isRelatedTo) throws NotFoundException, ResourceRegistryException; throws NotFoundException, ResourceRegistryException;
public String readIsRelatedTo(String isRelatedToType, UUID uuid) throws NotFoundException, ResourceRegistryException;
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> I updateIsRelatedTo(I isRelatedTo) public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> I updateIsRelatedTo(I isRelatedTo)
throws NotFoundException, ResourceRegistryException; throws SchemaViolationException, NotFoundException, ResourceRegistryException;
public String updateIsRelatedTo(String isRelatedTo) public String updateIsRelatedTo(String isRelatedTo)
throws NotFoundException, ResourceRegistryException; throws SchemaViolationException, NotFoundException, ResourceRegistryException;
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> boolean deleteIsRelatedTo(I isRelatedTo) public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> boolean deleteIsRelatedTo(I isRelatedTo)
throws ResourceRegistryException; throws SchemaViolationException, ResourceRegistryException;
public boolean deleteIsRelatedTo(String isRelatedToType, UUID uuid) throws ResourceRegistryException;
public boolean deleteIsRelatedTo(String isRelatedToType, UUID uuid)
throws SchemaViolationException, ResourceRegistryException;
/* ----- */ /* ----- */
public boolean addToContext(String type, UUID instanceUUID, UUID contextUUID) public boolean addToContext(String type, UUID instanceUUID, UUID contextUUID)
throws NotFoundException, ResourceRegistryException; throws SchemaViolationException, NotFoundException, ResourceRegistryException;
public <IE extends IdentifiableElement> boolean addToContext(IE identifiableElement, UUID contextUUID) public <IE extends IdentifiableElement> boolean addToContext(IE identifiableElement, UUID contextUUID)
throws NotFoundException, ResourceRegistryException; throws SchemaViolationException, NotFoundException, ResourceRegistryException;
public boolean addToCurrentContext(String type, UUID instanceUUID) public boolean addToCurrentContext(String type, UUID instanceUUID)
throws NotFoundException, ResourceRegistryException; throws SchemaViolationException, NotFoundException, ResourceRegistryException;
public <IE extends IdentifiableElement> boolean addToCurrentContext(IE identifiableElement) public <IE extends IdentifiableElement> boolean addToCurrentContext(IE identifiableElement)
throws NotFoundException, ResourceRegistryException; throws SchemaViolationException, NotFoundException, ResourceRegistryException;
public boolean removeFromContext(String type, UUID instanceUUID, UUID contextUUID) public boolean removeFromContext(String type, UUID instanceUUID, UUID contextUUID)
throws NotFoundException, ResourceRegistryException; throws SchemaViolationException, NotFoundException, ResourceRegistryException;
public <IE extends IdentifiableElement> boolean removeFromContext(IE identifiableElement, UUID contextUUID) public <IE extends IdentifiableElement> boolean removeFromContext(IE identifiableElement, UUID contextUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException,
ResourceRegistryException;
public boolean removeFromCurrentContext(String type, UUID instanceUUID) public boolean removeFromCurrentContext(String type, UUID instanceUUID) throws SchemaViolationException,
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
public <IE extends IdentifiableElement> boolean removeFromCurrentContext(IE identifiableElement) public <IE extends IdentifiableElement> boolean removeFromCurrentContext(IE identifiableElement)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException,
ResourceRegistryException;
public Set<UUID> getElementContexts(String type, UUID instanceUUID) public Set<UUID> getElementContexts(String type, UUID instanceUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
@ -203,33 +194,36 @@ public interface ResourceRegistryPublisher {
public <IE extends IdentifiableElement> Set<UUID> getElementContexts(IE identifiableElement) public <IE extends IdentifiableElement> Set<UUID> getElementContexts(IE identifiableElement)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
/* ----- */ /* ----- */
public boolean addResourceToContext(String resourceType, UUID resourceUUID, UUID contextUUID) public boolean addResourceToContext(String resourceType, UUID resourceUUID, UUID contextUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException,
ResourceRegistryException;
public <R extends Resource> boolean addResourceToContext(R resource, UUID contextUUID) public <R extends Resource> boolean addResourceToContext(R resource, UUID contextUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException,
ResourceRegistryException;
public boolean addResourceToCurrentContext(String resourceType, UUID resourceUUID) public boolean addResourceToCurrentContext(String resourceType, UUID resourceUUID) throws SchemaViolationException,
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
public <R extends Resource> boolean addResourceToCurrentContext(R resource) public <R extends Resource> boolean addResourceToCurrentContext(R resource) throws SchemaViolationException,
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
public boolean removeResourceFromContext(String resourceType, UUID resourceUUID, UUID contextUUID) public boolean removeResourceFromContext(String resourceType, UUID resourceUUID, UUID contextUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException,
ResourceRegistryException;
public <R extends Resource> boolean removeResourceFromContext(R resource, UUID contextUUID) public <R extends Resource> boolean removeResourceFromContext(R resource, UUID contextUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException,
ResourceRegistryException;
public boolean removeResourceFromCurrentContext(String resourceType, UUID resourceUUID) public boolean removeResourceFromCurrentContext(String resourceType, UUID resourceUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException,
ResourceRegistryException;
public <R extends Resource> boolean removeResourceFromCurrentContext(R resource) public <R extends Resource> boolean removeResourceFromCurrentContext(R resource) throws SchemaViolationException,
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
public Set<UUID> getResourceContexts(String resourceType, UUID resourceUUID) public Set<UUID> getResourceContexts(String resourceType, UUID resourceUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
@ -237,10 +231,8 @@ public interface ResourceRegistryPublisher {
public <R extends Resource> Set<UUID> getResourceContexts(R resource) public <R extends Resource> Set<UUID> getResourceContexts(R resource)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException;
/* ----- */ /* ----- */
public boolean addFacetToContext(String facetType, UUID facetUUID, UUID contextUUID) public boolean addFacetToContext(String facetType, UUID facetUUID, UUID contextUUID)
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException; throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
@ -254,16 +246,17 @@ public interface ResourceRegistryPublisher {
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException; throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
public boolean removeFacetFromContext(String facetType, UUID facetUUID, UUID contextUUID) public boolean removeFacetFromContext(String facetType, UUID facetUUID, UUID contextUUID)
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException; throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException,
ResourceRegistryException;
public <F extends Facet> boolean removeFacetFromContext(F facet, UUID contextUUID) public <F extends Facet> boolean removeFacetFromContext(F facet, UUID contextUUID) throws SchemaViolationException,
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException; FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
public boolean removeFacetFromCurrentContext(String facetType, UUID facetUUID) public boolean removeFacetFromCurrentContext(String facetType, UUID facetUUID) throws SchemaViolationException,
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException; FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
public <F extends Facet> boolean removeFacetFromCurrentContext(F facet) public <F extends Facet> boolean removeFacetFromCurrentContext(F facet) throws SchemaViolationException,
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException; FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
public Set<UUID> getFacetContexts(String facetType, UUID facetUUID) public Set<UUID> getFacetContexts(String facetType, UUID facetUUID)
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException; throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
@ -271,15 +264,12 @@ public interface ResourceRegistryPublisher {
public <F extends Facet> Set<UUID> getFacetContexts(F facet) public <F extends Facet> Set<UUID> getFacetContexts(F facet)
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException; throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException;
/* ----- */ /* ----- */
public Context getContext(UUID uuid) throws ContextNotFoundException, ResourceRegistryException; public Context getContext(UUID uuid) throws ContextNotFoundException, ResourceRegistryException;
public Context getCurrentContext() throws ContextNotFoundException, ResourceRegistryException; public Context getCurrentContext() throws ContextNotFoundException, ResourceRegistryException;
public List<Context> getAllContext() throws ResourceRegistryException; public List<Context> getAllContext() throws ResourceRegistryException;
} }

View File

@ -31,6 +31,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceAlreadyPresentException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceAlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath; import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
import org.gcube.informationsystem.resourceregistry.api.rest.InstancePath; import org.gcube.informationsystem.resourceregistry.api.rest.InstancePath;
import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath; import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath;
@ -46,18 +47,21 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
protected final String address; protected final String address;
private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest) throws UnsupportedEncodingException{ private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest)
throws UnsupportedEncodingException {
return includeAdditionalQueryParameters(gxHTTPStringRequest, null); return includeAdditionalQueryParameters(gxHTTPStringRequest, null);
} }
private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest, Map<String,String> queryParams) throws UnsupportedEncodingException{ private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest,
Map<String, String> queryParams) throws UnsupportedEncodingException {
gxHTTPStringRequest = checkHierarchicalMode(gxHTTPStringRequest, queryParams); gxHTTPStringRequest = checkHierarchicalMode(gxHTTPStringRequest, queryParams);
return checkIncludeContextsInInstanceHeader(gxHTTPStringRequest, queryParams); return checkIncludeContextsInInstanceHeader(gxHTTPStringRequest, queryParams);
} }
private GXHTTPStringRequest checkHierarchicalMode(GXHTTPStringRequest gxHTTPStringRequest, Map<String,String> queryParams) throws UnsupportedEncodingException{ private GXHTTPStringRequest checkHierarchicalMode(GXHTTPStringRequest gxHTTPStringRequest,
if(ResourceRegistryPublisherFactory.isHierarchicalMode()) { Map<String, String> queryParams) throws UnsupportedEncodingException {
if(queryParams==null) { if (ResourceRegistryPublisherFactory.isHierarchicalMode()) {
if (queryParams == null) {
queryParams = new HashMap<>(); queryParams = new HashMap<>();
} }
queryParams.put(AccessPath.HIERARCHICAL_MODE_PARAM, Boolean.toString(true)); queryParams.put(AccessPath.HIERARCHICAL_MODE_PARAM, Boolean.toString(true));
@ -65,9 +69,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
return gxHTTPStringRequest.queryParams(queryParams); return gxHTTPStringRequest.queryParams(queryParams);
} }
private GXHTTPStringRequest checkIncludeContextsInInstanceHeader(GXHTTPStringRequest gxHTTPStringRequest, Map<String,String> queryParams) throws UnsupportedEncodingException{ private GXHTTPStringRequest checkIncludeContextsInInstanceHeader(GXHTTPStringRequest gxHTTPStringRequest,
if(ResourceRegistryPublisherFactory.includeContextsInInstanceHeader()) { Map<String, String> queryParams) throws UnsupportedEncodingException {
if(queryParams==null) { if (ResourceRegistryPublisherFactory.includeContextsInInstanceHeader()) {
if (queryParams == null) {
queryParams = new HashMap<>(); queryParams = new HashMap<>();
} }
queryParams.put(AccessPath.INCLUDE_CONTEXTS_IN_HEADER_PARAM, Boolean.toString(true)); queryParams.put(AccessPath.INCLUDE_CONTEXTS_IN_HEADER_PARAM, Boolean.toString(true));
@ -105,12 +110,12 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
logger.debug("Got Contexts are {}", ret); logger.debug("Got Contexts are {}", ret);
return ElementMapper.unmarshalList(Context.class, ret); return ElementMapper.unmarshalList(Context.class, ret);
} catch(ResourceRegistryException e) { } catch (ResourceRegistryException e) {
// logger.trace("Error while getting {} schema for {}", polymorphic ? // logger.trace("Error while getting {} schema for {}", polymorphic ?
// AccessPath.POLYMORPHIC_PARAM + " " : "", // AccessPath.POLYMORPHIC_PARAM + " " : "",
// type, e); // type, e);
throw e; throw e;
} catch(Exception e) { } catch (Exception e) {
// logger.trace("Error while getting {}schema for {}", polymorphic ? // logger.trace("Error while getting {}schema for {}", polymorphic ?
// AccessPath.POLYMORPHIC_PARAM + " " : "", // AccessPath.POLYMORPHIC_PARAM + " " : "",
// type, e); // type, e);
@ -141,12 +146,12 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
logger.debug("Got Context is {}", ElementMapper.marshal(context)); logger.debug("Got Context is {}", ElementMapper.marshal(context));
return context; return context;
} catch(ResourceRegistryException e) { } catch (ResourceRegistryException e) {
// logger.trace("Error while getting {} schema for {}", polymorphic ? // logger.trace("Error while getting {} schema for {}", polymorphic ?
// AccessPath.POLYMORPHIC_PARAM + " " : "", // AccessPath.POLYMORPHIC_PARAM + " " : "",
// type, e); // type, e);
throw e; throw e;
} catch(Exception e) { } catch (Exception e) {
// logger.trace("Error while getting {}schema for {}", polymorphic ? // logger.trace("Error while getting {}schema for {}", polymorphic ?
// AccessPath.POLYMORPHIC_PARAM + " " : "", // AccessPath.POLYMORPHIC_PARAM + " " : "",
// type, e); // type, e);
@ -157,16 +162,19 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
@Override @Override
public Context getContext(UUID uuid) throws ContextNotFoundException, ResourceRegistryException { public Context getContext(UUID uuid) throws ContextNotFoundException, ResourceRegistryException {
ContextCache contextCache = ContextCache.getInstance(); ContextCache contextCache = ContextCache.getInstance();
Context context = ContextCache.getInstance().getContextByUUID(uuid);; Context context = ContextCache.getInstance().getContextByUUID(uuid);
if(context == null) { ;
if (context == null) {
context = getContextFromServer(uuid.toString()); context = getContextFromServer(uuid.toString());
contextCache.cleanCache(); contextCache.cleanCache();
contextCache.refreshContextsIfNeeded(); contextCache.refreshContextsIfNeeded();
Context c = contextCache.getContextByUUID(context.getHeader().getUUID()); Context c = contextCache.getContextByUUID(context.getHeader().getUUID());
if(c!=null){ if (c != null) {
context = c; context = c;
}else { } else {
logger.error("Context with UUID {} is {}. It is possibile to get it from the server but not from the cache. This is very strange and should not occur.", uuid, context); logger.error(
"Context with UUID {} is {}. It is possibile to get it from the server but not from the cache. This is very strange and should not occur.",
uuid, context);
} }
} }
return context; return context;
@ -178,17 +186,19 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
ContextCache contextCache = ContextCache.getInstance(); ContextCache contextCache = ContextCache.getInstance();
UUID uuid = contextCache.getUUIDByFullName(contextFullName); UUID uuid = contextCache.getUUIDByFullName(contextFullName);
Context context = null; Context context = null;
if(uuid == null) { if (uuid == null) {
context = getContextFromServer(AccessPath.CURRENT_CONTEXT); context = getContextFromServer(AccessPath.CURRENT_CONTEXT);
contextCache.cleanCache(); contextCache.cleanCache();
contextCache.refreshContextsIfNeeded(); contextCache.refreshContextsIfNeeded();
Context c = contextCache.getContextByUUID(context.getHeader().getUUID()); Context c = contextCache.getContextByUUID(context.getHeader().getUUID());
if(c!=null){ if (c != null) {
context = c; context = c;
}else { } else {
logger.error("Current Context is {}. It is possibile to get it from the server but not from the cache. This is very strange and should not occur.", contextFullName); logger.error(
"Current Context is {}. It is possibile to get it from the server but not from the cache. This is very strange and should not occur.",
contextFullName);
} }
}else { } else {
context = contextCache.getContextByUUID(uuid); context = contextCache.getContextByUUID(uuid);
} }
return context; return context;
@ -199,7 +209,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
} }
protected String create(String type, String json, UUID uuid) protected String create(String type, String json, UUID uuid)
throws AlreadyPresentException, ResourceRegistryException { throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException {
try { try {
logger.trace("Going to create {} : {}", type, json); logger.trace("Going to create {} : {}", type, json);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address); GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
@ -216,60 +226,63 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
logger.trace("{} successfully created", ret); logger.trace("{} successfully created", ret);
return ret; return ret;
} catch(ResourceRegistryException e) { } catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw e; throw e;
} catch(Exception e) { } catch (Exception e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
public <IE extends IdentifiableElement> String internalCreate(IE identifiableElement) throws AlreadyPresentException, ResourceRegistryException { public <IE extends IdentifiableElement> String internalCreate(IE identifiableElement)
throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException {
try { try {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(identifiableElement); String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
.getTypeName(identifiableElement);
String json = ElementMapper.marshal(identifiableElement); String json = ElementMapper.marshal(identifiableElement);
Header header = identifiableElement.getHeader(); Header header = identifiableElement.getHeader();
if(header==null) { if (header == null) {
header = new HeaderImpl(UUID.randomUUID()); header = new HeaderImpl(UUID.randomUUID());
identifiableElement.setHeader(header); identifiableElement.setHeader(header);
} }
UUID uuid = identifiableElement.getHeader().getUUID(); UUID uuid = identifiableElement.getHeader().getUUID();
return create(type, json, uuid); return create(type, json, uuid);
} catch(ResourceRegistryException e) { } catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw e; throw e;
} catch(Exception e) { } catch (Exception e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public <IE extends IdentifiableElement> IE create(IE identifiableElement) throws AlreadyPresentException, ResourceRegistryException { public <IE extends IdentifiableElement> IE create(IE identifiableElement)
throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException {
try { try {
String ret = internalCreate(identifiableElement); String ret = internalCreate(identifiableElement);
return (IE) ElementMapper.unmarshal(IdentifiableElement.class, ret); return (IE) ElementMapper.unmarshal(IdentifiableElement.class, ret);
} catch(ResourceRegistryException e) { } catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw e; throw e;
} catch(Exception e) { } catch (Exception e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@Override @Override
public String create(String json) throws AlreadyPresentException, ResourceRegistryException { public String create(String json)
throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException {
try { try {
IdentifiableElement e = ElementMapper.unmarshal(IdentifiableElement.class, json); IdentifiableElement e = ElementMapper.unmarshal(IdentifiableElement.class, json);
return internalCreate(e); return internalCreate(e);
} catch(ResourceRegistryException e) { } catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw e; throw e;
} catch(Exception e) { } catch (Exception e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -310,11 +323,11 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
logger.debug("{} with UUID {} exists", type, uuid); logger.debug("{} with UUID {} exists", type, uuid);
return true; return true;
} catch(ResourceRegistryException e) { } catch (ResourceRegistryException e) {
// logger.trace("Error while checking if {} with UUID {} exists.", type, uuid, // logger.trace("Error while checking if {} with UUID {} exists.", type, uuid,
// e); // e);
throw e; throw e;
} catch(Exception e) { } catch (Exception e) {
// logger.trace("Error while checking if {} with UUID {} exists.", type, uuid, // logger.trace("Error while checking if {} with UUID {} exists.", type, uuid,
// e); // e);
throw new RuntimeException(e); throw new RuntimeException(e);
@ -323,16 +336,18 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public <IE extends IdentifiableElement> IE read(IE identifiableElement) throws NotFoundException, ResourceRegistryException { public <IE extends IdentifiableElement> IE read(IE identifiableElement)
throws NotFoundException, ResourceRegistryException {
try { try {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(identifiableElement); String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
.getTypeName(identifiableElement);
UUID uuid = identifiableElement.getHeader().getUUID(); UUID uuid = identifiableElement.getHeader().getUUID();
String ret = read(type, uuid); String ret = read(type, uuid);
return (IE) ElementMapper.unmarshal(IdentifiableElement.class, ret); return (IE) ElementMapper.unmarshal(IdentifiableElement.class, ret);
} catch(ResourceRegistryException e) { } catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw e; throw e;
} catch(Exception e) { } catch (Exception e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -357,17 +372,17 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
logger.debug("Got {} with UUID {} is {}", type, uuid, ret); logger.debug("Got {} with UUID {} is {}", type, uuid, ret);
return ret; return ret;
} catch(ResourceRegistryException e) { } catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw e; throw e;
} catch(Exception e) { } catch (Exception e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
protected String update(String type, String json, UUID uuid) protected String update(String type, String json, UUID uuid)
throws AlreadyPresentException, ResourceRegistryException { throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException {
try { try {
logger.trace("Going to create {} : {}", type, json); logger.trace("Going to create {} : {}", type, json);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address); GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
@ -384,10 +399,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
logger.trace("{} with UUID {} successfully created : {}", type, uuid, ret); logger.trace("{} with UUID {} successfully created : {}", type, uuid, ret);
return ret; return ret;
} catch(ResourceRegistryException e) { } catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw e; throw e;
} catch(Exception e) { } catch (Exception e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -395,67 +410,73 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public <IE extends IdentifiableElement> IE update(IE identifiableElement) throws NotFoundException, ResourceRegistryException { public <IE extends IdentifiableElement> IE update(IE identifiableElement)
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
try { try {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(identifiableElement); String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
.getTypeName(identifiableElement);
String json = ElementMapper.marshal(identifiableElement); String json = ElementMapper.marshal(identifiableElement);
UUID uuid = identifiableElement.getHeader().getUUID(); UUID uuid = identifiableElement.getHeader().getUUID();
String ret = update(type, json, uuid); String ret = update(type, json, uuid);
return (IE) ElementMapper.unmarshal(Element.class, ret); return (IE) ElementMapper.unmarshal(Element.class, ret);
} catch(ResourceRegistryException e) { } catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw e; throw e;
} catch(Exception e) { } catch (Exception e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@Override @Override
public String update(String type, String json) throws NotFoundException, ResourceRegistryException { public String update(String type, String json)
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
try { try {
UUID uuid = Utility.getUUIDFromJSONString(json); UUID uuid = Utility.getUUIDFromJSONString(json);
return update(type, json, uuid); return update(type, json, uuid);
} catch(ResourceRegistryException e) { } catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw e; throw e;
} catch(Exception e) { } catch (Exception e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@Override @Override
public String update(String json) throws NotFoundException, ResourceRegistryException { public String update(String json) throws SchemaViolationException, NotFoundException, ResourceRegistryException {
try { try {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getClassFromJsonString(json); String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getClassFromJsonString(json);
return update(type, json); return update(type, json);
} catch(ResourceRegistryException e) { } catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw e; throw e;
} catch(Exception e) { } catch (Exception e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@Override @Override
public <IE extends IdentifiableElement> boolean delete(IE identifiableElement) throws NotFoundException, ResourceRegistryException { public <IE extends IdentifiableElement> boolean delete(IE identifiableElement)
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
try { try {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(identifiableElement); String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
.getTypeName(identifiableElement);
UUID uuid = identifiableElement.getHeader().getUUID(); UUID uuid = identifiableElement.getHeader().getUUID();
return delete(type, uuid); return delete(type, uuid);
} catch(ResourceRegistryException e) { } catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw e; throw e;
} catch(Exception e) { } catch (Exception e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@Override @Override
public boolean delete(String type, UUID uuid) throws NotFoundException, ResourceRegistryException { public boolean delete(String type, UUID uuid)
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
try { try {
logger.trace("Going to delete {} with UUID {}", type, uuid); logger.trace("Going to delete {} with UUID {}", type, uuid);
GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address); GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address);
@ -473,22 +494,24 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
logger.info("{} with UUID {} {}", type, uuid, deleted ? " successfully deleted" : "was NOT deleted"); logger.info("{} with UUID {} {}", type, uuid, deleted ? " successfully deleted" : "was NOT deleted");
return deleted; return deleted;
} catch(ResourceRegistryException e) { } catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw e; throw e;
} catch(Exception e) { } catch (Exception e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@Override @Override
public <F extends Facet> F createFacet(F facet) throws FacetAlreadyPresentException, ResourceRegistryException { public <F extends Facet> F createFacet(F facet)
throws SchemaViolationException, FacetAlreadyPresentException, ResourceRegistryException {
return create(facet); return create(facet);
} }
@Override @Override
public String createFacet(String facet) throws FacetAlreadyPresentException, ResourceRegistryException { public String createFacet(String facet)
throws SchemaViolationException, FacetAlreadyPresentException, ResourceRegistryException {
return create(facet); return create(facet);
} }
@ -503,33 +526,38 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
} }
@Override @Override
public <F extends Facet> F updateFacet(F facet) throws FacetNotFoundException, ResourceRegistryException { public <F extends Facet> F updateFacet(F facet)
throws SchemaViolationException, FacetNotFoundException, ResourceRegistryException {
return update(facet); return update(facet);
} }
@Override @Override
public String updateFacet(String facet) throws FacetNotFoundException, ResourceRegistryException { public String updateFacet(String facet)
throws SchemaViolationException, FacetNotFoundException, ResourceRegistryException {
return update(facet); return update(facet);
} }
@Override @Override
public <F extends Facet> boolean deleteFacet(F facet) throws FacetNotFoundException, ResourceRegistryException { public <F extends Facet> boolean deleteFacet(F facet)
throws SchemaViolationException, FacetNotFoundException, ResourceRegistryException {
return delete(facet); return delete(facet);
} }
@Override @Override
public boolean deleteFacet(String facetType, UUID uuid) throws FacetNotFoundException, ResourceRegistryException { public boolean deleteFacet(String facetType, UUID uuid)
throws SchemaViolationException, FacetNotFoundException, ResourceRegistryException {
return delete(facetType, uuid); return delete(facetType, uuid);
} }
@Override @Override
public <R extends Resource> R createResource(R resource) public <R extends Resource> R createResource(R resource)
throws ResourceAlreadyPresentException, ResourceRegistryException { throws SchemaViolationException, ResourceAlreadyPresentException, ResourceRegistryException {
return create(resource); return create(resource);
} }
@Override @Override
public String createResource(String resource) throws ResourceAlreadyPresentException, ResourceRegistryException { public String createResource(String resource)
throws SchemaViolationException, ResourceAlreadyPresentException, ResourceRegistryException {
return create(resource); return create(resource);
} }
@ -546,40 +574,42 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
@Override @Override
public <R extends Resource> R updateResource(R resource) public <R extends Resource> R updateResource(R resource)
throws ResourceNotFoundException, ResourceRegistryException { throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException {
return update(resource); return update(resource);
} }
@Override @Override
public String updateResource(String resource) throws ResourceNotFoundException, ResourceRegistryException { public String updateResource(String resource)
throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException {
return update(resource); return update(resource);
} }
@Override @Override
public <R extends Resource> boolean deleteResource(R resource) public <R extends Resource> boolean deleteResource(R resource)
throws ResourceNotFoundException, ResourceRegistryException { throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException {
return delete(resource); return delete(resource);
} }
@Override @Override
public boolean deleteResource(String resourceType, UUID uuid) public boolean deleteResource(String resourceType, UUID uuid)
throws ResourceNotFoundException, ResourceRegistryException { throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException {
return delete(resourceType, uuid); return delete(resourceType, uuid);
} }
@Override @Override
public <C extends ConsistsOf<? extends Resource,? extends Facet>> C createConsistsOf(C consistsOf) public <C extends ConsistsOf<? extends Resource, ? extends Facet>> C createConsistsOf(C consistsOf)
throws NotFoundException, ResourceRegistryException { throws SchemaViolationException, NotFoundException, ResourceRegistryException {
return create(consistsOf); return create(consistsOf);
} }
@Override @Override
public String createConsistsOf(String consistsOf) throws NotFoundException, ResourceRegistryException { public String createConsistsOf(String consistsOf)
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
return create(consistsOf); return create(consistsOf);
} }
@Override @Override
public <C extends ConsistsOf<? extends Resource,? extends Facet>> C readConsistsOf(C consistsOf) public <C extends ConsistsOf<? extends Resource, ? extends Facet>> C readConsistsOf(C consistsOf)
throws NotFoundException, ResourceRegistryException { throws NotFoundException, ResourceRegistryException {
return read(consistsOf); return read(consistsOf);
} }
@ -590,40 +620,43 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
} }
@Override @Override
public <C extends ConsistsOf<? extends Resource,? extends Facet>> C updateConsistsOf(C consistsOf) public <C extends ConsistsOf<? extends Resource, ? extends Facet>> C updateConsistsOf(C consistsOf)
throws NotFoundException, ResourceRegistryException { throws SchemaViolationException, NotFoundException, ResourceRegistryException {
return update(consistsOf); return update(consistsOf);
} }
@Override @Override
public String updateConsistsOf(String consistsOf) throws NotFoundException, ResourceRegistryException { public String updateConsistsOf(String consistsOf)
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
return update(consistsOf); return update(consistsOf);
} }
@Override @Override
public <C extends ConsistsOf<? extends Resource,? extends Facet>> boolean deleteConsistsOf(C consistsOf) public <C extends ConsistsOf<? extends Resource, ? extends Facet>> boolean deleteConsistsOf(C consistsOf)
throws ResourceRegistryException { throws SchemaViolationException, ResourceRegistryException {
return delete(consistsOf); return delete(consistsOf);
} }
@Override @Override
public boolean deleteConsistsOf(String consistsOfType, UUID uuid) throws ResourceRegistryException { public boolean deleteConsistsOf(String consistsOfType, UUID uuid)
throws SchemaViolationException, ResourceRegistryException {
return delete(consistsOfType, uuid); return delete(consistsOfType, uuid);
} }
@Override @Override
public <I extends IsRelatedTo<? extends Resource,? extends Resource>> I createIsRelatedTo(I isRelatedTo) public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> I createIsRelatedTo(I isRelatedTo)
throws ResourceNotFoundException, ResourceRegistryException { throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException {
return create(isRelatedTo); return create(isRelatedTo);
} }
@Override @Override
public String createIsRelatedTo(String isRelatedTo) throws ResourceNotFoundException, ResourceRegistryException { public String createIsRelatedTo(String isRelatedTo)
throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException {
return create(isRelatedTo); return create(isRelatedTo);
} }
@Override @Override
public <I extends IsRelatedTo<? extends Resource,? extends Resource>> I readIsRelatedTo(I isRelatedTo) public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> I readIsRelatedTo(I isRelatedTo)
throws NotFoundException, ResourceRegistryException { throws NotFoundException, ResourceRegistryException {
return read(isRelatedTo); return read(isRelatedTo);
} }
@ -635,30 +668,32 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
} }
@Override @Override
public <I extends IsRelatedTo<? extends Resource,? extends Resource>> I updateIsRelatedTo(I isRelatedTo) public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> I updateIsRelatedTo(I isRelatedTo)
throws NotFoundException, ResourceRegistryException { throws SchemaViolationException, NotFoundException, ResourceRegistryException {
return update(isRelatedTo); return update(isRelatedTo);
} }
@Override @Override
public String updateIsRelatedTo(String isRelatedTo) throws NotFoundException, ResourceRegistryException { public String updateIsRelatedTo(String isRelatedTo)
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
return update(isRelatedTo); return update(isRelatedTo);
} }
@Override @Override
public <I extends IsRelatedTo<? extends Resource,? extends Resource>> boolean deleteIsRelatedTo(I isRelatedTo) public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> boolean deleteIsRelatedTo(I isRelatedTo)
throws ResourceRegistryException { throws SchemaViolationException, ResourceRegistryException {
return delete(isRelatedTo); return delete(isRelatedTo);
} }
@Override @Override
public boolean deleteIsRelatedTo(String isRelatedToType, UUID uuid) throws ResourceRegistryException { public boolean deleteIsRelatedTo(String isRelatedToType, UUID uuid)
throws SchemaViolationException, ResourceRegistryException {
return delete(isRelatedToType, uuid); return delete(isRelatedToType, uuid);
} }
@Override @Override
public boolean addToContext(String type, UUID instanceUUID, UUID contextUUID) public boolean addToContext(String type, UUID instanceUUID, UUID contextUUID)
throws NotFoundException, ResourceRegistryException { throws SchemaViolationException, NotFoundException, ResourceRegistryException {
try { try {
logger.trace("Going to add {} with UUID {} to {} with UUID {} ", type, instanceUUID, Context.NAME, logger.trace("Going to add {} with UUID {} to {} with UUID {} ", type, instanceUUID, Context.NAME,
contextUUID); contextUUID);
@ -677,10 +712,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
added ? " successfully added" : "was NOT added", Context.NAME, contextUUID); added ? " successfully added" : "was NOT added", Context.NAME, contextUUID);
return added; return added;
} catch(ResourceRegistryException e) { } catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw e; throw e;
} catch(Exception e) { } catch (Exception e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -688,15 +723,16 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
@Override @Override
public <IE extends IdentifiableElement> boolean addToContext(IE identifiableElement, UUID contextUUID) public <IE extends IdentifiableElement> boolean addToContext(IE identifiableElement, UUID contextUUID)
throws NotFoundException, ResourceRegistryException { throws SchemaViolationException, NotFoundException, ResourceRegistryException {
try { try {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(identifiableElement); String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
.getTypeName(identifiableElement);
UUID instanceUUID = identifiableElement.getHeader().getUUID(); UUID instanceUUID = identifiableElement.getHeader().getUUID();
return addToContext(type, instanceUUID, contextUUID); return addToContext(type, instanceUUID, contextUUID);
} catch(ResourceRegistryException e) { } catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw e; throw e;
} catch(Exception e) { } catch (Exception e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -704,20 +740,21 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
@Override @Override
public boolean addToCurrentContext(String type, UUID instanceUUID) public boolean addToCurrentContext(String type, UUID instanceUUID)
throws NotFoundException, ResourceRegistryException { throws SchemaViolationException, NotFoundException, ResourceRegistryException {
UUID contextUUID = getCurrentContextUUID(); UUID contextUUID = getCurrentContextUUID();
return addToContext(type, instanceUUID, contextUUID); return addToContext(type, instanceUUID, contextUUID);
} }
@Override @Override
public <IE extends IdentifiableElement> boolean addToCurrentContext(IE identifiableElement) throws NotFoundException, ResourceRegistryException { public <IE extends IdentifiableElement> boolean addToCurrentContext(IE identifiableElement)
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
UUID contextUUID = getCurrentContextUUID(); UUID contextUUID = getCurrentContextUUID();
return addToContext(identifiableElement, contextUUID); return addToContext(identifiableElement, contextUUID);
} }
@Override @Override
public boolean removeFromContext(String type, UUID instanceUUID, UUID contextUUID) public boolean removeFromContext(String type, UUID instanceUUID, UUID contextUUID)
throws NotFoundException, ResourceRegistryException { throws SchemaViolationException, NotFoundException, ResourceRegistryException {
try { try {
logger.trace("Going to add {} with UUID {} to {} with UUID {} ", type, instanceUUID, Context.NAME, logger.trace("Going to add {} with UUID {} to {} with UUID {} ", type, instanceUUID, Context.NAME,
contextUUID); contextUUID);
@ -736,10 +773,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
removed ? " successfully removed" : "was NOT removed", Context.NAME, contextUUID); removed ? " successfully removed" : "was NOT removed", Context.NAME, contextUUID);
return removed; return removed;
} catch(ResourceRegistryException e) { } catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw e; throw e;
} catch(Exception e) { } catch (Exception e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -747,30 +784,33 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
@Override @Override
public <IE extends IdentifiableElement> boolean removeFromContext(IE identifiableElement, UUID contextUUID) public <IE extends IdentifiableElement> boolean removeFromContext(IE identifiableElement, UUID contextUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException,
ResourceRegistryException {
try { try {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(identifiableElement); String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
.getTypeName(identifiableElement);
UUID instanceUUID = identifiableElement.getHeader().getUUID(); UUID instanceUUID = identifiableElement.getHeader().getUUID();
return removeFromContext(type, instanceUUID, contextUUID); return removeFromContext(type, instanceUUID, contextUUID);
} catch(ResourceRegistryException e) { } catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw e; throw e;
} catch(Exception e) { } catch (Exception e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@Override @Override
public boolean removeFromCurrentContext(String type, UUID instanceUUID) public boolean removeFromCurrentContext(String type, UUID instanceUUID) throws SchemaViolationException,
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
UUID contextUUID = getCurrentContextUUID(); UUID contextUUID = getCurrentContextUUID();
return removeFromContext(type, instanceUUID, contextUUID); return removeFromContext(type, instanceUUID, contextUUID);
} }
@Override @Override
public <IE extends IdentifiableElement> boolean removeFromCurrentContext(IE identifiableElement) public <IE extends IdentifiableElement> boolean removeFromCurrentContext(IE identifiableElement)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException,
ResourceRegistryException {
UUID contextUUID = getCurrentContextUUID(); UUID contextUUID = getCurrentContextUUID();
return removeFromContext(identifiableElement, contextUUID); return removeFromContext(identifiableElement, contextUUID);
} }
@ -795,10 +835,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
return contexts; return contexts;
} catch(ResourceRegistryException e) { } catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw e; throw e;
} catch(Exception e) { } catch (Exception e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -812,52 +852,56 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
return getElementContexts(type, instanceUUID); return getElementContexts(type, instanceUUID);
} }
@Override @Override
public boolean addResourceToContext(String resourceType, UUID resourceUUID, UUID contextUUID) public boolean addResourceToContext(String resourceType, UUID resourceUUID, UUID contextUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException,
ResourceRegistryException {
return addToContext(resourceType, resourceUUID, contextUUID); return addToContext(resourceType, resourceUUID, contextUUID);
} }
@Override @Override
public <R extends Resource> boolean addResourceToContext(R resource, UUID contextUUID) public <R extends Resource> boolean addResourceToContext(R resource, UUID contextUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException,
ResourceRegistryException {
return addToContext(resource, contextUUID); return addToContext(resource, contextUUID);
} }
@Override @Override
public boolean addResourceToCurrentContext(String resourceType, UUID resourceUUID) public boolean addResourceToCurrentContext(String resourceType, UUID resourceUUID) throws SchemaViolationException,
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
return addToCurrentContext(resourceType, resourceUUID); return addToCurrentContext(resourceType, resourceUUID);
} }
@Override @Override
public <R extends Resource> boolean addResourceToCurrentContext(R resource) public <R extends Resource> boolean addResourceToCurrentContext(R resource) throws SchemaViolationException,
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
return addToCurrentContext(resource); return addToCurrentContext(resource);
} }
@Override @Override
public boolean removeResourceFromContext(String resourceType, UUID resourceUUID, UUID contextUUID) public boolean removeResourceFromContext(String resourceType, UUID resourceUUID, UUID contextUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException,
ResourceRegistryException {
return removeFromContext(resourceType, resourceUUID, contextUUID); return removeFromContext(resourceType, resourceUUID, contextUUID);
} }
@Override @Override
public <R extends Resource> boolean removeResourceFromContext(R resource, UUID contextUUID) public <R extends Resource> boolean removeResourceFromContext(R resource, UUID contextUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException,
ResourceRegistryException {
return removeFromContext(resource, contextUUID); return removeFromContext(resource, contextUUID);
} }
@Override @Override
public boolean removeResourceFromCurrentContext(String resourceType, UUID resourceUUID) public boolean removeResourceFromCurrentContext(String resourceType, UUID resourceUUID)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException,
ResourceRegistryException {
return removeFromCurrentContext(resourceType, resourceUUID); return removeFromCurrentContext(resourceType, resourceUUID);
} }
@Override @Override
public <R extends Resource> boolean removeResourceFromCurrentContext(R resource) public <R extends Resource> boolean removeResourceFromCurrentContext(R resource) throws SchemaViolationException,
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
return removeFromCurrentContext(resource); return removeFromCurrentContext(resource);
} }
@ -887,25 +931,26 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
@Override @Override
public boolean removeFacetFromContext(String facetType, UUID facetUUID, UUID contextUUID) public boolean removeFacetFromContext(String facetType, UUID facetUUID, UUID contextUUID)
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException,
ResourceRegistryException {
return removeFromContext(facetType, facetUUID, contextUUID); return removeFromContext(facetType, facetUUID, contextUUID);
} }
@Override @Override
public <F extends Facet> boolean removeFacetFromContext(F facet, UUID contextUUID) public <F extends Facet> boolean removeFacetFromContext(F facet, UUID contextUUID) throws SchemaViolationException,
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
return removeFromContext(facet, contextUUID); return removeFromContext(facet, contextUUID);
} }
@Override @Override
public boolean removeFacetFromCurrentContext(String facetType, UUID facetUUID) public boolean removeFacetFromCurrentContext(String facetType, UUID facetUUID) throws SchemaViolationException,
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
return removeFromCurrentContext(facetType, facetUUID); return removeFromCurrentContext(facetType, facetUUID);
} }
@Override @Override
public <F extends Facet> boolean removeFacetFromCurrentContext(F facet) public <F extends Facet> boolean removeFacetFromCurrentContext(F facet) throws SchemaViolationException,
throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { FacetNotFoundException, ContextNotFoundException, ResourceRegistryException {
return removeFromCurrentContext(facet); return removeFromCurrentContext(facet);
} }