implementing Publisher

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-publisher@131382 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2016-09-15 12:57:14 +00:00
parent 7440fd98ef
commit fc70aaffa6
3 changed files with 155 additions and 25 deletions

View File

@ -11,12 +11,12 @@ public interface ResourceRegistryPublisher {
public <F extends Facet> F updateFacet(F facet);
public <F extends Facet> F deleteFacet(F facet);
public <F extends Facet> boolean deleteFacet(F facet);
public <R extends Resource> R createResource(Class<R> resourceClass, R resource);
public <R extends Resource> R deleteResource(R resource);
public <R extends Resource> boolean deleteResource(R resource);
@ -24,14 +24,14 @@ public interface ResourceRegistryPublisher {
public <C extends ConsistsOf<Resource, Facet>> C updateConsistsOf(C consistsOf);
public <C extends ConsistsOf<Resource, Facet>> C deleteConsistsOf(C consistsOf);
public <C extends ConsistsOf<Resource, Facet>> boolean deleteConsistsOf(C consistsOf);
public <I extends IsRelatedTo<Resource, Resource>> I create(Class<I> isRelatedToClass, I isRelatedTo);
public <I extends IsRelatedTo<Resource, Resource>> I update(I isRelatedTo);
public <I extends IsRelatedTo<Resource, Resource>> I delete(I isRelatedTo);
public <I extends IsRelatedTo<Resource, Resource>> boolean delete(I isRelatedTo);
}

View File

@ -148,9 +148,23 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
@Override
public <F extends Facet> F deleteFacet(F facet) {
// TODO Auto-generated method stub
return null;
public <F extends Facet> 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<Boolean> 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 extends Resource> R deleteResource(R resource) {
// TODO Auto-generated method stub
return null;
public <R extends Resource> 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<Boolean> 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 extends ConsistsOf<Resource, Facet>> C createConsistsOf(
Class<C> 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<C> 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 extends ConsistsOf<Resource, Facet>> C deleteConsistsOf(
public <C extends ConsistsOf<Resource, Facet>> 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<Boolean> 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 extends IsRelatedTo<Resource, Resource>> I create(
Class<I> 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<I> 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 extends IsRelatedTo<Resource, Resource>> I delete(I isRelatedTo) {
// TODO Auto-generated method stub
return null;
public <I extends IsRelatedTo<Resource, Resource>> 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<Boolean> call = new ResourceRegistryCall<>(
Boolean.class, stringWriter, "DELETE");
return delegate.make(call);
} catch (Exception e) {
logger.error("Error Removing {}", isRelatedTo, e);
throw new ServiceException(e);
}
}
}

View File

@ -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);
}
}