Fixing specific exception management

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@147257 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-04-28 15:43:30 +00:00
parent faae4afaa7
commit a78e2dc505
4 changed files with 41 additions and 20 deletions

View File

@ -31,12 +31,16 @@ import org.gcube.informationsystem.model.relation.IsRelatedTo;
import org.gcube.informationsystem.model.relation.Relation;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAvailableInAnotherContextException;
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.ResourceAvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERAlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERAvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.RelationAlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.RelationAvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.RelationNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
@ -75,6 +79,8 @@ import com.tinkerpop.blueprints.impls.orient.OrientElement;
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
import com.tinkerpop.blueprints.util.StringFactory;
import ch.qos.logback.core.Context;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@ -341,36 +347,52 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
this.uuid = HeaderUtility.getHeader(element).getUUID();
}
protected ERNotFoundException getRightElementNotFoundException(ERNotFoundException e) {
protected ERNotFoundException getSpecificElementNotFoundException(ERNotFoundException e) {
switch (accessType) {
case RESOURCE:
return new ResourceNotFoundException(e);
return new ResourceNotFoundException(e.getMessage(), e.getCause());
case FACET:
return new FacetNotFoundException(e);
return new FacetNotFoundException(e.getMessage(), e.getCause());
case IS_RELATED_TO:
return new RelationNotFoundException(e);
return new RelationNotFoundException(e.getMessage(), e.getCause());
case CONSISTS_OF:
return new RelationNotFoundException(e);
return new RelationNotFoundException(e.getMessage(), e.getCause());
default:
return e;
}
}
protected ERAvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(){
protected ERAvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(String message){
switch (accessType) {
case RESOURCE:
return new ResourceAvailableInAnotherContextException("");
return new ResourceAvailableInAnotherContextException(message);
case FACET:
return new FacetAvailableInAnotherContextException("");
return new FacetAvailableInAnotherContextException(message);
case IS_RELATED_TO:
return new RelationAvailableInAnotherContextException("");
return new RelationAvailableInAnotherContextException(message);
case CONSISTS_OF:
return new RelationAvailableInAnotherContextException("");
return new RelationAvailableInAnotherContextException(message);
default:
return new ERAvailableInAnotherContextException("");
return new ERAvailableInAnotherContextException(message);
}
}
protected ERAlreadyPresentException getSpecificERAlreadyPresentException(String message){
switch (accessType) {
case RESOURCE:
return new ResourceAlreadyPresentException(message);
case FACET:
return new FacetAlreadyPresentException(message);
case IS_RELATED_TO:
return new RelationAlreadyPresentException(message);
case CONSISTS_OF:
return new RelationAlreadyPresentException(message);
default:
return new ERAlreadyPresentException(message);
}
}
public El getElement() throws ERNotFoundException, ERAvailableInAnotherContextException, ResourceRegistryException {
if (element == null) {
try {
@ -378,7 +400,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
}catch (ERNotFoundException e) {
try {
retrieveElementFromAnyContext();
throw getSpecificERAvailableInAnotherContextException();
throw getSpecificERAvailableInAnotherContextException(erType == null ? accessType.getName() : erType + " with UUID " + uuid + " is available in another " + Context.class.getSimpleName());
} catch (ERAvailableInAnotherContextException e1) {
throw e1;
}catch (Exception e1) {
@ -399,7 +421,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
return Utility.getElementByUUID(orientGraph,
erType == null ? accessType.getName() : erType, uuid, elementClass);
} catch (ERNotFoundException e) {
throw getRightElementNotFoundException(e);
throw getSpecificElementNotFoundException(e);
} catch (ResourceRegistryException e) {
throw e;
} catch (Exception e) {
@ -411,7 +433,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
try{
return Utility.getElementByUUIDAsAdmin(erType == null ? accessType.getName() : erType, uuid, elementClass);
}catch (ERNotFoundException e) {
throw getRightElementNotFoundException(e);
throw getSpecificElementNotFoundException(e);
} catch (ResourceRegistryException e) {
throw e;
} catch (Exception e) {

View File

@ -14,7 +14,6 @@ import org.gcube.informationsystem.model.relation.Relation;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.EntityAlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERAlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERAvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERNotFoundException;
import org.gcube.informationsystem.resourceregistry.context.ContextUtility;
@ -97,7 +96,7 @@ public abstract class EntityManagement<E extends Entity> extends
String error = String.format(
"UUID %s is already used by another %s. This is not allowed.",
uuid.toString(), (el instanceof Vertex) ? Entity.NAME : Relation.NAME);
throw new ERAlreadyPresentException(error);
throw getSpecificERAlreadyPresentException(error);
}catch (ERNotFoundException e1) {
// OK the UUID is not already used.

View File

@ -45,7 +45,7 @@ public class FacetManagement extends EntityManagement<Facet> {
}
@Override
public Vertex reallyUpdate() throws ResourceRegistryException {
public Vertex reallyUpdate() throws FacetNotFoundException, ResourceRegistryException {
Vertex facet = getElement();
facet = (Vertex) ERManagement.updateProperties(oClass, facet, jsonNode, ignoreKeys, ignoreStartWithKeys);
((OrientVertex) facet).save();

View File

@ -12,7 +12,7 @@ import org.gcube.informationsystem.model.entity.Resource;
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.entity.EntityAlreadyPresentException;
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.er.relation.ConsistsOfManagement;
import org.gcube.informationsystem.resourceregistry.er.relation.IsRelatedToManagement;
@ -130,7 +130,7 @@ public class ResourceManagement extends EntityManagement<Resource> {
}
@Override
public Vertex reallyCreate() throws EntityAlreadyPresentException,
public Vertex reallyCreate() throws ResourceAlreadyPresentException,
ResourceRegistryException {
createVertex();
@ -160,7 +160,7 @@ public class ResourceManagement extends EntityManagement<Resource> {
}
@Override
public Vertex reallyUpdate() throws ResourceRegistryException {
public Vertex reallyUpdate() throws ResourceNotFoundException, ResourceRegistryException {
getElement();