Skip to content

Commit

Permalink
ACS-5325 Invoke required policy (#2215)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Domenico Sibilio <[email protected]>
  • Loading branch information
2 people authored and GLaditya2024 committed Oct 12, 2023
1 parent c7816d9 commit 4e68ff5
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2020 Alfresco Software Limited
* Copyright (C) 2005 - 2023 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
Expand Down Expand Up @@ -48,19 +48,31 @@ public class NodePropertyFilter extends AbstractNodeEventFilter
ContentModel.PROP_CREATOR,
ContentModel.PROP_CREATED,
ContentModel.PROP_CONTENT);
// These properties should not be excluded from the properties object
private static final Set<QName> ALLOWED_PROPERTIES = Set.of(ContentModel.PROP_CASCADE_TX,
ContentModel.PROP_CASCADE_CRC);

private final List<String> nodeAspectsBlackList;
private final List<String> nodePropertiesBlackList;

public NodePropertyFilter()
{
this.nodeAspectsBlackList = parseFilterList(FILTERED_PROPERTIES);
this.nodePropertiesBlackList = parseFilterList(FILTERED_PROPERTIES);
}

@Override
public Set<QName> getExcludedTypes()
{
Set<QName> result = new HashSet<>(EXCLUDED_TOP_LEVEL_PROPS);
nodeAspectsBlackList.forEach(nodeAspect -> result.addAll(expandTypeDef(nodeAspect)));
nodePropertiesBlackList.forEach(nodeProperty-> result.addAll(expandTypeDef(nodeProperty)));
return result;
}

@Override
public boolean isExcluded(QName qName)
{
if(qName != null && ALLOWED_PROPERTIES.contains(qName)){
return false;
}
return super.isExcluded(qName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2022 Alfresco Software Limited
* Copyright (C) 2005 - 2023 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
Expand Down Expand Up @@ -3203,13 +3203,16 @@ else if (!nodeDAO.hasNodeAspect(childNodeId, ContentModel.ASPECT_AUDITABLE))
// Invoke policy behaviour
invokeBeforeUpdateNode(parentNodeRef);

Map<QName, Serializable> propertiesBefore = nodeDAO.getNodeProperties(parentNodeId);
// Touch the node; it is cm:auditable
boolean changed = nodeDAO.setModifiedProperties(parentNodeId, modifiedDate, modifiedByToPropagate);

if (changed)
{
Map<QName, Serializable> propertiesAfter = nodeDAO.getNodeProperties(parentNodeId);
// Invoke policy behaviour
invokeOnUpdateNode(parentNodeRef);
invokeOnUpdateProperties(parentNodeRef, propertiesBefore, propertiesAfter);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public Map<String, Serializable> answer(InvocationOnMock invocation) throws Thro
{
Object[] args = invocation.getArguments();
Map<String, Serializable> auditMap = (Map<String, Serializable>)args[1];
if ("/alfresco-access/transaction".equals(args[0]))
if ("/alfresco-access/transaction".equals(args[0]) && !"updateNodeProperties".equals(auditMap.get("action")))
{
auditMapList.add(auditMap);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2020 Alfresco Software Limited
* Copyright (C) 2005 - 2023 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
Expand Down Expand Up @@ -77,9 +77,9 @@ public void testAddChildAssociation()
assertEquals(1, childAssociationRefs.size());
assertFalse(childAssociationRefs.get(0).isPrimary());

checkNumOfEvents(3);
checkNumOfEvents(4);

final RepoEvent<EventData<ChildAssociationResource>> childAssocRepoEvent = getRepoEventWithoutWait(3);
final RepoEvent<EventData<ChildAssociationResource>> childAssocRepoEvent = getFilteredEvent(EventType.CHILD_ASSOC_CREATED, 0);

assertEquals("Wrong repo event type.", EventType.CHILD_ASSOC_CREATED.getType(), childAssocRepoEvent.getType());
assertNotNull("Repo event ID is not available.", childAssocRepoEvent.getId());
Expand Down Expand Up @@ -131,7 +131,7 @@ public void testRemoveChildAssociation()
assertEquals(1, childAssociationRefs.size());
assertFalse(childAssociationRefs.get(0).isPrimary());

checkNumOfEvents(3);
checkNumOfEvents(4);

retryingTransactionHelper.doInTransaction(() ->
nodeService.removeChildAssociation(childAssociationRef));
Expand All @@ -141,9 +141,9 @@ public void testRemoveChildAssociation()

assertEquals(0, childAssociationRefs.size());

checkNumOfEvents(4);
checkNumOfEvents(6);

final RepoEvent<EventData<ChildAssociationResource>> childAssocRepoEvent = getRepoEventWithoutWait(4);
final RepoEvent<EventData<ChildAssociationResource>> childAssocRepoEvent = getFilteredEvent(EventType.CHILD_ASSOC_DELETED, 0);

assertEquals("Wrong repo event type.", EventType.CHILD_ASSOC_DELETED.getType(), childAssocRepoEvent.getType());
assertNotNull("Repo event ID is not available. ", childAssocRepoEvent.getId());
Expand Down Expand Up @@ -212,7 +212,7 @@ public void testOneChildListOfParentsAssociations()
return null;
});

checkNumOfEvents(7);
checkNumOfEvents(8);

// 3 assoc.child.Created events should be created

Expand Down Expand Up @@ -268,7 +268,7 @@ public void testOneChildMultipleParentsSameTransaction()
return null;
});

checkNumOfEvents(7);
checkNumOfEvents(8);
// 3 assoc.child.Created events should be created
List<RepoEvent<EventData<ChildAssociationResource>>> childAssocEvents = getFilteredEvents(EventType.CHILD_ASSOC_CREATED);
assertEquals("Wrong association events number",3, childAssocEvents.size());
Expand Down Expand Up @@ -330,7 +330,7 @@ public void testOneChildMultipleParentsDifferentTransaction()
return null;
});

