Reorganizing code
This commit is contained in:
parent
35be405f8e
commit
dc481fbba6
|
@ -127,8 +127,11 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
||||||
this.operation = null;
|
this.operation = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setAsEntryPoint(Operation operation) {
|
protected void setAsEntryPoint() {
|
||||||
this.entryPoint = true;
|
this.entryPoint = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOperation(Operation operation) {
|
||||||
this.operation = operation;
|
this.operation = operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,6 +386,8 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
||||||
|
|
||||||
public El internalCreate() throws AlreadyPresentException, ResourceRegistryException {
|
public El internalCreate() throws AlreadyPresentException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
|
setOperation(Operation.CREATE);
|
||||||
|
|
||||||
reallyCreate();
|
reallyCreate();
|
||||||
|
|
||||||
Header entityHeader = HeaderUtility.getHeader(jsonNode, true);
|
Header entityHeader = HeaderUtility.getHeader(jsonNode, true);
|
||||||
|
@ -411,6 +416,7 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
||||||
|
|
||||||
public El internalUpdate() throws NotFoundException, ResourceRegistryException {
|
public El internalUpdate() throws NotFoundException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
|
setOperation(Operation.UPDATE);
|
||||||
|
|
||||||
reallyUpdate();
|
reallyUpdate();
|
||||||
|
|
||||||
|
@ -439,7 +445,7 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
||||||
protected abstract boolean reallyDelete() throws NotFoundException, ResourceRegistryException;
|
protected abstract boolean reallyDelete() throws NotFoundException, ResourceRegistryException;
|
||||||
|
|
||||||
public boolean internalDelete() throws NotFoundException, ResourceRegistryException {
|
public boolean internalDelete() throws NotFoundException, ResourceRegistryException {
|
||||||
// Added for consistency with create and update addToContext removeFromContext.
|
setOperation(Operation.DELETE);
|
||||||
return reallyDelete();
|
return reallyDelete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -509,10 +515,11 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
||||||
public abstract String reallyGetAll(boolean polymorphic) throws ResourceRegistryException;
|
public abstract String reallyGetAll(boolean polymorphic) throws ResourceRegistryException;
|
||||||
|
|
||||||
public String all(boolean polymorphic) throws ResourceRegistryException {
|
public String all(boolean polymorphic) throws ResourceRegistryException {
|
||||||
setAsEntryPoint(Operation.QUERY);
|
|
||||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||||
try {
|
try {
|
||||||
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.READER);
|
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.READER);
|
||||||
|
setAsEntryPoint();
|
||||||
|
setOperation(Operation.QUERY);
|
||||||
return reallyGetAll(polymorphic);
|
return reallyGetAll(polymorphic);
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -530,10 +537,11 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean exists() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
public boolean exists() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||||
setAsEntryPoint(Operation.EXISTS);
|
|
||||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||||
try {
|
try {
|
||||||
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.READER);
|
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.READER);
|
||||||
|
setAsEntryPoint();
|
||||||
|
setOperation(Operation.EXISTS);
|
||||||
|
|
||||||
getElement();
|
getElement();
|
||||||
|
|
||||||
|
@ -563,12 +571,12 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
||||||
oDatabaseDocument.begin();
|
oDatabaseDocument.begin();
|
||||||
boolean update = false;
|
boolean update = false;
|
||||||
try {
|
try {
|
||||||
setAsEntryPoint(Operation.UPDATE);
|
setAsEntryPoint();
|
||||||
getElement();
|
getElement();
|
||||||
update = true;
|
update = true;
|
||||||
internalUpdate();
|
internalUpdate();
|
||||||
} catch(NotFoundException e) {
|
} catch(NotFoundException e) {
|
||||||
setAsEntryPoint(Operation.CREATE);
|
setAsEntryPoint();
|
||||||
String calledMethod = CalledMethodProvider.instance.get();
|
String calledMethod = CalledMethodProvider.instance.get();
|
||||||
calledMethod = calledMethod.replace("update", "create");
|
calledMethod = calledMethod.replace("update", "create");
|
||||||
CalledMethodProvider.instance.set(calledMethod);
|
CalledMethodProvider.instance.set(calledMethod);
|
||||||
|
@ -609,11 +617,12 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String create() throws AlreadyPresentException, ResourceRegistryException {
|
public String create() throws AlreadyPresentException, ResourceRegistryException {
|
||||||
setAsEntryPoint(Operation.CREATE);
|
|
||||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||||
try {
|
try {
|
||||||
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.WRITER);
|
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||||
oDatabaseDocument.begin();
|
oDatabaseDocument.begin();
|
||||||
|
setAsEntryPoint();
|
||||||
|
|
||||||
internalCreate();
|
internalCreate();
|
||||||
|
|
||||||
|
@ -647,11 +656,14 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String read() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
public String read() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||||
setAsEntryPoint(Operation.READ);
|
|
||||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||||
try {
|
try {
|
||||||
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.READER);
|
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.READER);
|
||||||
|
|
||||||
|
setAsEntryPoint();
|
||||||
|
setOperation(Operation.READ);
|
||||||
|
|
||||||
getElement();
|
getElement();
|
||||||
|
|
||||||
return serializeAsJsonNode().toString();
|
return serializeAsJsonNode().toString();
|
||||||
|
@ -673,12 +685,13 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String update() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
public String update() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||||
setAsEntryPoint(Operation.UPDATE);
|
|
||||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||||
try {
|
try {
|
||||||
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.WRITER);
|
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||||
oDatabaseDocument.begin();
|
oDatabaseDocument.begin();
|
||||||
|
|
||||||
|
setAsEntryPoint();
|
||||||
internalUpdate();
|
internalUpdate();
|
||||||
|
|
||||||
oDatabaseDocument.commit();
|
oDatabaseDocument.commit();
|
||||||
|
@ -713,14 +726,14 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean delete() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
public boolean delete() throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||||
setAsEntryPoint(Operation.DELETE);
|
|
||||||
logger.debug("Going to delete {} with UUID {}", accessType.getName(), uuid);
|
logger.debug("Going to delete {} with UUID {}", accessType.getName(), uuid);
|
||||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||||
try {
|
try {
|
||||||
oDatabaseDocument = ContextUtility.getAdminSecurityContext().getDatabaseDocument(PermissionMode.WRITER);
|
oDatabaseDocument = ContextUtility.getAdminSecurityContext().getDatabaseDocument(PermissionMode.WRITER);
|
||||||
oDatabaseDocument.begin();
|
oDatabaseDocument.begin();
|
||||||
|
setAsEntryPoint();
|
||||||
|
|
||||||
boolean deleted = reallyDelete();
|
boolean deleted = internalDelete();
|
||||||
|
|
||||||
if(deleted) {
|
if(deleted) {
|
||||||
oDatabaseDocument.commit();
|
oDatabaseDocument.commit();
|
||||||
|
@ -757,13 +770,15 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
||||||
|
|
||||||
|
|
||||||
public Set<String> getContextsSet() throws NotFoundException, ContextException, ResourceRegistryException {
|
public Set<String> getContextsSet() throws NotFoundException, ContextException, ResourceRegistryException {
|
||||||
setAsEntryPoint(Operation.GET_METADATA);
|
|
||||||
logger.debug("Going to get contexts for {} with UUID", typeName, uuid);
|
logger.debug("Going to get contexts for {} with UUID", typeName, uuid);
|
||||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||||
try {
|
try {
|
||||||
AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext();
|
AdminSecurityContext adminSecurityContext = ContextUtility.getAdminSecurityContext();
|
||||||
oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.READER);
|
oDatabaseDocument = adminSecurityContext.getDatabaseDocument(PermissionMode.READER);
|
||||||
|
|
||||||
|
setAsEntryPoint();
|
||||||
|
setOperation(Operation.GET_METADATA);
|
||||||
|
|
||||||
Set<String> contexts = SecurityContext.getContexts(getElement());
|
Set<String> contexts = SecurityContext.getContexts(getElement());
|
||||||
return contexts;
|
return contexts;
|
||||||
} catch(ResourceRegistryException e) {
|
} catch(ResourceRegistryException e) {
|
||||||
|
|
|
@ -187,16 +187,15 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
|
||||||
/*
|
/*
|
||||||
* It works perfectly in case of any kind of update. In case of use from create
|
* It works perfectly in case of any kind of update. In case of use from create
|
||||||
* the cache does not work by using the ID because until commit the edge has a
|
* the cache does not work by using the ID because until commit the edge has a
|
||||||
* fake id starting with - (minus) sign. This not imply any collateral effect
|
* fake id starting with - (minus) sign. This not imply any collateral effect
|
||||||
* but a better solution is a desiderata.
|
* but a better solution is a desiderata.
|
||||||
*/
|
*/
|
||||||
protected RelationManagement getRelationManagement(OEdge edge) throws ResourceRegistryException {
|
protected RelationManagement<?,?> getRelationManagement(OEdge edge) throws ResourceRegistryException {
|
||||||
String id = edge.getIdentity().toString();
|
String id = edge.getIdentity().toString();
|
||||||
RelationManagement relationManagement = relationManagements.get(id);
|
RelationManagement<?,?> relationManagement = relationManagements.get(id);
|
||||||
if(relationManagement == null) {
|
if(relationManagement == null) {
|
||||||
relationManagement = ElementManagementUtility.getRelationManagement(getWorkingContext(), oDatabaseDocument, edge);
|
relationManagement = ElementManagementUtility.getRelationManagement(getWorkingContext(), oDatabaseDocument, edge);
|
||||||
relationManagements.put(id, relationManagement);
|
relationManagements.put(id, relationManagement);
|
||||||
|
@ -332,6 +331,7 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
||||||
public Map<UUID,JsonNode> internalAddToContext()
|
public Map<UUID,JsonNode> internalAddToContext()
|
||||||
throws ContextException, ResourceRegistryException {
|
throws ContextException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
|
setOperation(Operation.ADD_TO_CONTEXT);
|
||||||
Map<UUID,JsonNode> affectedInstances = reallyAddToContext();
|
Map<UUID,JsonNode> affectedInstances = reallyAddToContext();
|
||||||
if(!dryRunContextSharing) {
|
if(!dryRunContextSharing) {
|
||||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||||
|
@ -348,13 +348,13 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<UUID,JsonNode> addToContext(UUID contextUUID) throws SchemaViolationException, NotFoundException, ContextException, ResourceRegistryException {
|
public Map<UUID,JsonNode> addToContext(UUID contextUUID) throws SchemaViolationException, NotFoundException, ContextException, ResourceRegistryException {
|
||||||
setAsEntryPoint(Operation.ADD_TO_CONTEXT);
|
|
||||||
logger.info("Going to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid, contextUUID);
|
logger.info("Going to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid, contextUUID);
|
||||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||||
try {
|
try {
|
||||||
workingContext = ContextUtility.getAdminSecurityContext();
|
workingContext = ContextUtility.getAdminSecurityContext();
|
||||||
oDatabaseDocument = workingContext.getDatabaseDocument(PermissionMode.WRITER);
|
oDatabaseDocument = workingContext.getDatabaseDocument(PermissionMode.WRITER);
|
||||||
oDatabaseDocument.begin();
|
oDatabaseDocument.begin();
|
||||||
|
setAsEntryPoint();
|
||||||
|
|
||||||
targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||||
|
|
||||||
|
@ -393,6 +393,7 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
||||||
public Map<UUID,JsonNode> internalRemoveFromContext()
|
public Map<UUID,JsonNode> internalRemoveFromContext()
|
||||||
throws ContextException, ResourceRegistryException {
|
throws ContextException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
|
setOperation(Operation.REMOVE_FROM_CONTEXT);
|
||||||
Map<UUID,JsonNode> affectedInstances = reallyRemoveFromContext();
|
Map<UUID,JsonNode> affectedInstances = reallyRemoveFromContext();
|
||||||
if(!dryRunContextSharing) {
|
if(!dryRunContextSharing) {
|
||||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||||
|
@ -440,13 +441,14 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
||||||
|
|
||||||
public Map<UUID,JsonNode> removeFromContext(UUID contextUUID)
|
public Map<UUID,JsonNode> removeFromContext(UUID contextUUID)
|
||||||
throws SchemaViolationException, NotFoundException, ContextException, ResourceRegistryException {
|
throws SchemaViolationException, NotFoundException, ContextException, ResourceRegistryException {
|
||||||
setAsEntryPoint(Operation.REMOVE_FROM_CONTEXT);
|
|
||||||
logger.debug("Going to remove {} with UUID {} from Context with UUID {}", typeName, uuid, contextUUID);
|
logger.debug("Going to remove {} with UUID {} from Context with UUID {}", typeName, uuid, contextUUID);
|
||||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||||
try {
|
try {
|
||||||
workingContext = ContextUtility.getAdminSecurityContext();
|
workingContext = ContextUtility.getAdminSecurityContext();
|
||||||
oDatabaseDocument = workingContext.getDatabaseDocument(PermissionMode.WRITER);
|
oDatabaseDocument = workingContext.getDatabaseDocument(PermissionMode.WRITER);
|
||||||
oDatabaseDocument.begin();
|
oDatabaseDocument.begin();
|
||||||
|
setAsEntryPoint();
|
||||||
|
|
||||||
targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||||
|
|
||||||
|
@ -796,9 +798,14 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
||||||
|
|
||||||
public String query(String relationType, String referenceType, UUID referenceUUID, ODirection direction,
|
public String query(String relationType, String referenceType, UUID referenceUUID, ODirection direction,
|
||||||
boolean polymorphic, Map<String,String> constraint, boolean includeRelationInResult) throws ResourceRegistryException {
|
boolean polymorphic, Map<String,String> constraint, boolean includeRelationInResult) throws ResourceRegistryException {
|
||||||
|
|
||||||
|
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||||
try {
|
try {
|
||||||
setAsEntryPoint(Operation.QUERY);
|
workingContext = ContextUtility.getAdminSecurityContext();
|
||||||
oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.READER);
|
oDatabaseDocument = workingContext.getDatabaseDocument(PermissionMode.READER);
|
||||||
|
|
||||||
|
setAsEntryPoint();
|
||||||
|
setOperation(Operation.QUERY);
|
||||||
|
|
||||||
TypesCache typesCache = TypesCache.getInstance();
|
TypesCache typesCache = TypesCache.getInstance();
|
||||||
AccessType relationAccessType = typesCache.getCachedType(relationType).getAccessType();
|
AccessType relationAccessType = typesCache.getCachedType(relationType).getAccessType();
|
||||||
|
@ -861,6 +868,9 @@ public abstract class EntityManagement<E extends Entity, ET extends EntityType>
|
||||||
if(oDatabaseDocument != null) {
|
if(oDatabaseDocument != null) {
|
||||||
oDatabaseDocument.close();
|
oDatabaseDocument.close();
|
||||||
}
|
}
|
||||||
|
if(current!=null) {
|
||||||
|
current.activateOnCurrentThread();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -105,6 +105,7 @@ public class FacetManagement extends EntityManagement<Facet, FacetType> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resourceManagement.setOperation(operation);
|
||||||
resourceManagement.sanityCheck();
|
resourceManagement.sanityCheck();
|
||||||
|
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
|
|
|
@ -267,10 +267,11 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
|
||||||
relationManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
|
relationManagement.setHonourPropagationConstraintsInContextSharing(honourPropagationConstraintsInContextSharing);
|
||||||
relationManagement.setTargetSecurityContext(targetSecurityContext);
|
relationManagement.setTargetSecurityContext(targetSecurityContext);
|
||||||
Map<UUID,JsonNode> resourceCharacterisationInstances = relationManagement.internalAddToContext();
|
Map<UUID,JsonNode> resourceCharacterisationInstances = relationManagement.internalAddToContext();
|
||||||
|
affectedInstances.putAll(resourceCharacterisationInstances);
|
||||||
if(relationManagement instanceof ConsistsOfManagement) {
|
if(relationManagement instanceof ConsistsOfManagement) {
|
||||||
facetCounter = facetCounter + resourceCharacterisationInstances.size();
|
facetCounter = facetCounter + resourceCharacterisationInstances.size();
|
||||||
}
|
}
|
||||||
affectedInstances.putAll(resourceCharacterisationInstances);
|
relationManagement.sanityCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(facetCounter == 0) {
|
if(facetCounter == 0) {
|
||||||
|
@ -390,11 +391,6 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void sanityCheck() throws SchemaViolationException, ResourceRegistryException {
|
public void sanityCheck() throws SchemaViolationException, ResourceRegistryException {
|
||||||
/*
|
|
||||||
cleanCachedSerialization();
|
|
||||||
JsonNode resourceInstance = createCompleteJsonNode();
|
|
||||||
*/
|
|
||||||
|
|
||||||
TypesCache typesCache = TypesCache.getInstance();
|
TypesCache typesCache = TypesCache.getInstance();
|
||||||
|
|
||||||
Set<LinkedEntity> consistsOfFacetConstraints = getResourceTypeConstraint();
|
Set<LinkedEntity> consistsOfFacetConstraints = getResourceTypeConstraint();
|
||||||
|
@ -403,8 +399,6 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
|
||||||
|
|
||||||
Iterable<OEdge> edges = getElement().getEdges(ODirection.OUT);
|
Iterable<OEdge> edges = getElement().getEdges(ODirection.OUT);
|
||||||
|
|
||||||
//ArrayNode consistsOfArrayNode = (ArrayNode) resourceInstance.get(Resource.CONSISTS_OF_PROPERTY);
|
|
||||||
//for(JsonNode consistsOfJsonNode : consistsOfArrayNode) {
|
|
||||||
for(OEdge edge : edges) {
|
for(OEdge edge : edges) {
|
||||||
RelationManagement<?,?> relationManagement = getRelationManagement(edge);
|
RelationManagement<?,?> relationManagement = getRelationManagement(edge);
|
||||||
if(!(relationManagement instanceof ConsistsOfManagement)) {
|
if(!(relationManagement instanceof ConsistsOfManagement)) {
|
||||||
|
@ -413,10 +407,6 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
|
||||||
String consistsOfType = relationManagement.getTypeName();
|
String consistsOfType = relationManagement.getTypeName();
|
||||||
String facetType = relationManagement.getTargetEntityManagement().getTypeName();
|
String facetType = relationManagement.getTargetEntityManagement().getTypeName();
|
||||||
|
|
||||||
// String consistsOfType = consistsOfJsonNode.get(Element.CLASS_PROPERTY).asText();
|
|
||||||
// JsonNode facetJsonNode = consistsOfJsonNode.get(Relation.TARGET_PROPERTY);
|
|
||||||
// String facetType = facetJsonNode.get(Element.CLASS_PROPERTY).asText();
|
|
||||||
|
|
||||||
for(LinkedEntity constraint : consistsOfFacetConstraints) {
|
for(LinkedEntity constraint : consistsOfFacetConstraints) {
|
||||||
if(constraintSatisfied(typesCache, constraint, consistsOfType, facetType)) {
|
if(constraintSatisfied(typesCache, constraint, consistsOfType, facetType)) {
|
||||||
Integer integer = satisfiedConsistsOfFacet.get(constraint);
|
Integer integer = satisfiedConsistsOfFacet.get(constraint);
|
||||||
|
|
|
@ -491,6 +491,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
public Map<UUID,JsonNode> internalAddToContext()
|
public Map<UUID,JsonNode> internalAddToContext()
|
||||||
throws ContextException, ResourceRegistryException {
|
throws ContextException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
|
operation = Operation.ADD_TO_CONTEXT;
|
||||||
Map<UUID,JsonNode> affectedInstances = reallyAddToContext();
|
Map<UUID,JsonNode> affectedInstances = reallyAddToContext();
|
||||||
if(propagationConstraint.getAddConstraint()==PropagationConstraint.AddConstraint.propagate) {
|
if(propagationConstraint.getAddConstraint()==PropagationConstraint.AddConstraint.propagate) {
|
||||||
if(!dryRunContextSharing) {
|
if(!dryRunContextSharing) {
|
||||||
|
@ -512,6 +513,8 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
throws ContextException, ResourceRegistryException {
|
throws ContextException, ResourceRegistryException {
|
||||||
getElement();
|
getElement();
|
||||||
|
|
||||||
|
setOperation(Operation.ADD_TO_CONTEXT);
|
||||||
|
|
||||||
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
|
Map<UUID,JsonNode> affectedInstances = new HashMap<>();
|
||||||
|
|
||||||
/* Adding source to Context */
|
/* Adding source to Context */
|
||||||
|
@ -537,12 +540,12 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<UUID,JsonNode> addToContext(UUID contextUUID) throws NotFoundException, ContextException {
|
public Map<UUID,JsonNode> addToContext(UUID contextUUID) throws NotFoundException, ContextException {
|
||||||
setAsEntryPoint(Operation.ADD_TO_CONTEXT);
|
|
||||||
logger.debug("Going to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid, contextUUID);
|
logger.debug("Going to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid, contextUUID);
|
||||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||||
try {
|
try {
|
||||||
workingContext = ContextUtility.getAdminSecurityContext();
|
workingContext = ContextUtility.getAdminSecurityContext();
|
||||||
oDatabaseDocument = workingContext.getDatabaseDocument(PermissionMode.WRITER);
|
oDatabaseDocument = workingContext.getDatabaseDocument(PermissionMode.WRITER);
|
||||||
|
setAsEntryPoint();
|
||||||
|
|
||||||
targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||||
|
|
||||||
|
@ -663,6 +666,7 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
public Map<UUID,JsonNode> internalRemoveFromContext()
|
public Map<UUID,JsonNode> internalRemoveFromContext()
|
||||||
throws ContextException, ResourceRegistryException {
|
throws ContextException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
|
setOperation(Operation.REMOVE_FROM_CONTEXT);
|
||||||
Map<UUID,JsonNode> affectedInstances = reallyRemoveFromContext();
|
Map<UUID,JsonNode> affectedInstances = reallyRemoveFromContext();
|
||||||
if(!dryRunContextSharing) {
|
if(!dryRunContextSharing) {
|
||||||
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
HeaderUtility.updateModifiedByAndLastUpdate(element);
|
||||||
|
@ -680,13 +684,13 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
||||||
|
|
||||||
public Map<UUID,JsonNode> removeFromContext(UUID contextUUID)
|
public Map<UUID,JsonNode> removeFromContext(UUID contextUUID)
|
||||||
throws NotFoundException, ContextException, ResourceRegistryException {
|
throws NotFoundException, ContextException, ResourceRegistryException {
|
||||||
setAsEntryPoint(Operation.REMOVE_FROM_CONTEXT);
|
|
||||||
logger.debug("Going to remove {} with UUID {} from Context with UUID {}", typeName, uuid, contextUUID);
|
logger.debug("Going to remove {} with UUID {} from Context with UUID {}", typeName, uuid, contextUUID);
|
||||||
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
|
||||||
try {
|
try {
|
||||||
workingContext = ContextUtility.getAdminSecurityContext();
|
workingContext = ContextUtility.getAdminSecurityContext();
|
||||||
oDatabaseDocument = workingContext.getDatabaseDocument(PermissionMode.WRITER);
|
oDatabaseDocument = workingContext.getDatabaseDocument(PermissionMode.WRITER);
|
||||||
oDatabaseDocument.begin();
|
oDatabaseDocument.begin();
|
||||||
|
setAsEntryPoint();
|
||||||
|
|
||||||
targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID);
|
||||||
|
|
||||||
|
|
|
@ -150,22 +150,9 @@ public class BasicTest extends MultiContextTest {
|
||||||
Assert.assertTrue(deleted);
|
Assert.assertTrue(deleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = ResourceRegistryException.class)
|
@Test
|
||||||
public void testResourceWithOnlyOneFacet() throws Exception {
|
public void testResource() throws Exception {
|
||||||
EService eService = new EServiceImpl();
|
EService eService = ERManagementTest.instantiateValidEService();
|
||||||
|
|
||||||
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
|
|
||||||
softwareFacet.setGroup("InformationSystem");
|
|
||||||
softwareFacet.setName("resource-registry");
|
|
||||||
softwareFacet.setVersion("1.1.0");
|
|
||||||
|
|
||||||
PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
|
|
||||||
propagationConstraint.setAddConstraint(AddConstraint.unpropagate);
|
|
||||||
propagationConstraint.setRemoveConstraint(RemoveConstraint.cascade);
|
|
||||||
|
|
||||||
IsIdentifiedBy<EService, Facet> isIdentifiedBy = new IsIdentifiedByImpl<EService, Facet>(
|
|
||||||
eService, softwareFacet, propagationConstraint);
|
|
||||||
eService.addFacet(isIdentifiedBy);
|
|
||||||
|
|
||||||
ResourceManagement resourceManagement = new ResourceManagement();
|
ResourceManagement resourceManagement = new ResourceManagement();
|
||||||
resourceManagement.setElementType(EService.NAME);
|
resourceManagement.setElementType(EService.NAME);
|
||||||
|
@ -180,7 +167,9 @@ public class BasicTest extends MultiContextTest {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
addToContextThenTestIfBehaveProperly(eService, true, ALTERNATIVE_TEST_SCOPE);
|
addToContextThenTestIfBehaveProperly(eService, true, ALTERNATIVE_TEST_SCOPE);
|
||||||
}finally {
|
} catch (Exception e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
UUID eServiceUUID = eService.getHeader().getUUID();
|
UUID eServiceUUID = eService.getHeader().getUUID();
|
||||||
resourceManagement = new ResourceManagement();
|
resourceManagement = new ResourceManagement();
|
||||||
resourceManagement.setUUID(eServiceUUID);
|
resourceManagement.setUUID(eServiceUUID);
|
||||||
|
|
Loading…
Reference in New Issue