Fixed AddToContext
This commit is contained in:
parent
f17106e42e
commit
dd88daecab
|
@ -339,7 +339,9 @@ public class SecurityContext {
|
||||||
contextODatabaseDocument = getDatabaseDocument(PermissionMode.READER);
|
contextODatabaseDocument = getDatabaseDocument(PermissionMode.READER);
|
||||||
|
|
||||||
ORecord oRecord = contextODatabaseDocument.getRecord(orid);
|
ORecord oRecord = contextODatabaseDocument.getRecord(orid);
|
||||||
logger.trace("{}", oRecord);
|
if(oRecord==null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -137,15 +137,8 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
||||||
*/
|
*/
|
||||||
protected Map<String,RelationManagement<?, ?>> relationManagements;
|
protected Map<String,RelationManagement<?, ?>> relationManagements;
|
||||||
|
|
||||||
/*
|
/* Indicate that AddToContext skipped the isntance because it was not the source context */
|
||||||
public boolean isAvailableOnContext(SecurityContext securityContext) {
|
protected boolean skipped;
|
||||||
try {
|
|
||||||
return securityContext.isElementInContext(element);
|
|
||||||
} catch (ResourceRegistryException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
protected EntityManagement(AccessType accessType) {
|
protected EntityManagement(AccessType accessType) {
|
||||||
super(accessType);
|
super(accessType);
|
||||||
|
@ -164,6 +157,8 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
||||||
* so this variable is initialised as true.
|
* so this variable is initialised as true.
|
||||||
*/
|
*/
|
||||||
this.honourPropagationConstraintsInContextSharing = true;
|
this.honourPropagationConstraintsInContextSharing = true;
|
||||||
|
|
||||||
|
this.skipped = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -304,6 +299,7 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
||||||
throws ContextException, ResourceRegistryException {
|
throws ContextException, ResourceRegistryException {
|
||||||
if(!sourceSecurityContext.isElementInContext(getElement())) {
|
if(!sourceSecurityContext.isElementInContext(getElement())) {
|
||||||
// The element in not in the source security context. It will be skipped
|
// The element in not in the source security context. It will be skipped
|
||||||
|
skipped = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -337,10 +333,12 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
||||||
try {
|
try {
|
||||||
setOperation(Operation.ADD_TO_CONTEXT);
|
setOperation(Operation.ADD_TO_CONTEXT);
|
||||||
reallyAddToContext();
|
reallyAddToContext();
|
||||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
if(!skipped) {
|
||||||
element.save();
|
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||||
affectedInstances.put(uuid, serializeAsAffectedInstance());
|
element.save();
|
||||||
sanityCheck();
|
affectedInstances.put(uuid, serializeAsAffectedInstance());
|
||||||
|
sanityCheck();
|
||||||
|
}
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
|
|
|
@ -262,6 +262,12 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
|
||||||
protected void reallyAddToContext()
|
protected void reallyAddToContext()
|
||||||
throws ContextException, ResourceRegistryException {
|
throws ContextException, ResourceRegistryException {
|
||||||
|
|
||||||
|
if(!sourceSecurityContext.isElementInContext(getElement())) {
|
||||||
|
// The element in not in the source security context. It will be skipped
|
||||||
|
skipped = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
|
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -151,10 +151,14 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
*/
|
*/
|
||||||
this.honourPropagationConstraintsInContextSharing = true;
|
this.honourPropagationConstraintsInContextSharing = true;
|
||||||
|
|
||||||
|
this.skipped = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PropagationConstraint propagationConstraint;
|
protected PropagationConstraint propagationConstraint;
|
||||||
|
|
||||||
|
/* Indicate that AddToContext skipped the isntance because it was not the source context */
|
||||||
|
protected boolean skipped;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OEdge getElement() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
public OEdge getElement() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||||
|
@ -371,6 +375,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
throws ContextException, ResourceRegistryException {
|
throws ContextException, ResourceRegistryException {
|
||||||
if(!sourceSecurityContext.isElementInContext(getElement())) {
|
if(!sourceSecurityContext.isElementInContext(getElement())) {
|
||||||
// The element in not in the source security context. It will be skipped
|
// The element in not in the source security context. It will be skipped
|
||||||
|
skipped = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,7 +449,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
try {
|
try {
|
||||||
operation = Operation.ADD_TO_CONTEXT;
|
operation = Operation.ADD_TO_CONTEXT;
|
||||||
reallyAddToContext();
|
reallyAddToContext();
|
||||||
if(propagationConstraint.getAddConstraint()==PropagationConstraint.AddConstraint.propagate) {
|
if(!skipped && propagationConstraint.getAddConstraint()==PropagationConstraint.AddConstraint.propagate) {
|
||||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||||
element.save();
|
element.save();
|
||||||
affectedInstances.put(uuid, serializeAsAffectedInstance());
|
affectedInstances.put(uuid, serializeAsAffectedInstance());
|
||||||
|
|
|
@ -4,16 +4,20 @@ import java.net.URI;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.gcube.informationsystem.context.reference.entities.Context;
|
||||||
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
|
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
|
||||||
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
|
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
|
||||||
import org.gcube.informationsystem.model.reference.properties.Header;
|
import org.gcube.informationsystem.model.reference.properties.Header;
|
||||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
|
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
|
||||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
|
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
|
||||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
|
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCacheRenewal;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.contexts.entities.ContextManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.ERManagementTest;
|
import org.gcube.informationsystem.resourceregistry.instances.ERManagementTest;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
|
import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.model.relations.ConsistsOfManagement;
|
import org.gcube.informationsystem.resourceregistry.instances.model.relations.ConsistsOfManagement;
|
||||||
|
@ -133,9 +137,10 @@ public class AddToContextTest extends MultiContextTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
protected IsCorrelatedTo<Dataset, Dataset> createIsCorrelatedTo(Dataset source, Dataset target) throws Exception {
|
protected IsCorrelatedTo<Dataset, Dataset> createIsCorrelatedTo(Dataset source, Dataset target, String uuid) throws Exception {
|
||||||
PropagationConstraint propagationConstraint = getPropagationConstraint();
|
PropagationConstraint propagationConstraint = getPropagationConstraint();
|
||||||
IsCorrelatedTo<Dataset, Dataset> isCorrelatedTo = new IsCorrelatedToImpl<Dataset, Dataset>(source, target, propagationConstraint);
|
IsCorrelatedTo<Dataset, Dataset> isCorrelatedTo = new IsCorrelatedToImpl<Dataset, Dataset>(source, target, propagationConstraint);
|
||||||
|
isCorrelatedTo.setHeader(new HeaderImpl(UUID.fromString(uuid)));
|
||||||
|
|
||||||
IsRelatedToManagement isRelatedToManagement = getIsRelatedToManagement(isCorrelatedTo);
|
IsRelatedToManagement isRelatedToManagement = getIsRelatedToManagement(isCorrelatedTo);
|
||||||
String json = isRelatedToManagement.create();
|
String json = isRelatedToManagement.create();
|
||||||
|
@ -145,8 +150,67 @@ public class AddToContextTest extends MultiContextTest {
|
||||||
return isCorrelatedTo;
|
return isCorrelatedTo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void checkNumerOfContext(Dataset datasetR1, int r1Number, Dataset datasetR2, int r2Number, Dataset datasetR3, int r3Number) throws Exception {
|
||||||
|
setContextByName(GCUBE);
|
||||||
|
|
||||||
|
ContextUtility.getHierarchicalMode().set(true);
|
||||||
|
ContextUtility.getIncludeInstanceContexts().set(true);
|
||||||
|
|
||||||
|
Dataset r1 = ElementMapper.unmarshal(Dataset.class, getResourceManagement(datasetR1).read());
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<String> contextsR1 = (List<String>) r1.getHeader().getAdditionalProperty(Header.__CONTEXTS);
|
||||||
|
/*
|
||||||
|
Set<UUID> contextsR1UUID = org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility.getContextUUIDSet(contextsR1);
|
||||||
|
Set<String> contextsR1Fullname = org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility.getContextFullNameSet(contextsR1UUID);
|
||||||
|
logger.debug("{}", contextsR1Fullname);
|
||||||
|
*/
|
||||||
|
Assert.assertTrue(contextsR1.size()==r1Number);
|
||||||
|
|
||||||
|
Dataset r2 = ElementMapper.unmarshal(Dataset.class, getResourceManagement(datasetR2).read());
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<String> contextsR2 = (List<String>) r2.getHeader().getAdditionalProperty(Header.__CONTEXTS);
|
||||||
|
/*
|
||||||
|
Set<UUID> contextsR2UUID = org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility.getContextUUIDSet(contextsR2);
|
||||||
|
Set<String> contextsR2Fullname = org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility.getContextFullNameSet(contextsR2UUID);
|
||||||
|
logger.debug("{}", contextsR2Fullname);
|
||||||
|
*/
|
||||||
|
Assert.assertTrue(contextsR2.size()==r2Number);
|
||||||
|
|
||||||
|
Dataset r3 = ElementMapper.unmarshal(Dataset.class, getResourceManagement(datasetR3).read());
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<String> contextsR3 = (List<String>) r3.getHeader().getAdditionalProperty(Header.__CONTEXTS);
|
||||||
|
/*
|
||||||
|
Set<UUID> contextsR3UUID = org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility.getContextUUIDSet(contextsR3);
|
||||||
|
Set<String> contextsR3Fullname = org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility.getContextFullNameSet(contextsR3UUID);
|
||||||
|
logger.debug("{}", contextsR3Fullname);
|
||||||
|
*/
|
||||||
|
Assert.assertTrue(contextsR3.size()==r3Number);
|
||||||
|
|
||||||
|
ContextUtility.getHierarchicalMode().set(false);
|
||||||
|
ContextUtility.getIncludeInstanceContexts().set(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ContextCacheRenewal contextCacheRenewal = new ContextCacheRenewal() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Context> renew() throws ResourceRegistryException {
|
||||||
|
try {
|
||||||
|
ContextManagement contextManagement = new ContextManagement();
|
||||||
|
String allString = contextManagement.all(false);
|
||||||
|
logger.trace(allString);
|
||||||
|
List<Context> all = ElementMapper.unmarshalList(Context.class, allString);
|
||||||
|
return all;
|
||||||
|
}catch (Exception e) {
|
||||||
|
throw new ResourceRegistryException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddToContextFromDifferentSourceContext() throws Exception {
|
public void testAddToContextFromDifferentSourceContext() throws Exception {
|
||||||
|
|
||||||
setContextByName(GCUBE);
|
setContextByName(GCUBE);
|
||||||
|
|
||||||
Dataset datasetR1 = createDataset("R1", "da111111-dada-1111-1111-111111111111");
|
Dataset datasetR1 = createDataset("R1", "da111111-dada-1111-1111-111111111111");
|
||||||
|
@ -158,7 +222,7 @@ public class AddToContextTest extends MultiContextTest {
|
||||||
|
|
||||||
setContextByName(DEVNEXT);
|
setContextByName(DEVNEXT);
|
||||||
datasetR2 = createDataset("R2", "da222222-dada-2222-2222-222222222222");
|
datasetR2 = createDataset("R2", "da222222-dada-2222-2222-222222222222");
|
||||||
IsCorrelatedTo<Dataset, Dataset> isCorrelatedToR1R2 = createIsCorrelatedTo(datasetR1, datasetR2);
|
IsCorrelatedTo<Dataset, Dataset> isCorrelatedToR1R2 = createIsCorrelatedTo(datasetR1, datasetR2, "da111111-1111-aaaa-2222-222222222222");
|
||||||
|
|
||||||
getResourceManagement(datasetR1).exists();
|
getResourceManagement(datasetR1).exists();
|
||||||
getIsRelatedToManagement(isCorrelatedToR1R2).exists();
|
getIsRelatedToManagement(isCorrelatedToR1R2).exists();
|
||||||
|
@ -167,7 +231,7 @@ public class AddToContextTest extends MultiContextTest {
|
||||||
|
|
||||||
setContextByName(DEVSEC);
|
setContextByName(DEVSEC);
|
||||||
datasetR3 = createDataset("R3", "da333333-dada-3333-3333-333333333333");
|
datasetR3 = createDataset("R3", "da333333-dada-3333-3333-333333333333");
|
||||||
IsCorrelatedTo<Dataset, Dataset> isCorrelatedToR1R3 = createIsCorrelatedTo(datasetR1, datasetR3);
|
IsCorrelatedTo<Dataset, Dataset> isCorrelatedToR1R3 = createIsCorrelatedTo(datasetR1, datasetR3, "da111111-1111-aaaa-3333-333333333333");
|
||||||
|
|
||||||
getResourceManagement(datasetR1).exists();
|
getResourceManagement(datasetR1).exists();
|
||||||
getIsRelatedToManagement(isCorrelatedToR1R3).exists();
|
getIsRelatedToManagement(isCorrelatedToR1R3).exists();
|
||||||
|
@ -237,25 +301,15 @@ public class AddToContextTest extends MultiContextTest {
|
||||||
logger.trace("As expected");
|
logger.trace("As expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
ContextUtility.getHierarchicalMode().set(true);
|
checkNumerOfContext(datasetR1, 3, datasetR2, 1, datasetR3, 1);
|
||||||
ContextUtility.getIncludeInstanceContexts().set(true);
|
|
||||||
|
|
||||||
Dataset r1 = ElementMapper.unmarshal(Dataset.class, getResourceManagement(datasetR1).read());
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
List<String> contextsR1 = (List<String>) r1.getHeader().getAdditionalProperty(Header.__CONTEXTS);
|
|
||||||
Assert.assertTrue(contextsR1.size()==3);
|
|
||||||
|
|
||||||
Dataset r2 = ElementMapper.unmarshal(Dataset.class, getResourceManagement(datasetR2).read());
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
List<String> contextsR2 = (List<String>) r2.getHeader().getAdditionalProperty(Header.__CONTEXTS);
|
|
||||||
Assert.assertTrue(contextsR2.size()==1);
|
|
||||||
|
|
||||||
Dataset r3 = ElementMapper.unmarshal(Dataset.class, getResourceManagement(datasetR3).read());
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
List<String> contextsR3 = (List<String>) r3.getHeader().getAdditionalProperty(Header.__CONTEXTS);
|
|
||||||
Assert.assertTrue(contextsR3.size()==1);
|
|
||||||
|
|
||||||
|
setContextByName(DEVNEXT);
|
||||||
|
addToContextThenTestIfBehaveProperly(datasetR1, false, NEXTNEXT);
|
||||||
|
checkNumerOfContext(datasetR1, 4, datasetR2, 2, datasetR3, 1);
|
||||||
|
|
||||||
|
setContextByName(DEVSEC);
|
||||||
|
addToContextThenTestIfBehaveProperly(datasetR1, false, DEVVRE);
|
||||||
|
checkNumerOfContext(datasetR1, 5, datasetR2, 2, datasetR3, 2);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("", e);
|
logger.error("", e);
|
||||||
|
|
Loading…
Reference in New Issue