REPO-5209: Prevent creation of node updated event when property added and removed in same transaction (#113)

This commit is contained in:
Chris Shields
2020-11-09 11:34:53 +00:00
committed by GitHub
parent 6d5583c048
commit 27d5e144a9
3 changed files with 38 additions and 7 deletions

View File

@@ -128,7 +128,7 @@ cd acs-community-packaging
mvn clean install -PcommunityDocker -Dmaven.javadoc.skip=true
cd ..
~~~
In Itellij IDEA, create a new project using the `work` directory as the source.
In Intellij IDEA, create a new project using the `work` directory as the source.
* File > New Project from Existing Sources > .../work > Maven
## Docker

View File

@@ -292,6 +292,7 @@ public class EventConsolidator implements EventSupportedPolicies
Builder builder = NodeResource.builder();
ZonedDateTime modifiedAt = null;
Map<QName, Serializable> changedPropsBefore = getBeforeMapChanges(propertiesBefore, propertiesAfter);
if (!changedPropsBefore.isEmpty())
{
@@ -321,13 +322,8 @@ public class EventConsolidator implements EventSupportedPolicies
builder.setModifiedByUser(modifier);
resourceBeforeAllFieldsNull = false;
}
ZonedDateTime modifiedAt =
modifiedAt =
helper.getZonedDateTime((Date) changedPropsBefore.get(ContentModel.PROP_MODIFIED));
if (modifiedAt != null)
{
builder.setModifiedAt(modifiedAt);
resourceBeforeAllFieldsNull = false;
}
}
// Handle case where the content does not exist on the propertiesBefore
@@ -357,6 +353,12 @@ public class EventConsolidator implements EventSupportedPolicies
resourceBeforeAllFieldsNull = false;
}
// Only set modifiedAt if one of the other fields is also not null
if (modifiedAt != null && !resourceBeforeAllFieldsNull)
{
builder.setModifiedAt(modifiedAt);
}
return builder.build();
}

View File

@@ -30,6 +30,7 @@ import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -978,4 +979,32 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
assertEquals(1, aspectsBefore.size());
assertTrue(aspectsBefore.contains("cm:auditable"));
}
@Test
public void testAddAndRemovePropertyInTheSameTransaction()
{
final NodeRef nodeRef = createNode(ContentModel.TYPE_CONTENT);
checkNumOfEvents(1);
NodeResource resource = getNodeResource(1);
// Check properties
assertTrue(resource.getProperties().isEmpty());
// Add and remove cm:userName property
retryingTransactionHelper.doInTransaction(() -> {
Map<QName, Serializable> properties = Map.of(ContentModel.PROP_USERNAME, "user1");
nodeService.addProperties(nodeRef, properties);
nodeService.removeProperty(nodeRef, ContentModel.PROP_USERNAME);
return null;
});
// There should only be a create event
resource = getNodeResource(1);
assertTrue(resource.getProperties().isEmpty());
// Check there isn't a node update event
List<RepoEvent<EventData<NodeResource>>> nodeUpdatedEvents = getFilteredEvents(EventType.NODE_UPDATED);
assertEquals(0, nodeUpdatedEvents.size());
}
}