Added embedded management for unknown property

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@146361 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-03-27 13:04:44 +00:00
parent 8f87923fee
commit 0ebbef1c55
6 changed files with 34 additions and 23 deletions

View File

@ -35,7 +35,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.RelationNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException;
import org.gcube.informationsystem.resourceregistry.context.ContextUtility;
import org.gcube.informationsystem.resourceregistry.context.SecurityContextMapper;
import org.gcube.informationsystem.resourceregistry.context.SecurityContextMapper.PermissionMode;
@ -85,6 +85,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
protected final Set<String> ignoreKeys;
protected final Set<String> ignoreStartWithKeys;
protected OClass oClass;
protected Class<ERType> erTypeClass;
protected String baseType;
@ -223,6 +224,10 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
checkJSON();
}
protected void getSchema() throws SchemaException {
oClass = SchemaManagementImpl.getTypeSchema(erType, baseType);
}
public void setElementType(String erType) throws ResourceRegistryException {
this.erType = erType;
if (erType == null || erType.compareTo("") == 0) {
@ -261,6 +266,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
if (this.erType == null) {
this.erType = getClassProperty(jsonNode);
getSchema();
} else {
checkERMatch();
}
@ -277,12 +283,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
throw new ResourceRegistryException(error);
}
}
try {
SchemaManagementImpl.getTypeSchema(erType, baseType);
} catch (SchemaNotFoundException e) {
throw e;
}
getSchema();
}
protected void checkUUIDMatch() throws ResourceRegistryException {
@ -309,7 +310,6 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
public JSONObject serializeSelfOnly() throws ResourceRegistryException {
try {
return toJSONObject();
//return Utility.toJsonObject((OrientElement) getElement(), false);
}catch(Exception e){
throw new ResourceRegistryException(e);
}
@ -648,7 +648,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
return map;
}
public static Element updateProperties(Element element, JsonNode jsonNode,
public static Element updateProperties(OClass oClass, Element element, JsonNode jsonNode,
Set<String> ignoreKeys, Set<String> ignoreStartWithKeys)
throws ResourceRegistryException {
@ -672,7 +672,15 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
for (String key : properties.keySet()) {
try {
element.setProperty(key, properties.get(key));
Object object = properties.get(key);
if(!oClass.existsProperty(key) && object instanceof ODocument){
ODocument oDocument = (ODocument) object;
((OrientElement) element).setProperty(key, oDocument, OType.EMBEDDED);
} else{
element.setProperty(key, object);
}
} catch (Exception e) {
String error = String.format(
"Error while setting property %s : %s", key, properties

View File

@ -72,6 +72,8 @@ public class EmbeddedMangement {
return oDocument.fromJSON(jsonNode.toString());
}
return null;
ODocument oDocument = new ODocument();
return oDocument.fromJSON(jsonNode.toString());
}
}

View File

@ -103,7 +103,7 @@ public abstract class EntityManagement<E extends Entity> extends
if (Resource.class.isAssignableFrom(erTypeClass)) {
// Facet and relation are created in calling method
} else {
ERManagement.updateProperties(element, jsonNode, ignoreKeys,
ERManagement.updateProperties(oClass, element, jsonNode, ignoreKeys,
ignoreStartWithKeys);
}

View File

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

View File

@ -220,7 +220,7 @@ public abstract class RelationManagement<R extends Relation> extends
element = orientGraph.addEdge(null, source, target, erType);
ERManagement.updateProperties(element, jsonNode, ignoreKeys,
ERManagement.updateProperties(oClass, element, jsonNode, ignoreKeys,
ignoreStartWithKeys);
HeaderUtility.addHeader(element, null);
@ -263,7 +263,7 @@ public abstract class RelationManagement<R extends Relation> extends
logger.debug("Trying to update {} : {}", erType, jsonNode);
Edge edge = getElement();
ERManagement.updateProperties(edge, jsonNode, ignoreKeys,
ERManagement.updateProperties(oClass, edge, jsonNode, ignoreKeys,
ignoreStartWithKeys);
if (ConsistsOf.class.isAssignableFrom(erTypeClass)) {

View File

@ -194,7 +194,7 @@ public class ContextManagementImplTest {
logger.debug("The DB should be now clean");
}
//@Test
// @Test
public void createDevContext() throws Exception {
String gcubeJson = contextManagementImpl.create(null, "gcube");
Context gcubeContext = ISMapper.unmarshal(Context.class, gcubeJson);
@ -235,15 +235,16 @@ public class ContextManagementImplTest {
// logger.debug("The DB should be now clean");
}
// @Test
//@Test
public void removeContext() throws Exception {
/*
* contextManagementImpl.delete(UUID .fromString(""));
* contextManagementImpl.delete(UUID .fromString(""));
* contextManagementImpl.delete(UUID .fromString(""));
* contextManagementImpl.delete(UUID .fromString(""));
* contextManagementImpl.delete(UUID .fromString(""));
contextManagementImpl.delete(UUID .fromString(""));
contextManagementImpl.delete(UUID .fromString(""));
contextManagementImpl.delete(UUID .fromString(""));
contextManagementImpl.delete(UUID .fromString(""));
contextManagementImpl.delete(UUID .fromString(""));
*/
}
@Test