From 54715a07835d835e9949926638a8cbe40b27ae7b Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Tue, 16 Feb 2021 17:00:46 +0100 Subject: [PATCH] Involved methods thrown SchemaViolationExc. refs #7355 #18216 #20531 --- .../publisher/ResourceRegistryPublisher.java | 278 +++++---- .../ResourceRegistryPublisherImpl.java | 569 ++++++++++-------- 2 files changed, 441 insertions(+), 406 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisher.java b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisher.java index 267a4fd..7c47c24 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisher.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisher.java @@ -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.resource.ResourceAlreadyPresentException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException; /** * @author Luca Frosini (ISTI - CNR) @@ -26,260 +27,249 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resour public interface ResourceRegistryPublisher { public IE create(IE er) - throws AlreadyPresentException, ResourceRegistryException; - - public String create(String json) throws AlreadyPresentException, ResourceRegistryException; - - + throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException; + + public String create(String json) + throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException; + public boolean exists(Class clazz, UUID uuid) throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException; - + public boolean exists(IE identifiableElement) throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException; - + public boolean exists(String type, UUID uuid) throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException; - - - public IE read(IE identifiableElement) throws NotFoundException, ResourceRegistryException; + + public IE read(IE identifiableElement) + throws NotFoundException, ResourceRegistryException; public String read(String type, UUID uuid) throws NotFoundException, ResourceRegistryException; - - + public IE update(IE identifiableElement) - throws NotFoundException, ResourceRegistryException; - - public String update(String type, String json) throws NotFoundException, ResourceRegistryException; - - public String update(String json) throws NotFoundException, ResourceRegistryException; + throws SchemaViolationException, NotFoundException, ResourceRegistryException; - - public boolean delete(IE identifiableElement) throws NotFoundException, ResourceRegistryException; + public String update(String type, String json) + throws SchemaViolationException, NotFoundException, ResourceRegistryException; + + public String update(String json) throws SchemaViolationException, NotFoundException, ResourceRegistryException; + + public boolean delete(IE identifiableElement) + throws SchemaViolationException, 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 createFacet(F facet) - throws FacetAlreadyPresentException, ResourceRegistryException; - - public String createFacet(String facet) throws FacetAlreadyPresentException, ResourceRegistryException; - - + throws SchemaViolationException, FacetAlreadyPresentException, ResourceRegistryException; + + public String createFacet(String facet) + throws SchemaViolationException, FacetAlreadyPresentException, ResourceRegistryException; + public F readFacet(F facet) throws FacetNotFoundException, ResourceRegistryException; public String readFacet(String facetType, UUID uuid) throws FacetNotFoundException, ResourceRegistryException; - - + public 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 boolean deleteFacet(F facet) throws FacetNotFoundException, ResourceRegistryException; + public boolean deleteFacet(F facet) + throws SchemaViolationException, FacetNotFoundException, ResourceRegistryException; - public boolean deleteFacet(String facetType, UUID uuid) throws FacetNotFoundException, ResourceRegistryException; + public boolean deleteFacet(String facetType, UUID uuid) + throws SchemaViolationException, FacetNotFoundException, ResourceRegistryException; - /* ----- */ - - + public R createResource(R resource) - throws ResourceAlreadyPresentException, ResourceRegistryException; + throws SchemaViolationException, ResourceAlreadyPresentException, ResourceRegistryException; - public String createResource(String resource) throws ResourceAlreadyPresentException, ResourceRegistryException; - - - public R readResource(R resource) + public String createResource(String resource) + throws SchemaViolationException, ResourceAlreadyPresentException, ResourceRegistryException; + + public R readResource(R resource) throws ResourceNotFoundException, ResourceRegistryException; + + public String readResource(String resourceType, UUID uuid) throws ResourceNotFoundException, ResourceRegistryException; - public String readResource(String resourceType, UUID uuid) throws ResourceNotFoundException, ResourceRegistryException; - - public R updateResource(R resource) - throws ResourceNotFoundException, ResourceRegistryException; + throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException; public String updateResource(String resource) - throws ResourceNotFoundException, ResourceRegistryException; - - + throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException; + public 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 createConsistsOf( - C consistsOf) throws NotFoundException, ResourceRegistryException; + + public > C createConsistsOf(C consistsOf) + throws SchemaViolationException, NotFoundException, ResourceRegistryException; public String createConsistsOf(String consistsOf) + throws SchemaViolationException, NotFoundException, ResourceRegistryException; + + public > C readConsistsOf(C consistsOf) throws NotFoundException, ResourceRegistryException; - - - public > C readConsistsOf( - C consistsOf) throws NotFoundException, ResourceRegistryException; public String readConsistsOf(String consistsOfType, UUID uuid) throws NotFoundException, ResourceRegistryException; - public > C updateConsistsOf(C consistsOf) - throws NotFoundException, ResourceRegistryException; + throws SchemaViolationException, NotFoundException, ResourceRegistryException; public String updateConsistsOf(String consistsOf) - throws NotFoundException, ResourceRegistryException; - - + throws SchemaViolationException, NotFoundException, ResourceRegistryException; + public > 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 createIsRelatedTo( - I isRelatedTo) throws ResourceNotFoundException, ResourceRegistryException; + + public > I createIsRelatedTo(I isRelatedTo) + throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException; public String createIsRelatedTo(String isRelatedTo) - throws ResourceNotFoundException, ResourceRegistryException; - - - public > I readIsRelatedTo( - I isRelatedTo) throws NotFoundException, ResourceRegistryException; + throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException; - public String readIsRelatedTo(String isRelatedToType, UUID uuid) throws NotFoundException, ResourceRegistryException; - + public > I readIsRelatedTo(I isRelatedTo) + throws NotFoundException, ResourceRegistryException; + + public String readIsRelatedTo(String isRelatedToType, UUID uuid) + throws NotFoundException, ResourceRegistryException; public > I updateIsRelatedTo(I isRelatedTo) - throws NotFoundException, ResourceRegistryException; + throws SchemaViolationException, NotFoundException, ResourceRegistryException; public String updateIsRelatedTo(String isRelatedTo) - throws NotFoundException, ResourceRegistryException; - - + throws SchemaViolationException, NotFoundException, ResourceRegistryException; + public > 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) - throws NotFoundException, ResourceRegistryException; + throws SchemaViolationException, NotFoundException, ResourceRegistryException; public boolean addToContext(IE identifiableElement, UUID contextUUID) - throws NotFoundException, ResourceRegistryException; - + throws SchemaViolationException, NotFoundException, ResourceRegistryException; + public boolean addToCurrentContext(String type, UUID instanceUUID) - throws NotFoundException, ResourceRegistryException; + throws SchemaViolationException, NotFoundException, ResourceRegistryException; public boolean addToCurrentContext(IE identifiableElement) - throws NotFoundException, ResourceRegistryException; + throws SchemaViolationException, NotFoundException, ResourceRegistryException; public boolean removeFromContext(String type, UUID instanceUUID, UUID contextUUID) - throws NotFoundException, ResourceRegistryException; + throws SchemaViolationException, NotFoundException, ResourceRegistryException; public boolean removeFromContext(IE identifiableElement, UUID contextUUID) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; - - public boolean removeFromCurrentContext(String type, UUID instanceUUID) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; + throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, + ResourceRegistryException; + + public boolean removeFromCurrentContext(String type, UUID instanceUUID) throws SchemaViolationException, + ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; public boolean removeFromCurrentContext(IE identifiableElement) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; - + throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, + ResourceRegistryException; + public Set getElementContexts(String type, UUID instanceUUID) throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; public Set getElementContexts(IE identifiableElement) throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; - - + /* ----- */ - - + public boolean addResourceToContext(String resourceType, UUID resourceUUID, UUID contextUUID) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; + throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, + ResourceRegistryException; public boolean addResourceToContext(R resource, UUID contextUUID) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; - - public boolean addResourceToCurrentContext(String resourceType, UUID resourceUUID) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; + throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, + ResourceRegistryException; - public boolean addResourceToCurrentContext(R resource) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; + public boolean addResourceToCurrentContext(String resourceType, UUID resourceUUID) throws SchemaViolationException, + ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; + + public boolean addResourceToCurrentContext(R resource) throws SchemaViolationException, + ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; public boolean removeResourceFromContext(String resourceType, UUID resourceUUID, UUID contextUUID) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; + throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, + ResourceRegistryException; public boolean removeResourceFromContext(R resource, UUID contextUUID) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; - - public boolean removeResourceFromCurrentContext(String resourceType, UUID resourceUUID) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; + throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, + ResourceRegistryException; + + public boolean removeResourceFromCurrentContext(String resourceType, UUID resourceUUID) + throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, + ResourceRegistryException; + + public boolean removeResourceFromCurrentContext(R resource) throws SchemaViolationException, + ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; - public boolean removeResourceFromCurrentContext(R resource) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; - public Set getResourceContexts(String resourceType, UUID resourceUUID) throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; public Set getResourceContexts(R resource) throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; - - + /* ----- */ - - + public boolean addFacetToContext(String facetType, UUID facetUUID, UUID contextUUID) throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException; public boolean addFacetToContext(F facet, UUID contextUUID) throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException; - + public boolean addFacetToCurrentContext(String facetType, UUID facetUUID) throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException; public boolean addFacetToCurrentContext(F facet) throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException; - + public boolean removeFacetFromContext(String facetType, UUID facetUUID, UUID contextUUID) - throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException; + throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException, + ResourceRegistryException; - public boolean removeFacetFromContext(F facet, UUID contextUUID) - throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException; - - public boolean removeFacetFromCurrentContext(String facetType, UUID facetUUID) - throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException; + public boolean removeFacetFromContext(F facet, UUID contextUUID) throws SchemaViolationException, + FacetNotFoundException, ContextNotFoundException, ResourceRegistryException; + + public boolean removeFacetFromCurrentContext(String facetType, UUID facetUUID) throws SchemaViolationException, + FacetNotFoundException, ContextNotFoundException, ResourceRegistryException; + + public boolean removeFacetFromCurrentContext(F facet) throws SchemaViolationException, + FacetNotFoundException, ContextNotFoundException, ResourceRegistryException; - public boolean removeFacetFromCurrentContext(F facet) - throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException; - public Set getFacetContexts(String facetType, UUID facetUUID) throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException; public Set getFacetContexts(F facet) throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException; - - + /* ----- */ - - + public Context getContext(UUID uuid) throws ContextNotFoundException, ResourceRegistryException; - + public Context getCurrentContext() throws ContextNotFoundException, ResourceRegistryException; - + public List getAllContext() throws ResourceRegistryException; - - + } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherImpl.java b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherImpl.java index 33db5c2..c4c78e1 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherImpl.java @@ -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.resource.ResourceAlreadyPresentException; 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.InstancePath; import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath; @@ -41,165 +42,174 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher { - + private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryPublisherImpl.class); - + protected final String address; - - private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest) throws UnsupportedEncodingException{ + + private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest) + throws UnsupportedEncodingException { return includeAdditionalQueryParameters(gxHTTPStringRequest, null); } - - private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest, Map queryParams) throws UnsupportedEncodingException{ + + private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest, + Map queryParams) throws UnsupportedEncodingException { gxHTTPStringRequest = checkHierarchicalMode(gxHTTPStringRequest, queryParams); return checkIncludeContextsInInstanceHeader(gxHTTPStringRequest, queryParams); } - - private GXHTTPStringRequest checkHierarchicalMode(GXHTTPStringRequest gxHTTPStringRequest, Map queryParams) throws UnsupportedEncodingException{ - if(ResourceRegistryPublisherFactory.isHierarchicalMode()) { - if(queryParams==null) { + + private GXHTTPStringRequest checkHierarchicalMode(GXHTTPStringRequest gxHTTPStringRequest, + Map queryParams) throws UnsupportedEncodingException { + if (ResourceRegistryPublisherFactory.isHierarchicalMode()) { + if (queryParams == null) { queryParams = new HashMap<>(); } queryParams.put(AccessPath.HIERARCHICAL_MODE_PARAM, Boolean.toString(true)); } return gxHTTPStringRequest.queryParams(queryParams); } - - private GXHTTPStringRequest checkIncludeContextsInInstanceHeader(GXHTTPStringRequest gxHTTPStringRequest, Map queryParams) throws UnsupportedEncodingException{ - if(ResourceRegistryPublisherFactory.includeContextsInInstanceHeader()) { - if(queryParams==null) { + + private GXHTTPStringRequest checkIncludeContextsInInstanceHeader(GXHTTPStringRequest gxHTTPStringRequest, + Map queryParams) throws UnsupportedEncodingException { + if (ResourceRegistryPublisherFactory.includeContextsInInstanceHeader()) { + if (queryParams == null) { queryParams = new HashMap<>(); } queryParams.put(AccessPath.INCLUDE_CONTEXTS_IN_HEADER_PARAM, Boolean.toString(true)); } return gxHTTPStringRequest.queryParams(queryParams); } - + protected ContextCacheRenewal contextCacheRenewal = new ContextCacheRenewal() { - + @Override public List renew() throws ResourceRegistryException { return getAllContextFromServer(); } - + }; - + public ResourceRegistryPublisherImpl(String address) { this.address = address; ContextCache contextCache = ContextCache.getInstance(); contextCache.setContextCacheRenewal(contextCacheRenewal); } - + public List getAllContextFromServer() throws ResourceRegistryException { try { logger.info("Going to read all {}s", Context.NAME); - GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address); + GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address); gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName()); gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8); gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART); gxHTTPStringRequest.path(AccessPath.CONTEXTS_PATH_PART); - + HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); String ret = HTTPUtility.getResponse(String.class, httpURLConnection); - + logger.debug("Got Contexts are {}", ret); return ElementMapper.unmarshalList(Context.class, ret); - - } catch(ResourceRegistryException e) { + + } catch (ResourceRegistryException e) { // logger.trace("Error while getting {} schema for {}", polymorphic ? // AccessPath.POLYMORPHIC_PARAM + " " : "", // type, e); throw e; - } catch(Exception e) { + } catch (Exception e) { // logger.trace("Error while getting {}schema for {}", polymorphic ? // AccessPath.POLYMORPHIC_PARAM + " " : "", // type, e); throw new RuntimeException(e); } } - + @Override public List getAllContext() throws ResourceRegistryException { ContextCache contextCache = ContextCache.getInstance(); return contextCache.getContexts(); } - + protected Context getContextFromServer(String id) throws ContextNotFoundException, ResourceRegistryException { try { // TODO use cache - + logger.info("Going to get current {} ", Context.NAME); - GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address); + GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address); gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName()); gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8); gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART); gxHTTPStringRequest.path(AccessPath.CONTEXTS_PATH_PART); gxHTTPStringRequest.path(id); - + HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); Context context = HTTPUtility.getResponse(Context.class, httpURLConnection); - + logger.debug("Got Context is {}", ElementMapper.marshal(context)); return context; - } catch(ResourceRegistryException e) { + } catch (ResourceRegistryException e) { // logger.trace("Error while getting {} schema for {}", polymorphic ? // AccessPath.POLYMORPHIC_PARAM + " " : "", // type, e); throw e; - } catch(Exception e) { + } catch (Exception e) { // logger.trace("Error while getting {}schema for {}", polymorphic ? // AccessPath.POLYMORPHIC_PARAM + " " : "", // type, e); throw new RuntimeException(e); } } - + @Override public Context getContext(UUID uuid) throws ContextNotFoundException, ResourceRegistryException { ContextCache contextCache = ContextCache.getInstance(); - Context context = ContextCache.getInstance().getContextByUUID(uuid);; - if(context == null) { + Context context = ContextCache.getInstance().getContextByUUID(uuid); + ; + if (context == null) { context = getContextFromServer(uuid.toString()); contextCache.cleanCache(); contextCache.refreshContextsIfNeeded(); Context c = contextCache.getContextByUUID(context.getHeader().getUUID()); - if(c!=null){ + if (c != null) { context = c; - }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); + } 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); } } return context; } - + @Override public Context getCurrentContext() throws ContextNotFoundException, ResourceRegistryException { String contextFullName = ResourceRegistryPublisherFactory.getCurrentContextFullName(); ContextCache contextCache = ContextCache.getInstance(); UUID uuid = contextCache.getUUIDByFullName(contextFullName); Context context = null; - if(uuid == null) { + if (uuid == null) { context = getContextFromServer(AccessPath.CURRENT_CONTEXT); contextCache.cleanCache(); contextCache.refreshContextsIfNeeded(); Context c = contextCache.getContextByUUID(context.getHeader().getUUID()); - if(c!=null){ + if (c != null) { context = c; - }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); + } 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); } - }else { + } else { context = contextCache.getContextByUUID(uuid); } return context; } - + private UUID getCurrentContextUUID() throws ResourceRegistryException { return getCurrentContext().getHeader().getUUID(); } - + protected String create(String type, String json, UUID uuid) - throws AlreadyPresentException, ResourceRegistryException { + throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException { try { logger.trace("Going to create {} : {}", type, json); GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address); @@ -209,79 +219,82 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART); gxHTTPStringRequest.path(type); gxHTTPStringRequest.path(uuid.toString()); - + HttpURLConnection httpURLConnection = gxHTTPStringRequest.put(json); String ret = HTTPUtility.getResponse(String.class, httpURLConnection); - + logger.trace("{} successfully created", ret); return ret; - - } catch(ResourceRegistryException e) { + + } catch (ResourceRegistryException e) { // logger.trace("Error Creating {}", facet, e); throw e; - } catch(Exception e) { + } catch (Exception e) { // logger.trace("Error Creating {}", facet, e); throw new RuntimeException(e); } } - - public String internalCreate(IE identifiableElement) throws AlreadyPresentException, ResourceRegistryException { + + public String internalCreate(IE identifiableElement) + throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException { 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); Header header = identifiableElement.getHeader(); - if(header==null) { + if (header == null) { header = new HeaderImpl(UUID.randomUUID()); identifiableElement.setHeader(header); } UUID uuid = identifiableElement.getHeader().getUUID(); return create(type, json, uuid); - } catch(ResourceRegistryException e) { + } catch (ResourceRegistryException e) { // logger.trace("Error Creating {}", facet, e); throw e; - } catch(Exception e) { + } catch (Exception e) { // logger.trace("Error Creating {}", facet, e); throw new RuntimeException(e); } } - - + @SuppressWarnings("unchecked") @Override - public IE create(IE identifiableElement) throws AlreadyPresentException, ResourceRegistryException { + public IE create(IE identifiableElement) + throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException { try { String ret = internalCreate(identifiableElement); return (IE) ElementMapper.unmarshal(IdentifiableElement.class, ret); - } catch(ResourceRegistryException e) { + } catch (ResourceRegistryException e) { // logger.trace("Error Creating {}", facet, e); throw e; - } catch(Exception e) { + } catch (Exception e) { // logger.trace("Error Creating {}", facet, e); throw new RuntimeException(e); } } - + @Override - public String create(String json) throws AlreadyPresentException, ResourceRegistryException { + public String create(String json) + throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException { try { IdentifiableElement e = ElementMapper.unmarshal(IdentifiableElement.class, json); return internalCreate(e); - } catch(ResourceRegistryException e) { + } catch (ResourceRegistryException e) { // logger.trace("Error Creating {}", facet, e); throw e; - } catch(Exception e) { + } catch (Exception e) { // logger.trace("Error Creating {}", facet, e); throw new RuntimeException(e); } } - + @Override public boolean exists(Class clazz, UUID uuid) throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException { String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(clazz); return exists(type, uuid); } - + @Override public boolean exists(IE identifiableElement) throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException { @@ -289,55 +302,57 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher UUID uuid = identifiableElement.getHeader().getUUID(); return exists(type, uuid); } - + @Override public boolean exists(String type, UUID uuid) throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException { try { logger.info("Going to check if {} with UUID {} exists", type, uuid); - GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address); + GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address); gxHTTPStringRequest.from(ResourceRegistryPublisher.class.getSimpleName()); gxHTTPStringRequest.header("Accept", GXConnection.APPLICATION_JSON_CHARSET_UTF_8); gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART); gxHTTPStringRequest.path(AccessPath.INSTANCES_PATH_PART); gxHTTPStringRequest.path(type); gxHTTPStringRequest.path(uuid.toString()); - + includeAdditionalQueryParameters(gxHTTPStringRequest); - + HttpURLConnection httpURLConnection = gxHTTPStringRequest.head(); HTTPUtility.getResponse(String.class, httpURLConnection); - + logger.debug("{} with UUID {} exists", type, uuid); return true; - } catch(ResourceRegistryException e) { + } catch (ResourceRegistryException e) { // logger.trace("Error while checking if {} with UUID {} exists.", type, uuid, // e); throw e; - } catch(Exception e) { + } catch (Exception e) { // logger.trace("Error while checking if {} with UUID {} exists.", type, uuid, // e); throw new RuntimeException(e); } } - + @SuppressWarnings("unchecked") @Override - public IE read(IE identifiableElement) throws NotFoundException, ResourceRegistryException { + public IE read(IE identifiableElement) + throws NotFoundException, ResourceRegistryException { 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(); String ret = read(type, uuid); return (IE) ElementMapper.unmarshal(IdentifiableElement.class, ret); - } catch(ResourceRegistryException e) { + } catch (ResourceRegistryException e) { // logger.trace("Error Creating {}", facet, e); throw e; - } catch(Exception e) { + } catch (Exception e) { // logger.trace("Error Creating {}", facet, e); throw new RuntimeException(e); } } - + @Override public String read(String type, UUID uuid) throws NotFoundException, ResourceRegistryException { try { @@ -348,26 +363,26 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART); gxHTTPStringRequest.path(type); gxHTTPStringRequest.path(uuid.toString()); - + includeAdditionalQueryParameters(gxHTTPStringRequest); - + HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); String ret = HTTPUtility.getResponse(String.class, httpURLConnection); - + logger.debug("Got {} with UUID {} is {}", type, uuid, ret); return ret; - - } catch(ResourceRegistryException e) { + + } catch (ResourceRegistryException e) { // logger.trace("Error Creating {}", facet, e); throw e; - } catch(Exception e) { + } catch (Exception e) { // logger.trace("Error Creating {}", facet, e); throw new RuntimeException(e); } } - + protected String update(String type, String json, UUID uuid) - throws AlreadyPresentException, ResourceRegistryException { + throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException { try { logger.trace("Going to create {} : {}", type, json); GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address); @@ -377,85 +392,91 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART); gxHTTPStringRequest.path(type); gxHTTPStringRequest.path(uuid.toString()); - + HttpURLConnection httpURLConnection = gxHTTPStringRequest.put(json); String ret = HTTPUtility.getResponse(String.class, httpURLConnection); - + logger.trace("{} with UUID {} successfully created : {}", type, uuid, ret); return ret; - - } catch(ResourceRegistryException e) { + + } catch (ResourceRegistryException e) { // logger.trace("Error Creating {}", facet, e); throw e; - } catch(Exception e) { + } catch (Exception e) { // logger.trace("Error Creating {}", facet, e); throw new RuntimeException(e); } } - + @SuppressWarnings("unchecked") @Override - public IE update(IE identifiableElement) throws NotFoundException, ResourceRegistryException { + public IE update(IE identifiableElement) + throws SchemaViolationException, NotFoundException, ResourceRegistryException { 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); UUID uuid = identifiableElement.getHeader().getUUID(); String ret = update(type, json, uuid); return (IE) ElementMapper.unmarshal(Element.class, ret); - } catch(ResourceRegistryException e) { + } catch (ResourceRegistryException e) { // logger.trace("Error Creating {}", facet, e); throw e; - } catch(Exception e) { + } catch (Exception e) { // logger.trace("Error Creating {}", facet, e); throw new RuntimeException(e); } } - + @Override - public String update(String type, String json) throws NotFoundException, ResourceRegistryException { + public String update(String type, String json) + throws SchemaViolationException, NotFoundException, ResourceRegistryException { try { UUID uuid = Utility.getUUIDFromJSONString(json); return update(type, json, uuid); - } catch(ResourceRegistryException e) { + } catch (ResourceRegistryException e) { // logger.trace("Error Creating {}", facet, e); throw e; - } catch(Exception e) { + } catch (Exception e) { // logger.trace("Error Creating {}", facet, e); throw new RuntimeException(e); } } - + @Override - public String update(String json) throws NotFoundException, ResourceRegistryException { + public String update(String json) throws SchemaViolationException, NotFoundException, ResourceRegistryException { try { String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getClassFromJsonString(json); return update(type, json); - } catch(ResourceRegistryException e) { + } catch (ResourceRegistryException e) { // logger.trace("Error Creating {}", facet, e); throw e; - } catch(Exception e) { + } catch (Exception e) { // logger.trace("Error Creating {}", facet, e); throw new RuntimeException(e); } } - + @Override - public boolean delete(IE identifiableElement) throws NotFoundException, ResourceRegistryException { + public boolean delete(IE identifiableElement) + throws SchemaViolationException, NotFoundException, ResourceRegistryException { 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(); return delete(type, uuid); - } catch(ResourceRegistryException e) { + } catch (ResourceRegistryException e) { // logger.trace("Error Creating {}", facet, e); throw e; - } catch(Exception e) { + } catch (Exception e) { // logger.trace("Error Creating {}", facet, e); throw new RuntimeException(e); } } - + @Override - public boolean delete(String type, UUID uuid) throws NotFoundException, ResourceRegistryException { + public boolean delete(String type, UUID uuid) + throws SchemaViolationException, NotFoundException, ResourceRegistryException { try { logger.trace("Going to delete {} with UUID {}", type, uuid); GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address); @@ -464,201 +485,215 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART); gxHTTPStringRequest.path(type); gxHTTPStringRequest.path(uuid.toString()); - + HttpURLConnection httpURLConnection = gxHTTPStringRequest.delete(); HTTPUtility.getResponse(String.class, httpURLConnection); - + boolean deleted = true; - + logger.info("{} with UUID {} {}", type, uuid, deleted ? " successfully deleted" : "was NOT deleted"); return deleted; - - } catch(ResourceRegistryException e) { + + } catch (ResourceRegistryException e) { // logger.trace("Error Creating {}", facet, e); throw e; - } catch(Exception e) { + } catch (Exception e) { // logger.trace("Error Creating {}", facet, e); throw new RuntimeException(e); } } - + @Override - public F createFacet(F facet) throws FacetAlreadyPresentException, ResourceRegistryException { + public F createFacet(F facet) + throws SchemaViolationException, FacetAlreadyPresentException, ResourceRegistryException { return create(facet); } - + @Override - public String createFacet(String facet) throws FacetAlreadyPresentException, ResourceRegistryException { + public String createFacet(String facet) + throws SchemaViolationException, FacetAlreadyPresentException, ResourceRegistryException { return create(facet); } - + @Override public F readFacet(F facet) throws FacetNotFoundException, ResourceRegistryException { return read(facet); } - + @Override public String readFacet(String facetType, UUID uuid) throws FacetNotFoundException, ResourceRegistryException { return read(facetType, uuid); } - + @Override - public F updateFacet(F facet) throws FacetNotFoundException, ResourceRegistryException { + public F updateFacet(F facet) + throws SchemaViolationException, FacetNotFoundException, ResourceRegistryException { return update(facet); } - + @Override - public String updateFacet(String facet) throws FacetNotFoundException, ResourceRegistryException { + public String updateFacet(String facet) + throws SchemaViolationException, FacetNotFoundException, ResourceRegistryException { return update(facet); } - + @Override - public boolean deleteFacet(F facet) throws FacetNotFoundException, ResourceRegistryException { + public boolean deleteFacet(F facet) + throws SchemaViolationException, FacetNotFoundException, ResourceRegistryException { return delete(facet); } - + @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); } - + @Override public R createResource(R resource) - throws ResourceAlreadyPresentException, ResourceRegistryException { + throws SchemaViolationException, ResourceAlreadyPresentException, ResourceRegistryException { return create(resource); } - + @Override - public String createResource(String resource) throws ResourceAlreadyPresentException, ResourceRegistryException { + public String createResource(String resource) + throws SchemaViolationException, ResourceAlreadyPresentException, ResourceRegistryException { return create(resource); } - + @Override public R readResource(R resource) throws ResourceNotFoundException, ResourceRegistryException { return read(resource); } - + @Override public String readResource(String resourceType, UUID uuid) throws ResourceNotFoundException, ResourceRegistryException { return read(resourceType, uuid); } - + @Override public R updateResource(R resource) - throws ResourceNotFoundException, ResourceRegistryException { + throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException { return update(resource); } - + @Override - public String updateResource(String resource) throws ResourceNotFoundException, ResourceRegistryException { + public String updateResource(String resource) + throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException { return update(resource); } - + @Override public boolean deleteResource(R resource) - throws ResourceNotFoundException, ResourceRegistryException { + throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException { return delete(resource); } - + @Override public boolean deleteResource(String resourceType, UUID uuid) - throws ResourceNotFoundException, ResourceRegistryException { + throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException { return delete(resourceType, uuid); } - + @Override - public > C createConsistsOf(C consistsOf) - throws NotFoundException, ResourceRegistryException { + public > C createConsistsOf(C consistsOf) + throws SchemaViolationException, NotFoundException, ResourceRegistryException { return create(consistsOf); } - + @Override - public String createConsistsOf(String consistsOf) throws NotFoundException, ResourceRegistryException { + public String createConsistsOf(String consistsOf) + throws SchemaViolationException, NotFoundException, ResourceRegistryException { return create(consistsOf); } - + @Override - public > C readConsistsOf(C consistsOf) + public > C readConsistsOf(C consistsOf) throws NotFoundException, ResourceRegistryException { return read(consistsOf); } - + @Override public String readConsistsOf(String consistsOfType, UUID uuid) throws NotFoundException, ResourceRegistryException { return read(consistsOfType, uuid); } - + @Override - public > C updateConsistsOf(C consistsOf) - throws NotFoundException, ResourceRegistryException { + public > C updateConsistsOf(C consistsOf) + throws SchemaViolationException, NotFoundException, ResourceRegistryException { return update(consistsOf); } - + @Override - public String updateConsistsOf(String consistsOf) throws NotFoundException, ResourceRegistryException { + public String updateConsistsOf(String consistsOf) + throws SchemaViolationException, NotFoundException, ResourceRegistryException { return update(consistsOf); } - + @Override - public > boolean deleteConsistsOf(C consistsOf) - throws ResourceRegistryException { + public > boolean deleteConsistsOf(C consistsOf) + throws SchemaViolationException, ResourceRegistryException { return delete(consistsOf); } - + @Override - public boolean deleteConsistsOf(String consistsOfType, UUID uuid) throws ResourceRegistryException { + public boolean deleteConsistsOf(String consistsOfType, UUID uuid) + throws SchemaViolationException, ResourceRegistryException { return delete(consistsOfType, uuid); } - + @Override - public > I createIsRelatedTo(I isRelatedTo) - throws ResourceNotFoundException, ResourceRegistryException { + public > I createIsRelatedTo(I isRelatedTo) + throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException { return create(isRelatedTo); } - + @Override - public String createIsRelatedTo(String isRelatedTo) throws ResourceNotFoundException, ResourceRegistryException { + public String createIsRelatedTo(String isRelatedTo) + throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException { return create(isRelatedTo); } - + @Override - public > I readIsRelatedTo(I isRelatedTo) + public > I readIsRelatedTo(I isRelatedTo) throws NotFoundException, ResourceRegistryException { return read(isRelatedTo); } - + @Override public String readIsRelatedTo(String isRelatedToType, UUID uuid) throws NotFoundException, ResourceRegistryException { return read(isRelatedToType, uuid); } - + @Override - public > I updateIsRelatedTo(I isRelatedTo) - throws NotFoundException, ResourceRegistryException { + public > I updateIsRelatedTo(I isRelatedTo) + throws SchemaViolationException, NotFoundException, ResourceRegistryException { return update(isRelatedTo); } - + @Override - public String updateIsRelatedTo(String isRelatedTo) throws NotFoundException, ResourceRegistryException { + public String updateIsRelatedTo(String isRelatedTo) + throws SchemaViolationException, NotFoundException, ResourceRegistryException { return update(isRelatedTo); } - + @Override - public > boolean deleteIsRelatedTo(I isRelatedTo) - throws ResourceRegistryException { + public > boolean deleteIsRelatedTo(I isRelatedTo) + throws SchemaViolationException, ResourceRegistryException { return delete(isRelatedTo); } - + @Override - public boolean deleteIsRelatedTo(String isRelatedToType, UUID uuid) throws ResourceRegistryException { + public boolean deleteIsRelatedTo(String isRelatedToType, UUID uuid) + throws SchemaViolationException, ResourceRegistryException { return delete(isRelatedToType, uuid); } - + @Override public boolean addToContext(String type, UUID instanceUUID, UUID contextUUID) - throws NotFoundException, ResourceRegistryException { + throws SchemaViolationException, NotFoundException, ResourceRegistryException { try { logger.trace("Going to add {} with UUID {} to {} with UUID {} ", type, instanceUUID, Context.NAME, contextUUID); @@ -669,55 +704,57 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher gxHTTPStringRequest.path(contextUUID.toString()); gxHTTPStringRequest.path(type); gxHTTPStringRequest.path(instanceUUID.toString()); - + HttpURLConnection httpURLConnection = gxHTTPStringRequest.put(); boolean added = HTTPUtility.getResponse(Boolean.class, httpURLConnection); - + logger.info("{} with UUID {} {} to {} with UUID {}", type, instanceUUID, added ? " successfully added" : "was NOT added", Context.NAME, contextUUID); return added; - - } catch(ResourceRegistryException e) { + + } catch (ResourceRegistryException e) { // logger.trace("Error Creating {}", facet, e); throw e; - } catch(Exception e) { + } catch (Exception e) { // logger.trace("Error Creating {}", facet, e); throw new RuntimeException(e); } } - + @Override public boolean addToContext(IE identifiableElement, UUID contextUUID) - throws NotFoundException, ResourceRegistryException { + throws SchemaViolationException, NotFoundException, ResourceRegistryException { 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(); return addToContext(type, instanceUUID, contextUUID); - } catch(ResourceRegistryException e) { + } catch (ResourceRegistryException e) { // logger.trace("Error Creating {}", facet, e); throw e; - } catch(Exception e) { + } catch (Exception e) { // logger.trace("Error Creating {}", facet, e); throw new RuntimeException(e); } } - + @Override public boolean addToCurrentContext(String type, UUID instanceUUID) - throws NotFoundException, ResourceRegistryException { + throws SchemaViolationException, NotFoundException, ResourceRegistryException { UUID contextUUID = getCurrentContextUUID(); return addToContext(type, instanceUUID, contextUUID); } - + @Override - public boolean addToCurrentContext(IE identifiableElement) throws NotFoundException, ResourceRegistryException { + public boolean addToCurrentContext(IE identifiableElement) + throws SchemaViolationException, NotFoundException, ResourceRegistryException { UUID contextUUID = getCurrentContextUUID(); return addToContext(identifiableElement, contextUUID); } - + @Override public boolean removeFromContext(String type, UUID instanceUUID, UUID contextUUID) - throws NotFoundException, ResourceRegistryException { + throws SchemaViolationException, NotFoundException, ResourceRegistryException { try { logger.trace("Going to add {} with UUID {} to {} with UUID {} ", type, instanceUUID, Context.NAME, contextUUID); @@ -728,53 +765,56 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher gxHTTPStringRequest.path(contextUUID.toString()); gxHTTPStringRequest.path(type); gxHTTPStringRequest.path(instanceUUID.toString()); - + HttpURLConnection httpURLConnection = gxHTTPStringRequest.delete(); boolean removed = HTTPUtility.getResponse(Boolean.class, httpURLConnection); - + logger.info("{} with UUID {} {} to {} with UUID {}", type, instanceUUID, removed ? " successfully removed" : "was NOT removed", Context.NAME, contextUUID); return removed; - - } catch(ResourceRegistryException e) { + + } catch (ResourceRegistryException e) { // logger.trace("Error Creating {}", facet, e); throw e; - } catch(Exception e) { + } catch (Exception e) { // logger.trace("Error Creating {}", facet, e); throw new RuntimeException(e); } } - + @Override public boolean removeFromContext(IE identifiableElement, UUID contextUUID) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, + ResourceRegistryException { 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(); return removeFromContext(type, instanceUUID, contextUUID); - } catch(ResourceRegistryException e) { + } catch (ResourceRegistryException e) { // logger.trace("Error Creating {}", facet, e); throw e; - } catch(Exception e) { + } catch (Exception e) { // logger.trace("Error Creating {}", facet, e); throw new RuntimeException(e); } } - + @Override - public boolean removeFromCurrentContext(String type, UUID instanceUUID) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + public boolean removeFromCurrentContext(String type, UUID instanceUUID) throws SchemaViolationException, + ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { UUID contextUUID = getCurrentContextUUID(); return removeFromContext(type, instanceUUID, contextUUID); } - + @Override public boolean removeFromCurrentContext(IE identifiableElement) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, + ResourceRegistryException { UUID contextUUID = getCurrentContextUUID(); return removeFromContext(identifiableElement, contextUUID); } - + @Override public Set getElementContexts(String type, UUID instanceUUID) throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { @@ -786,19 +826,19 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher gxHTTPStringRequest.path(type); gxHTTPStringRequest.path(instanceUUID.toString()); gxHTTPStringRequest.path(SharingPath.CONTEXTS_PATH_PART); - + HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); String jsonArray = HTTPUtility.getResponse(String.class, httpURLConnection); Set contexts = ContextUtility.getContextUUIDSet(jsonArray); - + logger.info("Contexts of {} with UUID {} are {}", type, instanceUUID, contexts); - + return contexts; - - } catch(ResourceRegistryException e) { + + } catch (ResourceRegistryException e) { // logger.trace("Error Creating {}", facet, e); throw e; - } catch(Exception e) { + } catch (Exception e) { // logger.trace("Error Creating {}", facet, e); throw new RuntimeException(e); } @@ -811,101 +851,106 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher UUID instanceUUID = identifiableElement.getHeader().getUUID(); return getElementContexts(type, instanceUUID); } - - + @Override public boolean addResourceToContext(String resourceType, UUID resourceUUID, UUID contextUUID) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, + ResourceRegistryException { return addToContext(resourceType, resourceUUID, contextUUID); } - + @Override public boolean addResourceToContext(R resource, UUID contextUUID) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, + ResourceRegistryException { return addToContext(resource, contextUUID); } - + @Override - public boolean addResourceToCurrentContext(String resourceType, UUID resourceUUID) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + public boolean addResourceToCurrentContext(String resourceType, UUID resourceUUID) throws SchemaViolationException, + ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { return addToCurrentContext(resourceType, resourceUUID); } - + @Override - public boolean addResourceToCurrentContext(R resource) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + public boolean addResourceToCurrentContext(R resource) throws SchemaViolationException, + ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { return addToCurrentContext(resource); } - + @Override public boolean removeResourceFromContext(String resourceType, UUID resourceUUID, UUID contextUUID) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, + ResourceRegistryException { return removeFromContext(resourceType, resourceUUID, contextUUID); } - + @Override public boolean removeResourceFromContext(R resource, UUID contextUUID) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, + ResourceRegistryException { return removeFromContext(resource, contextUUID); } - + @Override public boolean removeResourceFromCurrentContext(String resourceType, UUID resourceUUID) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, + ResourceRegistryException { return removeFromCurrentContext(resourceType, resourceUUID); } - + @Override - public boolean removeResourceFromCurrentContext(R resource) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + public boolean removeResourceFromCurrentContext(R resource) throws SchemaViolationException, + ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { return removeFromCurrentContext(resource); } - + @Override public boolean addFacetToContext(String facetType, UUID facetUUID, UUID contextUUID) throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { return addToContext(facetType, facetUUID, contextUUID); } - + @Override public boolean addFacetToContext(F facet, UUID contextUUID) throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { return addToContext(facet, contextUUID); } - + @Override public boolean addFacetToCurrentContext(String facetType, UUID facetUUID) throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { return addToCurrentContext(facetType, facetUUID); } - + @Override public boolean addFacetToCurrentContext(F facet) throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { return addToCurrentContext(facet); } - + @Override public boolean removeFacetFromContext(String facetType, UUID facetUUID, UUID contextUUID) - throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { + throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException, + ResourceRegistryException { return removeFromContext(facetType, facetUUID, contextUUID); } - + @Override - public boolean removeFacetFromContext(F facet, UUID contextUUID) - throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { + public boolean removeFacetFromContext(F facet, UUID contextUUID) throws SchemaViolationException, + FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { return removeFromContext(facet, contextUUID); } - + @Override - public boolean removeFacetFromCurrentContext(String facetType, UUID facetUUID) - throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { + public boolean removeFacetFromCurrentContext(String facetType, UUID facetUUID) throws SchemaViolationException, + FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { return removeFromCurrentContext(facetType, facetUUID); } - + @Override - public boolean removeFacetFromCurrentContext(F facet) - throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { + public boolean removeFacetFromCurrentContext(F facet) throws SchemaViolationException, + FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { return removeFromCurrentContext(facet); } @@ -932,5 +977,5 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { return getElementContexts(facet); } - + }