checkNumOfEvents(7);
checkNumOfEvents(10);
// 3 assoc.child.Created events should be created
List<RepoEvent<EventData<ChildAssociationResource>>> childAssocEvents = getFilteredEvents(EventType.CHILD_ASSOC_CREATED);
assertEquals("Wrong association events number",3, childAssocEvents.size());
Expand Down Expand Up @@ -388,7 +388,7 @@ public void testOneParentMultipleChildrenSameTransaction()
return null;
});

checkNumOfEvents(7);
checkNumOfEvents(10);
// 3 assoc.child.Created events should be created
List<RepoEvent<EventData<ChildAssociationResource>>> childAssocEvents = getFilteredEvents(EventType.CHILD_ASSOC_CREATED);
assertEquals("Wrong association events number",3, childAssocEvents.size());
Expand Down Expand Up @@ -432,7 +432,7 @@ public void testOneParentMultipleChildrenDifferentTransaction()
return null;
});

checkNumOfEvents(7);
checkNumOfEvents(10);
// 3 assoc.child.Created events should be created
List<RepoEvent<EventData<ChildAssociationResource>>> childAssocEvents = getFilteredEvents(EventType.CHILD_ASSOC_CREATED);
assertEquals("Wrong association events number",3, childAssocEvents.size());
Expand Down Expand Up @@ -501,7 +501,7 @@ public void testDeleteAssociationsOneChildMultipleParentsSameTransaction()
return null;
});

checkNumOfEvents(10);
checkNumOfEvents(12);

// 3 assoc.child.Deleted events should be created
List<RepoEvent<EventData<ChildAssociationResource>>> childAssocEvents = getFilteredEvents(EventType.CHILD_ASSOC_DELETED);
Expand Down Expand Up @@ -557,7 +557,7 @@ public void testDeleteAssociationOneParentMultipleChildrenDifferentTransactions(
nodeService.removeChildAssociation(childAssociationRef));
}

