Denied Creation of Abstract Type.

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@146398 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-03-28 14:02:23 +00:00
parent dfb18b9144
commit c6fb345a3b
4 changed files with 56 additions and 12 deletions

View File

@ -388,6 +388,29 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
}
}
public boolean exists() throws ERNotFoundException, ResourceRegistryException {
try {
orientGraph = ContextUtility.getActualSecurityContextGraph(PermissionMode.READER);
getElement();
if(element==null){
return false;
}else{
return true;
}
} catch (ResourceRegistryException e) {
throw e;
} catch (Exception e) {
throw new ResourceRegistryException(e);
} finally {
if (orientGraph != null) {
orientGraph.shutdown();
}
}
}
public String read() throws ERNotFoundException,
ResourceRegistryException {
try {

View File

@ -73,6 +73,12 @@ public abstract class EntityManagement<E extends Entity> extends
try {
if(oClass.isAbstract()){
String error = String.format("Trying to create an instance of %s of type %s which is abstract. The operation will be aborted.",
baseType, erType);
throw new ResourceRegistryException(error);
}
Vertex vertexEntity = orientGraph.addVertex("class:" + erType);
try {
@ -164,7 +170,16 @@ public abstract class EntityManagement<E extends Entity> extends
@SuppressWarnings({ "rawtypes", "unchecked" })
public static EntityManagement getEntityManagement(OrientGraph orientGraph,
Vertex vertex) throws ResourceRegistryException {
OrientVertexType orientVertexType = ((OrientVertex) vertex).getType();
OrientVertexType orientVertexType = null;
try {
orientVertexType = ((OrientVertex) vertex).getType();
}catch (Exception e) {
String error = String.format("Unable to detect type of %s. This is really strage please contact the administrator", vertex.toString());
logger.error(error, e);
throw new ResourceRegistryException(error);
}
EntityManagement entityManagement = null;
if (orientVertexType.isSubClassOf(Resource.NAME)) {
entityManagement = new ResourceManagement(orientGraph);
@ -221,8 +236,12 @@ public abstract class EntityManagement<E extends Entity> extends
for(Vertex vertex : iterable){
@SuppressWarnings("rawtypes")
EntityManagement entityManagement = getEntityManagement(orientGraph, vertex);
try {
JSONObject jsonObject = entityManagement.serializeAsJson();
jsonArray.put(jsonObject);
}catch (ResourceRegistryException e) {
logger.error("Unable to correctly serialize {}. It will be excluded from results. This is really strange and should not occur.", vertex.toString());
}
}
return jsonArray.toString();
}

View File

@ -68,9 +68,13 @@ public class ResourceManagement extends EntityManagement<Resource> {
RelationManagement relationManagement = RelationManagement
.getRelationManagement(orientGraph, edge);
if (relationManagement instanceof ConsistsOfManagement) {
try {
JSONObject consistsOf = relationManagement
.serializeAsJson();
sourceResource = addConsistsOf(sourceResource, consistsOf);
}catch (ResourceRegistryException e) {
logger.error("Unable to correctly serialize {}. It will be excluded from results. This is really strange and should not occur.", edge.toString());
}
}
/*

View File

@ -12,7 +12,6 @@ import java.util.Map;
import java.util.UUID;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.gcube.informationsystem.model.embedded.PropagationConstraint;
import org.gcube.informationsystem.model.embedded.PropagationConstraint.AddConstraint;
@ -98,14 +97,13 @@ public abstract class RelationManagement<R extends Relation> extends
JSONObject relation = serializeSelfOnly();
Vertex target = element.getVertex(Direction.IN);
try {
EntityManagement entityManagement = EntityManagement
.getEntityManagement(orientGraph, target);
try {
relation.put(Relation.TARGET_PROPERTY,
entityManagement.serializeAsJson());
} catch (JSONException e) {
throw new ResourceRegistryException(e);
} catch (Exception e) {
logger.error("Unable to correctly serialize {}. It will be excluded from results. This is really strange and should not occur.", target.toString());
}
return relation;