ACS-9923 Removing an aspect needs to invoke onUpdateProperties (#3504) (#3505)

This commit is contained in:
Eva Vasques
2025-08-07 13:50:57 +01:00
committed by GitHub
parent dc0b1988ca
commit 7a49b4c331
2 changed files with 3359 additions and 3322 deletions

View File

@@ -39,6 +39,10 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.surf.util.I18NUtil;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.domain.node.ChildAssocEntity;
@@ -99,9 +103,6 @@ import org.alfresco.util.Pair;
import org.alfresco.util.ParameterCheck;
import org.alfresco.util.PropertyMap;
import org.alfresco.util.transaction.TransactionListenerAdapter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.surf.util.I18NUtil;
/**
* Node service using database persistence layer to fulfill functionality
@@ -150,7 +151,8 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
/**
*
* @param policyBehaviourFilter component used to enable and disable behaviours
* @param policyBehaviourFilter
* component used to enable and disable behaviours
*/
public void setPolicyBehaviourFilter(BehaviourFilter policyBehaviourFilter)
{
@@ -158,11 +160,10 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
}
/**
* Set whether <b>cm:auditable</b> timestamps should be propagated to parent nodes
* where the parent-child relationship has been marked using <b>propagateTimestamps</b>.
* Set whether <b>cm:auditable</b> timestamps should be propagated to parent nodes where the parent-child relationship has been marked using <b>propagateTimestamps</b>.
*
* @param enableTimestampPropagation <tt>true</tt> to propagate timestamps to the parent
* node where appropriate
* @param enableTimestampPropagation
* <tt>true</tt> to propagate timestamps to the parent node where appropriate
*/
public void setEnableTimestampPropagation(boolean enableTimestampPropagation)
{
@@ -172,9 +173,11 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
/**
* Performs a null-safe get of the node
*
* @param nodeRef the node to retrieve
* @param nodeRef
* the node to retrieve
* @return Returns the node entity (never null)
* @throws InvalidNodeRefException if the referenced node could not be found
* @throws InvalidNodeRefException
* if the referenced node could not be found
*/
private Pair<Long, NodeRef> getNodePairNotNull(NodeRef nodeRef) throws InvalidNodeRefException
{
@@ -264,7 +267,8 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
}
/**
* @throws UnsupportedOperationException Always
* @throws UnsupportedOperationException
* Always
*/
@Extend(traitAPI = NodeServiceTrait.class, extensionAPI = NodeServiceExtension.class)
public void deleteStore(StoreRef storeRef) throws InvalidStoreRefException
@@ -434,23 +438,23 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
return childAssocRef;
}
/**
* Adds all the aspects and properties required for the given node, along with mandatory aspects
* and related properties.
* Existing values will not be overridden. All required pre- and post-update notifications
* are sent for missing aspects.
* Adds all the aspects and properties required for the given node, along with mandatory aspects and related properties. Existing values will not be overridden. All required pre- and post-update notifications are sent for missing aspects.
*
* @param nodePair the node to which the details apply
* @param classQName the type or aspect QName for which the defaults must be applied.
* If this is <tt>null</tt> then properties and aspects are only applied
* for 'extra' aspects and 'extra' properties.
* @param existingAspects the existing aspects or <tt>null</tt> to have them fetched
* @param existingProperties the existing properties or <tt>null</tt> to have them fetched
* @param extraAspects any aspects that should be added to the 'missing' set (may be <tt>null</tt>)
* @param extraProperties any properties that should be added the the 'missing' set (may be <tt>null</tt>)
* @param overwriteExistingProperties <tt>true</tt> if the extra properties must completely overwrite
* the existing properties
* @param nodePair
* the node to which the details apply
* @param classQName
* the type or aspect QName for which the defaults must be applied. If this is <tt>null</tt> then properties and aspects are only applied for 'extra' aspects and 'extra' properties.
* @param existingAspects
* the existing aspects or <tt>null</tt> to have them fetched
* @param existingProperties
* the existing properties or <tt>null</tt> to have them fetched
* @param extraAspects
* any aspects that should be added to the 'missing' set (may be <tt>null</tt>)
* @param extraProperties
* any properties that should be added the the 'missing' set (may be <tt>null</tt>)
* @param overwriteExistingProperties
* <tt>true</tt> if the extra properties must completely overwrite the existing properties
* @return <tt>true</tt> if properties or aspects were added
*/
private boolean addAspectsAndProperties(
@@ -595,11 +599,10 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
}
/**
* Get any aspects that should be added given the type, properties and existing aspects.
* Note that this <b>does not</b> included a search for properties required for the missing
* aspects.
* Get any aspects that should be added given the type, properties and existing aspects. Note that this <b>does not</b> included a search for properties required for the missing aspects.
*
* @param classQName the type, aspect or association
* @param classQName
* the type, aspect or association
* @return Returns any aspects that should be added
*/
private Set<QName> getMissingAspects(
@@ -669,8 +672,10 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
}
/**
* @param existingProperties existing node properties
* @param classQNames the types or aspects to introspect
* @param existingProperties
* existing node properties
* @param classQNames
* the types or aspects to introspect
* @return Returns any properties that should be added
*/
private Map<QName, Serializable> getMissingProperties(Map<QName, Serializable> existingProperties, Set<QName> classQNames)
@@ -838,9 +843,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
throw new IllegalArgumentException("The aspect is reserved for system use: " + aspectTypeQName);
}
/*
* Note: Aspect and property removal is resilient to missing dictionary definitions
*/
/* Note: Aspect and property removal is resilient to missing dictionary definitions */
// get the node
final Pair<Long, NodeRef> nodePair = getNodePairNotNull(nodeRef);
final Long nodeId = nodePair.getFirst();
@@ -859,22 +862,31 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
if (aspectDef != null)
{
// Remove default properties
Map<QName, Serializable> propsBefore = nodeDAO.getNodeProperties(nodeId);
Map<QName, PropertyDefinition> propertyDefs = aspectDef.getProperties();
Set<QName> propertyToRemoveQNames = propertyDefs.keySet();
nodeDAO.removeNodeProperties(nodeId, propertyToRemoveQNames);
boolean propertiesRemoved = nodeDAO.removeNodeProperties(nodeId, propertyToRemoveQNames);
if (propertiesRemoved)
{
invokeOnUpdateProperties(
nodeRef,
propsBefore, // before
nodeDAO.getNodeProperties(nodeId)); // after
}
// Remove child associations
// We have to iterate over the associations and remove all those between the parent and child
final List<Pair<Long, ChildAssociationRef>> assocsToDelete = new ArrayList<Pair<Long, ChildAssociationRef>>(5);
final List<Pair<Long, NodeRef>> nodesToDelete = new ArrayList<Pair<Long, NodeRef>>(5);
NodeDAO.ChildAssocRefQueryCallback callback = new NodeDAO.ChildAssocRefQueryCallback()
{
NodeDAO.ChildAssocRefQueryCallback callback = new NodeDAO.ChildAssocRefQueryCallback() {
public boolean preLoadNodes()
{
return true;
}
@Override public boolean orderResults()
@Override
public boolean orderResults()
{
return false;
}
@@ -907,8 +919,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
}
public void done()
{
}
{}
};
// Get all the QNames to remove
Set<QName> assocTypeQNamesToRemove = new HashSet<QName>(aspectDef.getChildAssociations().keySet());
@@ -1037,7 +1048,8 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
}
/**
* @throws IllegalStateException if the node is pending delete
* @throws IllegalStateException
* if the node is pending delete
*
* @see #KEY_PENDING_DELETE_NODES
*/
@@ -1064,9 +1076,10 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
/**
* Delete a node
*
* @param nodeRef the node to delete
* @param allowArchival <tt>true</tt> if normal archival may occur or
* <tt>false</tt> if the node must be forcibly deleted
* @param nodeRef
* the node to delete
* @param allowArchival
* <tt>true</tt> if normal archival may occur or <tt>false</tt> if the node must be forcibly deleted
*/
private void deleteNode(NodeRef nodeRef, boolean allowArchival)
{
@@ -1364,8 +1377,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
// We have to iterate over the associations and remove all those between the parent and child
final List<Pair<Long, ChildAssociationRef>> assocsToDelete = new ArrayList<Pair<Long, ChildAssociationRef>>(5);
NodeDAO.ChildAssocRefQueryCallback callback = new NodeDAO.ChildAssocRefQueryCallback()
{
NodeDAO.ChildAssocRefQueryCallback callback = new NodeDAO.ChildAssocRefQueryCallback() {
public boolean preLoadNodes()
{
return true;
@@ -1394,8 +1406,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
}
public void done()
{
}
{}
};
nodeDAO.getChildAssocs(parentNodeId, childNodeId, null, null, null, null, callback);
@@ -1584,8 +1595,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
}
/**
* Gets the properties map, sets the value (null is allowed) and checks that the new set
* of properties is valid.
* Gets the properties map, sets the value (null is allowed) and checks that the new set of properties is valid.
*
*/
@Extend(traitAPI = NodeServiceTrait.class, extensionAPI = NodeServiceExtension.class)
@@ -1625,14 +1635,11 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
}
/**
* Ensures that all required properties are present on the node and copies the
* property values to the <code>Node</code>.
* Ensures that all required properties are present on the node and copies the property values to the <code>Node</code>.
* <p>
* To remove a property, <b>remove it from the map</b> before calling this method.
* Null-valued properties are allowed.
* To remove a property, <b>remove it from the map</b> before calling this method. Null-valued properties are allowed.
* <p>
* If any of the values are null, a marker object is put in to mimic nulls. They will be turned back into
* a real nulls when the properties are requested again.
* If any of the values are null, a marker object is put in to mimic nulls. They will be turned back into a real nulls when the properties are requested again.
*
*/
@Extend(traitAPI = NodeServiceTrait.class, extensionAPI = NodeServiceExtension.class)
@@ -1740,8 +1747,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
final List<ChildAssociationRef> results = new ArrayList<ChildAssociationRef>(10);
// We have a callback handler to filter results
ChildAssocRefQueryCallback callback = new ChildAssocRefQueryCallback()
{
ChildAssocRefQueryCallback callback = new ChildAssocRefQueryCallback() {
public boolean preLoadNodes()
{
return false;
@@ -1771,8 +1777,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
}
public void done()
{
}
{}
};
// Get the assocs pointing to it
@@ -1829,8 +1834,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
// We have a callback handler to filter results
final List<ChildAssociationRef> results = new ArrayList<ChildAssociationRef>(10);
ChildAssocRefQueryCallback callback = new ChildAssocRefQueryCallback()
{
ChildAssocRefQueryCallback callback = new ChildAssocRefQueryCallback() {
public boolean preLoadNodes()
{
return preload;
@@ -1860,8 +1864,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
}
public void done()
{
}
{}
};
// Get the assocs pointing to it
QName typeQName = (typeQNamePattern instanceof QName) ? (QName) typeQNamePattern : null;
@@ -1881,8 +1884,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
final List<ChildAssociationRef> results = new ArrayList<ChildAssociationRef>(100);
NodeDAO.ChildAssocRefQueryCallback callback = new NodeDAO.ChildAssocRefQueryCallback()
{
NodeDAO.ChildAssocRefQueryCallback callback = new NodeDAO.ChildAssocRefQueryCallback() {
public boolean preLoadNodes()
{
return true;
@@ -1905,8 +1907,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
}
public void done()
{
}
{}
};
// Get all child associations with the specific qualified name
nodeDAO.getChildAssocsByChildTypes(nodeId, childNodeTypeQNames, callback);
@@ -1945,8 +1946,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
final List<ChildAssociationRef> results = new ArrayList<ChildAssociationRef>(100);
NodeDAO.ChildAssocRefQueryCallback callback = new NodeDAO.ChildAssocRefQueryCallback()
{
NodeDAO.ChildAssocRefQueryCallback callback = new NodeDAO.ChildAssocRefQueryCallback() {
public boolean preLoadNodes()
{
return true;
@@ -1969,8 +1969,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
}
public void done()
{
}
{}
};
// Get all child associations with the specific qualified name
nodeDAO.getChildAssocs(nodeId, assocTypeQName, childNames, callback);
@@ -2103,8 +2102,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
final List<ChildAssociationRef> results = new ArrayList<ChildAssociationRef>(100);
NodeDAO.ChildAssocRefQueryCallback callback = new NodeDAO.ChildAssocRefQueryCallback()
{
NodeDAO.ChildAssocRefQueryCallback callback = new NodeDAO.ChildAssocRefQueryCallback() {
public boolean preLoadNodes()
{
return false;
@@ -2125,8 +2123,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
}
public void done()
{
}
{}
};
// Get the child associations that meet the criteria
nodeDAO.getChildAssocsWithoutParentAssocsOfType(parentNodeId, assocTypeQName, callback);
@@ -2143,6 +2140,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
return nodeDAO.selectAssocsNotLinkedByTwoOtherAssocs(parentNodeId);
}
/**
* Specific properties <b>not</b> supported by {@link #getChildAssocsByPropertyValue(NodeRef, QName, Serializable)}
*/
@@ -2179,8 +2177,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
final List<ChildAssociationRef> results = new ArrayList<ChildAssociationRef>(10);
// We have a callback handler to filter results
ChildAssocRefQueryCallback callback = new ChildAssocRefQueryCallback()
{
ChildAssocRefQueryCallback callback = new ChildAssocRefQueryCallback() {
public boolean preLoadNodes()
{
return false;
@@ -2202,8 +2199,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
}
public void done()
{
}
{}
};
// Get the assocs pointing to it
nodeDAO.getChildAssocsByPropertyValue(nodeId, propertyQName, value, callback);
@@ -2308,6 +2304,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
// done
return nodeAssocRefs;
}
@Extend(traitAPI = NodeServiceTrait.class, extensionAPI = NodeServiceExtension.class)
public List<AssociationRef> getSourceAssocs(NodeRef targetRef, QNamePattern qnamePattern)
{
@@ -2350,8 +2347,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
}
/**
* When searching for <code>primaryOnly == true</code>, checks that there is exactly
* one path.
* When searching for <code>primaryOnly == true</code>, checks that there is exactly one path.
*/
@Extend(traitAPI = NodeServiceTrait.class, extensionAPI = NodeServiceExtension.class)
public List<Path> getPaths(NodeRef nodeRef, boolean primaryOnly) throws InvalidNodeRefException
@@ -2381,8 +2377,10 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
/**
* Archive (direct copy) a node hierarchy
*
* @param walker the node hierarchy to archive
* @param archiveStoreRef StoreRef
* @param walker
* the node hierarchy to archive
* @param archiveStoreRef
* StoreRef
*/
private void archiveHierarchyImpl(NodeHierarchyWalker walker, StoreRef archiveStoreRef)
{
@@ -2880,8 +2878,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
{
// Get the node's children, but only one's that aren't in the same store
final List<ChildAssociationRef> childAssocs = new LinkedList<ChildAssociationRef>();
NodeDAO.ChildAssocRefQueryCallback callback = new NodeDAO.ChildAssocRefQueryCallback()
{
NodeDAO.ChildAssocRefQueryCallback callback = new NodeDAO.ChildAssocRefQueryCallback() {
public boolean preLoadNodes()
{
return true;
@@ -2896,8 +2893,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
public boolean handle(
Pair<Long, ChildAssociationRef> childAssocPair,
Pair<Long, NodeRef> parentNodePair,
Pair<Long, NodeRef> childNodePair
)
Pair<Long, NodeRef> childNodePair)
{
// Add it if it's not in the target store
NodeRef childNodeRef = childNodePair.getSecond();
@@ -2911,8 +2907,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
}
public void done()
{
}
{}
};
// We need to get all primary children and do the store filtering ourselves
nodeDAO.getChildAssocs(nodeId, null, null, null, Boolean.TRUE, null, callback);
@@ -2957,8 +2952,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
}
/**
* Ensures name uniqueness for the child and the child association. Note that nothing is done if the
* association type doesn't enforce name uniqueness.
* Ensures name uniqueness for the child and the child association. Note that nothing is done if the association type doesn't enforce name uniqueness.
*
* @return Returns <tt>true</tt> if the child association <b>cm:name</b> was written
*/
@@ -2983,12 +2977,10 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
}
/**
* Propagate, if necessary, a <b>cm:modified</b> timestamp change to the parent of the
* given association, along with the <b>cm:modifier</b> of who changed it.
* The parent node has to be <b>cm:auditable</b> and the association
* has to be marked for propagation as well.
* Propagate, if necessary, a <b>cm:modified</b> timestamp change to the parent of the given association, along with the <b>cm:modifier</b> of who changed it. The parent node has to be <b>cm:auditable</b> and the association has to be marked for propagation as well.
*
* @param assocRef the association to propagate along
* @param assocRef
* the association to propagate along
*/
private void propagateTimeStamps(ChildAssociationRef assocRef)
{
@@ -3082,9 +3074,9 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
private static final String KEY_AUDITABLE_PROPAGATION_PRE = "node.auditable.propagation.pre";
private static final String KEY_AUDITABLE_PROPAGATION_POST = "node.auditable.propagation.post";
private AuditableTransactionListener auditableTransactionListener = new AuditableTransactionListener();
/**
* Wrapper to set the <b>cm:modified</b> time and <b>cm:modifier</b> on
* individual nodes.
* Wrapper to set the <b>cm:modified</b> time and <b>cm:modifier</b> on individual nodes.
*
* @author Derek Hulley
* @since 3.4.6
@@ -3123,9 +3115,12 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
}
/**
* @param parentNodeIds the parent node IDs that need to be touched for <b>cm:modified</b>, and the updating child node from which to get the <b>cm:modifier</b> from
* @param modifiedDate the date to set
* @param useCurrentTxn <tt>true</tt> to use the current transaction
* @param parentNodeIds
* the parent node IDs that need to be touched for <b>cm:modified</b>, and the updating child node from which to get the <b>cm:modifier</b> from
* @param modifiedDate
* the date to set
* @param useCurrentTxn
* <tt>true</tt> to use the current transaction
*/
private void process(final Map<Long, Long> parentNodeIds, Date modifiedDate, boolean useCurrentTxn)
{
@@ -3139,17 +3134,20 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
/**
* Touch a single node in a new, writable txn
*
* @param parentNodeId the parent node to touch
* @param childNodeId the child node from which to get the <b>cm:modifier</b> from
* @param modifiedDate the date to set
* @param useCurrentTxn <tt>true</tt> to use the current transaction
* @param parentNodeId
* the parent node to touch
* @param childNodeId
* the child node from which to get the <b>cm:modifier</b> from
* @param modifiedDate
* the date to set
* @param useCurrentTxn
* <tt>true</tt> to use the current transaction
*/
private void processSingle(final Long parentNodeId, final Long childNodeId, final Date modifiedDate, boolean useCurrentTxn)
{
RetryingTransactionHelper txnHelper = transactionService.getRetryingTransactionHelper();
txnHelper.setMaxRetries(1);
RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>()
{
RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable
{
@@ -3237,7 +3235,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl implements Extens
}
}
@SuppressWarnings("unchecked")
@Override
public <M extends Trait> ExtendedTrait<M> getTrait(Class<? extends M> traitAPI)

View File

@@ -26,6 +26,12 @@
package org.alfresco.repo.event2;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.alfresco.model.ContentModel.PROP_DESCRIPTION;
import java.io.Serializable;
@@ -35,6 +41,9 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.junit.Test;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.dictionary.M2Model;
@@ -53,7 +62,6 @@ import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.GUID;
import org.alfresco.util.Pair;
import org.junit.Test;
/**
* @author Iulian Aftene
@@ -370,7 +378,6 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
assertEquals("new test title", title);
assertEquals("new test title", getLocalizedProperty(resource, "cm:title", defaultLocale));
resourceBefore = getNodeResourceBefore(3);
title = getProperty(resourceBefore, "cm:title");
assertEquals("Wrong old property.", "test title", title);
@@ -544,6 +551,49 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
assertEquals(aspectsBeforeRemove, resourceBefore.getAspectNames());
}
@Test
public void testRemoveAspectPropertiesTest()
{
final NodeRef nodeRef = createNode(ContentModel.TYPE_CONTENT);
NodeResource resource = getNodeResource(1);
final Set<String> originalAspects = resource.getAspectNames();
assertNotNull(originalAspects);
// Add cm:geographic aspect with properties
retryingTransactionHelper.doInTransaction(() -> {
Map<QName, Serializable> aspectProperties = new HashMap<>();
aspectProperties.put(ContentModel.PROP_LATITUDE, "12.345678");
aspectProperties.put(ContentModel.PROP_LONGITUDE, "12.345678");
nodeService.addAspect(nodeRef, ContentModel.ASPECT_GEOGRAPHIC, aspectProperties);
return null;
});
resource = getNodeResource(2);
Set<String> aspectsBeforeRemove = resource.getAspectNames();
assertNotNull(aspectsBeforeRemove);
assertTrue(aspectsBeforeRemove.contains("cm:geographic"));
// Remove cm:geographic aspect - this automatically removes the properties from the node
retryingTransactionHelper.doInTransaction(() -> {
nodeService.removeAspect(nodeRef, ContentModel.ASPECT_GEOGRAPHIC);
return null;
});
resource = getNodeResource(3);
assertEquals(originalAspects, resource.getAspectNames());
NodeResource resourceBefore = getNodeResourceBefore(3);
assertNotNull(resourceBefore.getAspectNames());
assertEquals(aspectsBeforeRemove, resourceBefore.getAspectNames());
// Resource before should contain cm:latitude and cm:longitude properties
assertNotNull(resourceBefore.getProperties());
assertTrue(resourceBefore.getProperties().containsKey("cm:latitude"));
assertTrue(resourceBefore.getProperties().containsKey("cm:longitude"));
// Resource after should NOT contain cm:latitude and cm:longitude properties
assertNotNull(resource.getProperties());
assertFalse(resource.getProperties().containsKey("cm:latitude"));
assertFalse(resource.getProperties().containsKey("cm:longitude"));
}
@Test
public void testCreateAndUpdateInTheSameTransaction()
{
@@ -624,8 +674,7 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
m2Type.setTitle("Test type title");
// Create active model
CustomModelDefinition modelDefinition =
retryingTransactionHelper.doInTransaction(() -> customModelService.createCustomModel(model, true));
CustomModelDefinition modelDefinition = retryingTransactionHelper.doInTransaction(() -> customModelService.createCustomModel(model, true));
assertNotNull(modelDefinition);
assertEquals(modelName, modelDefinition.getName().getLocalName());
@@ -845,10 +894,8 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
final String grandParentID = getNodeResource(1).getId();
final String parentID = getNodeResource(2).getId();
final String moveFolderParentBeforeMove =
getNodeResourceBefore(4).getPrimaryHierarchy().get(0);
final String moveFolderParentAfterMove =
getNodeResource(4).getPrimaryHierarchy().get(0);
final String moveFolderParentBeforeMove = getNodeResourceBefore(4).getPrimaryHierarchy().get(0);
final String moveFolderParentAfterMove = getNodeResource(4).getPrimaryHierarchy().get(0);
assertEquals("Wrong node parent.", parentID, moveFolderParentBeforeMove);
assertEquals("Wrong node parent.", grandParentID, moveFolderParentAfterMove);
@@ -877,18 +924,15 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
checkNumOfEvents(6);
final String root2ID = getNodeResource(2).getId();
final String grandParentParentAfterMove =
getNodeResource(6).getPrimaryHierarchy().get(0);
final String grandParentParentAfterMove = getNodeResource(6).getPrimaryHierarchy().get(0);
assertEquals("Wrong node parent.", root2ID, grandParentParentAfterMove);
final String grandParentID = getNodeResource(3).getId();
final String parentIDOfTheParentFolder =
getNodeResource(4).getPrimaryHierarchy().get(0);
final String parentIDOfTheParentFolder = getNodeResource(4).getPrimaryHierarchy().get(0);
assertEquals("Wrong node parent.", grandParentID, parentIDOfTheParentFolder);
final String parentID = getNodeResource(4).getId();
final String contentParentID =
getNodeResource(5).getPrimaryHierarchy().get(0);
final String contentParentID = getNodeResource(5).getPrimaryHierarchy().get(0);
assertEquals("Wrong node parent.", parentID, contentParentID);
}
@@ -918,8 +962,7 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
assertTrue("Wrong aspect.", resource.getAspectNames().contains("cm:versionable"));
final String folder2ID = getNodeResource(2).getId();
final String moveFileParentAfterMove =
getNodeResource(5).getPrimaryHierarchy().get(0);
final String moveFileParentAfterMove = getNodeResource(5).getPrimaryHierarchy().get(0);
assertEquals("Wrong node parent.", folder2ID, moveFileParentAfterMove);
}
@@ -946,8 +989,7 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
assertEquals("test_new_name", resource.getName());
final String folder2ID = getNodeResource(2).getId();
final String moveFileParentAfterMove =
getNodeResource(4).getPrimaryHierarchy().get(0);
final String moveFileParentAfterMove = getNodeResource(4).getPrimaryHierarchy().get(0);
assertEquals("Wrong node parent.", folder2ID, moveFileParentAfterMove);
}
@@ -989,8 +1031,7 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
checkNumOfEvents(3);
final String folder2ID = getNodeResource(2).getId();
final String moveFileParentAfterMove =
getNodeResource(3).getPrimaryHierarchy().get(0);
final String moveFileParentAfterMove = getNodeResource(3).getPrimaryHierarchy().get(0);
assertEquals("Wrong node parent.", folder2ID, moveFileParentAfterMove);
}
@@ -1003,7 +1044,6 @@ public class UpdateRepoEventIT extends AbstractContextAwareRepoEvent
final Set<String> originalAspects = resource.getAspectNames();
assertNotNull(originalAspects);
retryingTransactionHelper.doInTransaction(() -> {
// Add cm:geographic aspect with default value
nodeService.addAspect(nodeRef, ContentModel.ASPECT_GEOGRAPHIC, null);