checkNumOfEvents(10);
checkNumOfEvents(14);

// 3 assoc.child.Deleted events should be created
List<RepoEvent<EventData<ChildAssociationResource>>> childAssocEvents = getFilteredEvents(EventType.CHILD_ASSOC_DELETED);
Expand Down Expand Up @@ -619,7 +619,7 @@ public void testDeleteParentWithMultipleChildAssociations()

deleteNode(parentNodeRef);

checkNumOfEvents(11);
checkNumOfEvents(17);

// 3 assoc.child.Deleted events should be created
List<RepoEvent<EventData<ChildAssociationResource>>> childAssocEvents = getFilteredEvents(EventType.CHILD_ASSOC_DELETED);
Expand Down Expand Up @@ -670,7 +670,7 @@ public void testDeleteChildWithMultipleParentAssociations()

deleteNode(childNodeRef);

checkNumOfEvents(11);
checkNumOfEvents(12);

// 3 assoc.child.Deleted events should be created
List<RepoEvent<EventData<ChildAssociationResource>>> childAssocEvents = getFilteredEvents(EventType.CHILD_ASSOC_DELETED);
Expand Down Expand Up @@ -708,13 +708,14 @@ public void testUpdateNodeAddChildAssociationNodeEventsFirst()
assertEquals(1, childAssociationRefs.size());
assertFalse(childAssociationRefs.get(0).isPrimary());

checkNumOfEvents(4);
checkNumOfEvents(5);

// Check the node events occur before the child association event
List<RepoEvent<?>> repoEvents = getRepoEventsContainer().getEvents();
assertEquals("org.alfresco.event.node.Created", repoEvents.get(0).getType());
assertEquals("org.alfresco.event.node.Created", repoEvents.get(1).getType());
assertEquals("org.alfresco.event.node.Updated", repoEvents.get(2).getType());
assertEquals("org.alfresco.event.assoc.child.Created", repoEvents.get(3).getType());
assertEquals("org.alfresco.event.node.Updated", repoEvents.get(3).getType());
assertEquals("org.alfresco.event.assoc.child.Created", repoEvents.get(4).getType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ public void nodePropertyFilter()
assertTrue("System properties are excluded by default.",
propertyFilter.isExcluded(ContentModel.PROP_NODE_DBID));

assertFalse("Property cascadeTx is not excluded", propertyFilter.isExcluded(ContentModel.PROP_CASCADE_TX));
assertFalse("Property cascadeCRC is not excluded", propertyFilter.isExcluded(ContentModel.PROP_CASCADE_CRC));

assertFalse(propertyFilter.isExcluded(ContentModel.PROP_TITLE));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void testUpdateNodeResourceContent()
});

checkNumOfEvents(2);

resultRepoEvent = getRepoEvent(2);
assertEquals("Wrong repo event type.", EventType.NODE_UPDATED.getType(),
resultRepoEvent.getType());
Expand Down Expand Up @@ -227,7 +227,7 @@ public void testUpdateNodeResourceContentSameContentSize()
});

checkNumOfEvents(2);

resultRepoEvent = getRepoEvent(2);
assertEquals("Wrong repo event type.", EventType.NODE_UPDATED.getType(), resultRepoEvent.getType());

Expand Down Expand Up @@ -625,7 +625,7 @@ public void testUpdateNodeTypeWithCustomType()

// Create active model
CustomModelDefinition modelDefinition =
retryingTransactionHelper.doInTransaction(() -> customModelService.createCustomModel(model, true));
retryingTransactionHelper.doInTransaction(() -> customModelService.createCustomModel(model, true));

assertNotNull(modelDefinition);
assertEquals(modelName, modelDefinition.getName().getLocalName());
Expand All @@ -635,8 +635,11 @@ public void testUpdateNodeTypeWithCustomType()
Collection<TypeDefinition> types = modelDefinition.getTypeDefinitions();
assertEquals(1, types.size());

