Fixing exception management

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-publisher@144257 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-02-24 11:46:18 +00:00
parent 68b96c5a6e
commit 098892dc7d
3 changed files with 60 additions and 30 deletions

View File

@ -8,7 +8,9 @@ import org.gcube.informationsystem.model.relation.ConsistsOf;
import org.gcube.informationsystem.model.relation.IsRelatedTo;
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;
/**
@ -16,31 +18,38 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resour
*/
public interface ResourceRegistryPublisher {
public <F extends Facet> F createFacet(Class<F> facetClass, F facet) throws ResourceRegistryException;
public <F extends Facet> F updateFacet(Class<F> facetClass, F facet) throws ResourceRegistryException;
public <F extends Facet> F createFacet(Class<F> facetClass, F facet) throws FacetAlreadyPresentException, ResourceRegistryException;
public <F extends Facet> F updateFacet(Class<F> facetClass, F facet) throws FacetNotFoundException, ResourceRegistryException;
public <F extends Facet> boolean deleteFacet(F facet) throws FacetNotFoundException, ResourceRegistryException;
public <F extends Facet> boolean deleteFacet(F facet) throws ResourceRegistryException;
public <R extends Resource> R createResource(Class<R> resourceClass,
R resource) throws ResourceRegistryException;
R resource) throws ResourceAlreadyPresentException, ResourceRegistryException;
public <R extends Resource> R updateResource(Class<R> resourceClass, R resource) throws ResourceRegistryException;
public <R extends Resource> R updateResource(Class<R> resourceClass, R resource) throws ResourceNotFoundException, ResourceRegistryException;
public <R extends Resource> boolean deleteResource(R resource) throws ResourceNotFoundException, ResourceRegistryException;
public <R extends Resource> boolean deleteResource(R resource) throws ResourceRegistryException;
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> C createConsistsOf(
Class<C> consistsOfClass, C consistsOf) throws ResourceRegistryException;
Class<C> consistsOfClass, C consistsOf) throws FacetNotFoundException, ResourceNotFoundException, ResourceRegistryException;
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> boolean deleteConsistsOf(
C consistsOf) throws ResourceRegistryException;
public boolean deleteConsistsOf(UUID uuid) throws ResourceRegistryException;
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> I createIsRelatedTo(
Class<I> isRelatedToClass, I isRelatedTo) throws ResourceRegistryException;
Class<I> isRelatedToClass, I isRelatedTo) throws ResourceNotFoundException, ResourceRegistryException;
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> boolean deleteIsRelatedTo(
I isRelatedTo) throws ResourceRegistryException;
public boolean deleteIsRelatedTo(UUID uuid) throws ResourceRegistryException;
public boolean addResourceToContext(UUID uuid)
@ -51,6 +60,7 @@ public interface ResourceRegistryPublisher {
throws ResourceNotFoundException, ContextNotFoundException,
ResourceRegistryException;
public boolean addFacetToContext(UUID uuid) throws FacetNotFoundException,
ContextNotFoundException, ResourceRegistryException;
@ -67,6 +77,7 @@ public interface ResourceRegistryPublisher {
throws ResourceNotFoundException, ContextNotFoundException,
ResourceRegistryException;
public boolean removeFacetFromContext(UUID uuid) throws FacetNotFoundException,
ContextNotFoundException, ResourceRegistryException;

View File

@ -20,7 +20,9 @@ import org.gcube.informationsystem.model.relation.ConsistsOf;
import org.gcube.informationsystem.model.relation.IsRelatedTo;
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.httputils.HTTPCall;
@ -57,7 +59,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
@Override
public <F extends Facet> F createFacet(Class<F> facetClass, F facet) throws ResourceRegistryException {
public <F extends Facet> F createFacet(Class<F> facetClass, F facet) throws FacetAlreadyPresentException, ResourceRegistryException {
try {
logger.info("Going to create: {}", facet);
@ -91,7 +93,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
@Override
public <F extends Facet> F updateFacet(Class<F> facetClass, F facet) throws ResourceRegistryException {
public <F extends Facet> F updateFacet(Class<F> facetClass, F facet) throws FacetNotFoundException, ResourceRegistryException {
try {
logger.info("Going to update: {}", facet);
StringWriter stringWriter = new StringWriter();
@ -123,7 +125,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
@Override
public <F extends Facet> boolean deleteFacet(F facet) throws ResourceRegistryException {
public <F extends Facet> boolean deleteFacet(F facet) throws FacetNotFoundException, ResourceRegistryException {
try {
logger.info("Going to delete: {}", facet);
StringWriter stringWriter = new StringWriter();
@ -154,9 +156,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
}
@Override
public <R extends Resource> R createResource(Class<R> resourceClass,
R resource) throws ResourceRegistryException {
R resource) throws ResourceAlreadyPresentException, ResourceRegistryException {
try {
logger.info("Going to create: {}", resource);
StringWriter stringWriter = new StringWriter();
@ -191,7 +194,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
@Override
public <R extends Resource> R updateResource(Class<R> resourceClass,
R resource) throws ResourceRegistryException {
R resource) throws ResourceNotFoundException, ResourceRegistryException {
try {
logger.info("Going to update: {}", resource);
StringWriter stringWriter = new StringWriter();
@ -224,7 +227,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
@Override
public <R extends Resource> boolean deleteResource(R resource) throws ResourceRegistryException {
public <R extends Resource> boolean deleteResource(R resource) throws ResourceNotFoundException, ResourceRegistryException {
try {
logger.info("Going to delete: {}", resource);
StringWriter stringWriter = new StringWriter();
@ -255,9 +258,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
}
@Override
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> C createConsistsOf(
Class<C> consistsOfClass, C consistsOf) throws ResourceRegistryException {
Class<C> consistsOfClass, C consistsOf) throws FacetNotFoundException, ResourceNotFoundException, ResourceRegistryException {
try {
logger.info("Going to create: {}", consistsOf);
StringWriter stringWriter = new StringWriter();
@ -302,15 +306,21 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
@Override
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> boolean deleteConsistsOf(
C consistsOf) throws ResourceRegistryException {
try {
logger.info("Going to delete: {}", consistsOf);
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(consistsOf.getHeader().getUUID().toString());
stringWriter.append(uuid.toString());
HTTPCall<Boolean> httpCall = new HTTPCall<>(stringWriter.toString(),
HTTPMETHOD.DELETE, null);
@ -319,22 +329,23 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
Boolean.class, httpCall);
boolean deleted = delegate.make(call);
logger.info("{} {}", consistsOf, deleted ? " successfully deleted"
logger.info("{} with UUID {} {}", ConsistsOf.NAME, uuid, deleted ? " successfully deleted"
: "was NOT deleted");
return deleted;
} catch (ResourceRegistryException e) {
logger.error("Error Removing {}", consistsOf, e);
logger.error("Error Removing {} with UUID {}", ConsistsOf.NAME, uuid, e);
throw e;
} catch (Exception e) {
logger.error("Error Removing {}", consistsOf, e);
logger.error("Error Removing {} with UUID {}", ConsistsOf.NAME, uuid, e);
throw new ServiceException(e);
}
}
@Override
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> I createIsRelatedTo(
Class<I> isRelatedToClass, I isRelatedTo) throws ResourceRegistryException {
Class<I> isRelatedToClass, I isRelatedTo) throws ResourceNotFoundException, ResourceRegistryException {
try {
logger.info("Going to create: {}", isRelatedTo);
@ -380,15 +391,20 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
@Override
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> boolean deleteIsRelatedTo(
I isRelatedTo) throws ResourceRegistryException {
return deleteIsRelatedTo(isRelatedTo.getHeader().getUUID());
}
@Override
public boolean deleteIsRelatedTo(UUID uuid) throws ResourceRegistryException {
try {
logger.info("Going to delete: {}", isRelatedTo);
logger.info("Going to delete {} with UUID {}", IsRelatedTo.NAME, uuid);
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(isRelatedTo.getHeader().getUUID().toString());
stringWriter.append(uuid.toString());
HTTPCall<Boolean> httpCall = new HTTPCall<>(stringWriter.toString(),
HTTPMETHOD.DELETE, null);
@ -397,19 +413,20 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
Boolean.class, httpCall);
boolean deleted = delegate.make(call);
logger.info("{} {}", isRelatedTo, deleted ? " successfully deleted"
logger.info("{} with UUID {} {}", IsRelatedTo.NAME, uuid, deleted ? " successfully deleted"
: "was NOT deleted");
return deleted;
} catch (ResourceRegistryException e) {
logger.error("Error Removing {}", isRelatedTo, e);
logger.error("Error Removing {} with UUID {}", IsRelatedTo.NAME, uuid, e);
throw e;
} catch (Exception e) {
logger.error("Error Removing {}", isRelatedTo, e);
logger.error("Error Removing {} with UUID {}", IsRelatedTo.NAME, uuid, e);
throw new ServiceException(e);
}
}
@Override
public boolean addResourceToContext(UUID uuid)
throws ResourceNotFoundException, ContextNotFoundException,
@ -459,6 +476,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
return addResourceToContext(resource.getHeader().getUUID());
}
@Override
public boolean addFacetToContext(UUID uuid) throws FacetNotFoundException,
ContextNotFoundException, ResourceRegistryException {
@ -507,7 +525,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
return addFacetToContext(facet.getHeader().getUUID());
}
/* -------------------------------------------------------------------- */
@Override
public boolean removeResourceFromContext(UUID uuid)
throws ResourceNotFoundException, ContextNotFoundException,
@ -558,6 +576,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
return removeResourceFromContext(resource.getHeader().getUUID());
}
@Override
public boolean removeFacetFromContext(UUID uuid)
throws FacetNotFoundException, ContextNotFoundException,
@ -608,4 +627,5 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
return removeFacetFromContext(facet.getHeader().getUUID());
}
}

View File

@ -38,7 +38,6 @@ import org.gcube.informationsystem.model.relation.IsIdentifiedBy;
import org.gcube.informationsystem.model.relation.consistsof.HasPersistentMemory;
import org.gcube.informationsystem.model.relation.consistsof.HasVolatileMemory;
import org.gcube.informationsystem.model.relation.isrelatedto.Hosts;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
import org.gcube.informationsystem.resourceregistry.client.proxy.ResourceRegistryClient;
import org.gcube.informationsystem.resourceregistry.client.proxy.ResourceRegistryClientFactory;