Refs #10390: The serialized resource is the old verson in some cases after update
Task-Url: https://support.d4science.org/issues/10390 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@158739 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
93187f062d
commit
92075c38b3
|
@ -87,6 +87,15 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
||||||
protected String erType;
|
protected String erType;
|
||||||
|
|
||||||
protected El element;
|
protected El element;
|
||||||
|
protected boolean reload;
|
||||||
|
|
||||||
|
public boolean isReload() {
|
||||||
|
return reload;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReload(boolean reload) {
|
||||||
|
this.reload = reload;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This boolean is used to force the use of ADMIN user instead of the user of the context
|
* This boolean is used to force the use of ADMIN user instead of the user of the context
|
||||||
|
@ -114,6 +123,8 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
||||||
|
|
||||||
this.ignoreStartWithKeys.add(AT);
|
this.ignoreStartWithKeys.add(AT);
|
||||||
this.ignoreStartWithKeys.add(UNDERSCORE);
|
this.ignoreStartWithKeys.add(UNDERSCORE);
|
||||||
|
|
||||||
|
this.reload = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ERManagement(AccessType accessType, OrientGraph orientGraph) {
|
protected ERManagement(AccessType accessType, OrientGraph orientGraph) {
|
||||||
|
@ -364,6 +375,10 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
||||||
throw new ResourceRegistryException(e);
|
throw new ResourceRegistryException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}else {
|
||||||
|
if(reload){
|
||||||
|
((OrientElement) element).reload();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
@ -495,7 +510,9 @@ public abstract class ERManagement<ERType extends ER, El extends Element> {
|
||||||
|
|
||||||
orientGraph.commit();
|
orientGraph.commit();
|
||||||
|
|
||||||
|
setReload(true);
|
||||||
// TODO Notify to subscriptionNotification
|
// TODO Notify to subscriptionNotification
|
||||||
|
|
||||||
return serialize();
|
return serialize();
|
||||||
// TODO Serialized resource is the old version. This really strange and should be an orient bug
|
// TODO Serialized resource is the old version. This really strange and should be an orient bug
|
||||||
|
|
||||||
|
|
|
@ -87,10 +87,13 @@ public class ResourceManagement extends EntityManagement<Resource> {
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
RelationManagement relationManagement = getRelationManagement(edge);
|
RelationManagement relationManagement = getRelationManagement(edge);
|
||||||
|
relationManagement.setReload(reload);
|
||||||
|
|
||||||
if(relationManagement.giveMeSourceEntityManagementAsIs()==null) {
|
if(relationManagement.giveMeSourceEntityManagementAsIs()==null) {
|
||||||
relationManagement.setSourceEntityManagement(this);
|
relationManagement.setSourceEntityManagement(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(relationManagement.giveMeSourceEntityManagementAsIs()!=this) {
|
if(relationManagement.giveMeSourceEntityManagementAsIs()!=this) {
|
||||||
StringBuilder errorMessage = new StringBuilder();
|
StringBuilder errorMessage = new StringBuilder();
|
||||||
errorMessage.append("SourceEntityManagement for ");
|
errorMessage.append("SourceEntityManagement for ");
|
||||||
|
|
|
@ -105,6 +105,7 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
sourceEntityManagement = newSourceEntityManagement();
|
sourceEntityManagement = newSourceEntityManagement();
|
||||||
sourceEntityManagement.setElement(source);
|
sourceEntityManagement.setElement(source);
|
||||||
}
|
}
|
||||||
|
sourceEntityManagement.setReload(reload);
|
||||||
return sourceEntityManagement;
|
return sourceEntityManagement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,6 +116,7 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
targetEntityManagement = newTargetEntityManagement();
|
targetEntityManagement = newTargetEntityManagement();
|
||||||
targetEntityManagement.setElement(target);
|
targetEntityManagement.setElement(target);
|
||||||
}
|
}
|
||||||
|
targetEntityManagement.setReload(reload);
|
||||||
return targetEntityManagement;
|
return targetEntityManagement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,11 +143,13 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (includeSource) {
|
if (includeSource) {
|
||||||
relation.put(Relation.SOURCE_PROPERTY, getSourceEntityManagement().serializeSelfOnly());
|
EntityManagement sourceEntityManagement = getSourceEntityManagement();
|
||||||
|
relation.put(Relation.SOURCE_PROPERTY, sourceEntityManagement.serializeSelfOnly());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (includeTarget) {
|
if (includeTarget) {
|
||||||
relation.put(Relation.TARGET_PROPERTY, getTargetEntityManagement().serializeAsJson());
|
EntityManagement targetEntityManagement = getTargetEntityManagement();
|
||||||
|
relation.put(Relation.TARGET_PROPERTY, targetEntityManagement.serializeAsJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (ResourceRegistryException e) {
|
} catch (ResourceRegistryException e) {
|
||||||
|
@ -161,15 +165,16 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
|
|
||||||
protected Map<String, JSONObject> fullSerialize(Map<String, JSONObject> visitedSourceResources)
|
protected Map<String, JSONObject> fullSerialize(Map<String, JSONObject> visitedSourceResources)
|
||||||
throws ResourceRegistryException {
|
throws ResourceRegistryException {
|
||||||
Vertex source = element.getVertex(Direction.OUT);
|
|
||||||
|
Vertex source = getElement().getVertex(Direction.OUT);
|
||||||
|
|
||||||
String id = source.getId().toString();
|
String id = source.getId().toString();
|
||||||
|
|
||||||
JSONObject sourceResource = visitedSourceResources.get(id);
|
JSONObject sourceResource = visitedSourceResources.get(id);
|
||||||
|
ResourceManagement resourceManagement = null;
|
||||||
|
|
||||||
if (sourceResource == null) {
|
if (sourceResource == null) {
|
||||||
ResourceManagement resourceManagement = (ResourceManagement) ERManagementUtility
|
resourceManagement = (ResourceManagement) ERManagementUtility.getEntityManagement(orientGraph, source);
|
||||||
.getEntityManagement(orientGraph, source);
|
|
||||||
if (this instanceof IsRelatedToManagement) {
|
if (this instanceof IsRelatedToManagement) {
|
||||||
sourceResource = resourceManagement.serializeAsJson();
|
sourceResource = resourceManagement.serializeAsJson();
|
||||||
} else if (this instanceof ConsistsOfManagement) {
|
} else if (this instanceof ConsistsOfManagement) {
|
||||||
|
@ -183,6 +188,7 @@ public abstract class RelationManagement<R extends Relation, S extends EntityMan
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (this instanceof IsRelatedToManagement) {
|
if (this instanceof IsRelatedToManagement) {
|
||||||
sourceResource = ResourceManagement.addIsRelatedTo(sourceResource, serializeAsJson());
|
sourceResource = ResourceManagement.addIsRelatedTo(sourceResource, serializeAsJson());
|
||||||
} else if (this instanceof ConsistsOfManagement) {
|
} else if (this instanceof ConsistsOfManagement) {
|
||||||
|
|
|
@ -141,6 +141,7 @@ public class HeaderUtility {
|
||||||
oDocument.field(Header.MODIFIED_BY_PROPERTY, modifiedBy);
|
oDocument.field(Header.MODIFIED_BY_PROPERTY, modifiedBy);
|
||||||
Date lastUpdateTime = Calendar.getInstance().getTime();
|
Date lastUpdateTime = Calendar.getInstance().getTime();
|
||||||
oDocument.field(Header.LAST_UPDATE_TIME_PROPERTY, lastUpdateTime);
|
oDocument.field(Header.LAST_UPDATE_TIME_PROPERTY, lastUpdateTime);
|
||||||
|
element.setProperty(Entity.HEADER_PROPERTY, oDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,169 @@
|
||||||
|
package org.gcube.informationsystem.resourceregistry.er.entity;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.gcube.informationsystem.impl.entity.facet.SoftwareFacetImpl;
|
||||||
|
import org.gcube.informationsystem.impl.utils.ISMapper;
|
||||||
|
import org.gcube.informationsystem.model.ER;
|
||||||
|
import org.gcube.informationsystem.model.entity.facet.SoftwareFacet;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.ScopedTest;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAlreadyPresentException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.er.ERManagementTest;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.utils.HeaderUtility;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class FacetManagementTest extends ScopedTest {
|
||||||
|
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(ERManagementTest.class);
|
||||||
|
|
||||||
|
public static final String GROUP = "InformationSystem";
|
||||||
|
public static final String NAME = "resource-registry";
|
||||||
|
public static final String VERSION = "1.0.0";
|
||||||
|
public static final String NEW_VERSION = "2.0.0";
|
||||||
|
|
||||||
|
public static SoftwareFacet getSoftwareFacet() {
|
||||||
|
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
|
||||||
|
softwareFacet.setGroup(GROUP);
|
||||||
|
softwareFacet.setName(NAME);
|
||||||
|
softwareFacet.setVersion(VERSION);
|
||||||
|
return softwareFacet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkHeader(ER er, UUID uuid, boolean create) {
|
||||||
|
Assert.assertTrue(er.getHeader()!=null);
|
||||||
|
Assert.assertTrue(er.getHeader().getUUID()!=null);
|
||||||
|
|
||||||
|
if(uuid!=null) {
|
||||||
|
Assert.assertTrue(er.getHeader().getUUID().compareTo(uuid)==0);
|
||||||
|
}
|
||||||
|
|
||||||
|
String user = HeaderUtility.getUser();
|
||||||
|
Assert.assertTrue(er.getHeader().getModifiedBy().compareTo(user)==0);
|
||||||
|
|
||||||
|
if(create){
|
||||||
|
Assert.assertTrue(er.getHeader().getCreator().compareTo(user)==0);
|
||||||
|
Assert.assertTrue(er.getHeader().getCreationTime().compareTo(er.getHeader().getLastUpdateTime())==0);
|
||||||
|
}else {
|
||||||
|
Assert.assertTrue(er.getHeader().getCreationTime().before(er.getHeader().getLastUpdateTime()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkAssertion(SoftwareFacet softwareFacet, String version, UUID uuid, boolean create) {
|
||||||
|
checkHeader(softwareFacet, uuid, create);
|
||||||
|
|
||||||
|
Assert.assertTrue(softwareFacet.getGroup().compareTo(GROUP)==0);
|
||||||
|
Assert.assertTrue(softwareFacet.getName().compareTo(NAME)==0);
|
||||||
|
Assert.assertTrue(softwareFacet.getVersion().compareTo(version)==0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createUpdateReadDelete() throws Exception {
|
||||||
|
SoftwareFacet softwareFacet = getSoftwareFacet();
|
||||||
|
|
||||||
|
|
||||||
|
/* Testing Create */
|
||||||
|
FacetManagement facetManagement = new FacetManagement();
|
||||||
|
facetManagement.setElementType(SoftwareFacet.NAME);
|
||||||
|
facetManagement.setJSON(ISMapper.marshal(softwareFacet));
|
||||||
|
|
||||||
|
String json = facetManagement.create();
|
||||||
|
logger.debug("Created : {}", json);
|
||||||
|
softwareFacet = ISMapper.unmarshal(SoftwareFacet.class, json);
|
||||||
|
logger.debug("Unmarshalled {}", softwareFacet);
|
||||||
|
|
||||||
|
checkAssertion(softwareFacet, VERSION, null, true);
|
||||||
|
UUID uuid = softwareFacet.getHeader().getUUID();
|
||||||
|
|
||||||
|
Thread.sleep(1000);
|
||||||
|
|
||||||
|
|
||||||
|
/* Testing Update */
|
||||||
|
softwareFacet.setVersion(NEW_VERSION);
|
||||||
|
|
||||||
|
facetManagement = new FacetManagement();
|
||||||
|
facetManagement.setElementType(SoftwareFacet.NAME);
|
||||||
|
facetManagement.setJSON(ISMapper.marshal(softwareFacet));
|
||||||
|
|
||||||
|
json = facetManagement.update();
|
||||||
|
logger.debug("Updated : {}", json);
|
||||||
|
softwareFacet = ISMapper.unmarshal(SoftwareFacet.class, json);
|
||||||
|
logger.debug("Unmarshalled {}", softwareFacet);
|
||||||
|
|
||||||
|
checkAssertion(softwareFacet, NEW_VERSION, uuid, false);
|
||||||
|
|
||||||
|
|
||||||
|
/* Testing Read */
|
||||||
|
facetManagement = new FacetManagement();
|
||||||
|
facetManagement.setElementType(SoftwareFacet.NAME);
|
||||||
|
facetManagement.setUUID(uuid);
|
||||||
|
|
||||||
|
json = facetManagement.read();
|
||||||
|
logger.debug("Read : {}", json);
|
||||||
|
softwareFacet = ISMapper.unmarshal(SoftwareFacet.class, json);
|
||||||
|
logger.debug("Unmarshalled {}", softwareFacet);
|
||||||
|
|
||||||
|
checkAssertion(softwareFacet, NEW_VERSION, uuid, false);
|
||||||
|
|
||||||
|
|
||||||
|
/* Testing Create the facet with the same UUID */
|
||||||
|
facetManagement = new FacetManagement();
|
||||||
|
facetManagement.setElementType(SoftwareFacet.NAME);
|
||||||
|
facetManagement.setJSON(ISMapper.marshal(softwareFacet));
|
||||||
|
|
||||||
|
try {
|
||||||
|
facetManagement.create();
|
||||||
|
}catch (FacetAlreadyPresentException e) {
|
||||||
|
logger.info("Facet already present as expected");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Testing Delete */
|
||||||
|
boolean deleted = facetManagement.delete();
|
||||||
|
Assert.assertTrue(deleted);
|
||||||
|
|
||||||
|
facetManagement = new FacetManagement();
|
||||||
|
facetManagement.setElementType(SoftwareFacet.NAME);
|
||||||
|
facetManagement.setUUID(uuid);
|
||||||
|
|
||||||
|
try {
|
||||||
|
facetManagement.read();
|
||||||
|
}catch (FacetNotFoundException e) {
|
||||||
|
logger.info("Facet not found as expected");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Testing new Create to check creation with provided UUID */
|
||||||
|
facetManagement = new FacetManagement();
|
||||||
|
facetManagement.setElementType(SoftwareFacet.NAME);
|
||||||
|
facetManagement.setJSON(ISMapper.marshal(softwareFacet));
|
||||||
|
|
||||||
|
json = facetManagement.create();
|
||||||
|
logger.debug("Created : {}", json);
|
||||||
|
softwareFacet = ISMapper.unmarshal(SoftwareFacet.class, json);
|
||||||
|
logger.debug("Unmarshalled {}", softwareFacet);
|
||||||
|
|
||||||
|
checkAssertion(softwareFacet, NEW_VERSION, uuid, true);
|
||||||
|
|
||||||
|
|
||||||
|
/* Testing Delete */
|
||||||
|
deleted = facetManagement.delete();
|
||||||
|
Assert.assertTrue(deleted);
|
||||||
|
|
||||||
|
facetManagement = new FacetManagement();
|
||||||
|
facetManagement.setElementType(SoftwareFacet.NAME);
|
||||||
|
facetManagement.setUUID(uuid);
|
||||||
|
|
||||||
|
try {
|
||||||
|
facetManagement.read();
|
||||||
|
}catch (FacetNotFoundException e) {
|
||||||
|
logger.info("Facet not found as expected");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -2,15 +2,23 @@ package org.gcube.informationsystem.resourceregistry.er.entity;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.gcube.informationsystem.impl.entity.resource.EServiceImpl;
|
||||||
|
import org.gcube.informationsystem.impl.relation.IsIdentifiedByImpl;
|
||||||
|
import org.gcube.informationsystem.impl.utils.ISMapper;
|
||||||
|
import org.gcube.informationsystem.model.entity.Facet;
|
||||||
import org.gcube.informationsystem.model.entity.facet.SoftwareFacet;
|
import org.gcube.informationsystem.model.entity.facet.SoftwareFacet;
|
||||||
|
import org.gcube.informationsystem.model.entity.resource.EService;
|
||||||
import org.gcube.informationsystem.model.entity.resource.Service;
|
import org.gcube.informationsystem.model.entity.resource.Service;
|
||||||
import org.gcube.informationsystem.model.relation.ConsistsOf;
|
import org.gcube.informationsystem.model.relation.ConsistsOf;
|
||||||
|
import org.gcube.informationsystem.model.relation.IsIdentifiedBy;
|
||||||
import org.gcube.informationsystem.resourceregistry.ScopedTest;
|
import org.gcube.informationsystem.resourceregistry.ScopedTest;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
|
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
|
||||||
import org.gcube.informationsystem.resourceregistry.er.ERManagement;
|
import org.gcube.informationsystem.resourceregistry.er.ERManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.er.ERManagementUtility;
|
import org.gcube.informationsystem.resourceregistry.er.ERManagementUtility;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -19,6 +27,62 @@ public class ResourceManagementTest extends ScopedTest {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(ResourceManagementTest.class);
|
private static Logger logger = LoggerFactory.getLogger(ResourceManagementTest.class);
|
||||||
|
|
||||||
|
public static void checkAssertion(EService eService, String version, UUID eServiceUUID, boolean create) {
|
||||||
|
FacetManagementTest.checkHeader(eService, eServiceUUID, create);
|
||||||
|
|
||||||
|
SoftwareFacet softwareFacet = eService.getFacets(SoftwareFacet.class).get(0);
|
||||||
|
FacetManagementTest.checkAssertion(softwareFacet, version, null, create);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createUpdateReadDelete() throws Exception {
|
||||||
|
|
||||||
|
/* Creating EService*/
|
||||||
|
EService eService = new EServiceImpl();
|
||||||
|
|
||||||
|
|
||||||
|
SoftwareFacet softwareFacet = FacetManagementTest.getSoftwareFacet();
|
||||||
|
IsIdentifiedBy<EService, Facet> isIdentifiedBy = new IsIdentifiedByImpl<EService, Facet>(
|
||||||
|
eService, softwareFacet, null);
|
||||||
|
eService.addFacet(isIdentifiedBy);
|
||||||
|
|
||||||
|
ResourceManagement resourceManagement = new ResourceManagement();
|
||||||
|
resourceManagement.setElementType(EService.NAME);
|
||||||
|
resourceManagement.setJSON(ISMapper.marshal(eService));
|
||||||
|
String json = resourceManagement.create();
|
||||||
|
logger.trace("Created {}", json);
|
||||||
|
eService = ISMapper.unmarshal(EService.class, json);
|
||||||
|
|
||||||
|
checkAssertion(eService, FacetManagementTest.VERSION, null, true);
|
||||||
|
|
||||||
|
UUID uuid = eService.getHeader().getUUID();
|
||||||
|
softwareFacet = eService.getFacets(SoftwareFacet.class).get(0);
|
||||||
|
|
||||||
|
|
||||||
|
/* Updating a Facet of the EService via EServcie update */
|
||||||
|
softwareFacet.setVersion(FacetManagementTest.NEW_VERSION);
|
||||||
|
|
||||||
|
resourceManagement = new ResourceManagement();
|
||||||
|
resourceManagement.setUUID(eService.getHeader().getUUID());
|
||||||
|
resourceManagement.setJSON(ISMapper.marshal(eService));
|
||||||
|
|
||||||
|
json = resourceManagement.update();
|
||||||
|
logger.trace("Updated {}", json);
|
||||||
|
eService = ISMapper.unmarshal(EService.class, json);
|
||||||
|
|
||||||
|
checkAssertion(eService, FacetManagementTest.NEW_VERSION, uuid, false);
|
||||||
|
|
||||||
|
|
||||||
|
resourceManagement = new ResourceManagement();
|
||||||
|
resourceManagement.setUUID(eService.getHeader().getUUID());
|
||||||
|
|
||||||
|
boolean deleted = resourceManagement.delete();
|
||||||
|
Assert.assertTrue(deleted);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAllWithCostraint() throws ResourceRegistryException {
|
public void testAllWithCostraint() throws ResourceRegistryException {
|
||||||
String relationType = ConsistsOf.NAME;
|
String relationType = ConsistsOf.NAME;
|
||||||
|
|
Loading…
Reference in New Issue