// we should have only 2 events, node.Created and node.Updated
checkNumOfEvents(2);

// node.Created event should be generated for the model
RepoEvent<EventData<NodeResource>> resultRepoEvent = getRepoEvent(1);
RepoEvent<EventData<NodeResource>> resultRepoEvent = getFilteredEvent(EventType.NODE_CREATED, 0);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
NodeResource nodeResource = getNodeResource(resultRepoEvent);
assertEquals("Incorrect node type was found", "cm:dictionaryModel", nodeResource.getNodeType());
Expand All @@ -647,9 +650,9 @@ public void testUpdateNodeTypeWithCustomType()
assertEquals(ContentModel.TYPE_CONTENT, nodeService.getType(nodeRef));

// node.Created event should be generated
resultRepoEvent = getRepoEvent(2);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
resultRepoEvent = getRepoEvent(3);
nodeResource = getNodeResource(resultRepoEvent);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
assertEquals("cm:content node type was not found", "cm:content", nodeResource.getNodeType());

QName typeQName = QName.createQName("{" + namespacePair.getFirst()+ "}" + typeName);
Expand All @@ -661,15 +664,15 @@ public void testUpdateNodeTypeWithCustomType()
return null;
});

// we should have 3 events, node.Created for the model, node.Created for the node and node.Updated
checkNumOfEvents(3);
// we should have 4 events, node.Created for the model, node.Updated for the parent, node.Created for the node and node.Updated
checkNumOfEvents(4);

resultRepoEvent = getRepoEvent(3);
resultRepoEvent = getRepoEvent(4);
assertEquals("Wrong repo event type.", EventType.NODE_UPDATED.getType(), resultRepoEvent.getType());
nodeResource = getNodeResource(resultRepoEvent);
assertEquals("Incorrect node type was found", namespacePair.getSecond() + QName.NAMESPACE_PREFIX + typeName, nodeResource.getNodeType());

NodeResource resourceBefore = getNodeResourceBefore(3);
NodeResource resourceBefore = getNodeResourceBefore(4);
assertEquals("Incorrect node type was found", "cm:content", resourceBefore.getNodeType());
assertNull(resourceBefore.getId());
assertNull(resourceBefore.getContent());
Expand Down Expand Up @@ -788,7 +791,7 @@ public void testMoveFile()
});

checkNumOfEvents(4);

NodeResource resourceBefore = getNodeResourceBefore(4);
NodeResource resource = getNodeResource(4);

Expand All @@ -808,7 +811,7 @@ public void testMoveFile()
assertNull(resourceBefore.getModifiedByUser());
assertNull(resourceBefore.getCreatedAt());
assertNull(resourceBefore.getCreatedByUser());
assertNull(resourceBefore.getProperties());
assertNotNull(resourceBefore.getProperties());
assertNull(resourceBefore.getAspectNames());
assertNotNull(resourceBefore.getPrimaryHierarchy());
assertNull("Content should have been null.", resource.getContent());
Expand All @@ -818,7 +821,7 @@ public void testMoveFile()
assertNotNull(resource.getModifiedByUser());
assertNotNull(resource.getAspectNames());
assertNull(resource.getContent());
assertTrue(resource.getProperties().isEmpty());
assertFalse(resource.getProperties().isEmpty());
}

@Test
Expand Down Expand Up @@ -1020,7 +1023,7 @@ public void testAddAspectRemoveAspectAddAspectFromContentSameTransactionTest()
NodeResource resource = getNodeResource(1);
final Set<String> originalAspects = resource.getAspectNames();
assertNotNull(originalAspects);

retryingTransactionHelper.doInTransaction(() -> {
// Add cm:geographic aspect with default value
nodeService.addAspect(nodeRef, ContentModel.ASPECT_GEOGRAPHIC, null);
Expand Down

0 comments on commit 4e68ff5

Please sign in to comment.