From 6e984b7acb65fcf64bfb72b76ecabc97e451ff4f Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Mon, 11 Jun 2018 17:47:40 +0000 Subject: [PATCH] Refs #11903: Use new REST interface in Resource Registry Publisher Task-Url: https://support.d4science.org/issues/11903 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-publisher@169034 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../publisher/ResourceRegistryPublisher.java | 207 ++- .../ResourceRegistryPublisherImpl.java | 1230 ++++++++--------- .../publisher/ERManagementTest.java | 3 +- .../publisher/EntityManagementTest.java | 2 +- .../publisher/MultiContextTest.java | 52 +- 5 files changed, 720 insertions(+), 774 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 2e4900f..4d25543 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisher.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisher.java @@ -2,10 +2,13 @@ package org.gcube.informationsystem.resourceregistry.publisher; import java.util.UUID; +import org.gcube.informationsystem.model.ER; import org.gcube.informationsystem.model.entity.Facet; import org.gcube.informationsystem.model.entity.Resource; import org.gcube.informationsystem.model.relation.ConsistsOf; import org.gcube.informationsystem.model.relation.IsRelatedTo; +import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAlreadyPresentException; @@ -18,10 +21,36 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resour */ public interface ResourceRegistryPublisher { - @Deprecated - public F createFacet(Class facetClass, F facet) - throws FacetAlreadyPresentException, ResourceRegistryException; + public E create(E er) + throws AlreadyPresentException, ResourceRegistryException; + + public String create(String erType, String er) + throws AlreadyPresentException, ResourceRegistryException; + public String create(String er) throws AlreadyPresentException, ResourceRegistryException; + + + public E read(E er) throws NotFoundException, ResourceRegistryException; + + public String read(String erType, UUID uuid) throws NotFoundException, ResourceRegistryException; + + + public E update(E er) + throws NotFoundException, ResourceRegistryException; + + public String update(String erType, String er) throws NotFoundException, ResourceRegistryException; + + public String update(String er) throws NotFoundException, ResourceRegistryException; + + + public boolean delete(E er) throws NotFoundException, ResourceRegistryException; + + public boolean delete(String erType, UUID uuid) throws NotFoundException, ResourceRegistryException; + + + /* ----- */ + + public F createFacet(F facet) throws FacetAlreadyPresentException, ResourceRegistryException; @@ -29,26 +58,27 @@ public interface ResourceRegistryPublisher { throws FacetAlreadyPresentException, ResourceRegistryException; public String createFacet(String facet) throws FacetAlreadyPresentException, ResourceRegistryException; + + + public F readFacet(F facet) throws FacetNotFoundException, ResourceRegistryException; - @Deprecated - public F updateFacet(Class facetClass, F facet) - throws FacetNotFoundException, ResourceRegistryException; + public String readFacet(String facetType, UUID uuid) throws FacetNotFoundException, ResourceRegistryException; + public F updateFacet(F facet) throws FacetNotFoundException, ResourceRegistryException; - - public String updateFacet(UUID uuid, String facet) throws FacetNotFoundException, ResourceRegistryException; public String updateFacet(String facet) throws FacetNotFoundException, ResourceRegistryException; + public boolean deleteFacet(F facet) throws FacetNotFoundException, ResourceRegistryException; - public boolean deleteFacet(UUID uuid) throws FacetNotFoundException, ResourceRegistryException; - - @Deprecated - public R createResource(Class resourceClass, R resource) - throws ResourceAlreadyPresentException, ResourceRegistryException; + public boolean deleteFacet(String facetType, UUID uuid) throws FacetNotFoundException, ResourceRegistryException; + + /* ----- */ + + public R createResource(R resource) throws ResourceAlreadyPresentException, ResourceRegistryException; @@ -56,47 +86,62 @@ public interface ResourceRegistryPublisher { throws ResourceAlreadyPresentException, ResourceRegistryException; public String createResource(String resource) throws ResourceAlreadyPresentException, ResourceRegistryException; - - @Deprecated - public R updateResource(Class resourceClass, R resource) + + + public R readResource(R resource) throws ResourceNotFoundException, ResourceRegistryException; + public String readResource(String resourceType, UUID uuid) throws ResourceNotFoundException, ResourceRegistryException; + + public R updateResource(R resource) throws ResourceNotFoundException, ResourceRegistryException; - - public String updateResource(UUID uuid, String resource) - throws ResourceNotFoundException, ResourceRegistryException; public String updateResource(String resource) throws ResourceNotFoundException, ResourceRegistryException; + public boolean deleteResource(R resource) throws ResourceNotFoundException, ResourceRegistryException; - public boolean deleteResource(UUID uuid) throws ResourceNotFoundException, ResourceRegistryException; + public boolean deleteResource(String resourceType, UUID uuid) throws ResourceNotFoundException, ResourceRegistryException; - @Deprecated - public > C createConsistsOf(Class consistsOfClass, - C consistsOf) throws FacetNotFoundException, ResourceNotFoundException, ResourceRegistryException; + + /* ----- */ + public > C createConsistsOf( - C consistsOf) throws FacetNotFoundException, ResourceNotFoundException, ResourceRegistryException; + C consistsOf) throws NotFoundException, ResourceRegistryException; public String createConsistsOf(String consistsOfType, String consistsOf) - throws FacetNotFoundException, ResourceNotFoundException, ResourceRegistryException; + throws NotFoundException, ResourceRegistryException; public String createConsistsOf(String consistsOf) - throws FacetNotFoundException, ResourceNotFoundException, ResourceRegistryException; + 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; + + public String updateConsistsOf(String consistsOf) + throws NotFoundException, ResourceRegistryException; + public > boolean deleteConsistsOf(C consistsOf) throws ResourceRegistryException; - public boolean deleteConsistsOf(UUID uuid) throws ResourceRegistryException; - - @Deprecated - public > I createIsRelatedTo( - Class isRelatedToClass, I isRelatedTo) throws ResourceNotFoundException, ResourceRegistryException; + public boolean deleteConsistsOf(String consistsOfType, UUID uuid) throws ResourceRegistryException; + + /* ----- */ + + public > I createIsRelatedTo( I isRelatedTo) throws ResourceNotFoundException, ResourceRegistryException; @@ -106,32 +151,106 @@ public interface ResourceRegistryPublisher { public String createIsRelatedTo(String isRelatedTo) throws ResourceNotFoundException, 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; + + public String updateIsRelatedTo(String isRelatedTo) + throws NotFoundException, ResourceRegistryException; + + public > boolean deleteIsRelatedTo(I isRelatedTo) throws ResourceRegistryException; - public boolean deleteIsRelatedTo(UUID uuid) throws ResourceRegistryException; + public boolean deleteIsRelatedTo(String isRelatedToType, UUID uuid) throws ResourceRegistryException; - public boolean addResourceToContext(UUID uuid) + + /* ----- */ + + + public boolean addToContext(UUID contextUUID, String erType, UUID instanceUUID) + throws NotFoundException, ResourceRegistryException; + + public boolean addToContext(UUID contextUUID, E er) + throws NotFoundException, ResourceRegistryException; + + public boolean addToCurrentContext(String erType, UUID instanceUUID) + throws NotFoundException, ResourceRegistryException; + + public boolean addToCurrentContext(E er) + throws NotFoundException, ResourceRegistryException; + + public boolean removeFromContext(UUID contextUUID, String erType, UUID instanceUUID) + throws NotFoundException, ResourceRegistryException; + + public boolean removeFromContext(UUID contextUUID, E er) + throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; + + public boolean removeFromCurrentContext(String erType, UUID instanceUUID) throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; - public boolean addResourceToContext(R resource) + public boolean removeFromCurrentContext(E er) + throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; + + + /* ----- */ + + + public boolean addResourceToContext(UUID contextUUID, String resourceType, UUID resourceUUID) throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; - public boolean addFacetToContext(UUID uuid) + public boolean addResourceToContext(UUID contextUUID, R resource) + throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; + + public boolean addResourceToCurrentContext(String resourceType, UUID resourceUUID) + throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; + + public boolean addResourceToCurrentContext(R resource) + throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; + + public boolean removeResourceFromContext(UUID contextUUID, String resourceType, UUID resourceUUID) + throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; + + public boolean removeResourceFromContext(UUID contextUUID, R resource) + throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; + + public boolean removeResourceFromCurrentContext(String resourceType, UUID resourceUUID) + throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; + + public boolean removeResourceFromCurrentContext(R resource) + throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; + + + /* ----- */ + + + public boolean addFacetToContext(UUID contextUUID, String facetType, UUID facetUUID) throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException; - public boolean addFacetToContext(F facet) + public boolean addFacetToContext(UUID contextUUID, F facet) + throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException; + + public boolean addFacetToCurrentContext(String facetType, UUID facetUUID) throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException; - public boolean removeResourceFromContext(UUID uuid) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; - - public boolean removeResourceFromContext(R resource) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; - - public boolean removeFacetFromContext(UUID uuid) + public boolean addFacetToCurrentContext(F facet) + throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException; + + public boolean removeFacetFromContext(UUID contextUUID, String facetType, UUID facetUUID) throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException; - public boolean removeFacetFromContext(F facet) + public boolean removeFacetFromContext(UUID contextUUID, F facet) + throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException; + + public boolean removeFacetFromCurrentContext(String facetType, UUID facetUUID) + throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException; + + public boolean removeFacetFromCurrentContext(F facet) throws FacetNotFoundException, ContextNotFoundException, 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 b3e0d2f..61f5891 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherImpl.java @@ -9,68 +9,86 @@ import org.gcube.common.authorization.library.AuthorizationEntry; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.informationsystem.impl.utils.ISMapper; +import org.gcube.informationsystem.impl.utils.Utility; +import org.gcube.informationsystem.model.ER; import org.gcube.informationsystem.model.entity.Context; import org.gcube.informationsystem.model.entity.Facet; import org.gcube.informationsystem.model.entity.Resource; import org.gcube.informationsystem.model.relation.ConsistsOf; import org.gcube.informationsystem.model.relation.IsRelatedTo; +import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAlreadyPresentException; 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.rest.ERPath; +import org.gcube.informationsystem.resourceregistry.api.rest.InstancePath; +import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath; import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPCall; import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPCall.HTTPMETHOD; -import org.gcube.informationsystem.resourceregistry.api.utils.Utility; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - * @author Luca Frosini (ISTI - CNR) - */ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher { - + private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryPublisherImpl.class); - + public static final String PATH_SEPARATOR = "/"; - + protected final String address; protected HTTPCall httpCall; - + public ResourceRegistryPublisherImpl(String address) { this.address = address; } - + protected HTTPCall getHTTPCall() throws MalformedURLException { - if (httpCall == null) { + if(httpCall == null) { httpCall = new HTTPCall(address, ResourceRegistryPublisher.class.getSimpleName()); } return httpCall; } - + private static String getCurrentContext() { String token = SecurityTokenProvider.instance.get(); AuthorizationEntry authorizationEntry = null; try { authorizationEntry = Constants.authorizationService().get(token); - } catch (Exception e) { + } catch(Exception e) { return ScopeProvider.instance.get(); } return authorizationEntry.getContext(); } - - @Override - @Deprecated - public F createFacet(Class facetClass, F facet) - throws FacetAlreadyPresentException, ResourceRegistryException { + + private UUID getCurrentContextUUID() { + // TODO Auto-generated method stub + return null; + } + + protected String create(String erType, String er, UUID uuid) + throws AlreadyPresentException, ResourceRegistryException { try { - return createFacet(facet); - } catch (ResourceRegistryException e) { + logger.trace("Going to create {} : {}", erType, er); + StringWriter stringWriter = new StringWriter(); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(InstancePath.INSTANCES_PATH_PART); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(erType); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(uuid.toString()); + + HTTPCall httpCall = getHTTPCall(); + String ret = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.PUT, er); + + logger.trace("{} successfully created", ret); + return ret; + + } 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); } @@ -78,769 +96,629 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher @SuppressWarnings("unchecked") @Override - public F createFacet(F facet) - throws FacetAlreadyPresentException, ResourceRegistryException { + public E create(E er) throws AlreadyPresentException, ResourceRegistryException { try { - String facetString = ISMapper.marshal(facet); - String facetType = Utility.getType(facet); - String res = createFacet(facetType, facetString); - return (F) ISMapper.unmarshal(Facet.class, res); - } catch (ResourceRegistryException e) { + String erType = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getType(er); + String erString = ISMapper.marshal(er); + UUID uuid = er.getHeader().getUUID(); + String ret = create(erType, erString, uuid); + return (E) ISMapper.unmarshal(ER.class, ret); + } 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 createFacet(String facet) throws FacetAlreadyPresentException, ResourceRegistryException { + public String create(String erType, String er) throws AlreadyPresentException, ResourceRegistryException { try { - String facetType = Utility.getClassFromJsonString(facet); - return createFacet(facetType, facet); - } catch (ResourceRegistryException e) { + UUID uuid = Utility.getUUIDFromJSONString(er); + return create(erType, er, uuid); + } 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 er) throws AlreadyPresentException, ResourceRegistryException { + try { + String erType = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getClassFromJsonString(er); + return create(erType, er); + } catch(ResourceRegistryException e) { + // logger.trace("Error Creating {}", facet, e); + throw e; + } catch(Exception e) { // logger.trace("Error Creating {}", facet, e); throw new RuntimeException(e); } } - + + @SuppressWarnings("unchecked") + @Override + public E read(E er) throws NotFoundException, ResourceRegistryException { + try { + String erType = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getType(er); + UUID uuid = er.getHeader().getUUID(); + String ret = read(erType, uuid); + return (E) ISMapper.unmarshal(ER.class, ret); + } catch(ResourceRegistryException e) { + // logger.trace("Error Creating {}", facet, e); + throw e; + } catch(Exception e) { + // logger.trace("Error Creating {}", facet, e); + throw new RuntimeException(e); + } + } + + @Override + public String read(String erType, UUID uuid) throws NotFoundException, ResourceRegistryException { + try { + logger.trace("Going to read {} with UUID {}", erType, uuid); + StringWriter stringWriter = new StringWriter(); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(InstancePath.INSTANCES_PATH_PART); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(erType); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(uuid.toString()); + + HTTPCall httpCall = getHTTPCall(); + String ret = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.GET); + + logger.debug("Got {} with UUID {} is {}", erType, uuid, ret); + return ret; + + } catch(ResourceRegistryException e) { + // logger.trace("Error Creating {}", facet, e); + throw e; + } catch(Exception e) { + // logger.trace("Error Creating {}", facet, e); + throw new RuntimeException(e); + } + } + + protected String update(String erType, String er, UUID uuid) + throws AlreadyPresentException, ResourceRegistryException { + try { + logger.trace("Going to create {} : {}", erType, er); + StringWriter stringWriter = new StringWriter(); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(InstancePath.INSTANCES_PATH_PART); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(erType); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(uuid.toString()); + + HTTPCall httpCall = getHTTPCall(); + String ret = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.PUT, er); + + logger.trace("{} with UUID {} successfully created : {}", erType, uuid, ret); + return ret; + + } catch(ResourceRegistryException e) { + // logger.trace("Error Creating {}", facet, e); + throw e; + } catch(Exception e) { + // logger.trace("Error Creating {}", facet, e); + throw new RuntimeException(e); + } + } + + @SuppressWarnings("unchecked") + @Override + public E update(E er) throws NotFoundException, ResourceRegistryException { + try { + String erType = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getType(er); + String erString = ISMapper.marshal(er); + UUID uuid = er.getHeader().getUUID(); + String ret = update(erType, erString, uuid); + return (E) ISMapper.unmarshal(ER.class, ret); + } catch(ResourceRegistryException e) { + // logger.trace("Error Creating {}", facet, e); + throw e; + } catch(Exception e) { + // logger.trace("Error Creating {}", facet, e); + throw new RuntimeException(e); + } + } + + @Override + public String update(String erType, String er) throws NotFoundException, ResourceRegistryException { + try { + UUID uuid = Utility.getUUIDFromJSONString(er); + return update(erType, er, uuid); + } catch(ResourceRegistryException e) { + // logger.trace("Error Creating {}", facet, e); + throw e; + } catch(Exception e) { + // logger.trace("Error Creating {}", facet, e); + throw new RuntimeException(e); + } + } + + @Override + public String update(String er) throws NotFoundException, ResourceRegistryException { + try { + String erType = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getClassFromJsonString(er); + return update(erType, er); + } catch(ResourceRegistryException e) { + // logger.trace("Error Creating {}", facet, e); + throw e; + } catch(Exception e) { + // logger.trace("Error Creating {}", facet, e); + throw new RuntimeException(e); + } + } + + @Override + public boolean delete(E er) throws NotFoundException, ResourceRegistryException { + try { + String erType = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getType(er); + UUID uuid = er.getHeader().getUUID(); + return delete(erType, uuid); + } catch(ResourceRegistryException e) { + // logger.trace("Error Creating {}", facet, e); + throw e; + } catch(Exception e) { + // logger.trace("Error Creating {}", facet, e); + throw new RuntimeException(e); + } + } + + @Override + public boolean delete(String erType, UUID uuid) throws NotFoundException, ResourceRegistryException { + try { + logger.trace("Going to delete {} with UUID {}", erType, uuid); + StringWriter stringWriter = new StringWriter(); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(InstancePath.INSTANCES_PATH_PART); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(erType); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(uuid.toString()); + + HTTPCall httpCall = getHTTPCall(); + boolean deleted = httpCall.call(Boolean.class, stringWriter.toString(), HTTPMETHOD.DELETE); + + logger.info("{} with UUID {} {}", erType, uuid, deleted ? " successfully deleted" : "was NOT deleted"); + return deleted; + + } catch(ResourceRegistryException e) { + // logger.trace("Error Creating {}", facet, e); + throw e; + } catch(Exception e) { + // logger.trace("Error Creating {}", facet, e); + throw new RuntimeException(e); + } + } + + @Override + public F createFacet(F facet) throws FacetAlreadyPresentException, ResourceRegistryException { + return create(facet); + } + @Override public String createFacet(String facetType, String facet) throws FacetAlreadyPresentException, ResourceRegistryException { - try { - logger.trace("Going to create: {}", facet); - StringWriter stringWriter = new StringWriter(); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.ER_PATH_PART); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.FACET_PATH_PART); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(facetType); - - HTTPCall httpCall = getHTTPCall(); - String f = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.PUT, facet); - - logger.trace("{} successfully created", f); - return f; - - } catch (ResourceRegistryException e) { - // logger.trace("Error Creating {}", facet, e); - throw e; - } catch (Exception e) { - // logger.trace("Error Creating {}", facet, e); - throw new RuntimeException(e); - } - } - - @Override - @Deprecated - public F updateFacet(Class facetClass, F facet) - throws FacetNotFoundException, ResourceRegistryException { - try { - return updateFacet(facet); - } catch (ResourceRegistryException e) { - // logger.trace("Error Updating {}", facet, e); - throw e; - } catch (Exception e) { - // logger.trace("Error Updating {}", facet, e); - throw new RuntimeException(e); - } + return create(facetType, facet); } - @SuppressWarnings("unchecked") @Override - public F updateFacet(F facet) - throws FacetNotFoundException, ResourceRegistryException { - try { - String facetString = ISMapper.marshal(facet); - UUID uuid = facet.getHeader().getUUID(); - String res = updateFacet(uuid, facetString); - return (F) ISMapper.unmarshal(Facet.class, res); - } catch (ResourceRegistryException e) { - // logger.trace("Error Updating {}", facet, e); - throw e; - } catch (Exception e) { - // logger.trace("Error Updating {}", facet, e); - throw new RuntimeException(e); - } + public String createFacet(String facet) throws 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 { + return update(facet); + } + @Override public String updateFacet(String facet) throws FacetNotFoundException, ResourceRegistryException { - try { - UUID uuid = Utility.getUUIDFromJsonString(facet); - return updateFacet(uuid, facet); - } catch (ResourceRegistryException e) { - // logger.trace("Error Updating {}", facet, e); - throw e; - } catch (Exception e) { - // logger.trace("Error Updating {}", facet, e); - throw new RuntimeException(e); - } + return update(facet); } - - @Override - public String updateFacet(UUID uuid, String facet) throws FacetNotFoundException, ResourceRegistryException { - try { - logger.trace("Going to update: {}", facet); - StringWriter stringWriter = new StringWriter(); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.ER_PATH_PART); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.FACET_PATH_PART); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(uuid.toString()); - - HTTPCall httpCall = getHTTPCall(); - String f = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.POST, facet); - - logger.trace("{} successfully updated", f); - return f; - - } catch (ResourceRegistryException e) { - // logger.trace("Error Updating {}", facet, e); - throw e; - } catch (Exception e) { - // logger.trace("Error Updating {}", facet, e); - throw new RuntimeException(e); - } - } - + @Override public boolean deleteFacet(F facet) throws FacetNotFoundException, ResourceRegistryException { - logger.info("Going to delete : {}", facet); - return deleteFacet(facet.getHeader().getUUID()); + return delete(facet); } - + @Override - public boolean deleteFacet(UUID uuid) throws FacetNotFoundException, ResourceRegistryException { - try { - logger.info("Going to delete {} with UUID {}", Facet.NAME, uuid.toString()); - StringWriter stringWriter = new StringWriter(); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.ER_PATH_PART); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.FACET_PATH_PART); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(uuid.toString()); - - HTTPCall httpCall = getHTTPCall(); - boolean deleted = httpCall.call(Boolean.class, stringWriter.toString(), HTTPMETHOD.DELETE); - - logger.info("{} with UUID {} {}", Facet.NAME, uuid.toString(), - deleted ? " successfully deleted" : "was NOT deleted"); - return deleted; - - } catch (ResourceRegistryException e) { - // logger.trace("Error Removing {}", facet, e); - throw e; - } catch (Exception e) { - // logger.trace("Error Removing {}", facet, e); - throw new RuntimeException(e); - } + public boolean deleteFacet(String facetType, UUID uuid) throws FacetNotFoundException, ResourceRegistryException { + return delete(facetType, uuid); } - - @Deprecated - @Override - public R createResource(Class resourceClass, R resource) - throws ResourceAlreadyPresentException, ResourceRegistryException { - try { - return createResource(resource); - } catch (ResourceRegistryException e) { - // logger.trace("Error Creating {}", resource, e); - throw e; - - } catch (Exception e) { - // logger.trace("Error Creating {}", resource, e); - throw new RuntimeException(e); - } - } - - @SuppressWarnings("unchecked") + @Override public R createResource(R resource) throws ResourceAlreadyPresentException, ResourceRegistryException { - try { - String resourceString = ISMapper.marshal(resource); - String resourceType = Utility.getType(resource); - String res = createResource(resourceType, resourceString); - return (R) ISMapper.unmarshal(Resource.class, res); - } catch (ResourceRegistryException e) { - // logger.trace("Error Creating {}", resource, e); - throw e; - - } catch (Exception e) { - // logger.trace("Error Creating {}", resource, e); - throw new RuntimeException(e); - } + return create(resource); + } + + @Override + public String createResource(String resourceType, String resource) + throws ResourceAlreadyPresentException, ResourceRegistryException { + return create(resourceType, resource); } @Override public String createResource(String resource) throws ResourceAlreadyPresentException, ResourceRegistryException { - try { - String resourceType = Utility.getClassFromJsonString(resource); - return createResource(resourceType, resource); - } catch (ResourceRegistryException e) { - // logger.trace("Error Creating {}", resource, e); - throw e; - - } catch (Exception e) { - // logger.trace("Error Creating {}", resource, e); - throw new RuntimeException(e); - } - } - - @Override - public String createResource(String resourceType, String resource) - throws ResourceAlreadyPresentException, ResourceRegistryException { - try { - logger.trace("Going to create: {}", resource); - StringWriter stringWriter = new StringWriter(); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.ER_PATH_PART); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.RESOURCE_PATH_PART); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(resourceType); - - HTTPCall httpCall = getHTTPCall(); - String r = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.PUT, resource); - - logger.trace("{} successfully created", r); - return r; - - } catch (ResourceRegistryException e) { - // logger.trace("Error Creating {}", resource, e); - throw e; - - } catch (Exception e) { - // logger.trace("Error Creating {}", resource, e); - throw new RuntimeException(e); - } - } - - @Deprecated - @Override - public R updateResource(Class resourceClass, R resource) - throws ResourceNotFoundException, ResourceRegistryException { - try { - return updateResource(resource); - } catch (ResourceRegistryException e) { - // logger.trace("Error Creating {}", resource, e); - throw e; - } catch (Exception e) { - // logger.trace("Error Creating {}", resource, e); - throw new RuntimeException(e); - } + 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); } - @SuppressWarnings("unchecked") @Override public R updateResource(R resource) throws ResourceNotFoundException, ResourceRegistryException { - try { - String resourceString = ISMapper.marshal(resource); - UUID uuid = resource.getHeader().getUUID(); - String res = updateResource(uuid, resourceString); - return (R) ISMapper.unmarshal(Resource.class, res); - } catch (ResourceRegistryException e) { - // logger.trace("Error Creating {}", resource, e); - throw e; - } catch (Exception e) { - // logger.trace("Error Creating {}", resource, e); - throw new RuntimeException(e); - } + return update(resource); } @Override public String updateResource(String resource) throws ResourceNotFoundException, ResourceRegistryException { - try { - UUID uuid = Utility.getUUIDFromJsonString(resource); - return updateResource(uuid, resource); - } catch (ResourceRegistryException e) { - // logger.trace("Error Creating {}", resource, e); - throw e; - } catch (Exception e) { - // logger.trace("Error Creating {}", resource, e); - throw new RuntimeException(e); - } + return update(resource); } - - @Override - public String updateResource(UUID uuid, String resource) - throws ResourceNotFoundException, ResourceRegistryException { - try { - logger.trace("Going to update: {}", resource); - StringWriter stringWriter = new StringWriter(); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.ER_PATH_PART); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.RESOURCE_PATH_PART); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(uuid.toString()); - - HTTPCall httpCall = getHTTPCall(); - String r = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.POST, resource); - - logger.trace("{} successfully updated", r); - return r; - - } catch (ResourceRegistryException e) { - // logger.trace("Error Creating {}", resource, e); - throw e; - } catch (Exception e) { - // logger.trace("Error Creating {}", resource, e); - throw new RuntimeException(e); - } - } - + @Override public boolean deleteResource(R resource) throws ResourceNotFoundException, ResourceRegistryException { - logger.info("Going to delete {}", resource); - return deleteResource(resource.getHeader().getUUID()); - } - - @Override - public boolean deleteResource(UUID uuid) throws ResourceNotFoundException, ResourceRegistryException { - try { - logger.info("Going to delete {} with UUID {}", Resource.NAME, uuid.toString()); - StringWriter stringWriter = new StringWriter(); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.ER_PATH_PART); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.RESOURCE_PATH_PART); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(uuid.toString()); - - HTTPCall httpCall = getHTTPCall(); - boolean deleted = httpCall.call(Boolean.class, stringWriter.toString(), HTTPMETHOD.DELETE); - - logger.info("{} with UUID {} {}", Resource.NAME, uuid.toString(), - deleted ? " successfully deleted" : "was NOT deleted"); - return deleted; - - } catch (ResourceRegistryException e) { - // logger.trace("Error Removing {}", resource, e); - throw e; - } catch (Exception e) { - // logger.trace("Error Removing {}", resource, e); - throw new RuntimeException(e); - } - } - - @Deprecated - @Override - public > C createConsistsOf(Class consistsOfClass, - C consistsOf) throws FacetNotFoundException, ResourceNotFoundException, ResourceRegistryException { - try { - return createConsistsOf(consistsOf); - } catch (ResourceRegistryException e) { - // logger.trace("Error Creating {}", consistsOf, e); - throw e; - } catch (Exception e) { - // logger.trace("Error Creating {}", consistsOf, e); - throw new RuntimeException(e); - } - } - - @SuppressWarnings("unchecked") - @Override - public > C createConsistsOf( - C consistsOf) throws FacetNotFoundException, ResourceNotFoundException, ResourceRegistryException { - try { - String consistsOfString = ISMapper.marshal(consistsOf); - String consistsOfType = Utility.getType(consistsOf); - String res = createConsistsOf(consistsOfType, consistsOfString); - return (C) ISMapper.unmarshal(ConsistsOf.class, res); - } catch (ResourceRegistryException e) { - // logger.trace("Error Creating {}", consistsOf, e); - throw e; - } catch (Exception e) { - // logger.trace("Error Creating {}", consistsOf, e); - throw new RuntimeException(e); - } + return delete(resource); } @Override - public String createConsistsOf(String consistsOf) - throws FacetNotFoundException, ResourceNotFoundException, ResourceRegistryException { - try { - String consistsOfType = Utility.getClassFromJsonString(consistsOf); - return createConsistsOf(consistsOfType, consistsOf); - } catch (ResourceRegistryException e) { - // logger.trace("Error Creating {}", consistsOf, e); - throw e; - } catch (Exception e) { - // logger.trace("Error Creating {}", consistsOf, e); - throw new RuntimeException(e); - } + public boolean deleteResource(String resourceType, UUID uuid) + throws ResourceNotFoundException, ResourceRegistryException { + return delete(resourceType, uuid); } - + + @Override + public > C createConsistsOf(C consistsOf) + throws NotFoundException, ResourceRegistryException { + return create(consistsOf); + } + @Override public String createConsistsOf(String consistsOfType, String consistsOf) - throws FacetNotFoundException, ResourceNotFoundException, ResourceRegistryException { - try { - logger.trace("Going to create: {}", consistsOf); - - StringWriter stringWriter = new StringWriter(); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.ER_PATH_PART); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.CONSISTS_OF_PATH_PART); - /* - * stringWriter.append(PATH_SEPARATOR); - * stringWriter.append(ERPath.SOURCE_PATH_PART); - * stringWriter.append(PATH_SEPARATOR); - * stringWriter.append(consistsOf.getSource().getHeader().getUUID() - * .toString()); stringWriter.append(PATH_SEPARATOR); - * stringWriter.append(ERPath.TARGET_PATH_PART); - * stringWriter.append(PATH_SEPARATOR); - * stringWriter.append(consistsOf.getTarget().getHeader().getUUID() - * .toString()); - */ - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(consistsOfType); - - HTTPCall httpCall = getHTTPCall(); - String c = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.PUT, consistsOf); - - logger.trace("{} successfully created", c); - return c; - - } catch (ResourceRegistryException e) { - // logger.trace("Error Creating {}", consistsOf, e); - throw e; - } catch (Exception e) { - // logger.trace("Error Creating {}", consistsOf, e); - throw new RuntimeException(e); - } - } - - @Override - public > boolean deleteConsistsOf(C consistsOf) - throws ResourceRegistryException { - return deleteConsistsOf(consistsOf.getHeader().getUUID()); - } - - @Override - public boolean deleteConsistsOf(UUID uuid) throws ResourceRegistryException { - try { - logger.info("Going to delete {} with UUID {}", ConsistsOf.NAME, uuid); - StringWriter stringWriter = new StringWriter(); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.ER_PATH_PART); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.CONSISTS_OF_PATH_PART); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(uuid.toString()); - - HTTPCall httpCall = getHTTPCall(); - boolean deleted = httpCall.call(Boolean.class, stringWriter.toString(), HTTPMETHOD.DELETE); - - logger.info("{} with UUID {} {}", ConsistsOf.NAME, uuid, - deleted ? " successfully deleted" : "was NOT deleted"); - return deleted; - - } catch (ResourceRegistryException e) { - // logger.trace("Error Removing {} with UUID {}", ConsistsOf.NAME, - // uuid, e); - throw e; - } catch (Exception e) { - // logger.trace("Error Removing {} with UUID {}", ConsistsOf.NAME, - // uuid, e); - throw new RuntimeException(e); - } - } - - @Deprecated - @Override - public > I createIsRelatedTo( - Class isRelatedToClass, I isRelatedTo) throws ResourceNotFoundException, ResourceRegistryException { - try { - return createIsRelatedTo(isRelatedTo); - } catch (ResourceRegistryException e) { - // logger.trace("Error Creating {}", isRelatedTo, e); - throw e; - } catch (Exception e) { - // logger.trace("Error Creating {}", isRelatedTo, e); - throw new RuntimeException(e); - } - } - - @SuppressWarnings("unchecked") - @Override - public > I createIsRelatedTo( - I isRelatedTo) throws ResourceNotFoundException, ResourceRegistryException { - try { - String isRelatedToString = ISMapper.marshal(isRelatedTo); - String isRelatedToType = Utility.getType(isRelatedTo); - String res = createIsRelatedTo(isRelatedToType, isRelatedToString); - return (I) ISMapper.unmarshal(IsRelatedTo.class, res); - } catch (ResourceRegistryException e) { - // logger.trace("Error Creating {}", isRelatedTo, e); - throw e; - } catch (Exception e) { - // logger.trace("Error Creating {}", isRelatedTo, e); - throw new RuntimeException(e); - } + throws NotFoundException, ResourceRegistryException { + return create(consistsOfType, consistsOf); } @Override - public String createIsRelatedTo(String isRelatedTo) throws ResourceNotFoundException, ResourceRegistryException { - try { - String isRelatedToType = Utility.getClassFromJsonString(isRelatedTo); - return createIsRelatedTo(isRelatedToType, isRelatedTo); - } catch (ResourceRegistryException e) { - // logger.trace("Error Creating {}", isRelatedTo, e); - throw e; - } catch (Exception e) { - // logger.trace("Error Creating {}", isRelatedTo, e); - throw new RuntimeException(e); - } + public String createConsistsOf(String consistsOf) throws NotFoundException, ResourceRegistryException { + return create(consistsOf); + } + + @Override + 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 { + return update(consistsOf); + } + + @Override + public String updateConsistsOf(String consistsOf) throws NotFoundException, ResourceRegistryException { + return update(consistsOf); + } + + @Override + public > boolean deleteConsistsOf(C consistsOf) + throws ResourceRegistryException { + return delete(consistsOf); + } + + @Override + public boolean deleteConsistsOf(String consistsOfType, UUID uuid) throws ResourceRegistryException { + return delete(consistsOfType, uuid); + } + + @Override + public > I createIsRelatedTo(I isRelatedTo) + throws ResourceNotFoundException, ResourceRegistryException { + return create(isRelatedTo); } @Override public String createIsRelatedTo(String isRelatedToType, String isRelatedTo) throws ResourceNotFoundException, ResourceRegistryException { - try { - logger.trace("Going to create: {}", isRelatedTo); - StringWriter stringWriter = new StringWriter(); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.ER_PATH_PART); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.IS_RELATED_TO_PATH_PART); - /* - * stringWriter.append(PATH_SEPARATOR); - * stringWriter.append(ERPath.SOURCE_PATH_PART); - * stringWriter.append(PATH_SEPARATOR); - * stringWriter.append(isRelatedTo.getSource().getHeader().getUUID() - * .toString()); stringWriter.append(PATH_SEPARATOR); - * stringWriter.append(ERPath.TARGET_PATH_PART); - * stringWriter.append(PATH_SEPARATOR); - * stringWriter.append(isRelatedTo.getTarget().getHeader().getUUID() - * .toString()); - */ - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(isRelatedToType); - - HTTPCall httpCall = getHTTPCall(); - String i = httpCall.call(String.class, stringWriter.toString(), HTTPMETHOD.PUT, isRelatedTo); - - logger.trace("{} successfully created", i); - return i; - - } catch (ResourceRegistryException e) { - // logger.trace("Error Creating {}", isRelatedTo, e); - throw e; - } catch (Exception e) { - // logger.trace("Error Creating {}", isRelatedTo, e); - throw new RuntimeException(e); - } + return create(isRelatedToType, isRelatedTo); } - + @Override - public > boolean deleteIsRelatedTo(I isRelatedTo) + public String createIsRelatedTo(String isRelatedTo) throws ResourceNotFoundException, ResourceRegistryException { + return create(isRelatedTo); + } + + @Override + 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 { + return update(isRelatedTo); + } + + @Override + public String updateIsRelatedTo(String isRelatedTo) throws NotFoundException, ResourceRegistryException { + return update(isRelatedTo); + } + + @Override + public > boolean deleteIsRelatedTo(I isRelatedTo) throws ResourceRegistryException { - return deleteIsRelatedTo(isRelatedTo.getHeader().getUUID()); + return delete(isRelatedTo); } - + @Override - public boolean deleteIsRelatedTo(UUID uuid) throws ResourceRegistryException { + public boolean deleteIsRelatedTo(String isRelatedToType, UUID uuid) throws ResourceRegistryException { + return delete(isRelatedToType, uuid); + } + + @Override + public boolean addToContext(UUID contextUUID, String erType, UUID instanceUUID) + throws NotFoundException, ResourceRegistryException { try { - logger.info("Going to delete {} with UUID {}", IsRelatedTo.NAME, uuid); + logger.trace("Going to add {} with UUID {} to {} with UUID {} ", erType, instanceUUID, Context.NAME, + contextUUID); StringWriter stringWriter = new StringWriter(); stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.ER_PATH_PART); + stringWriter.append(SharingPath.SHARING_PATH_PART); stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.IS_RELATED_TO_PATH_PART); + stringWriter.append(SharingPath.CONTEXTS_PATH_PART); stringWriter.append(PATH_SEPARATOR); - stringWriter.append(uuid.toString()); - + stringWriter.append(contextUUID.toString()); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(erType); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(instanceUUID.toString()); + HTTPCall httpCall = getHTTPCall(); - boolean deleted = httpCall.call(Boolean.class, stringWriter.toString(), HTTPMETHOD.DELETE); - - logger.info("{} with UUID {} {}", IsRelatedTo.NAME, uuid, - deleted ? " successfully deleted" : "was NOT deleted"); - return deleted; - - } catch (ResourceRegistryException e) { - // logger.trace("Error Removing {} with UUID {}", IsRelatedTo.NAME, - // uuid, e); - throw e; - } catch (Exception e) { - // logger.trace("Error Removing {} with UUID {}", IsRelatedTo.NAME, - // uuid, e); - throw new RuntimeException(e); - } - } - - @Override - public boolean addResourceToContext(UUID uuid) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { - String context = getCurrentContext(); - try { - logger.info("Going to add {} with UUID {} to current {} : {}", Resource.NAME, uuid, Context.NAME, context); - - StringWriter stringWriter = new StringWriter(); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.ER_PATH_PART); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.ADD_PATH_PART); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.RESOURCE_PATH_PART); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(uuid.toString()); - - HTTPCall httpCall = getHTTPCall(); - boolean added = httpCall.call(Boolean.class, stringWriter.toString(), HTTPMETHOD.POST); - - logger.info("{} with UUID {} was {} added to current {} : {}", Resource.NAME, uuid, - added ? "successfully" : "NOT", Context.NAME, context); + boolean added = httpCall.call(Boolean.class, stringWriter.toString(), HTTPMETHOD.PUT); + + logger.info("{} with UUID {} {} to {} with UUID {}", erType, instanceUUID, + added ? " successfully added" : "was NOT added", Context.NAME, contextUUID); return added; - - } catch (ResourceRegistryException e) { - // logger.trace("Error Adding {} with UUID {} to current {} : {}", - // Resource.NAME, uuid, Context.NAME, context, e); + + } catch(ResourceRegistryException e) { + // logger.trace("Error Creating {}", facet, e); throw e; - } catch (Exception e) { - // logger.trace("Error Adding {} with UUID {} to current {} : {}", - // Resource.NAME, uuid, Context.NAME, context, e); + } catch(Exception e) { + // logger.trace("Error Creating {}", facet, e); throw new RuntimeException(e); } } - + @Override - public boolean addResourceToContext(R resource) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { - return addResourceToContext(resource.getHeader().getUUID()); - } - - @Override - public boolean addFacetToContext(UUID uuid) - throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { - String context = getCurrentContext(); + public boolean addToContext(UUID contextUUID, E er) + throws NotFoundException, ResourceRegistryException { try { - logger.info("Going to add {} with UUID {} to current {} : {}", Facet.NAME, uuid, Context.NAME, context); - - StringWriter stringWriter = new StringWriter(); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.ER_PATH_PART); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.ADD_PATH_PART); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.FACET_PATH_PART); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(uuid.toString()); - - HTTPCall httpCall = getHTTPCall(); - boolean added = httpCall.call(Boolean.class, stringWriter.toString(), HTTPMETHOD.POST); - - logger.info("{} with UUID {} was {} added to current {} : {}", Facet.NAME, uuid, - added ? "successfully" : "NOT", Context.NAME, context); - return added; - - } catch (ResourceRegistryException e) { - // logger.trace("Error Adding {} with UUID {} to current {} : {}", - // Facet.NAME, uuid, Context.NAME, context, e); + String erType = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getType(er); + UUID instanceUUID = er.getHeader().getUUID(); + return addToContext(contextUUID, erType, instanceUUID); + } catch(ResourceRegistryException e) { + // logger.trace("Error Creating {}", facet, e); throw e; - } catch (Exception e) { - // logger.trace("Error Adding {} with UUID {} to current {} : {}", - // Facet.NAME, uuid, Context.NAME, context, e); + } catch(Exception e) { + // logger.trace("Error Creating {}", facet, e); throw new RuntimeException(e); } } - + @Override - public boolean addFacetToContext(F facet) - throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { - return addFacetToContext(facet.getHeader().getUUID()); + public boolean addToCurrentContext(String erType, UUID instanceUUID) + throws NotFoundException, ResourceRegistryException { + UUID contextUUID = getCurrentContextUUID(); + return addToContext(contextUUID, erType, instanceUUID); } - + @Override - public boolean removeResourceFromContext(UUID uuid) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { - String context = getCurrentContext(); + public boolean addToCurrentContext(E er) throws NotFoundException, ResourceRegistryException { + UUID contextUUID = getCurrentContextUUID(); + return addToContext(contextUUID, er); + } + + @Override + public boolean removeFromContext(UUID contextUUID, String erType, UUID instanceUUID) + throws NotFoundException, ResourceRegistryException { try { - logger.info("Going to add {} with UUID {} to current {} : {}", Resource.NAME, uuid, Context.NAME, context); - + logger.trace("Going to add {} with UUID {} to {} with UUID {} ", erType, instanceUUID, Context.NAME, + contextUUID); StringWriter stringWriter = new StringWriter(); stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.ER_PATH_PART); + stringWriter.append(SharingPath.SHARING_PATH_PART); stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.REMOVE_PATH_PART); + stringWriter.append(SharingPath.CONTEXTS_PATH_PART); stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.RESOURCE_PATH_PART); + stringWriter.append(contextUUID.toString()); stringWriter.append(PATH_SEPARATOR); - stringWriter.append(uuid.toString()); - + stringWriter.append(erType); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(instanceUUID.toString()); + HTTPCall httpCall = getHTTPCall(); - boolean removed = httpCall.call(Boolean.class, stringWriter.toString(), HTTPMETHOD.POST); - - logger.info("{} with UUID {} was {} removed from current {} : {}", Resource.NAME, uuid, - removed ? "successfully" : "NOT", Context.NAME, context); + boolean removed = httpCall.call(Boolean.class, stringWriter.toString(), HTTPMETHOD.DELETE); + + logger.info("{} with UUID {} {} to {} with UUID {}", erType, instanceUUID, + removed ? " successfully removed" : "was NOT removed", Context.NAME, contextUUID); return removed; - - } catch (ResourceRegistryException e) { - // logger.trace("Error Adding {} with UUID {} to current {} : {}", - // Resource.NAME, uuid, Context.NAME, context, e); + + } catch(ResourceRegistryException e) { + // logger.trace("Error Creating {}", facet, e); throw e; - - } catch (Exception e) { - // logger.trace("Error Adding {} with UUID {} to current {} : {}", - // Resource.NAME, uuid, Context.NAME, context, e); + } catch(Exception e) { + // logger.trace("Error Creating {}", facet, e); throw new RuntimeException(e); } } - + @Override - public boolean removeResourceFromContext(R resource) + public boolean removeFromContext(UUID contextUUID, E er) throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { - return removeResourceFromContext(resource.getHeader().getUUID()); - } - - @Override - public boolean removeFacetFromContext(UUID uuid) - throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { - String context = getCurrentContext(); try { - logger.info("Going to add {} with UUID {} to current {} : {}", Facet.NAME, uuid, Context.NAME, context); - - StringWriter stringWriter = new StringWriter(); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.ER_PATH_PART); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.REMOVE_PATH_PART); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(ERPath.FACET_PATH_PART); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(uuid.toString()); - - HTTPCall httpCall = getHTTPCall(); - boolean removed = httpCall.call(Boolean.class, stringWriter.toString(), HTTPMETHOD.POST); - - logger.info("{} with UUID {} was {} removed from current {} : {}", Facet.NAME, uuid, - removed ? "successfully" : "NOT", Context.NAME, context); - return removed; - - } catch (ResourceRegistryException e) { - // logger.trace("Error Adding {} with UUID {} to current {} : {}", - // Facet.NAME, uuid, Context.NAME, context, e); + String erType = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getType(er); + UUID instanceUUID = er.getHeader().getUUID(); + return removeFromContext(contextUUID, erType, instanceUUID); + } catch(ResourceRegistryException e) { + // logger.trace("Error Creating {}", facet, e); throw e; - } catch (Exception e) { - // logger.trace("Error Adding {} with UUID {} to current {} : {}", - // Facet.NAME, uuid, Context.NAME, context, e); + } catch(Exception e) { + // logger.trace("Error Creating {}", facet, e); throw new RuntimeException(e); } } - + @Override - public boolean removeFacetFromContext(F facet) - throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { - return removeFacetFromContext(facet.getHeader().getUUID()); + public boolean removeFromCurrentContext(String erType, UUID instanceUUID) + throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + UUID contextUUID = getCurrentContextUUID(); + return removeFromContext(contextUUID, erType, instanceUUID); } - + + @Override + public boolean removeFromCurrentContext(E er) + throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + UUID contextUUID = getCurrentContextUUID(); + return removeFromContext(contextUUID, er); + } + + @Override + public boolean addResourceToContext(UUID contextUUID, String resourceType, UUID resourceUUID) + throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + return addToContext(contextUUID, resourceType, resourceUUID); + } + + @Override + public boolean addResourceToContext(UUID contextUUID, R resource) + throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + return addToContext(contextUUID, resource); + } + + @Override + public boolean addResourceToCurrentContext(String resourceType, UUID resourceUUID) + throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + return addToCurrentContext(resourceType, resourceUUID); + } + + @Override + public boolean addResourceToCurrentContext(R resource) + throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + return addToCurrentContext(resource); + } + + @Override + public boolean removeResourceFromContext(UUID contextUUID, String resourceType, UUID resourceUUID) + throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + return removeFromContext(contextUUID, resourceType, resourceUUID); + } + + @Override + public boolean removeResourceFromContext(UUID contextUUID, R resource) + throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + return removeFromContext(contextUUID, resource); + } + + @Override + public boolean removeResourceFromCurrentContext(String resourceType, UUID resourceUUID) + throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + return removeFromCurrentContext(resourceType, resourceUUID); + } + + @Override + public boolean removeResourceFromCurrentContext(R resource) + throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + return removeFromCurrentContext(resource); + } + + @Override + public boolean addFacetToContext(UUID contextUUID, String facetType, UUID facetUUID) + throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { + return addToContext(contextUUID, facetType, facetUUID); + } + + @Override + public boolean addFacetToContext(UUID contextUUID, F facet) + throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { + return addToContext(contextUUID, facet); + } + + @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(UUID contextUUID, String facetType, UUID facetUUID) + throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { + return removeFromContext(contextUUID, facetType, facetUUID); + } + + @Override + public boolean removeFacetFromContext(UUID contextUUID, F facet) + throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { + return removeFromContext(contextUUID, facet); + } + + @Override + public boolean removeFacetFromCurrentContext(String facetType, UUID facetUUID) + throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { + return removeFromCurrentContext(facetType, facetUUID); + } + + @Override + public boolean removeFacetFromCurrentContext(F facet) + throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { + return removeFromCurrentContext(facet); + } + } diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/ERManagementTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/ERManagementTest.java index 46d0f0b..ed4c17d 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/ERManagementTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/ERManagementTest.java @@ -230,8 +230,7 @@ public class ERManagementTest extends ScopedTest { eService.getFacets(SoftwareFacet.class).get(0).setVersion("1.2.0"); - eServiceString = resourceRegistryPublisher.updateResource(eService.getHeader().getUUID(), - ISMapper.marshal(eService)); + eServiceString = resourceRegistryPublisher.updateResource(ISMapper.marshal(eService)); eService = ISMapper.unmarshal(EService.class, eServiceString); Assert.assertTrue(eService.getFacets(SoftwareFacet.class).get(0).getVersion().compareTo("1.2.0") == 0); diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/EntityManagementTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/EntityManagementTest.java index e9fae62..d7702e9 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/EntityManagementTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/EntityManagementTest.java @@ -105,7 +105,7 @@ public class EntityManagementTest extends ScopedTest { String additionPropertyValue = "Test"; createdCpuFacet.setAdditionalProperty(additionPropertyKey, additionPropertyValue); - String updatedCpuFacetString = resourceRegistryPublisher.updateFacet(createdCpuFacet.getHeader().getUUID(), ISMapper.marshal(createdCpuFacet)); + String updatedCpuFacetString = resourceRegistryPublisher.updateFacet(ISMapper.marshal(createdCpuFacet)); CPUFacet updatedCpuFacet = ISMapper.unmarshal(CPUFacet.class, updatedCpuFacetString); Assert.assertTrue(createdCpuFacet.getClockSpeed().compareTo(updatedCpuFacet.getClockSpeed())==0); diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/MultiContextTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/MultiContextTest.java index 6cf9dfb..6f953eb 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/MultiContextTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/MultiContextTest.java @@ -3,14 +3,9 @@ */ package org.gcube.informationsystem.resourceregistry.publisher; -import java.io.File; import java.net.URI; import java.net.URL; -import java.util.ArrayList; import java.util.Calendar; -import java.util.HashSet; -import java.util.List; -import java.util.Set; import java.util.UUID; import org.gcube.informationsystem.impl.entity.facet.AccessPointFacetImpl; @@ -54,9 +49,6 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - /** * @author Luca Frosini (ISTI - CNR) * @@ -74,48 +66,6 @@ public class MultiContextTest extends ScopedTest { resourceRegistryClient = ResourceRegistryClientFactory.create(); } - @Test - public void production() throws Exception { - File src = new File("src"); - File test = new File(src, "test"); - File resources = new File(test, "resources"); - - File tokenFile = new File(resources, "production-tokens-is-exporter.json"); - - ObjectMapper objectMapper = new ObjectMapper(); - JsonNode jsonNode = objectMapper.readTree(tokenFile); - - Set contexts = new HashSet<>(); - contexts.add("/d4science.research-infrastructures.eu/ParthenosVO"); - contexts.add("/d4science.research-infrastructures.eu/ParthenosVO/RubRIcA"); - contexts.add("/d4science.research-infrastructures.eu/ParthenosVO/PARTHENOS_Registry"); - - - String rootToken = jsonNode.get("/d4science.research-infrastructures.eu").asText(); - ScopedTest.setContext(rootToken); - - ResourceRegistryPublisher resourceRegistryPublisher = ResourceRegistryPublisherFactory.create(); - //ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create(); - - - List uuids = new ArrayList<>(); - uuids.add("ac88cc20-9589-4e0b-9115-7af6e0bd7abc"); - uuids.add("38823ddc-0713-4e83-9670-79e472408b0c"); - - for(String context : contexts){ - String token = jsonNode.get(context).asText(); - ScopedTest.setContext(token); - - for(String uuidString : uuids){ - UUID uuid = UUID.fromString(uuidString); - resourceRegistryPublisher.addResourceToContext(uuid); - } - - } - - - } - @Test public void testCreateEServiceHostingNode() throws Exception { EService eService = new EServiceImpl(); @@ -230,7 +180,7 @@ public class MultiContextTest extends ScopedTest { } - boolean addedToContext = resourceRegistryPublisher.addResourceToContext(hostingNodeUUID); + boolean addedToContext = resourceRegistryPublisher.addResourceToCurrentContext(createdHN); Assert.assertTrue(addedToContext); try {