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:
parent
faae4afaa7
commit
a78e2dc505
|
@ -31,12 +31,16 @@ import org.gcube.informationsystem.model.relation.IsRelatedTo;
|
||||||
import org.gcube.informationsystem.model.relation.Relation;
|
import org.gcube.informationsystem.model.relation.Relation;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
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.FacetAvailableInAnotherContextException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException;
|
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.ResourceAvailableInAnotherContextException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
|
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.ERAvailableInAnotherContextException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERNotFoundException;
|
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.RelationAvailableInAnotherContextException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.RelationNotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.RelationNotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
|
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.impls.orient.OrientGraph;
|
||||||
import com.tinkerpop.blueprints.util.StringFactory;
|
import com.tinkerpop.blueprints.util.StringFactory;
|
||||||
|
|
||||||
|
import ch.qos.logback.core.Context;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @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();
|
this.uuid = HeaderUtility.getHeader(element).getUUID();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ERNotFoundException getRightElementNotFoundException(ERNotFoundException e) {
|
protected ERNotFoundException getSpecificElementNotFoundException(ERNotFoundException e) {
|
||||||
switch (accessType) {
|
switch (accessType) {
|
||||||
case RESOURCE:
|
case RESOURCE:
|
||||||
return new ResourceNotFoundException(e);
|
return new ResourceNotFoundException(e.getMessage(), e.getCause());
|
||||||
case FACET:
|
case FACET:
|
||||||
return new FacetNotFoundException(e);
|
return new FacetNotFoundException(e.getMessage(), e.getCause());
|
||||||
case IS_RELATED_TO:
|
case IS_RELATED_TO:
|
||||||
return new RelationNotFoundException(e);
|
return new RelationNotFoundException(e.getMessage(), e.getCause());
|
||||||
case CONSISTS_OF:
|
case CONSISTS_OF:
|
||||||
return new RelationNotFoundException(e);
|
return new RelationNotFoundException(e.getMessage(), e.getCause());
|
||||||
default:
|
default:
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ERAvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(){
|
protected ERAvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(String message){
|
||||||
switch (accessType) {
|
switch (accessType) {
|
||||||
case RESOURCE:
|
case RESOURCE:
|
||||||
return new ResourceAvailableInAnotherContextException("");
|
return new ResourceAvailableInAnotherContextException(message);
|
||||||
case FACET:
|
case FACET:
|
||||||
return new FacetAvailableInAnotherContextException("");
|
return new FacetAvailableInAnotherContextException(message);
|
||||||
case IS_RELATED_TO:
|
case IS_RELATED_TO:
|
||||||
return new RelationAvailableInAnotherContextException("");
|
return new RelationAvailableInAnotherContextException(message);
|
||||||
case CONSISTS_OF:
|
case CONSISTS_OF:
|
||||||
return new RelationAvailableInAnotherContextException("");
|
return new RelationAvailableInAnotherContextException(message);
|
||||||
default:
|
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 {
|
public El getElement() throws ERNotFoundException, ERAvailableInAnotherContextException, ResourceRegistryException {
|
||||||
if (element == null) {
|
if (element == null) {
|
||||||
try {
|
try {
|
||||||
|
@ -378,7 +400,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
||||||
}catch (ERNotFoundException e) {
|
}catch (ERNotFoundException e) {
|
||||||
try {
|
try {
|
||||||
retrieveElementFromAnyContext();
|
retrieveElementFromAnyContext();
|
||||||
throw getSpecificERAvailableInAnotherContextException();
|
throw getSpecificERAvailableInAnotherContextException(erType == null ? accessType.getName() : erType + " with UUID " + uuid + " is available in another " + Context.class.getSimpleName());
|
||||||
} catch (ERAvailableInAnotherContextException e1) {
|
} catch (ERAvailableInAnotherContextException e1) {
|
||||||
throw e1;
|
throw e1;
|
||||||
}catch (Exception e1) {
|
}catch (Exception e1) {
|
||||||
|
@ -399,7 +421,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
||||||
return Utility.getElementByUUID(orientGraph,
|
return Utility.getElementByUUID(orientGraph,
|
||||||
erType == null ? accessType.getName() : erType, uuid, elementClass);
|
erType == null ? accessType.getName() : erType, uuid, elementClass);
|
||||||
} catch (ERNotFoundException e) {
|
} catch (ERNotFoundException e) {
|
||||||
throw getRightElementNotFoundException(e);
|
throw getSpecificElementNotFoundException(e);
|
||||||
} catch (ResourceRegistryException e) {
|
} catch (ResourceRegistryException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -411,7 +433,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
||||||
try{
|
try{
|
||||||
return Utility.getElementByUUIDAsAdmin(erType == null ? accessType.getName() : erType, uuid, elementClass);
|
return Utility.getElementByUUIDAsAdmin(erType == null ? accessType.getName() : erType, uuid, elementClass);
|
||||||
}catch (ERNotFoundException e) {
|
}catch (ERNotFoundException e) {
|
||||||
throw getRightElementNotFoundException(e);
|
throw getSpecificElementNotFoundException(e);
|
||||||
} catch (ResourceRegistryException e) {
|
} catch (ResourceRegistryException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -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.ResourceRegistryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
|
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.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.ERAvailableInAnotherContextException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERNotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERNotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.context.ContextUtility;
|
import org.gcube.informationsystem.resourceregistry.context.ContextUtility;
|
||||||
|
@ -97,7 +96,7 @@ public abstract class EntityManagement<E extends Entity> extends
|
||||||
String error = String.format(
|
String error = String.format(
|
||||||
"UUID %s is already used by another %s. This is not allowed.",
|
"UUID %s is already used by another %s. This is not allowed.",
|
||||||
uuid.toString(), (el instanceof Vertex) ? Entity.NAME : Relation.NAME);
|
uuid.toString(), (el instanceof Vertex) ? Entity.NAME : Relation.NAME);
|
||||||
throw new ERAlreadyPresentException(error);
|
throw getSpecificERAlreadyPresentException(error);
|
||||||
|
|
||||||
}catch (ERNotFoundException e1) {
|
}catch (ERNotFoundException e1) {
|
||||||
// OK the UUID is not already used.
|
// OK the UUID is not already used.
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class FacetManagement extends EntityManagement<Facet> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Vertex reallyUpdate() throws ResourceRegistryException {
|
public Vertex reallyUpdate() throws FacetNotFoundException, ResourceRegistryException {
|
||||||
Vertex facet = getElement();
|
Vertex facet = getElement();
|
||||||
facet = (Vertex) ERManagement.updateProperties(oClass, facet, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
facet = (Vertex) ERManagement.updateProperties(oClass, facet, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
||||||
((OrientVertex) facet).save();
|
((OrientVertex) facet).save();
|
||||||
|
|
|
@ -12,7 +12,7 @@ import org.gcube.informationsystem.model.entity.Resource;
|
||||||
import org.gcube.informationsystem.model.relation.ConsistsOf;
|
import org.gcube.informationsystem.model.relation.ConsistsOf;
|
||||||
import org.gcube.informationsystem.model.relation.IsRelatedTo;
|
import org.gcube.informationsystem.model.relation.IsRelatedTo;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
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.api.exceptions.entity.resource.ResourceNotFoundException;
|
||||||
import org.gcube.informationsystem.resourceregistry.er.relation.ConsistsOfManagement;
|
import org.gcube.informationsystem.resourceregistry.er.relation.ConsistsOfManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.er.relation.IsRelatedToManagement;
|
import org.gcube.informationsystem.resourceregistry.er.relation.IsRelatedToManagement;
|
||||||
|
@ -130,7 +130,7 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Vertex reallyCreate() throws EntityAlreadyPresentException,
|
public Vertex reallyCreate() throws ResourceAlreadyPresentException,
|
||||||
ResourceRegistryException {
|
ResourceRegistryException {
|
||||||
|
|
||||||
createVertex();
|
createVertex();
|
||||||
|
@ -160,7 +160,7 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Vertex reallyUpdate() throws ResourceRegistryException {
|
public Vertex reallyUpdate() throws ResourceNotFoundException, ResourceRegistryException {
|
||||||
|
|
||||||
getElement();
|
getElement();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue