mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
ACS-5325 Invoke required policy (#2215)
--------- Co-authored-by: Domenico Sibilio <domenicosibilio@gmail.com>
This commit is contained in:
@@ -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
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
@@ -3203,13 +3203,16 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
|
||||
// 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;
|
||||
|
@@ -158,7 +158,7 @@ public class AccessAuditorTest
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@@ -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
|
||||
@@ -77,9 +77,9 @@ public class ChildAssociationRepoEventIT extends AbstractContextAwareRepoEvent
|
||||
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());
|
||||
@@ -131,7 +131,7 @@ public class ChildAssociationRepoEventIT extends AbstractContextAwareRepoEvent
|
||||
assertEquals(1, childAssociationRefs.size());
|
||||
assertFalse(childAssociationRefs.get(0).isPrimary());
|
||||
|
||||
checkNumOfEvents(3);
|
||||
checkNumOfEvents(4);
|
||||
|
||||
retryingTransactionHelper.doInTransaction(() ->
|
||||
nodeService.removeChildAssociation(childAssociationRef));
|
||||
@@ -141,9 +141,9 @@ public class ChildAssociationRepoEventIT extends AbstractContextAwareRepoEvent
|
||||
|
||||
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());
|
||||
@@ -212,7 +212,7 @@ public class ChildAssociationRepoEventIT extends AbstractContextAwareRepoEvent
|
||||
return null;
|
||||
});
|
||||
|
||||
checkNumOfEvents(7);
|
||||
checkNumOfEvents(8);
|
||||
|
||||
// 3 assoc.child.Created events should be created
|
||||
|
||||
@@ -268,7 +268,7 @@ public class ChildAssociationRepoEventIT extends AbstractContextAwareRepoEvent
|
||||
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());
|
||||
@@ -330,7 +330,7 @@ public class ChildAssociationRepoEventIT extends AbstractContextAwareRepoEvent
|
||||
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());
|
||||
@@ -388,7 +388,7 @@ public class ChildAssociationRepoEventIT extends AbstractContextAwareRepoEvent
|
||||
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());
|
||||
@@ -432,7 +432,7 @@ public class ChildAssociationRepoEventIT extends AbstractContextAwareRepoEvent
|
||||
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());
|
||||
@@ -501,7 +501,7 @@ public class ChildAssociationRepoEventIT extends AbstractContextAwareRepoEvent
|
||||
return null;
|
||||
});
|
||||
|
||||
checkNumOfEvents(10);
|
||||
checkNumOfEvents(12);
|
||||
|
||||
// 3 assoc.child.Deleted events should be created
|
||||
List<RepoEvent<EventData<ChildAssociationResource>>> childAssocEvents = getFilteredEvents(EventType.CHILD_ASSOC_DELETED);
|
||||
@@ -557,7 +557,7 @@ public class ChildAssociationRepoEventIT extends AbstractContextAwareRepoEvent
|
||||
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);
|
||||
@@ -619,7 +619,7 @@ public class ChildAssociationRepoEventIT extends AbstractContextAwareRepoEvent
|
||||
|
||||
deleteNode(parentNodeRef);
|
||||
|
||||
checkNumOfEvents(11);
|
||||
checkNumOfEvents(17);
|
||||
|
||||
// 3 assoc.child.Deleted events should be created
|
||||
List<RepoEvent<EventData<ChildAssociationResource>>> childAssocEvents = getFilteredEvents(EventType.CHILD_ASSOC_DELETED);
|
||||
@@ -670,7 +670,7 @@ public class ChildAssociationRepoEventIT extends AbstractContextAwareRepoEvent
|
||||
|
||||
deleteNode(childNodeRef);
|
||||
|
||||
checkNumOfEvents(11);
|
||||
checkNumOfEvents(12);
|
||||
|
||||
// 3 assoc.child.Deleted events should be created
|
||||
List<RepoEvent<EventData<ChildAssociationResource>>> childAssocEvents = getFilteredEvents(EventType.CHILD_ASSOC_DELETED);
|
||||
@@ -708,13 +708,14 @@ public class ChildAssociationRepoEventIT extends AbstractContextAwareRepoEvent
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
@@ -119,6 +119,9 @@ public class EventFilterUnitTest
|
||||
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));
|
||||
}
|
||||
|
||||
|
@@ -87,7 +87,7 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
|
||||
});
|
||||
|
||||
checkNumOfEvents(2);
|
||||
|
||||
|
||||
resultRepoEvent = getRepoEvent(2);
|
||||
assertEquals("Wrong repo event type.", EventType.NODE_UPDATED.getType(),
|
||||
resultRepoEvent.getType());
|
||||
@@ -227,7 +227,7 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
|
||||
});
|
||||
|
||||
checkNumOfEvents(2);
|
||||
|
||||
|
||||
resultRepoEvent = getRepoEvent(2);
|
||||
assertEquals("Wrong repo event type.", EventType.NODE_UPDATED.getType(), resultRepoEvent.getType());
|
||||
|
||||
@@ -625,7 +625,7 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
|
||||
|
||||
// Create active model
|
||||
CustomModelDefinition modelDefinition =
|
||||
retryingTransactionHelper.doInTransaction(() -> customModelService.createCustomModel(model, true));
|
||||
retryingTransactionHelper.doInTransaction(() -> customModelService.createCustomModel(model, true));
|
||||
|
||||
assertNotNull(modelDefinition);
|
||||
assertEquals(modelName, modelDefinition.getName().getLocalName());
|
||||
@@ -635,8 +635,11 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
|
||||
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());
|
||||
@@ -647,9 +650,9 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
|
||||
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);
|
||||
@@ -661,15 +664,15 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
|
||||
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());
|
||||
@@ -788,7 +791,7 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
|
||||
});
|
||||
|
||||
checkNumOfEvents(4);
|
||||
|
||||
|
||||
NodeResource resourceBefore = getNodeResourceBefore(4);
|
||||
NodeResource resource = getNodeResource(4);
|
||||
|
||||
@@ -808,7 +811,7 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
|
||||
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());
|
||||
@@ -818,7 +821,7 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
|
||||
assertNotNull(resource.getModifiedByUser());
|
||||
assertNotNull(resource.getAspectNames());
|
||||
assertNull(resource.getContent());
|
||||
assertTrue(resource.getProperties().isEmpty());
|
||||
assertFalse(resource.getProperties().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1020,7 +1023,7 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
|
||||
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);
|
||||
|
Reference in New Issue
Block a user