Fixed Resource Creation

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@131301 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2016-09-12 15:16:08 +00:00
parent 9343645236
commit 780ac9215d
2 changed files with 68 additions and 11 deletions

View File

@ -15,10 +15,10 @@ import java.util.Set;
import org.gcube.informationsystem.impl.utils.Entities;
import org.gcube.informationsystem.model.embedded.Embedded;
import org.gcube.informationsystem.model.embedded.Header;
import org.gcube.informationsystem.model.entity.Entity;
import org.gcube.informationsystem.model.entity.Facet;
import org.gcube.informationsystem.model.entity.Resource;
import org.gcube.informationsystem.model.orientdb.impl.embedded.Header;
import org.gcube.informationsystem.model.relation.ConsistsOf;
import org.gcube.informationsystem.model.relation.IsRelatedTo;
import org.gcube.informationsystem.model.relation.Relation;
@ -148,7 +148,7 @@ public class EntityManagementImpl implements EntityManagement {
// Header can be ignored or managed. Actually is managed.
if(validType && notEmbedded){
Header header = null;
org.gcube.informationsystem.model.embedded.Header header = null;
try {
header = getHeader(jsonNode);
} catch (Exception e){
@ -500,7 +500,7 @@ public class EntityManagementImpl implements EntityManagement {
SchemaManagementImpl schemaManagement = new SchemaManagementImpl();
try {
schemaManagement.getTypeSchema(relationType, relationBaseClass.getClass().getSimpleName());
schemaManagement.getTypeSchema(relationType, relationBaseClass.getSimpleName());
} catch (SchemaNotFoundException e) {
throw e;
}
@ -809,7 +809,7 @@ public class EntityManagementImpl implements EntityManagement {
logger.trace("Trying to create {} : {}", resourceType,
jsonRepresentation);
OrientGraph orientGraph;
OrientGraph orientGraph = null;
try {
orientGraph = ContextUtility
.getActualSecurityContextGraph(PermissionMode.WRITER);
@ -831,12 +831,24 @@ public class EntityManagementImpl implements EntityManagement {
createRelation(orientGraph, resource, jsonNodeArray, IsRelatedTo.class);
}
orientGraph.commit();
return marshallResource(resource);
} catch(ResourceRegistryException rre) {
} catch(ResourceRegistryException rre) {
if (orientGraph != null) {
orientGraph.rollback();
}
throw rre;
} catch(Exception e){
if (orientGraph != null) {
orientGraph.rollback();
}
throw new ResourceRegistryException(e);
} finally {
if (orientGraph != null) {
orientGraph.shutdown();
}
}
}

View File

@ -10,16 +10,28 @@ import org.codehaus.jettison.json.JSONObject;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.informationsystem.impl.entity.facet.CPUFacetImpl;
import org.gcube.informationsystem.impl.entity.facet.ContactFacetImpl;
import org.gcube.informationsystem.impl.entity.facet.NetworkingFacetImpl;
import org.gcube.informationsystem.impl.entity.facet.SoftwareFacetImpl;
import org.gcube.informationsystem.impl.entity.resource.EServiceImpl;
import org.gcube.informationsystem.impl.entity.resource.HostingNodeImpl;
import org.gcube.informationsystem.impl.relation.IsIdentifiedByImpl;
import org.gcube.informationsystem.impl.relation.isrelatedto.HostsImpl;
import org.gcube.informationsystem.impl.utils.Entities;
import org.gcube.informationsystem.impl.utils.Utility;
import org.gcube.informationsystem.model.embedded.Header;
import org.gcube.informationsystem.model.entity.Entity;
import org.gcube.informationsystem.model.entity.Facet;
import org.gcube.informationsystem.model.entity.Resource;
import org.gcube.informationsystem.model.entity.facet.CPUFacet;
import org.gcube.informationsystem.model.entity.facet.ContactFacet;
import org.gcube.informationsystem.model.entity.facet.NetworkingFacet;
import org.gcube.informationsystem.model.entity.facet.SoftwareFacet;
import org.gcube.informationsystem.model.entity.resource.EService;
import org.gcube.informationsystem.model.entity.resource.HostingNode;
import org.gcube.informationsystem.model.relation.ConsistsOf;
import org.gcube.informationsystem.model.relation.IsIdentifiedBy;
import org.gcube.informationsystem.model.relation.Relation;
import org.gcube.informationsystem.model.relation.isrelatedto.Hosts;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.FacetNotFoundException;
import org.junit.Assert;
import org.junit.Test;
@ -224,6 +236,35 @@ public class EntityManagementImplTest {
public void testCreateHostingNode() throws Exception {
ScopeProvider.instance.set("/gcube/devNext");
EService eService = new EServiceImpl();
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
softwareFacet.setGroup("InformationSystem");
softwareFacet.setName("resource-registry");
softwareFacet.setVersion("1.1.0");
IsIdentifiedBy<Resource, Facet> isIdentifiedBy = new IsIdentifiedByImpl<Resource, Facet>(eService, softwareFacet, null);
eService.addFacet(isIdentifiedBy);
String json = entityManagementImpl.createResource(EService.NAME, Entities.marshal(eService));
logger.debug("Created : {}", json);
eService = Entities.unmarshal(EService.class, json);
logger.debug("Unmarshalled {} {}", EService.NAME, eService);
NetworkingFacet networkingFacet = new NetworkingFacetImpl();
networkingFacet.setIPAddress("146.48.87.183");
networkingFacet.setHostName("pc-frosini.isti.cnr.it");
networkingFacet.setDomainName("isti.cnr.it");
networkingFacet.setMask("255.255.248.0");
networkingFacet.setBroadcastAddress("146.48.87.255");
json = entityManagementImpl.createFacet(NetworkingFacet.NAME, Entities.marshal(networkingFacet));
logger.debug("Created : {}", json);
networkingFacet = Entities.unmarshal(NetworkingFacet.class, json);
logger.debug("Unmarshalled {} {}", NetworkingFacet.NAME, networkingFacet);
HostingNode hostingNode = new HostingNodeImpl();
CPUFacetImpl cpuFacetImpl = new CPUFacetImpl();
@ -233,8 +274,17 @@ public class EntityManagementImplTest {
hostingNode.addFacet(cpuFacetImpl);
String json = entityManagementImpl.createResource(HostingNode.NAME, Entities.marshal(hostingNode));
isIdentifiedBy = new IsIdentifiedByImpl<Resource, Facet>(hostingNode, networkingFacet, null);
hostingNode.attachFacet(isIdentifiedBy);
Hosts<HostingNode, EService> hosts = new HostsImpl<HostingNode, EService>(hostingNode, eService, null);
hostingNode.attachResource(hosts);
json = entityManagementImpl.createResource(HostingNode.NAME, Entities.marshal(hostingNode));
logger.debug("Created : {}", json);
}
@ -312,8 +362,6 @@ public class EntityManagementImplTest {
logger.debug("Created : {}", json);
String createdFacetUUID = Utility.getUUIDFromJSONString(json);
HostingNode hostingNode = new HostingNodeImpl();
CPUFacetImpl cpuFacetImpl = new CPUFacetImpl();
@ -331,9 +379,6 @@ public class EntityManagementImplTest {
logger.trace(resourceStringWriter.toString());
json = entityManagementImpl.createResource(
HostingNode.class.getSimpleName(), resourceStringWriter.toString());
String resourceUUID = Utility.getUUIDFromJSONString(json);