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:
parent
dfb18b9144
commit
c6fb345a3b
|
@ -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,
|
public String read() throws ERNotFoundException,
|
||||||
ResourceRegistryException {
|
ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -73,6 +73,12 @@ public abstract class EntityManagement<E extends Entity> extends
|
||||||
|
|
||||||
try {
|
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);
|
Vertex vertexEntity = orientGraph.addVertex("class:" + erType);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -164,7 +170,16 @@ public abstract class EntityManagement<E extends Entity> extends
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
public static EntityManagement getEntityManagement(OrientGraph orientGraph,
|
public static EntityManagement getEntityManagement(OrientGraph orientGraph,
|
||||||
Vertex vertex) throws ResourceRegistryException {
|
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;
|
EntityManagement entityManagement = null;
|
||||||
if (orientVertexType.isSubClassOf(Resource.NAME)) {
|
if (orientVertexType.isSubClassOf(Resource.NAME)) {
|
||||||
entityManagement = new ResourceManagement(orientGraph);
|
entityManagement = new ResourceManagement(orientGraph);
|
||||||
|
@ -221,8 +236,12 @@ public abstract class EntityManagement<E extends Entity> extends
|
||||||
for(Vertex vertex : iterable){
|
for(Vertex vertex : iterable){
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
EntityManagement entityManagement = getEntityManagement(orientGraph, vertex);
|
EntityManagement entityManagement = getEntityManagement(orientGraph, vertex);
|
||||||
JSONObject jsonObject = entityManagement.serializeAsJson();
|
try {
|
||||||
jsonArray.put(jsonObject);
|
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();
|
return jsonArray.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,9 +68,13 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
||||||
RelationManagement relationManagement = RelationManagement
|
RelationManagement relationManagement = RelationManagement
|
||||||
.getRelationManagement(orientGraph, edge);
|
.getRelationManagement(orientGraph, edge);
|
||||||
if (relationManagement instanceof ConsistsOfManagement) {
|
if (relationManagement instanceof ConsistsOfManagement) {
|
||||||
JSONObject consistsOf = relationManagement
|
try {
|
||||||
.serializeAsJson();
|
JSONObject consistsOf = relationManagement
|
||||||
sourceResource = addConsistsOf(sourceResource, consistsOf);
|
.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());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -12,7 +12,6 @@ import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.codehaus.jettison.json.JSONArray;
|
import org.codehaus.jettison.json.JSONArray;
|
||||||
import org.codehaus.jettison.json.JSONException;
|
|
||||||
import org.codehaus.jettison.json.JSONObject;
|
import org.codehaus.jettison.json.JSONObject;
|
||||||
import org.gcube.informationsystem.model.embedded.PropagationConstraint;
|
import org.gcube.informationsystem.model.embedded.PropagationConstraint;
|
||||||
import org.gcube.informationsystem.model.embedded.PropagationConstraint.AddConstraint;
|
import org.gcube.informationsystem.model.embedded.PropagationConstraint.AddConstraint;
|
||||||
|
@ -98,14 +97,13 @@ public abstract class RelationManagement<R extends Relation> extends
|
||||||
JSONObject relation = serializeSelfOnly();
|
JSONObject relation = serializeSelfOnly();
|
||||||
|
|
||||||
Vertex target = element.getVertex(Direction.IN);
|
Vertex target = element.getVertex(Direction.IN);
|
||||||
EntityManagement entityManagement = EntityManagement
|
|
||||||
.getEntityManagement(orientGraph, target);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
EntityManagement entityManagement = EntityManagement
|
||||||
|
.getEntityManagement(orientGraph, target);
|
||||||
relation.put(Relation.TARGET_PROPERTY,
|
relation.put(Relation.TARGET_PROPERTY,
|
||||||
entityManagement.serializeAsJson());
|
entityManagement.serializeAsJson());
|
||||||
} catch (JSONException e) {
|
} catch (Exception e) {
|
||||||
throw new ResourceRegistryException(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;
|
return relation;
|
||||||
|
|
Loading…
Reference in New Issue