Fixed exception management

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-publisher@144248 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-02-24 10:51:22 +00:00
parent d0290d6bd4
commit 68b96c5a6e
4 changed files with 90 additions and 24 deletions

View File

@ -16,31 +16,33 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resour
*/
public interface ResourceRegistryPublisher {
public <F extends Facet> F createFacet(Class<F> facetClass, F facet);
public <F extends Facet> F createFacet(Class<F> facetClass, F facet) throws ResourceRegistryException;
public <F extends Facet> F updateFacet(Class<F> facetClass, F facet);
public <F extends Facet> F updateFacet(Class<F> facetClass, F facet) throws ResourceRegistryException;
public <F extends Facet> boolean deleteFacet(F facet);
public <F extends Facet> boolean deleteFacet(F facet) throws ResourceRegistryException;
public <R extends Resource> R createResource(Class<R> resourceClass,
R resource);
R resource) throws ResourceRegistryException;
public <R extends Resource> R updateResource(Class<R> resourceClass, R resource);
public <R extends Resource> R updateResource(Class<R> resourceClass, R resource) throws ResourceRegistryException;
public <R extends Resource> boolean deleteResource(R resource);
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);
Class<C> consistsOfClass, C consistsOf) throws ResourceRegistryException;
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> boolean deleteConsistsOf(
C consistsOf);
C consistsOf) throws ResourceRegistryException;
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> I createIsRelatedTo(
Class<I> isRelatedToClass, I isRelatedTo);
Class<I> isRelatedToClass, I isRelatedTo) throws ResourceRegistryException;
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> boolean deleteIsRelatedTo(
I isRelatedTo);
I isRelatedTo) throws ResourceRegistryException;
public boolean addResourceToContext(UUID uuid)
throws ResourceNotFoundException, ContextNotFoundException,
ResourceRegistryException;

View File

