Improving code
This commit is contained in:
parent
d58dcc20cf
commit
151ad9add4
|
@ -173,7 +173,7 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
|||
checkJsonNode();
|
||||
}
|
||||
|
||||
public void setoDatabaseDocument(ODatabaseDocument oDatabaseDocument) {
|
||||
public void setODatabaseDocument(ODatabaseDocument oDatabaseDocument) {
|
||||
this.oDatabaseDocument = oDatabaseDocument;
|
||||
}
|
||||
|
||||
|
|
|
@ -151,7 +151,7 @@ public class ElementManagementUtility {
|
|||
Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||
throw new ResourceRegistryException(error);
|
||||
}
|
||||
entityManagement.setoDatabaseDocument(oDatabaseDocument);
|
||||
entityManagement.setODatabaseDocument(oDatabaseDocument);
|
||||
entityManagement.setWorkingContext(workingContext);
|
||||
entityManagement.setElement(vertex);
|
||||
return entityManagement;
|
||||
|
@ -185,7 +185,7 @@ public class ElementManagementUtility {
|
|||
}
|
||||
|
||||
|
||||
relationManagement.setoDatabaseDocument(oDatabaseDocument);
|
||||
relationManagement.setODatabaseDocument(oDatabaseDocument);
|
||||
relationManagement.setWorkingContext(workingContext);
|
||||
|
||||
relationManagement.setElement(edge);
|
||||
|
|
|
@ -193,7 +193,7 @@ public abstract class RelationElementManagement<SEM extends EntityElementManagem
|
|||
if(target != null) {
|
||||
FacetManagement fm = new FacetManagement();
|
||||
fm.setWorkingContext(getWorkingContext());
|
||||
fm.setoDatabaseDocument(oDatabaseDocument);
|
||||
fm.setODatabaseDocument(oDatabaseDocument);
|
||||
fm.setJsonNode(target);
|
||||
fm.internalUpdate();
|
||||
}
|
||||
|
|
|
@ -34,7 +34,8 @@ public interface ERManagement {
|
|||
throws SchemaViolationException, NotFoundException, ContextException, ResourceRegistryException;
|
||||
|
||||
public void sanityCheck() throws SchemaViolationException, ResourceRegistryException;
|
||||
//public void sanityCheck(Map<UUID, JsonNode> expectedInstances) throws SchemaViolationException, ResourceRegistryException;
|
||||
|
||||
// public void contextSanityCheck(SecurityContext target, Map<UUID, JsonNode> expectedInstances) throws SchemaViolationException, ResourceRegistryException;
|
||||
|
||||
public AvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(String message);
|
||||
|
||||
|
|
|
@ -38,35 +38,39 @@ public class ERManagementUtility {
|
|||
|
||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
|
||||
// Map<UUID, JsonNode> enforcedInstances = new HashMap<>();
|
||||
|
||||
Map<UUID, ElementManagement<?,?>> instancesManagement = new HashMap<>();
|
||||
for(UUID uuid : expectedInstances.keySet()) {
|
||||
Set<UUID> uuids = expectedInstances.keySet();
|
||||
for(UUID uuid : uuids) {
|
||||
String type = expectedInstances.get(uuid).get(Element.CLASS_PROPERTY).asText();
|
||||
ElementManagement<?,?> elementManagement = ElementManagementUtility.getERManagement(type);
|
||||
elementManagement.setWorkingContext(adminSecurityContext);
|
||||
elementManagement.setoDatabaseDocument(oDatabaseDocument);
|
||||
elementManagement.setODatabaseDocument(oDatabaseDocument);
|
||||
elementManagement.setUUID(uuid);
|
||||
elementManagement.setElementType(type);
|
||||
((ERManagement) elementManagement).setHonourPropagationConstraintsInContextSharing(false);
|
||||
((ERManagement) elementManagement).setDryRunContextSharing(dryRun);
|
||||
// enforcedInstances.putAll(((ERManagement) elementManagement).internalAddToContext(targetSecurityContext));
|
||||
((ERManagement) elementManagement).internalAddToContext(targetSecurityContext);
|
||||
instancesManagement.put(uuid, elementManagement);
|
||||
}
|
||||
|
||||
for(UUID uuid : expectedInstances.keySet()) {
|
||||
/*
|
||||
for(UUID uuid : uuids) {
|
||||
ElementManagement<?,?> elementManagement = instancesManagement.get(uuid);
|
||||
// TODO
|
||||
elementManagement.sanityCheck();
|
||||
((ERManagement) elementManagement).contextSanityCheck(targetSecurityContext, expectedInstances);
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
Map<UUID,JsonNode> expectedAdditionaInstances = new HashMap<>();
|
||||
SharingOperationValidator operationValidator = new SharingOperationValidator(expectedInstances, SharingOperation.ADD);
|
||||
|
||||
if(operationValidator.isValidOperation(affectedInstances)) {
|
||||
if(operationValidator.isValidOperation(enforcedInstances)) {
|
||||
oDatabaseDocument.commit();
|
||||
}
|
||||
*/
|
||||
|
||||
oDatabaseDocument.activateOnCurrentThread();
|
||||
oDatabaseDocument.commit();
|
||||
staticLogger.info("{} successfully added to Context with UUID {} not following Propagation Constraints", instances, contextUUID);
|
||||
|
||||
|
@ -113,15 +117,18 @@ public class ERManagementUtility {
|
|||
|
||||
SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||
|
||||
//Map<UUID, JsonNode> enforcedInstances = new HashMap<>();
|
||||
|
||||
Map<UUID, ElementManagement<?,?>> instancesManagement = new HashMap<>();
|
||||
for(UUID uuid : expectedInstances.keySet()) {
|
||||
String type = expectedInstances.get(uuid).get(Element.CLASS_PROPERTY).asText();
|
||||
ElementManagement<?,?> elementManagement = ElementManagementUtility.getERManagement(type);
|
||||
elementManagement.setWorkingContext(adminSecurityContext);
|
||||
elementManagement.setoDatabaseDocument(oDatabaseDocument);
|
||||
elementManagement.setODatabaseDocument(oDatabaseDocument);
|
||||
elementManagement.setUUID(uuid);
|
||||
((ERManagement) elementManagement).setHonourPropagationConstraintsInContextSharing(false);
|
||||
((ERManagement) elementManagement).setDryRunContextSharing(dryRun);
|
||||
//enforcedInstances.putAll(((ERManagement) elementManagement).internalRemoveFromContext(targetSecurityContext));
|
||||
((ERManagement) elementManagement).internalRemoveFromContext(targetSecurityContext);
|
||||
instancesManagement.put(uuid, elementManagement);
|
||||
}
|
||||
|
@ -135,11 +142,12 @@ public class ERManagementUtility {
|
|||
/*
|
||||
SharingOperationValidator operationValidator = new SharingOperationValidator(expectedInstances, SharingOperation.REMOVE);
|
||||
|
||||
if(operationValidator.isValidOperation(affectedInstances)) {
|
||||
if(operationValidator.isValidOperation(enforcedInstances)) {
|
||||
oDatabaseDocument.commit();
|
||||
}
|
||||
*/
|
||||
|
||||
oDatabaseDocument.commit();
|
||||
staticLogger.info("{} successfully removed from Context with UUID {} not following Propagation Constraints", instances, contextUUID);
|
||||
|
||||
/*
|
||||
|
|
|
@ -438,6 +438,8 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
|||
|
||||
Map<UUID,JsonNode> affectedInstances = internalRemoveFromContext(targetSecurityContext);
|
||||
|
||||
// check here
|
||||
|
||||
oDatabaseDocument.commit();
|
||||
logger.info("{} with UUID {} successfully removed from Context with UUID {}", typeName, uuid, contextUUID);
|
||||
|
||||
|
|
|
@ -146,7 +146,7 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
|
|||
for(JsonNode consistOfJsonNode : jsonNodeArray) {
|
||||
ConsistsOfManagement com = new ConsistsOfManagement();
|
||||
com.setWorkingContext(getWorkingContext());
|
||||
com.setoDatabaseDocument(oDatabaseDocument);
|
||||
com.setODatabaseDocument(oDatabaseDocument);
|
||||
com.setJsonNode(consistOfJsonNode);
|
||||
com.setSourceEntityManagement(this);
|
||||
com.internalCreate();
|
||||
|
@ -160,7 +160,7 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
|
|||
for(JsonNode relationJsonNode : jsonNodeArray) {
|
||||
IsRelatedToManagement irtm = new IsRelatedToManagement();
|
||||
irtm.setWorkingContext(getWorkingContext());
|
||||
irtm.setoDatabaseDocument(oDatabaseDocument);
|
||||
irtm.setODatabaseDocument(oDatabaseDocument);
|
||||
irtm.setJsonNode(relationJsonNode);
|
||||
irtm.setSourceEntityManagement(this);
|
||||
irtm.internalCreate();
|
||||
|
@ -182,7 +182,7 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
|
|||
for(JsonNode relationJsonNode : jsonNodeArray) {
|
||||
ConsistsOfManagement com = new ConsistsOfManagement();
|
||||
com.setWorkingContext(getWorkingContext());
|
||||
com.setoDatabaseDocument(oDatabaseDocument);
|
||||
com.setODatabaseDocument(oDatabaseDocument);
|
||||
com.setJsonNode(relationJsonNode);
|
||||
com.internalCreateOrUdate();
|
||||
addToRelationManagement(com);
|
||||
|
@ -195,7 +195,7 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
|
|||
for(JsonNode relationJsonNode : jsonNodeArray) {
|
||||
IsRelatedToManagement irtm = new IsRelatedToManagement();
|
||||
irtm.setWorkingContext(getWorkingContext());
|
||||
irtm.setoDatabaseDocument(oDatabaseDocument);
|
||||
irtm.setODatabaseDocument(oDatabaseDocument);
|
||||
irtm.setJsonNode(relationJsonNode);
|
||||
irtm.internalUpdate();
|
||||
addToRelationManagement(irtm);
|
||||
|
@ -231,7 +231,7 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
|
|||
}
|
||||
if(relationManagement != null) {
|
||||
relationManagement.setWorkingContext(getWorkingContext());
|
||||
relationManagement.setoDatabaseDocument(oDatabaseDocument);
|
||||
relationManagement.setODatabaseDocument(oDatabaseDocument);
|
||||
relationManagement.setElement(edge);
|
||||
relationManagement.internalDelete();
|
||||
}
|
||||
|
@ -474,8 +474,16 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
|
|||
stringBuffer.append(").");
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
@Override
|
||||
public void contextSanityCheck(SecurityContext targetSecurityContext, Map<UUID, JsonNode> expectedInstances) throws SchemaViolationException, ResourceRegistryException {
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
public void sanityCheck(Map<UUID, JsonNode> expectedInstances) throws SchemaViolationException, ResourceRegistryException {
|
||||
JsonNode resourceInstance = createCompleteJsonNode();
|
||||
|
||||
|
@ -575,5 +583,4 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
|
|||
}
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ public class ConsistsOfManagement extends RelationManagement<FacetManagement, Fa
|
|||
@Override
|
||||
protected FacetManagement newTargetEntityManagement() throws ResourceRegistryException {
|
||||
FacetManagement facetManagement = new FacetManagement();
|
||||
facetManagement.setoDatabaseDocument(oDatabaseDocument);
|
||||
facetManagement.setODatabaseDocument(oDatabaseDocument);
|
||||
facetManagement.setWorkingContext(getWorkingContext());
|
||||
return facetManagement;
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ public class IsRelatedToManagement extends RelationManagement<ResourceManagement
|
|||
protected ResourceManagement newTargetEntityManagement() throws ResourceRegistryException {
|
||||
ResourceManagement resourceManagement = new ResourceManagement();
|
||||
resourceManagement.setWorkingContext(getWorkingContext());
|
||||
resourceManagement.setoDatabaseDocument(oDatabaseDocument);
|
||||
resourceManagement.setODatabaseDocument(oDatabaseDocument);
|
||||
return resourceManagement;
|
||||
}
|
||||
|
||||
|
|
|
@ -335,7 +335,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
protected ResourceManagement newSourceEntityManagement() throws ResourceRegistryException {
|
||||
ResourceManagement resourceManagement = new ResourceManagement();
|
||||
resourceManagement.setWorkingContext(getWorkingContext());
|
||||
resourceManagement.setoDatabaseDocument(oDatabaseDocument);
|
||||
resourceManagement.setODatabaseDocument(oDatabaseDocument);
|
||||
return resourceManagement;
|
||||
}
|
||||
|
||||
|
@ -354,7 +354,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
if(target != null) {
|
||||
FacetManagement facetManagement = new FacetManagement();
|
||||
facetManagement.setWorkingContext(getWorkingContext());
|
||||
facetManagement.setoDatabaseDocument(oDatabaseDocument);
|
||||
facetManagement.setODatabaseDocument(oDatabaseDocument);
|
||||
facetManagement.setJsonNode(target);
|
||||
facetManagement.internalUpdate();
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ public class ConsistsOfTypeDefinitionManagement
|
|||
protected FacetTypeDefinitionManagement newTargetEntityManagement() throws ResourceRegistryException {
|
||||
FacetTypeDefinitionManagement ftdm = new FacetTypeDefinitionManagement();
|
||||
ftdm.setWorkingContext(getWorkingContext());
|
||||
ftdm.setoDatabaseDocument(oDatabaseDocument);
|
||||
ftdm.setODatabaseDocument(oDatabaseDocument);
|
||||
return ftdm;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ public class IsRelatedToTypeDefinitionManagement
|
|||
protected ResourceTypeDefinitionManagement newTargetEntityManagement() throws ResourceRegistryException {
|
||||
ResourceTypeDefinitionManagement rtdm = new ResourceTypeDefinitionManagement();
|
||||
rtdm.setWorkingContext(getWorkingContext());
|
||||
rtdm.setoDatabaseDocument(oDatabaseDocument);
|
||||
rtdm.setODatabaseDocument(oDatabaseDocument);
|
||||
return rtdm;
|
||||
}
|
||||
|
||||
|
|
|
@ -205,7 +205,7 @@ public abstract class RelationTypeDefinitionManagement<T extends EntityTypeDefin
|
|||
protected ResourceTypeDefinitionManagement newSourceEntityManagement() throws ResourceRegistryException {
|
||||
ResourceTypeDefinitionManagement rtdm = new ResourceTypeDefinitionManagement();
|
||||
rtdm.setWorkingContext(getWorkingContext());
|
||||
rtdm.setoDatabaseDocument(oDatabaseDocument);
|
||||
rtdm.setODatabaseDocument(oDatabaseDocument);
|
||||
return rtdm;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue