mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
ACS-771: Fix update event to handle content and property update from null (#35)
* ACS-771: Fix update event to handle content and property update from null.
This commit is contained in:
@@ -330,6 +330,14 @@ public class EventConsolidator implements EventSupportedPolicies
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle case where the content does not exist on the propertiesBefore
|
||||||
|
if (propertiesBefore != null && !propertiesBefore.containsKey(ContentModel.PROP_CONTENT) &&
|
||||||
|
propertiesAfter != null && propertiesAfter.containsKey(ContentModel.PROP_CONTENT))
|
||||||
|
{
|
||||||
|
builder.setContent(new ContentInfo());
|
||||||
|
resourceBeforeAllFieldsNull = false;
|
||||||
|
}
|
||||||
|
|
||||||
Set<String> aspectsBefore = getMappedAspectsBefore(after.getAspectNames());
|
Set<String> aspectsBefore = getMappedAspectsBefore(after.getAspectNames());
|
||||||
if (!aspectsBefore.isEmpty())
|
if (!aspectsBefore.isEmpty())
|
||||||
{
|
{
|
||||||
@@ -407,6 +415,16 @@ public class EventConsolidator implements EventSupportedPolicies
|
|||||||
Map<K, V> beforeDelta = new HashMap<>(before);
|
Map<K, V> beforeDelta = new HashMap<>(before);
|
||||||
beforeDelta.entrySet().removeAll(after.entrySet());
|
beforeDelta.entrySet().removeAll(after.entrySet());
|
||||||
|
|
||||||
|
// Add nulls for before properties
|
||||||
|
Set<K> beforeKeys = before.keySet();
|
||||||
|
Set<K> newKeys = after.keySet();
|
||||||
|
newKeys.removeAll(beforeKeys);
|
||||||
|
|
||||||
|
for (K key : newKeys)
|
||||||
|
{
|
||||||
|
beforeDelta.put(key, null);
|
||||||
|
}
|
||||||
|
|
||||||
return beforeDelta;
|
return beforeDelta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -171,18 +171,15 @@ public class NodeResourceHelper implements InitializingBean
|
|||||||
Map<String, Serializable> filteredProps = new HashMap<>(props.size());
|
Map<String, Serializable> filteredProps = new HashMap<>(props.size());
|
||||||
|
|
||||||
props.forEach((k, v) -> {
|
props.forEach((k, v) -> {
|
||||||
if (!nodePropertyFilter.isExcluded(k) && v != null)
|
if (!nodePropertyFilter.isExcluded(k))
|
||||||
{
|
{
|
||||||
if (v instanceof MLText)
|
if (v != null && v instanceof MLText)
|
||||||
{
|
{
|
||||||
//TODO - should we send all of the values if multiple locales exist?
|
//TODO - should we send all of the values if multiple locales exist?
|
||||||
v = ((MLText) v).getDefaultValue();
|
v = ((MLText) v).getDefaultValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNotEmptyString(v))
|
filteredProps.put(getQNamePrefixString(k), v);
|
||||||
{
|
|
||||||
filteredProps.put(getQNamePrefixString(k), v);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -26,8 +26,11 @@
|
|||||||
|
|
||||||
package org.alfresco.repo.event2;
|
package org.alfresco.repo.event2;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
@@ -92,7 +95,7 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
|
|||||||
assertTrue(content.getSizeInBytes() > 0);
|
assertTrue(content.getSizeInBytes() > 0);
|
||||||
|
|
||||||
NodeResource resourceBefore = getNodeResourceBefore(resultRepoEvent);
|
NodeResource resourceBefore = getNodeResourceBefore(resultRepoEvent);
|
||||||
assertNull("Content should have been null.", resourceBefore.getContent());
|
assertNotNull("Content should not have been null.", resourceBefore.getContent());
|
||||||
|
|
||||||
// Update the content again
|
// Update the content again
|
||||||
retryingTransactionHelper.doInTransaction(() -> {
|
retryingTransactionHelper.doInTransaction(() -> {
|
||||||
@@ -135,6 +138,66 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
|
|||||||
assertNull(resourceBefore.getPrimaryHierarchy());
|
assertNull(resourceBefore.getPrimaryHierarchy());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateNodeResourceContent_NullBefore()
|
||||||
|
{
|
||||||
|
ContentService contentService = (ContentService) applicationContext.getBean(
|
||||||
|
"contentService");
|
||||||
|
|
||||||
|
final NodeRef nodeRef = createNode(ContentModel.TYPE_CONTENT);
|
||||||
|
|
||||||
|
RepoEvent<EventData<NodeResource>> resultRepoEvent = getRepoEvent(1);
|
||||||
|
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(),
|
||||||
|
resultRepoEvent.getType());
|
||||||
|
|
||||||
|
NodeResource resource = getNodeResource(resultRepoEvent);
|
||||||
|
assertNull("Content should have been null.", resource.getContent());
|
||||||
|
|
||||||
|
retryingTransactionHelper.doInTransaction(() -> {
|
||||||
|
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.TYPE_CONTENT,
|
||||||
|
true);
|
||||||
|
writer.setMimetype(MimetypeMap.MIMETYPE_PDF);
|
||||||
|
writer.setEncoding("UTF-8");
|
||||||
|
writer.putContent("test content.");
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
checkNumOfEvents(2);
|
||||||
|
|
||||||
|
resultRepoEvent = getRepoEvent(2);
|
||||||
|
assertEquals("Wrong repo event type.", EventType.NODE_UPDATED.getType(),
|
||||||
|
resultRepoEvent.getType());
|
||||||
|
|
||||||
|
resource = getNodeResource(resultRepoEvent);
|
||||||
|
ContentInfo content = resource.getContent();
|
||||||
|
assertNotNull(content);
|
||||||
|
assertEquals(MimetypeMap.MIMETYPE_PDF, content.getMimeType());
|
||||||
|
assertEquals("UTF-8", content.getEncoding());
|
||||||
|
assertTrue(content.getSizeInBytes() > 0);
|
||||||
|
|
||||||
|
NodeResource resourceBefore = getNodeResourceBefore(resultRepoEvent);
|
||||||
|
assertNotNull("Content should not have been null.", resourceBefore.getContent());
|
||||||
|
content = resourceBefore.getContent();
|
||||||
|
assertNull(content.getMimeType());
|
||||||
|
assertNull(content.getEncoding());
|
||||||
|
assertNull(content.getSizeInBytes());
|
||||||
|
assertNotNull(resourceBefore.getModifiedAt());
|
||||||
|
|
||||||
|
// Apart from the 'content' and 'modifiedAt' properties the rest should not be set
|
||||||
|
// for the resourceBefore object
|
||||||
|
assertNull(resourceBefore.getId());
|
||||||
|
assertNull(resourceBefore.getName());
|
||||||
|
assertNull(resourceBefore.getNodeType());
|
||||||
|
assertNull(resourceBefore.isFile());
|
||||||
|
assertNull(resourceBefore.isFolder());
|
||||||
|
assertNull(resourceBefore.getModifiedByUser());
|
||||||
|
assertNull(resourceBefore.getCreatedAt());
|
||||||
|
assertNull(resourceBefore.getCreatedByUser());
|
||||||
|
assertNull(resourceBefore.getProperties());
|
||||||
|
assertNull(resourceBefore.getAspectNames());
|
||||||
|
assertNull(resourceBefore.getPrimaryHierarchy());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateNodeResourceContentSameContentSize()
|
public void testUpdateNodeResourceContentSameContentSize()
|
||||||
{
|
{
|
||||||
@@ -169,7 +232,7 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
|
|||||||
assertEquals(14, (long) content.getSizeInBytes());
|
assertEquals(14, (long) content.getSizeInBytes());
|
||||||
|
|
||||||
NodeResource resourceBefore = getNodeResourceBefore(resultRepoEvent);
|
NodeResource resourceBefore = getNodeResourceBefore(resultRepoEvent);
|
||||||
assertNull("Content should have been null.", resourceBefore.getContent());
|
assertNotNull("Content should not have been null.", resourceBefore.getContent());
|
||||||
|
|
||||||
// Update the content again - different content but same size
|
// Update the content again - different content but same size
|
||||||
retryingTransactionHelper.doInTransaction(() -> {
|
retryingTransactionHelper.doInTransaction(() -> {
|
||||||
@@ -247,6 +310,34 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
|
|||||||
assertNotNull(resourceBefore.getModifiedAt());
|
assertNotNull(resourceBefore.getModifiedAt());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateContentTitleFromNull()
|
||||||
|
{
|
||||||
|
final NodeRef nodeRef = createNode(ContentModel.TYPE_CONTENT);
|
||||||
|
NodeResource resource = getNodeResource(1);
|
||||||
|
|
||||||
|
assertNotNull(resource.getProperties());
|
||||||
|
String title = getProperty(resource, "cm:title");
|
||||||
|
assertNull("Title should have been null.", title);
|
||||||
|
|
||||||
|
// update content cm:title property with "test title" value
|
||||||
|
retryingTransactionHelper.doInTransaction(() -> {
|
||||||
|
nodeService.setProperty(nodeRef, ContentModel.PROP_TITLE, "test title");
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
resource = getNodeResource(2);
|
||||||
|
title = getProperty(resource, "cm:title");
|
||||||
|
assertEquals("test title", title);
|
||||||
|
|
||||||
|
NodeResource resourceBefore = getNodeResourceBefore(2);
|
||||||
|
Map<String, Serializable> expectedResourceBeforeProperties = new HashMap<>();
|
||||||
|
expectedResourceBeforeProperties.put("cm:title", null);
|
||||||
|
assertEquals(expectedResourceBeforeProperties, resourceBefore.getProperties());
|
||||||
|
|
||||||
|
assertNotNull(resourceBefore.getModifiedAt());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateContentDescription()
|
public void testUpdateContentDescription()
|
||||||
{
|
{
|
||||||
@@ -267,7 +358,11 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
|
|||||||
assertEquals("test description", desc);
|
assertEquals("test description", desc);
|
||||||
|
|
||||||
NodeResource resourceBefore = getNodeResourceBefore(2);
|
NodeResource resourceBefore = getNodeResourceBefore(2);
|
||||||
assertNull(resourceBefore.getProperties());
|
assertNotNull(resourceBefore.getProperties());
|
||||||
|
|
||||||
|
Map<String, Serializable> expectedResourceBeforeProperties = new HashMap<>();
|
||||||
|
expectedResourceBeforeProperties.put("cm:description", null);
|
||||||
|
assertEquals(expectedResourceBeforeProperties, resourceBefore.getProperties());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -338,7 +433,15 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
|
|||||||
NodeResource resourceBefore = getNodeResourceBefore(2);
|
NodeResource resourceBefore = getNodeResourceBefore(2);
|
||||||
assertNotNull(resourceBefore.getAspectNames());
|
assertNotNull(resourceBefore.getAspectNames());
|
||||||
assertEquals(originalAspects, resourceBefore.getAspectNames());
|
assertEquals(originalAspects, resourceBefore.getAspectNames());
|
||||||
assertNull(resourceBefore.getProperties());
|
assertNotNull(resourceBefore.getProperties());
|
||||||
|
|
||||||
|
Map<String, Serializable> expectedResourceBeforeProperties = new HashMap<>();
|
||||||
|
expectedResourceBeforeProperties.put("cm:autoVersion", null);
|
||||||
|
expectedResourceBeforeProperties.put("cm:initialVersion", null);
|
||||||
|
expectedResourceBeforeProperties.put("cm:versionType", null);
|
||||||
|
expectedResourceBeforeProperties.put("cm:autoVersionOnUpdateProps", null);
|
||||||
|
expectedResourceBeforeProperties.put("cm:versionLabel", null);
|
||||||
|
assertEquals(expectedResourceBeforeProperties, resourceBefore.getProperties());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user