@ -57,7 +57,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
@Override
public <F extends Facet> F createFacet(Class<F> facetClass, F facet) {
public <F extends Facet> F createFacet(Class<F> facetClass, F facet) throws ResourceRegistryException {
try {
logger.info("Going to create: {}", facet);
@ -80,6 +80,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
F f = delegate.make(call);
logger.info("{} successfully created", f);
return f;
} catch (ResourceRegistryException e) {
logger.error("Error Creating {}", facet, e);
throw e;
} catch (Exception e) {
logger.error("Error Creating {}", facet, e);
throw new ServiceException(e);
@ -87,7 +91,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
@Override
public <F extends Facet> F updateFacet(Class<F> facetClass, F facet) {
public <F extends Facet> F updateFacet(Class<F> facetClass, F facet) throws ResourceRegistryException {
try {
logger.info("Going to update: {}", facet);
StringWriter stringWriter = new StringWriter();
@ -108,6 +112,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
F f = delegate.make(call);
logger.info("{} successfully updated", f);
return f;
} catch (ResourceRegistryException e) {
logger.error("Error Updating {}", facet, e);
throw e;
} catch (Exception e) {
logger.error("Error Updating {}", facet, e);
throw new ServiceException(e);
@ -115,7 +123,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
@Override
public <F extends Facet> boolean deleteFacet(F facet) {
public <F extends Facet> boolean deleteFacet(F facet) throws ResourceRegistryException {
try {
logger.info("Going to delete: {}", facet);
StringWriter stringWriter = new StringWriter();
@ -136,6 +144,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
logger.info("{} {}", facet, deleted ? " successfully deleted"
: "was NOT deleted");
return deleted;
} catch (ResourceRegistryException e) {
logger.error("Error Removing {}", facet, e);
throw e;
} catch (Exception e) {
logger.error("Error Removing {}", facet, e);
throw new ServiceException(e);
@ -144,7 +156,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
@Override
public <R extends Resource> R createResource(Class<R> resourceClass,
R resource) {
R resource) throws ResourceRegistryException {
try {
logger.info("Going to create: {}", resource);
StringWriter stringWriter = new StringWriter();
@ -166,6 +178,11 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
R r = delegate.make(call);
logger.info("{} successfully created", r);
return r;
} catch (ResourceRegistryException e) {
logger.error("Error Creating {}", resource, e);
throw e;
} catch (Exception e) {
logger.error("Error Creating {}", resource, e);
throw new ServiceException(e);
@ -174,7 +191,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
@Override
public <R extends Resource> R updateResource(Class<R> resourceClass,
R resource) {
R resource) throws ResourceRegistryException {
try {
logger.info("Going to update: {}", resource);
StringWriter stringWriter = new StringWriter();
@ -196,6 +213,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
R r = delegate.make(call);
logger.info("{} update created", r);
return r;
} catch (ResourceRegistryException e) {
logger.error("Error Creating {}", resource, e);
throw e;
} catch (Exception e) {
logger.error("Error Creating {}", resource, e);
throw new ServiceException(e);
@ -203,7 +224,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
}
@Override
public <R extends Resource> boolean deleteResource(R resource) {
public <R extends Resource> boolean deleteResource(R resource) throws ResourceRegistryException {
try {
logger.info("Going to delete: {}", resource);
StringWriter stringWriter = new StringWriter();
@ -224,6 +245,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
logger.info("{} {}", resource, deleted ? " successfully deleted"
: "was NOT deleted");
return deleted;
} catch (ResourceRegistryException e) {
logger.error("Error Removing {}", resource, e);
throw e;
} catch (Exception e) {
logger.error("Error Removing {}", resource, e);
throw new ServiceException(e);
@ -232,7 +257,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
@Override
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> C createConsistsOf(
Class<C> consistsOfClass, C consistsOf) {
Class<C> consistsOfClass, C consistsOf) throws ResourceRegistryException {
try {
logger.info("Going to create: {}", consistsOf);
StringWriter stringWriter = new StringWriter();
@ -264,6 +289,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
C c = delegate.make(call);
logger.info("{} successfully created", c);
return c;
} catch (ResourceRegistryException e) {
logger.error("Error Creating {}", consistsOf, e);
throw e;
} catch (Exception e) {
logger.error("Error Creating {}", consistsOf, e);
throw new ServiceException(e);
@ -272,7 +301,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
@Override
public <C extends ConsistsOf<? extends Resource, ? extends Facet>> boolean deleteConsistsOf(
C consistsOf) {
C consistsOf) throws ResourceRegistryException {
try {
logger.info("Going to delete: {}", consistsOf);
StringWriter stringWriter = new StringWriter();
@ -293,6 +322,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
logger.info("{} {}", consistsOf, deleted ? " successfully deleted"
: "was NOT deleted");
return deleted;
} catch (ResourceRegistryException e) {
logger.error("Error Removing {}", consistsOf, e);
throw e;
} catch (Exception e) {
logger.error("Error Removing {}", consistsOf, e);
throw new ServiceException(e);
@ -301,7 +334,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
@Override
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> I createIsRelatedTo(
Class<I> isRelatedToClass, I isRelatedTo) {
Class<I> isRelatedToClass, I isRelatedTo) throws ResourceRegistryException {
try {
logger.info("Going to create: {}", isRelatedTo);
@ -334,6 +367,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
I i = delegate.make(call);
logger.info("{} successfully created", i);
return i;
} catch (ResourceRegistryException e) {
logger.error("Error Creating {}", isRelatedTo, e);
throw e;
} catch (Exception e) {
logger.error("Error Creating {}", isRelatedTo, e);
throw new ServiceException(e);
@ -342,7 +379,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
@Override
public <I extends IsRelatedTo<? extends Resource, ? extends Resource>> boolean deleteIsRelatedTo(
I isRelatedTo) {
I isRelatedTo) throws ResourceRegistryException {
try {
logger.info("Going to delete: {}", isRelatedTo);
StringWriter stringWriter = new StringWriter();
@ -363,6 +400,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
logger.info("{} {}", isRelatedTo, deleted ? " successfully deleted"
: "was NOT deleted");
return deleted;
} catch (ResourceRegistryException e) {
logger.error("Error Removing {}", isRelatedTo, e);
throw e;
} catch (Exception e) {
logger.error("Error Removing {}", isRelatedTo, e);
throw new ServiceException(e);
@ -399,6 +440,11 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
Resource.NAME, uuid, added ? "successfully" : "NOT",
Context.NAME, context);
return added;
} catch (ResourceRegistryException e) {
logger.error("Error Adding {} with UUID {} to current {} : {}",
Resource.NAME, uuid, Context.NAME, context, e);
throw e;
} catch (Exception e) {
logger.error("Error Adding {} with UUID {} to current {} : {}",
Resource.NAME, uuid, Context.NAME, context, e);
@ -442,6 +488,11 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
Facet.NAME, uuid, added ? "successfully" : "NOT",
Context.NAME, context);
return added;
} catch (ResourceRegistryException e) {
logger.error("Error Adding {} with UUID {} to current {} : {}",
Facet.NAME, uuid, Context.NAME, context, e);
throw e;
} catch (Exception e) {
logger.error("Error Adding {} with UUID {} to current {} : {}",
Facet.NAME, uuid, Context.NAME, context, e);
@ -487,6 +538,12 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
Resource.NAME, uuid, removed ? "successfully" : "NOT",
Context.NAME, context);
return removed;
} catch (ResourceRegistryException e) {
logger.error("Error Adding {} with UUID {} to current {} : {}",
Resource.NAME, uuid, Context.NAME, context, e);
throw e;
} catch (Exception e) {
logger.error("Error Adding {} with UUID {} to current {} : {}",
Resource.NAME, uuid, Context.NAME, context, e);
@ -531,6 +588,12 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
Facet.NAME, uuid, removed ? "successfully" : "NOT",
Context.NAME, context);
return removed;
} catch (ResourceRegistryException e) {
logger.error("Error Adding {} with UUID {} to current {} : {}",
Facet.NAME, uuid, Context.NAME, context, e);
throw e;
} catch (Exception e) {
logger.error("Error Adding {} with UUID {} to current {} : {}",
Facet.NAME, uuid, Context.NAME, context, e);

View File

@ -39,6 +39,7 @@ 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;
import org.gcube.informationsystem.resourceregistry.publisher.proxy.ResourceRegistryPublisher;
@ -152,13 +153,13 @@ public class MultiContextTest extends ScopedTest {
Assert.assertTrue(addedToContext);
UUID eServiceUUID = createEService.getHeader().getUUID();
try {
resourceRegistryClient.getInstance(EService.class, eServiceUUID);
}catch(ResourceRegistryException e){
}catch(ResourceNotFoundException e){
logger.debug("Resource with {} Not Found as Expected", uuid.toString());
}
boolean deleted = resourceRegistryPublisher.deleteResource(createdHN);
Assert.assertTrue(deleted);

View File

@ -59,8 +59,8 @@ public class ScopedTest {
GCUBE_DEVSEC = properties.getProperty(GCUBE_DEVSEC_VARNAME);
GCUBE_DEVSEC_DEVVRE = properties.getProperty(GCUBE_DEVSEC_DEVVRE_VARNAME);
DEFAULT_TEST_SCOPE = GCUBE_DEVNEXT;
ALTERNATIVE_TEST_SCOPE = GCUBE_DEVNEXT_NEXTNEXT;
DEFAULT_TEST_SCOPE = GCUBE_DEVSEC;
ALTERNATIVE_TEST_SCOPE = GCUBE_DEVSEC_DEVVRE;
}
public static String getCurrentScope(String token) throws ObjectNotFound, Exception{