diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/ResourceRegistryPublisher.java b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/ResourceRegistryPublisher.java index b329374..0414f1b 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/ResourceRegistryPublisher.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/ResourceRegistryPublisher.java @@ -11,12 +11,12 @@ public interface ResourceRegistryPublisher { public F updateFacet(F facet); - public F deleteFacet(F facet); + public boolean deleteFacet(F facet); public R createResource(Class resourceClass, R resource); - public R deleteResource(R resource); + public boolean deleteResource(R resource); @@ -24,14 +24,14 @@ public interface ResourceRegistryPublisher { public > C updateConsistsOf(C consistsOf); - public > C deleteConsistsOf(C consistsOf); + public > boolean deleteConsistsOf(C consistsOf); public > I create(Class isRelatedToClass, I isRelatedTo); public > I update(I isRelatedTo); - public > I delete(I isRelatedTo); + public > boolean delete(I isRelatedTo); } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/ResourceRegistryPublisherImpl.java b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/ResourceRegistryPublisherImpl.java index 1aba10b..c5189ce 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/ResourceRegistryPublisherImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/ResourceRegistryPublisherImpl.java @@ -148,9 +148,23 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher } @Override - public F deleteFacet(F facet) { - // TODO Auto-generated method stub - return null; + public boolean deleteFacet(F facet) { + try { + StringWriter stringWriter = new StringWriter(); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(EntityPath.ENTITY_PATH_PART); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(EntityPath.FACET_PATH_PART); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(facet.getHeader().getUUID().toString()); + + ResourceRegistryCall call = new ResourceRegistryCall<>( + Boolean.class, stringWriter, "DELETE"); + return delegate.make(call); + } catch (Exception e) { + logger.error("Error Removing {}", facet, e); + throw new ServiceException(e); + } } @Override @@ -179,16 +193,58 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher } @Override - public R deleteResource(R resource) { - // TODO Auto-generated method stub - return null; + public boolean deleteResource(R resource) { + try { + StringWriter stringWriter = new StringWriter(); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(EntityPath.ENTITY_PATH_PART); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(EntityPath.RESOURCE_PATH_PART); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(resource.getHeader().getUUID().toString()); + + ResourceRegistryCall call = new ResourceRegistryCall<>( + Boolean.class, stringWriter, "DELETE"); + return delegate.make(call); + } catch (Exception e) { + logger.error("Error Removing {}", resource, e); + throw new ServiceException(e); + } } @Override public > C createConsistsOf( Class consistsOfClass, C consistsOf) { - // TODO Auto-generated method stub - return null; + try { + StringWriter stringWriter = new StringWriter(); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(EntityPath.ENTITY_PATH_PART); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(EntityPath.CONSISTS_OF_PATH_PART); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(EntityPath.SOURCE_PATH_PART); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(consistsOf.getSource().getHeader().getUUID().toString()); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(EntityPath.TARGET_PATH_PART); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(consistsOf.getTarget().getHeader().getUUID().toString()); + stringWriter.append(PARAM_STARTER); + stringWriter.append(EntityPath.TYPE_PARAM); + stringWriter.append(PARAM_EQUALS); + stringWriter.append(consistsOfClass.getSimpleName()); + stringWriter.append(PARAM_SEPARATOR); + stringWriter.append(EntityPath.PROPERTIES_PARAM); + stringWriter.append(PARAM_EQUALS); + Entities.marshal(consistsOf, stringWriter); + + ResourceRegistryCall call = new ResourceRegistryCall<>( + consistsOfClass, stringWriter, "PUT"); + return delegate.make(call); + } catch (Exception e) { + logger.error("Error Creating Facet", e); + throw new ServiceException(e); + } } @Override @@ -199,17 +255,60 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher } @Override - public > C deleteConsistsOf( + public > boolean deleteConsistsOf( C consistsOf) { - // TODO Auto-generated method stub - return null; + try { + StringWriter stringWriter = new StringWriter(); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(EntityPath.ENTITY_PATH_PART); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(EntityPath.CONSISTS_OF_PATH_PART); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(consistsOf.getHeader().getUUID().toString()); + + ResourceRegistryCall call = new ResourceRegistryCall<>( + Boolean.class, stringWriter, "DELETE"); + return delegate.make(call); + } catch (Exception e) { + logger.error("Error Removing {}", consistsOf, e); + throw new ServiceException(e); + } } @Override public > I create( Class isRelatedToClass, I isRelatedTo) { - // TODO Auto-generated method stub - return null; + + try { + StringWriter stringWriter = new StringWriter(); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(EntityPath.ENTITY_PATH_PART); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(EntityPath.IS_RELATED_TO_PATH_PART); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(EntityPath.SOURCE_PATH_PART); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(isRelatedTo.getSource().getHeader().getUUID().toString()); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(EntityPath.TARGET_PATH_PART); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(isRelatedTo.getTarget().getHeader().getUUID().toString()); + stringWriter.append(PARAM_STARTER); + stringWriter.append(EntityPath.TYPE_PARAM); + stringWriter.append(PARAM_EQUALS); + stringWriter.append(isRelatedToClass.getSimpleName()); + stringWriter.append(PARAM_SEPARATOR); + stringWriter.append(EntityPath.PROPERTIES_PARAM); + stringWriter.append(PARAM_EQUALS); + Entities.marshal(isRelatedTo, stringWriter); + + ResourceRegistryCall call = new ResourceRegistryCall<>( + isRelatedToClass, stringWriter, "PUT"); + return delegate.make(call); + } catch (Exception e) { + logger.error("Error Creating Facet", e); + throw new ServiceException(e); + } } @Override @@ -219,9 +318,23 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher } @Override - public > I delete(I isRelatedTo) { - // TODO Auto-generated method stub - return null; + public > boolean delete(I isRelatedTo) { + try { + StringWriter stringWriter = new StringWriter(); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(EntityPath.ENTITY_PATH_PART); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(EntityPath.IS_RELATED_TO_PATH_PART); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(isRelatedTo.getHeader().getUUID().toString()); + + ResourceRegistryCall call = new ResourceRegistryCall<>( + Boolean.class, stringWriter, "DELETE"); + return delegate.make(call); + } catch (Exception e) { + logger.error("Error Removing {}", isRelatedTo, e); + throw new ServiceException(e); + } } } diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherTest.java index 4422c25..c2559b9 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherTest.java @@ -3,11 +3,16 @@ */ package org.gcube.informationsystem.resourceregistry.publisher; +import java.util.UUID; + import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.informationsystem.impl.entity.DummyFacet; import org.gcube.informationsystem.impl.entity.facet.ContactFacetImpl; +import org.gcube.informationsystem.model.entity.Facet; import org.gcube.informationsystem.model.entity.facet.ContactFacet; import org.gcube.informationsystem.resourceregistry.publisher.proxy.ResourceRegistryPublisher; import org.gcube.informationsystem.resourceregistry.publisher.proxy.ResourceRegistryPublisherFactory; +import org.junit.Before; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -20,13 +25,17 @@ public class ResourceRegistryPublisherTest { private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryPublisherTest.class); + + protected ResourceRegistryPublisher resourceRegistryPublisher; + + @Before + public void before(){ + ScopeProvider.instance.set("/gcube/devNext/NextNext"); + resourceRegistryPublisher = ResourceRegistryPublisherFactory.create(); + } + @Test public void testCreateFacet(){ - ScopeProvider.instance.set("/gcube/devNext/NextNext"); - - ResourceRegistryPublisher resourceRegistryPublisher = - ResourceRegistryPublisherFactory.create(); - ContactFacet contactFacet = new ContactFacetImpl(); contactFacet.setName("Luca"); contactFacet.setSurname("Frosini"); @@ -35,4 +44,12 @@ public class ResourceRegistryPublisherTest { ContactFacet created = resourceRegistryPublisher.createFacet(ContactFacet.class, contactFacet); logger.trace("Created {} is {}", ContactFacet.NAME, created); } + + @Test + public void testRemoveFacet(){ + Facet facet = new DummyFacet(UUID.fromString("03082640-289d-403e-8155-adc6b9276a04")); + boolean deleted = resourceRegistryPublisher.deleteFacet(facet); + logger.trace("{} with UUID {} deleted : {}", Facet.NAME, facet.getHeader().getUUID(), deleted); + } + }