From 04f7dac6d111a4025e72649a25e6e80f900a33e8 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Tue, 3 Oct 2017 15:44:13 +0000 Subject: [PATCH] Removed the needs to pass the class to create/update methods git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-publisher@154781 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../publisher/ResourceRegistryPublisher.java | 26 +++- .../ResourceRegistryPublisherImpl.java | 141 +++++++++++++++--- 2 files changed, 144 insertions(+), 23 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 9ec4009..2e4900f 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisher.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisher.java @@ -18,17 +18,25 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resour */ public interface ResourceRegistryPublisher { + @Deprecated public F createFacet(Class facetClass, F facet) throws FacetAlreadyPresentException, ResourceRegistryException; + public F createFacet(F facet) + throws FacetAlreadyPresentException, ResourceRegistryException; + public String createFacet(String facetType, String facet) throws FacetAlreadyPresentException, ResourceRegistryException; public String createFacet(String facet) throws FacetAlreadyPresentException, ResourceRegistryException; + @Deprecated public F updateFacet(Class facetClass, F facet) 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; @@ -37,17 +45,25 @@ public interface ResourceRegistryPublisher { public boolean deleteFacet(UUID uuid) throws FacetNotFoundException, ResourceRegistryException; + @Deprecated public R createResource(Class resourceClass, R resource) throws ResourceAlreadyPresentException, ResourceRegistryException; + public R createResource(R resource) + throws ResourceAlreadyPresentException, ResourceRegistryException; + public String createResource(String resourceType, String resource) throws ResourceAlreadyPresentException, ResourceRegistryException; public String createResource(String resource) throws ResourceAlreadyPresentException, ResourceRegistryException; + @Deprecated public R updateResource(Class resourceClass, R resource) throws ResourceNotFoundException, ResourceRegistryException; + public R updateResource(R resource) + throws ResourceNotFoundException, ResourceRegistryException; + public String updateResource(UUID uuid, String resource) throws ResourceNotFoundException, ResourceRegistryException; @@ -59,8 +75,12 @@ public interface ResourceRegistryPublisher { public boolean deleteResource(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; public String createConsistsOf(String consistsOfType, String consistsOf) throws FacetNotFoundException, ResourceNotFoundException, ResourceRegistryException; @@ -73,9 +93,13 @@ public interface ResourceRegistryPublisher { public boolean deleteConsistsOf(UUID uuid) throws ResourceRegistryException; + @Deprecated public > I createIsRelatedTo( Class isRelatedToClass, I isRelatedTo) throws ResourceNotFoundException, ResourceRegistryException; + public > I createIsRelatedTo( + I isRelatedTo) throws ResourceNotFoundException, ResourceRegistryException; + public String createIsRelatedTo(String isRelatedToType, String isRelatedTo) throws ResourceNotFoundException, 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 e901f61..62fdbf6 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherImpl.java @@ -62,13 +62,29 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher } @Override + @Deprecated public F createFacet(Class facetClass, F facet) throws FacetAlreadyPresentException, ResourceRegistryException { try { - String facetString = ISMapper.marshal(facet); - String facetType = facetClass.getSimpleName(); - String res = createFacet(facetType, facetString); - return ISMapper.unmarshal(facetClass, res); + return createFacet(facet); + } 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 F createFacet(F facet) + throws FacetAlreadyPresentException, 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) { // logger.trace("Error Creating {}", facet, e); throw e; @@ -77,7 +93,6 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher throw new RuntimeException(e); } } - @Override public String createFacet(String facet) throws FacetAlreadyPresentException, ResourceRegistryException { try { @@ -121,13 +136,29 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher } @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); + } + } + + @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 ISMapper.unmarshal(facetClass, res); + return (F) ISMapper.unmarshal(Facet.class, res); } catch (ResourceRegistryException e) { // logger.trace("Error Updating {}", facet, e); throw e; @@ -212,14 +243,12 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher } } + @Deprecated @Override public R createResource(Class resourceClass, R resource) throws ResourceAlreadyPresentException, ResourceRegistryException { try { - String resourceString = ISMapper.marshal(resource); - String resourceType = resourceClass.getSimpleName(); - String res = createResource(resourceType, resourceString); - return ISMapper.unmarshal(resourceClass, res); + return createResource(resource); } catch (ResourceRegistryException e) { // logger.trace("Error Creating {}", resource, e); throw e; @@ -230,6 +259,25 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher } } + @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); + } + } + @Override public String createResource(String resource) throws ResourceAlreadyPresentException, ResourceRegistryException { try { @@ -274,14 +322,12 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher } } + @Deprecated @Override public R updateResource(Class resourceClass, R resource) throws ResourceNotFoundException, ResourceRegistryException { try { - String resourceString = ISMapper.marshal(resource); - UUID uuid = resource.getHeader().getUUID(); - String res = updateResource(uuid, resourceString); - return ISMapper.unmarshal(resourceClass, res); + return updateResource(resource); } catch (ResourceRegistryException e) { // logger.trace("Error Creating {}", resource, e); throw e; @@ -290,7 +336,26 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher throw new RuntimeException(e); } } - + + @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); + } + } + + @Override public String updateResource(String resource) throws ResourceNotFoundException, ResourceRegistryException { try { UUID uuid = Utility.getUUIDFromJsonString(resource); @@ -367,14 +432,12 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher } } + @Deprecated @Override public > C createConsistsOf(Class consistsOfClass, C consistsOf) throws FacetNotFoundException, ResourceNotFoundException, ResourceRegistryException { try { - String consistsOfString = ISMapper.marshal(consistsOf); - String consistsOfType = consistsOfClass.getSimpleName(); - String res = createConsistsOf(consistsOfType, consistsOfString); - return ISMapper.unmarshal(consistsOfClass, res); + return createConsistsOf(consistsOf); } catch (ResourceRegistryException e) { // logger.trace("Error Creating {}", consistsOf, e); throw e; @@ -384,6 +447,24 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher } } + @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); + } + } + @Override public String createConsistsOf(String consistsOf) throws FacetNotFoundException, ResourceNotFoundException, ResourceRegistryException { @@ -399,6 +480,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher } } + @Override public String createConsistsOf(String consistsOfType, String consistsOf) throws FacetNotFoundException, ResourceNotFoundException, ResourceRegistryException { try { @@ -447,7 +529,6 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher @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); @@ -475,15 +556,30 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher } } + @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 = isRelatedToClass.getSimpleName(); + String isRelatedToType = Utility.getType(isRelatedTo); String res = createConsistsOf(isRelatedToType, isRelatedToString); - return ISMapper.unmarshal(isRelatedToClass, res); + return (I) ISMapper.unmarshal(IsRelatedTo.class, res); } catch (ResourceRegistryException e) { // logger.trace("Error Creating {}", isRelatedTo, e); throw e; @@ -507,6 +603,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher } } + @Override public String createIsRelatedTo(String isRelatedToType, String isRelatedTo) throws ResourceNotFoundException, ResourceRegistryException { try {