nodePair = getNodePairNotNull(nodeRef);
// Invoke policy behaviour
invokeBeforeUpdateNode(nodeRef);
// cm:name special handling
setPropertiesCommonWork(
nodePair,
Collections.singletonMap(qname, value));
// Add the property and all required defaults
boolean changed = addAspectsAndProperties(
nodePair, null,
null, null,
null, Collections.singletonMap(qname, value), false);
if (changed)
{
// Invoke policy behaviour
invokeOnUpdateNode(nodeRef);
// Index
nodeIndexer.indexUpdateNode(nodeRef);
}
}
/**
* Ensures that all required properties are present on the node and copies the
* property values to the Node
.
*
* To remove a property, remove it from the map before calling this method.
* Null-valued properties are allowed.
*
* 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.
*
* @see Node#getProperties()
*/
public void setProperties(NodeRef nodeRef, Map properties) throws InvalidNodeRefException
{
Pair nodePair = getNodePairNotNull(nodeRef);
// Invoke policy behaviours
invokeBeforeUpdateNode(nodeRef);
// SetProperties common tasks
setPropertiesCommonWork(nodePair, properties);
// Set properties and defaults, overwriting the existing properties
boolean changed = addAspectsAndProperties(nodePair, null, null, null, null, properties, true);
if (changed)
{
// Invoke policy behaviours
invokeOnUpdateNode(nodeRef);
// Index
nodeIndexer.indexUpdateNode(nodeRef);
}
}
public void addProperties(NodeRef nodeRef, Map properties) throws InvalidNodeRefException
{
Pair nodePair = getNodePairNotNull(nodeRef);
// Invoke policy behaviours
invokeBeforeUpdateNode(nodeRef);
// cm:name special handling
setPropertiesCommonWork(nodePair, properties);
// Add properties and defaults
boolean changed = addAspectsAndProperties(nodePair, null, null, null, null, properties, false);
if (changed)
{
// Invoke policy behaviours
invokeOnUpdateNode(nodeRef);
// Index
nodeIndexer.indexUpdateNode(nodeRef);
}
}
public void removeProperty(NodeRef nodeRef, QName qname) throws InvalidNodeRefException
{
// Get the node
Pair nodePair = getNodePairNotNull(nodeRef);
Long nodeId = nodePair.getFirst();
// Invoke policy behaviours
invokeBeforeUpdateNode(nodeRef);
// Get the values before
Map propertiesBefore = getPropertiesImpl(nodePair);
// cm:name special handling
if (qname.equals(ContentModel.PROP_NAME))
{
String oldName = extractNameProperty(nodeDAO.getNodeProperties(nodeId));
String newName = null;
setChildNameUnique(nodePair, newName, oldName);
}
// Remove
nodeDAO.removeNodeProperties(nodeId, Collections.singleton(qname));
// Invoke policy behaviours
Map propertiesAfter = getPropertiesImpl(nodePair);
invokeOnUpdateNode(nodeRef);
invokeOnUpdateProperties(nodeRef, propertiesBefore, propertiesAfter);
// Index
nodeIndexer.indexUpdateNode(nodeRef);
}
public Collection getParents(NodeRef nodeRef) throws InvalidNodeRefException
{
List parentAssocs = getParentAssocs(
nodeRef,
RegexQNamePattern.MATCH_ALL,
RegexQNamePattern.MATCH_ALL);
// Copy into the set to avoid duplicates
Set parentNodeRefs = new HashSet(parentAssocs.size());
for (ChildAssociationRef parentAssoc : parentAssocs)
{
NodeRef parentNodeRef = parentAssoc.getParentRef();
parentNodeRefs.add(parentNodeRef);
}
// Done
return new ArrayList(parentNodeRefs);
}
/**
* Filters out any associations if their qname is not a match to the given pattern.
*/
public List getParentAssocs(
final NodeRef nodeRef,
final QNamePattern typeQNamePattern,
final QNamePattern qnamePattern)
{
// Get the node
Pair nodePair = getNodePairNotNull(nodeRef);
Long nodeId = nodePair.getFirst();
final List results = new ArrayList(10);
// We have a callback handler to filter results
ChildAssocRefQueryCallback callback = new ChildAssocRefQueryCallback()
{
public boolean preLoadNodes()
{
return false;
}
public boolean handle(
Pair childAssocPair,
Pair parentNodePair,
Pair childNodePair)
{
if (!typeQNamePattern.isMatch(childAssocPair.getSecond().getTypeQName()))
{
return true;
}
if (!qnamePattern.isMatch(childAssocPair.getSecond().getQName()))
{
return true;
}
results.add(childAssocPair.getSecond());
return true;
}
public void done()
{
}
};
// Get the assocs pointing to it
QName typeQName = (typeQNamePattern instanceof QName) ? (QName) typeQNamePattern : null;
QName qname = (qnamePattern instanceof QName) ? (QName) qnamePattern : null;
nodeDAO.getParentAssocs(nodeId, typeQName, qname, null, callback);
// done
return results;
}
/**
* Filters out any associations if their qname is not a match to the given pattern.
*/
public List getChildAssocs(NodeRef nodeRef, final QNamePattern typeQNamePattern, final QNamePattern qnamePattern)
{
return getChildAssocs(nodeRef, typeQNamePattern, qnamePattern, true) ;
}
/**
* Filters out any associations if their qname is not a match to the given pattern.
*/
public List getChildAssocs(
NodeRef nodeRef,
final QNamePattern typeQNamePattern,
final QNamePattern qnamePattern,
final boolean preload)
{
// Get the node
Pair nodePair = getNodePairNotNull(nodeRef);
Long nodeId = nodePair.getFirst();
final List results = new ArrayList(10);
// We have a callback handler to filter results
ChildAssocRefQueryCallback callback = new ChildAssocRefQueryCallback()
{
public boolean preLoadNodes()
{
return preload;
}
public boolean handle(
Pair childAssocPair,
Pair parentNodePair,
Pair childNodePair)
{
if (!typeQNamePattern.isMatch(childAssocPair.getSecond().getTypeQName()))
{
return true;
}
if (!qnamePattern.isMatch(childAssocPair.getSecond().getQName()))
{
return true;
}
results.add(childAssocPair.getSecond());
return true;
}
public void done()
{
}
};
// Get the assocs pointing to it
QName typeQName = (typeQNamePattern instanceof QName) ? (QName) typeQNamePattern : null;
QName qname = (qnamePattern instanceof QName) ? (QName) qnamePattern : null;
nodeDAO.getChildAssocs(nodeId, null, typeQName, qname, null, null, callback);
// sort the results
List orderedList = reorderChildAssocs(results);
// Done
return orderedList;
}
public List getChildAssocs(NodeRef nodeRef, Set childNodeTypeQNames)
{
// Get the node
Pair nodePair = getNodePairNotNull(nodeRef);
Long nodeId = nodePair.getFirst();
final List results = new ArrayList(100);
NodeDAO.ChildAssocRefQueryCallback callback = new NodeDAO.ChildAssocRefQueryCallback()
{
public boolean handle(
Pair childAssocPair,
Pair parentNodePair,
Pair childNodePair)
{
results.add(childAssocPair.getSecond());
// More results
return true;
}
public boolean preLoadNodes()
{
return true;
}
public void done()
{
}
};
// Get all child associations with the specific qualified name
nodeDAO.getChildAssocsByChildTypes(nodeId, childNodeTypeQNames, callback);
// Sort the results
List orderedList = reorderChildAssocs(results);
// Done
return orderedList;
}
private List reorderChildAssocs(Collection childAssocRefs)
{
// shortcut if there are no assocs
if (childAssocRefs.size() == 0)
{
return Collections.emptyList();
}
// sort results
ArrayList orderedList = new ArrayList(childAssocRefs);
Collections.sort(orderedList);
// list of results
int nthSibling = 0;
Iterator iterator = orderedList.iterator();
while(iterator.hasNext())
{
ChildAssociationRef childAssocRef = iterator.next();
childAssocRef.setNthSibling(nthSibling);
nthSibling++;
}
// done
return orderedList;
}
public NodeRef getChildByName(NodeRef nodeRef, QName assocTypeQName, String childName)
{
// Get the node
Pair nodePair = getNodePairNotNull(nodeRef);
Long nodeId = nodePair.getFirst();
Pair childAssocPair = nodeDAO.getChildAssoc(nodeId, assocTypeQName, childName);
if (childAssocPair != null)
{
return childAssocPair.getSecond().getChildRef();
}
else
{
return null;
}
}
public List getChildrenByName(NodeRef nodeRef, QName assocTypeQName, Collection childNames)
{
// Get the node
Pair nodePair = getNodePairNotNull(nodeRef);
Long nodeId = nodePair.getFirst();
final List results = new ArrayList(100);
NodeDAO.ChildAssocRefQueryCallback callback = new NodeDAO.ChildAssocRefQueryCallback()
{
public boolean handle(
Pair childAssocPair,
Pair parentNodePair,
Pair childNodePair)
{
results.add(childAssocPair.getSecond());
// More results
return true;
}
public boolean preLoadNodes()
{
return true;
}
public void done()
{
}
};
// Get all child associations with the specific qualified name
nodeDAO.getChildAssocs(nodeId, assocTypeQName, childNames, callback);
// Sort the results
List orderedList = reorderChildAssocs(results);
// Done
return orderedList;
}
public ChildAssociationRef getPrimaryParent(NodeRef nodeRef) throws InvalidNodeRefException
{
// Get the node
Pair nodePair = getNodePairNotNull(nodeRef);
Long nodeId = nodePair.getFirst();
// get the primary parent assoc
Pair assocPair = nodeDAO.getPrimaryParentAssoc(nodeId);
// done - the assoc may be null for a root node
ChildAssociationRef assocRef = null;
if (assocPair == null)
{
assocRef = new ChildAssociationRef(null, null, null, nodeRef);
}
else
{
assocRef = assocPair.getSecond();
}
return assocRef;
}
public AssociationRef createAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName)
throws InvalidNodeRefException, AssociationExistsException
{
Pair sourceNodePair = getNodePairNotNull(sourceRef);
long sourceNodeId = sourceNodePair.getFirst();
Pair targetNodePair = getNodePairNotNull(targetRef);
long targetNodeId = targetNodePair.getFirst();
// we are sure that the association doesn't exist - make it
Long assocId = nodeDAO.newNodeAssoc(sourceNodeId, targetNodeId, assocTypeQName);
AssociationRef assocRef = new AssociationRef(assocId, sourceRef, assocTypeQName, targetRef);
// Invoke policy behaviours
invokeOnCreateAssociation(assocRef);
// Add missing aspects
addAspectsAndProperties(sourceNodePair, assocTypeQName, null, null, null, null, false);
return assocRef;
}
public Collection getChildAssocsWithoutParentAssocsOfType(NodeRef parent, QName assocTypeQName)
{
// Get the parent node
Pair nodePair = getNodePairNotNull(parent);
Long parentNodeId = nodePair.getFirst();
final List results = new ArrayList(100);
NodeDAO.ChildAssocRefQueryCallback callback = new NodeDAO.ChildAssocRefQueryCallback()
{
public boolean handle(Pair childAssocPair, Pair parentNodePair,
Pair childNodePair)
{
results.add(childAssocPair.getSecond());
// More results
return true;
}
public boolean preLoadNodes()
{
return false;
}
public void done()
{
}
};
// Get the child associations that meet the criteria
nodeDAO.getChildAssocsWithoutParentAssocsOfType(parentNodeId, assocTypeQName, callback);
// done
return results;
}
public void removeAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName)
throws InvalidNodeRefException
{
Pair sourceNodePair = getNodePairNotNull(sourceRef);
long sourceNodeId = sourceNodePair.getFirst();
Pair targetNodePair = getNodePairNotNull(targetRef);
long targetNodeId = targetNodePair.getFirst();
// delete it
int assocsDeleted = nodeDAO.removeNodeAssoc(sourceNodeId, targetNodeId, assocTypeQName);
if (assocsDeleted > 0)
{
AssociationRef assocRef = new AssociationRef(sourceRef, assocTypeQName, targetRef);
// Invoke policy behaviours
invokeOnDeleteAssociation(assocRef);
}
}
public AssociationRef getAssoc(Long id)
{
return nodeDAO.getNodeAssoc(id).getSecond();
}
public List getTargetAssocs(NodeRef sourceRef, QNamePattern qnamePattern)
{
Pair sourceNodePair = getNodePairNotNull(sourceRef);
long sourceNodeId = sourceNodePair.getFirst();
// get all assocs to target
Collection> assocPairs = nodeDAO.getTargetNodeAssocs(sourceNodeId);
List nodeAssocRefs = new ArrayList(assocPairs.size());
for (Pair assocPair : assocPairs)
{
AssociationRef assocRef = assocPair.getSecond();
// check qname pattern
if (!qnamePattern.isMatch(assocRef.getTypeQName()))
{
continue; // the assoc name doesn't match the pattern given
}
nodeAssocRefs.add(assocRef);
}
// done
return nodeAssocRefs;
}
public List getSourceAssocs(NodeRef targetRef, QNamePattern qnamePattern)
{
Pair targetNodePair = getNodePairNotNull(targetRef);
long targetNodeId = targetNodePair.getFirst();
// get all assocs to target
Collection> assocPairs = nodeDAO.getSourceNodeAssocs(targetNodeId);
List nodeAssocRefs = new ArrayList(assocPairs.size());
for (Pair assocPair : assocPairs)
{
AssociationRef assocRef = assocPair.getSecond();
// check qname pattern
if (!qnamePattern.isMatch(assocRef.getTypeQName()))
{
continue; // the assoc name doesn't match the pattern given
}
nodeAssocRefs.add(assocRef);
}
// done
return nodeAssocRefs;
}
/**
* @see #getPaths(NodeRef, boolean)
* @see #prependPaths(Node, Path, Collection, Stack, boolean)
*/
public Path getPath(NodeRef nodeRef) throws InvalidNodeRefException
{
List paths = getPaths(nodeRef, true); // checks primary path count
if (paths.size() == 1)
{
return paths.get(0); // we know there is only one
}
throw new RuntimeException("Primary path count not checked"); // checked by getPaths()
}
/**
* When searching for primaryOnly == true
, checks that there is exactly
* one path.
* @see #prependPaths(Node, Path, Collection, Stack, boolean)
*/
public List getPaths(NodeRef nodeRef, boolean primaryOnly) throws InvalidNodeRefException
{
// get the starting node
Pair nodePair = getNodePairNotNull(nodeRef);
return nodeDAO.getPaths(nodePair, primaryOnly);
}
private void archiveNode(NodeRef nodeRef, StoreRef archiveStoreRef)
{
Pair nodePair = getNodePairNotNull(nodeRef);
Long nodeId = nodePair.getFirst();
Pair primaryParentAssocPair = nodeDAO.getPrimaryParentAssoc(nodeId);
Set newAspects = new HashSet(5);
Map existingProperties = nodeDAO.getNodeProperties(nodeId);
Map newProperties = new HashMap(11);
// add the aspect
newAspects.add(ContentModel.ASPECT_ARCHIVED);
newProperties.put(ContentModel.PROP_ARCHIVED_BY, AuthenticationUtil.getFullyAuthenticatedUser());
newProperties.put(ContentModel.PROP_ARCHIVED_DATE, new Date());
newProperties.put(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC, primaryParentAssocPair.getSecond());
Serializable originalOwner = existingProperties.get(ContentModel.PROP_OWNER);
Serializable originalCreator = existingProperties.get(ContentModel.PROP_CREATOR);
if (originalOwner != null || originalCreator != null)
{
newProperties.put(
ContentModel.PROP_ARCHIVED_ORIGINAL_OWNER,
originalOwner != null ? originalOwner : originalCreator);
}
// change the node ownership
newAspects.add(ContentModel.ASPECT_OWNABLE);
newProperties.put(ContentModel.PROP_OWNER, AuthenticationUtil.getFullyAuthenticatedUser());
// Set the aspects and properties
nodeDAO.addNodeProperties(nodeId, newProperties);
nodeDAO.addNodeAspects(nodeId, newAspects);
// move the node
Pair archiveStoreRootNodePair = nodeDAO.getRootNode(archiveStoreRef);
moveNode(
nodeRef,
archiveStoreRootNodePair.getSecond(),
ContentModel.ASSOC_CHILDREN,
QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "archivedItem"));
}
public NodeRef restoreNode(NodeRef archivedNodeRef, NodeRef destinationParentNodeRef, QName assocTypeQName, QName assocQName)
{
Pair archivedNodePair = getNodePairNotNull(archivedNodeRef);
Long archivedNodeId = archivedNodePair.getFirst();
Set existingAspects = nodeDAO.getNodeAspects(archivedNodeId);
Set newAspects = new HashSet(5);
Map existingProperties = nodeDAO.getNodeProperties(archivedNodeId);
Map newProperties = new HashMap(11);
// the node must be a top-level archive node
if (!existingAspects.contains(ContentModel.ASPECT_ARCHIVED))
{
throw new AlfrescoRuntimeException("The node to restore is not an archive node");
}
ChildAssociationRef originalPrimaryParentAssocRef = (ChildAssociationRef) existingProperties.get(
ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC);
Serializable originalOwner = existingProperties.get(ContentModel.PROP_ARCHIVED_ORIGINAL_OWNER);
// remove the archived aspect
Set removePropertyQNames = new HashSet(11);
removePropertyQNames.add(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC);
removePropertyQNames.add(ContentModel.PROP_ARCHIVED_BY);
removePropertyQNames.add(ContentModel.PROP_ARCHIVED_DATE);
removePropertyQNames.add(ContentModel.PROP_ARCHIVED_ORIGINAL_OWNER);
nodeDAO.removeNodeProperties(archivedNodeId, removePropertyQNames);
nodeDAO.removeNodeAspects(archivedNodeId, Collections.singleton(ContentModel.ASPECT_ARCHIVED));
// restore the original ownership
if (originalOwner != null)
{
newAspects.add(ContentModel.ASPECT_OWNABLE);
newProperties.put(ContentModel.PROP_OWNER, originalOwner);
}
if (destinationParentNodeRef == null)
{
// we must restore to the original location
destinationParentNodeRef = originalPrimaryParentAssocRef.getParentRef();
}
// check the associations
if (assocTypeQName == null)
{
assocTypeQName = originalPrimaryParentAssocRef.getTypeQName();
}
if (assocQName == null)
{
assocQName = originalPrimaryParentAssocRef.getQName();
}
// move the node to the target parent, which may or may not be the original parent
ChildAssociationRef newChildAssocRef = moveNode(
archivedNodeRef,
destinationParentNodeRef,
assocTypeQName,
assocQName);
// the node reference has changed due to the store move
NodeRef restoredNodeRef = newChildAssocRef.getChildRef();
invokeOnRestoreNode(newChildAssocRef);
// done
if (logger.isDebugEnabled())
{
logger.debug("Restored node: \n" +
" original noderef: " + archivedNodeRef + "\n" +
" restored noderef: " + restoredNodeRef + "\n" +
" new parent: " + destinationParentNodeRef);
}
return restoredNodeRef;
}
/**
* Move Node
*
* Drops the old primary association and creates a new one
*/
public ChildAssociationRef moveNode(
NodeRef nodeToMoveRef,
NodeRef newParentRef,
QName assocTypeQName,
QName assocQName)
{
if (isDeletedNodeRef(newParentRef))
{
throw new InvalidNodeRefException("The parent node has been deleted", newParentRef);
}
Pair nodeToMovePair = getNodePairNotNull(nodeToMoveRef);
Pair parentNodePair = getNodePairNotNull(newParentRef);
Long nodeToMoveId = nodeToMovePair.getFirst();
QName nodeToMoveTypeQName = nodeDAO.getNodeType(nodeToMoveId);
NodeRef oldNodeToMoveRef = nodeToMovePair.getSecond();
Long parentNodeId = parentNodePair.getFirst();
NodeRef parentNodeRef = parentNodePair.getSecond();
StoreRef oldStoreRef = oldNodeToMoveRef.getStoreRef();
StoreRef newStoreRef = parentNodeRef.getStoreRef();
NodeRef newNodeToMoveRef = new NodeRef(newStoreRef, oldNodeToMoveRef.getId());
Pair newNodeToMovePair = new Pair(nodeToMoveId, newNodeToMoveRef);
// Get the primary parent association
Pair oldParentAssocPair = nodeDAO.getPrimaryParentAssoc(nodeToMoveId);
if (oldParentAssocPair == null)
{
// The node doesn't have parent. Moving it is not possible.
throw new IllegalArgumentException("Node " + nodeToMoveId + " doesn't have a parent. Use 'addChild' instead of move.");
}
ChildAssociationRef oldParentAssocRef = oldParentAssocPair.getSecond();
// Shortcut this whole process if nothing has changed
if (EqualsHelper.nullSafeEquals(oldParentAssocRef.getParentRef(), newParentRef) &&
EqualsHelper.nullSafeEquals(oldParentAssocRef.getTypeQName(), assocTypeQName) &&
EqualsHelper.nullSafeEquals(oldParentAssocRef.getQName(), assocQName))
{
// It's all just the same
return oldParentAssocRef;
}
boolean movingStore = !oldStoreRef.equals(newStoreRef);
// Invoke "Before"policy behaviour
if (movingStore)
{
// remove the deleted node from the list of new nodes
untrackNewNodeRef(nodeToMoveRef);
// track the deletion of this node - so we can prevent new associations to it.
trackDeletedNodeRef(nodeToMoveRef);
invokeBeforeDeleteNode(nodeToMoveRef);
invokeBeforeCreateNode(newParentRef, assocTypeQName, assocQName, nodeToMoveTypeQName);
}
else
{
invokeBeforeDeleteChildAssociation(oldParentAssocRef);
invokeBeforeCreateChildAssociation(newParentRef, nodeToMoveRef, assocTypeQName, assocQName, false);
}
// Move node under the new parent
Pair newParentAssocPair = nodeDAO.moveNode(
nodeToMoveId,
parentNodeId,
assocTypeQName,
assocQName);
ChildAssociationRef newParentAssocRef = newParentAssocPair.getSecond();
// Handle indexing differently if it is a store move
if (movingStore)
{
// The association existed before and the node is moving to a new store
nodeIndexer.indexDeleteNode(oldParentAssocRef);
nodeIndexer.indexCreateNode(newParentAssocRef);
}
else
{
// The node is in the same store and is just having it's child association modified
nodeIndexer.indexUpdateChildAssociation(oldParentAssocRef, newParentAssocRef);
}
// Call behaviours
if (movingStore)
{
Set nodeToMoveAspectQNames = nodeDAO.getNodeAspects(nodeToMoveId);
// The Node changes NodeRefs, so this is really the deletion of the old node and creation
// of a node in a new store as far as the clients are concerned.
invokeOnDeleteNode(oldParentAssocRef, nodeToMoveTypeQName, nodeToMoveAspectQNames, true);
invokeOnCreateNode(newParentAssocRef);
// Pull children to the new store
pullNodeChildrenToSameStore(newNodeToMovePair);
}
else
{
invokeOnCreateChildAssociation(newParentAssocRef, false);
invokeOnDeleteChildAssociation(oldParentAssocRef);
invokeOnMoveNode(oldParentAssocRef, newParentAssocRef);
}
// Done
return newParentAssocRef;
}
/**
* This process is less invasive than the move method as the child associations
* do not need to be remade.
*/
private void pullNodeChildrenToSameStore(Pair nodePair)
{
Long nodeId = nodePair.getFirst();
// Get the node's children, but only one's that aren't in the same store
final List> childNodePairs = new ArrayList>(5);
NodeDAO.ChildAssocRefQueryCallback callback = new NodeDAO.ChildAssocRefQueryCallback()
{
public boolean handle(
Pair childAssocPair,
Pair parentNodePair,
Pair childNodePair
)
{
// Add it
childNodePairs.add(childNodePair);
// More results
return true;
}
public boolean preLoadNodes()
{
return true;
}
public void done()
{
}
};
// We only need to move child nodes that are not already in the same store
nodeDAO.getChildAssocs(nodeId, null, null, null, Boolean.TRUE, Boolean.FALSE, callback);
// Each child must be moved to the same store as the parent
for (Pair oldChildNodePair : childNodePairs)
{
Long childNodeId = oldChildNodePair.getFirst();
NodeRef childNodeRef = oldChildNodePair.getSecond();
if (nodeDAO.getNodeRefStatus(childNodeRef).isDeleted())
{
// Node has already been deleted.
continue;
}
QName childNodeTypeQName = nodeDAO.getNodeType(childNodeId);
Set childNodeAspectQNames = nodeDAO.getNodeAspects(childNodeId);
Pair oldParentAssocPair = nodeDAO.getPrimaryParentAssoc(childNodeId);
Pair newChildNodePair = oldChildNodePair;
Pair newParentAssocPair = oldParentAssocPair;
ChildAssociationRef newParentAssocRef = newParentAssocPair.getSecond();
// remove the deleted node from the list of new nodes
untrackNewNodeRef(childNodeRef);
// track the deletion of this node - so we can prevent new associations to it.
trackDeletedNodeRef(childNodeRef);
// Fire node policies. This ensures that each node in the hierarchy gets a notification fired.
invokeBeforeDeleteNode(childNodeRef);
invokeBeforeCreateNode(
newParentAssocRef.getParentRef(),
newParentAssocRef.getTypeQName(),
newParentAssocRef.getQName(),
childNodeTypeQName);
// Move the node as this gives back the primary parent association
newParentAssocPair = nodeDAO.moveNode(childNodeId, nodeId, null,null);
// Index
nodeIndexer.indexCreateNode(newParentAssocPair.getSecond());
// Fire node policies. This ensures that each node in the hierarchy gets a notification fired.
invokeOnDeleteNode(oldParentAssocPair.getSecond(), childNodeTypeQName, childNodeAspectQNames, true);
invokeOnCreateNode(newParentAssocPair.getSecond());
// Cascade
pullNodeChildrenToSameStore(newChildNodePair);
}
}
public NodeRef getStoreArchiveNode(StoreRef storeRef)
{
StoreRef archiveStoreRef = storeArchiveMap.get(storeRef);
if (archiveStoreRef == null)
{
// no mapping for the given store
return null;
}
else
{
return getRootNode(archiveStoreRef);
}
}
private String extractNameProperty(Map properties)
{
Serializable nameValue = properties.get(ContentModel.PROP_NAME);
String name = (String) DefaultTypeConverter.INSTANCE.convert(String.class, nameValue);
return name;
}
/**
* 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 true if the child association cm:name was written
*/
private boolean setChildNameUnique(Pair childNodePair, String newName, String oldName)
{
if (newName == null)
{
newName = childNodePair.getSecond().getId(); // Use the node's GUID
}
Long childNodeId = childNodePair.getFirst();
if (EqualsHelper.nullSafeEquals(newName, oldName))
{
// The name has not changed
return false;
}
else
{
nodeDAO.setChildAssocsUniqueName(childNodeId, newName);
return true;
}
}
}