IMproved affected instances management
This commit is contained in:
parent
56265d35bc
commit
5db160a2dc
|
@ -396,6 +396,10 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
|||
}
|
||||
}
|
||||
|
||||
public JsonNode serializeAsAffectedInstance() throws ResourceRegistryException {
|
||||
return serializeSelfAsJsonNode();
|
||||
}
|
||||
|
||||
public JsonNode serializeSelfAsJsonNode() throws ResourceRegistryException {
|
||||
try {
|
||||
if(self==null || reload) {
|
||||
|
|
|
@ -213,7 +213,7 @@ public abstract class RelationElementManagement<SEM extends EntityElementManagem
|
|||
protected void reallyDelete() throws RelationNotFoundException, ResourceRegistryException {
|
||||
logger.debug("Going to remove {} with UUID {}. Related {}s will be detached.", accessType.getName(), uuid,
|
||||
targetEntityClass.getSimpleName());
|
||||
affectedInstances.put(uuid, serializeSelfAsJsonNode());
|
||||
affectedInstances.put(uuid, serializeAsAffectedInstance());
|
||||
getElement().delete();
|
||||
}
|
||||
|
||||
|
|
|
@ -331,7 +331,7 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
reallyAddToContext();
|
||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||
element.save();
|
||||
affectedInstances.put(uuid, serializeSelfAsJsonNode());
|
||||
affectedInstances.put(uuid, serializeAsAffectedInstance());
|
||||
sanityCheck();
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
|
@ -392,7 +392,7 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
reallyRemoveFromContext();
|
||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||
element.save();
|
||||
affectedInstances.put(uuid, serializeSelfAsJsonNode());
|
||||
affectedInstances.put(uuid, serializeAsAffectedInstance());
|
||||
sanityCheck();
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
|
|
|
@ -74,7 +74,7 @@ public class FacetManagement extends EntityManagement<Facet, FacetType> {
|
|||
consistsOfManagement = new ConsistsOfManagement();
|
||||
consistsOfManagement.setElement(oEdge);
|
||||
consistsOfManagement.setTargetEntityManagement(this);
|
||||
affectedInstances.put(uuid, consistsOfManagement.serializeSelfAsJsonNode());
|
||||
affectedInstances.put(uuid, consistsOfManagement.serializeAsAffectedInstance());
|
||||
|
||||
OVertex oVertex = getElement().getVertices(ODirection.IN).iterator().next();
|
||||
resourceManagement = new ResourceManagement();
|
||||
|
@ -91,7 +91,7 @@ public class FacetManagement extends EntityManagement<Facet, FacetType> {
|
|||
consistsOfManagement = new ConsistsOfManagement();
|
||||
consistsOfManagement.setElement(oEdge);
|
||||
consistsOfManagement.setTargetEntityManagement(this);
|
||||
affectedInstances.put(uuid, consistsOfManagement.serializeSelfAsJsonNode());
|
||||
affectedInstances.put(uuid, consistsOfManagement.serializeAsAffectedInstance());
|
||||
|
||||
OVertex oVertex = getElement().getVertices(ODirection.IN).iterator().next();
|
||||
resourceManagement = new ResourceManagement();
|
||||
|
@ -99,7 +99,7 @@ public class FacetManagement extends EntityManagement<Facet, FacetType> {
|
|||
resourceManagement.addToRelationManagements(consistsOfManagement);
|
||||
}
|
||||
|
||||
affectedInstances.put(uuid, serializeSelfAsJsonNode());
|
||||
affectedInstances.put(uuid, serializeAsAffectedInstance());
|
||||
getElement().delete();
|
||||
}
|
||||
|
||||
|
|
|
@ -251,7 +251,7 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
|
|||
|
||||
}
|
||||
|
||||
affectedInstances.put(uuid, serializeSelfAsJsonNode());
|
||||
affectedInstances.put(uuid, serializeAsAffectedInstance());
|
||||
element.delete();
|
||||
}
|
||||
|
||||
|
|
|
@ -382,7 +382,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
|
||||
}
|
||||
|
||||
protected Map<UUID,JsonNode> reallyAddToContext()
|
||||
protected void reallyAddToContext()
|
||||
throws ContextException, ResourceRegistryException {
|
||||
getElement();
|
||||
|
||||
|
@ -447,8 +447,6 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
* the update of Header metadata i.e. modifiedBy, lastUpdateTime
|
||||
*/
|
||||
}
|
||||
|
||||
return affectedInstances;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -460,7 +458,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
if(propagationConstraint.getAddConstraint()==PropagationConstraint.AddConstraint.propagate) {
|
||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||
element.save();
|
||||
affectedInstances.put(uuid, serializeSelfAsJsonNode());
|
||||
affectedInstances.put(uuid, serializeAsAffectedInstance());
|
||||
}
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
|
@ -470,7 +468,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
}
|
||||
}
|
||||
|
||||
public Map<UUID,JsonNode> forcedAddToContext()
|
||||
public void forcedAddToContext()
|
||||
throws ContextException, ResourceRegistryException {
|
||||
setOperation(Operation.ADD_TO_CONTEXT);
|
||||
|
||||
|
@ -490,9 +488,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
|
||||
targetSecurityContext.addElement(getElement(), oDatabaseDocument);
|
||||
|
||||
affectedInstances.put(uuid, serializeSelfAsJsonNode());
|
||||
|
||||
return affectedInstances;
|
||||
affectedInstances.put(uuid, serializeAsAffectedInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -570,7 +566,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
*/
|
||||
targetSecurityContext.removeElement(getElement(), oDatabaseDocument);
|
||||
|
||||
affectedInstances.put(uuid, serializeSelfAsJsonNode());
|
||||
affectedInstances.put(uuid, serializeAsAffectedInstance());
|
||||
|
||||
T targetEntityManagement = getTargetEntityManagement();
|
||||
targetEntityManagement.setDryRun(dryRun);
|
||||
|
@ -631,7 +627,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
reallyRemoveFromContext();
|
||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||
element.save();
|
||||
affectedInstances.put(uuid, serializeSelfAsJsonNode());
|
||||
affectedInstances.put(uuid, serializeAsAffectedInstance());
|
||||
} catch(ResourceRegistryException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
|
@ -721,7 +717,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
((ResourceManagement) targetEntityManagement).setSanityCheckNotRequired();
|
||||
}
|
||||
|
||||
affectedInstances.put(uuid, serializeSelfAsJsonNode());
|
||||
affectedInstances.put(uuid, serializeAsAffectedInstance());
|
||||
element.delete();
|
||||
|
||||
switch(removeConstraint) {
|
||||
|
|
|
@ -392,6 +392,7 @@ public class BasicTest extends MultiContextTest {
|
|||
resourceManagement = new ResourceManagement();
|
||||
resourceManagement.setUUID(hnUUID);
|
||||
resourceManagement.removeFromContext(ContextUtility.getCurrentSecurityContext().getUUID());
|
||||
|
||||
Map<UUID,JsonNode> affectedInstances = resourceManagement.getAffectedInstances();
|
||||
logger.debug("Remove from Context affects the following instances {}", affectedInstances.values());
|
||||
|
||||
|
|
|
@ -73,21 +73,21 @@ public class RuleTest extends ContextTest {
|
|||
@SuppressWarnings("unused")
|
||||
UUID softwareFacetUUID = checkFacetCreation(eService);
|
||||
|
||||
SoftwareFacet softwareFacet = (SoftwareFacet) eService.getIdentificationFacets().get(0);
|
||||
String softwareFacetString = ElementMapper.marshal(softwareFacet);
|
||||
|
||||
// Trying to recreate SoftwareFacet
|
||||
FacetManagement softwareFacetManagement = new FacetManagement();
|
||||
softwareFacetManagement.setElementType(SoftwareFacet.NAME);
|
||||
softwareFacetManagement.setJson(softwareFacetString);
|
||||
try{
|
||||
softwareFacetManagement.create();
|
||||
}catch (FacetAlreadyPresentException e) {
|
||||
// OK
|
||||
logger.debug("As expected {} cannot be recreated", softwareFacetString, e);
|
||||
}catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
// SoftwareFacet softwareFacet = (SoftwareFacet) eService.getIdentificationFacets().get(0);
|
||||
// String softwareFacetString = ElementMapper.marshal(softwareFacet);
|
||||
//
|
||||
// // Trying to recreate SoftwareFacet
|
||||
// FacetManagement softwareFacetManagement = new FacetManagement();
|
||||
// softwareFacetManagement.setElementType(SoftwareFacet.NAME);
|
||||
// softwareFacetManagement.setJson(softwareFacetString);
|
||||
// try{
|
||||
// softwareFacetManagement.create();
|
||||
// }catch (FacetAlreadyPresentException e) {
|
||||
// // OK
|
||||
// logger.debug("As expected {} cannot be recreated", softwareFacetString, e);
|
||||
// }catch (Exception e) {
|
||||
// throw e;
|
||||
// }
|
||||
|
||||
|
||||
// Trying to recreate EService
|
||||
|
|
Loading…
Reference in New Issue