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:
parent
8f87923fee
commit
0ebbef1c55
|
@ -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.entity.resource.ResourceNotFoundException;
|
||||||
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.RelationNotFoundException;
|
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.ContextUtility;
|
||||||
import org.gcube.informationsystem.resourceregistry.context.SecurityContextMapper;
|
import org.gcube.informationsystem.resourceregistry.context.SecurityContextMapper;
|
||||||
import org.gcube.informationsystem.resourceregistry.context.SecurityContextMapper.PermissionMode;
|
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> ignoreKeys;
|
||||||
protected final Set<String> ignoreStartWithKeys;
|
protected final Set<String> ignoreStartWithKeys;
|
||||||
|
|
||||||
|
protected OClass oClass;
|
||||||
protected Class<ERType> erTypeClass;
|
protected Class<ERType> erTypeClass;
|
||||||
protected String baseType;
|
protected String baseType;
|
||||||
|
|
||||||
|
@ -223,6 +224,10 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
||||||
checkJSON();
|
checkJSON();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void getSchema() throws SchemaException {
|
||||||
|
oClass = SchemaManagementImpl.getTypeSchema(erType, baseType);
|
||||||
|
}
|
||||||
|
|
||||||
public void setElementType(String erType) throws ResourceRegistryException {
|
public void setElementType(String erType) throws ResourceRegistryException {
|
||||||
this.erType = erType;
|
this.erType = erType;
|
||||||
if (erType == null || erType.compareTo("") == 0) {
|
if (erType == null || erType.compareTo("") == 0) {
|
||||||
|
@ -261,6 +266,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
||||||
|
|
||||||
if (this.erType == null) {
|
if (this.erType == null) {
|
||||||
this.erType = getClassProperty(jsonNode);
|
this.erType = getClassProperty(jsonNode);
|
||||||
|
getSchema();
|
||||||
} else {
|
} else {
|
||||||
checkERMatch();
|
checkERMatch();
|
||||||
}
|
}
|
||||||
|
@ -277,12 +283,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
||||||
throw new ResourceRegistryException(error);
|
throw new ResourceRegistryException(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
getSchema();
|
||||||
try {
|
|
||||||
SchemaManagementImpl.getTypeSchema(erType, baseType);
|
|
||||||
} catch (SchemaNotFoundException e) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void checkUUIDMatch() throws ResourceRegistryException {
|
protected void checkUUIDMatch() throws ResourceRegistryException {
|
||||||
|
@ -309,7 +310,6 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
||||||
public JSONObject serializeSelfOnly() throws ResourceRegistryException {
|
public JSONObject serializeSelfOnly() throws ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
return toJSONObject();
|
return toJSONObject();
|
||||||
//return Utility.toJsonObject((OrientElement) getElement(), false);
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
throw new ResourceRegistryException(e);
|
throw new ResourceRegistryException(e);
|
||||||
}
|
}
|
||||||
|
@ -648,7 +648,7 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
||||||
return map;
|
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)
|
Set<String> ignoreKeys, Set<String> ignoreStartWithKeys)
|
||||||
throws ResourceRegistryException {
|
throws ResourceRegistryException {
|
||||||
|
|
||||||
|
@ -672,7 +672,15 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
||||||
|
|
||||||
for (String key : properties.keySet()) {
|
for (String key : properties.keySet()) {
|
||||||
try {
|
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) {
|
} catch (Exception e) {
|
||||||
String error = String.format(
|
String error = String.format(
|
||||||
"Error while setting property %s : %s", key, properties
|
"Error while setting property %s : %s", key, properties
|
||||||
|
|
|
@ -72,6 +72,8 @@ public class EmbeddedMangement {
|
||||||
return oDocument.fromJSON(jsonNode.toString());
|
return oDocument.fromJSON(jsonNode.toString());
|
||||||
|
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
|
ODocument oDocument = new ODocument();
|
||||||
|
return oDocument.fromJSON(jsonNode.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,7 +103,7 @@ public abstract class EntityManagement<E extends Entity> extends
|
||||||
if (Resource.class.isAssignableFrom(erTypeClass)) {
|
if (Resource.class.isAssignableFrom(erTypeClass)) {
|
||||||
// Facet and relation are created in calling method
|
// Facet and relation are created in calling method
|
||||||
} else {
|
} else {
|
||||||
ERManagement.updateProperties(element, jsonNode, ignoreKeys,
|
ERManagement.updateProperties(oClass, element, jsonNode, ignoreKeys,
|
||||||
ignoreStartWithKeys);
|
ignoreStartWithKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class FacetManagement extends EntityManagement<Facet> {
|
||||||
@Override
|
@Override
|
||||||
public Vertex reallyUpdate() throws ResourceRegistryException {
|
public Vertex reallyUpdate() throws ResourceRegistryException {
|
||||||
Vertex facet = getElement();
|
Vertex facet = getElement();
|
||||||
facet = (Vertex) ERManagement.updateProperties(facet, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
facet = (Vertex) ERManagement.updateProperties(oClass, facet, jsonNode, ignoreKeys, ignoreStartWithKeys);
|
||||||
((OrientVertex) facet).save();
|
((OrientVertex) facet).save();
|
||||||
return facet;
|
return facet;
|
||||||
}
|
}
|
||||||
|
|
|
@ -220,7 +220,7 @@ public abstract class RelationManagement<R extends Relation> extends
|
||||||
|
|
||||||
element = orientGraph.addEdge(null, source, target, erType);
|
element = orientGraph.addEdge(null, source, target, erType);
|
||||||
|
|
||||||
ERManagement.updateProperties(element, jsonNode, ignoreKeys,
|
ERManagement.updateProperties(oClass, element, jsonNode, ignoreKeys,
|
||||||
ignoreStartWithKeys);
|
ignoreStartWithKeys);
|
||||||
|
|
||||||
HeaderUtility.addHeader(element, null);
|
HeaderUtility.addHeader(element, null);
|
||||||
|
@ -263,7 +263,7 @@ public abstract class RelationManagement<R extends Relation> extends
|
||||||
logger.debug("Trying to update {} : {}", erType, jsonNode);
|
logger.debug("Trying to update {} : {}", erType, jsonNode);
|
||||||
|
|
||||||
Edge edge = getElement();
|
Edge edge = getElement();
|
||||||
ERManagement.updateProperties(edge, jsonNode, ignoreKeys,
|
ERManagement.updateProperties(oClass, edge, jsonNode, ignoreKeys,
|
||||||
ignoreStartWithKeys);
|
ignoreStartWithKeys);
|
||||||
|
|
||||||
if (ConsistsOf.class.isAssignableFrom(erTypeClass)) {
|
if (ConsistsOf.class.isAssignableFrom(erTypeClass)) {
|
||||||
|
|
|
@ -238,12 +238,13 @@ public class ContextManagementImplTest {
|
||||||
//@Test
|
//@Test
|
||||||
public void removeContext() throws Exception {
|
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
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue