Fixing header
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@134422 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
3a0541a8b4
commit
f7784bfb39
|
@ -36,15 +36,12 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.Schema
|
||||||
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;
|
||||||
import org.gcube.informationsystem.resourceregistry.resources.utils.ContextUtility;
|
import org.gcube.informationsystem.resourceregistry.resources.utils.ContextUtility;
|
||||||
import org.gcube.informationsystem.resourceregistry.resources.utils.HeaderOrient;
|
|
||||||
import org.gcube.informationsystem.resourceregistry.resources.utils.HeaderUtility;
|
import org.gcube.informationsystem.resourceregistry.resources.utils.HeaderUtility;
|
||||||
import org.gcube.informationsystem.resourceregistry.resources.utils.Utility;
|
import org.gcube.informationsystem.resourceregistry.resources.utils.Utility;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonParseException;
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.node.JsonNodeType;
|
import com.fasterxml.jackson.databind.node.JsonNodeType;
|
||||||
|
@ -126,24 +123,6 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Header getHeader(JsonNode jsonNode)
|
|
||||||
throws JsonParseException, JsonMappingException, IOException {
|
|
||||||
if (jsonNode.has(Resource.HEADER_PROPERTY)) {
|
|
||||||
JsonNode headerNode = jsonNode.get(Resource.HEADER_PROPERTY);
|
|
||||||
if (headerNode.isNull()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* ObjectMapper mapper = new ObjectMapper(); Header header =
|
|
||||||
* mapper.readValue(headerNode.toString(), Header.class);
|
|
||||||
*/
|
|
||||||
HeaderOrient headerOrient = new HeaderOrient();
|
|
||||||
headerOrient.fromJSON(headerNode.toString());
|
|
||||||
return headerOrient;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ODocument getEmbeddedType(JsonNode jsonNode)
|
private static ODocument getEmbeddedType(JsonNode jsonNode)
|
||||||
throws ResourceRegistryException {
|
throws ResourceRegistryException {
|
||||||
if (jsonNode.has(Entities.CLASS_PROPERTY)) {
|
if (jsonNode.has(Entities.CLASS_PROPERTY)) {
|
||||||
|
@ -159,7 +138,7 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
|
|
||||||
Header header = null;
|
Header header = null;
|
||||||
try {
|
try {
|
||||||
header = getHeader(jsonNode);
|
header = HeaderUtility.getHeader(jsonNode, false);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.warn("An invalid Header has been provided. An embedded object cannot have an Header. It will be ignored.");
|
logger.warn("An invalid Header has been provided. An embedded object cannot have an Header. It will be ignored.");
|
||||||
throw new ResourceRegistryException(
|
throw new ResourceRegistryException(
|
||||||
|
@ -292,7 +271,7 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
|
|
||||||
Header targetHeader = null;
|
Header targetHeader = null;
|
||||||
try {
|
try {
|
||||||
targetHeader = getHeader(target);
|
targetHeader = HeaderUtility.getHeader(target, false);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ResourceRegistryException(e);
|
throw new ResourceRegistryException(e);
|
||||||
}
|
}
|
||||||
|
@ -401,7 +380,7 @@ public class EntityManagementImpl implements EntityManagement {
|
||||||
|
|
||||||
OrientVertex vertex = orientGraph.addVertex("class:" + entityType);
|
OrientVertex vertex = orientGraph.addVertex("class:" + entityType);
|
||||||
|
|
||||||
Header entityHeader = getHeader(jsonNode);
|
Header entityHeader = HeaderUtility.getHeader(jsonNode, true);
|
||||||
if (entityHeader != null) {
|
if (entityHeader != null) {
|
||||||
vertex.setProperty(Entity.HEADER_PROPERTY, entityHeader);
|
vertex.setProperty(Entity.HEADER_PROPERTY, entityHeader);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
*/
|
*/
|
||||||
package org.gcube.informationsystem.resourceregistry.resources.utils;
|
package org.gcube.informationsystem.resourceregistry.resources.utils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -13,9 +14,13 @@ import org.gcube.common.authorization.library.provider.ClientInfo;
|
||||||
import org.gcube.common.authorization.library.utils.Caller;
|
import org.gcube.common.authorization.library.utils.Caller;
|
||||||
import org.gcube.informationsystem.model.embedded.Header;
|
import org.gcube.informationsystem.model.embedded.Header;
|
||||||
import org.gcube.informationsystem.model.entity.Entity;
|
import org.gcube.informationsystem.model.entity.Entity;
|
||||||
|
import org.gcube.informationsystem.model.entity.Resource;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonParseException;
|
||||||
|
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.tinkerpop.blueprints.Edge;
|
import com.tinkerpop.blueprints.Edge;
|
||||||
import com.tinkerpop.blueprints.Vertex;
|
import com.tinkerpop.blueprints.Vertex;
|
||||||
|
|
||||||
|
@ -64,6 +69,25 @@ public class HeaderUtility {
|
||||||
return header;
|
return header;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Header getHeader(JsonNode jsonNode, boolean creation)
|
||||||
|
throws JsonParseException, JsonMappingException, IOException {
|
||||||
|
if (jsonNode.has(Resource.HEADER_PROPERTY)) {
|
||||||
|
JsonNode headerNode = jsonNode.get(Resource.HEADER_PROPERTY);
|
||||||
|
if (headerNode.isNull()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
HeaderOrient header = null;
|
||||||
|
if(creation){
|
||||||
|
UUID uuid = UUID.fromString(headerNode.get(Header.UUID_PROPERTY).asText());
|
||||||
|
header = (HeaderOrient) createHeader(uuid);
|
||||||
|
}else{
|
||||||
|
header = new HeaderOrient();
|
||||||
|
header.fromJSON(headerNode.toString());
|
||||||
|
}
|
||||||
|
return header;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static Header addHeader(Vertex vertex, UUID uuid) {
|
public static Header addHeader(Vertex vertex, UUID uuid) {
|
||||||
Header header = createHeader(uuid);
|
Header header = createHeader(uuid);
|
||||||
|
|
Loading…
Reference in New Issue