properties)
{
@@ -1046,26 +1048,27 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
properties.remove(ContentModel.PROP_NODE_UUID);
properties.remove(ContentModel.PROP_NODE_DBID);
}
-
+
/**
- * Adds all properties used by the
- * {@link ContentModel#ASPECT_REFERENCEABLE referencable aspect}.
+ * Adds all properties used by the {@link ContentModel#ASPECT_REFERENCEABLE referencable aspect}.
*
- * This method can be used to ensure that the values used by the aspect
- * are present as node properties.
+ * This method can be used to ensure that the values used by the aspect are present as node properties.
*
- * This method also ensures that the {@link ContentModel#PROP_NAME name property}
- * is always present as a property on a node.
+ * This method also ensures that the {@link ContentModel#PROP_NAME name property} is always present as a property on
+ * a node.
*
- * @param node the node with the values
- * @param nodeRef the node reference containing the values required
- * @param properties the node properties
+ * @param node
+ * the node with the values
+ * @param nodeRef
+ * the node reference containing the values required
+ * @param properties
+ * the node properties
*/
private void addIntrinsicProperties(Node node, Map properties)
{
NodeRef nodeRef = tenantService.getBaseName(node.getNodeRef());
properties.put(ContentModel.PROP_STORE_PROTOCOL, nodeRef.getStoreRef().getProtocol());
- properties.put(ContentModel.PROP_STORE_IDENTIFIER, nodeRef.getStoreRef().getIdentifier());
+ properties.put(ContentModel.PROP_STORE_IDENTIFIER, nodeRef.getStoreRef().getIdentifier());
properties.put(ContentModel.PROP_NODE_UUID, nodeRef.getId());
properties.put(ContentModel.PROP_NODE_DBID, node.getId());
// add the ID as the name, if required
@@ -1080,21 +1083,21 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
Node node = getNodeNotNull(nodeRef);
return getPropertiesImpl(node);
}
-
+
private Map getPropertiesImpl(Node node) throws InvalidNodeRefException
{
- Map propDefs = dictionaryService.getPropertyDefs(node.getTypeQName().getQName());
+ Map propDefs = dictionaryService.getPropertyDefs(node.getTypeQName().getQName());
Map nodeProperties = node.getProperties();
Map ret = new HashMap(nodeProperties.size());
// copy values
- for (Map.Entry entry: nodeProperties.entrySet())
+ for (Map.Entry entry : nodeProperties.entrySet())
{
Long propertyQNameId = entry.getKey();
QName propertyQName = qnameDAO.getQNameEntity(propertyQNameId).getQName();
PropertyValue propertyValue = entry.getValue();
// get the property definition
PropertyDefinition propertyDef = propDefs.get(propertyQName);
-
+
// convert to the correct type
Serializable value = makeSerializableValue(propertyDef, propertyValue);
// copy across
@@ -1105,12 +1108,12 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// done
return ret;
}
-
+
public Serializable getProperty(NodeRef nodeRef, QName qname) throws InvalidNodeRefException
{
// get the property from the node
Node node = getNodeNotNull(nodeRef);
-
+
// spoof referencable properties
if (qname.equals(ContentModel.PROP_STORE_PROTOCOL))
{
@@ -1129,7 +1132,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
{
return node.getId();
}
-
+
// Get the QName entity
QNameEntity qnameEntity = qnameDAO.getQNameEntity(qname);
if (qnameEntity == null)
@@ -1141,16 +1144,16 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
{
Map properties = node.getProperties();
PropertyValue propertyValue = properties.get(qnameEntity.getId());
-
+
// check if we need to provide a spoofed name
if (propertyValue == null && qname.equals(ContentModel.PROP_NAME))
{
return nodeRef.getId();
}
-
+
// Convert any NodeRefs using multi-tenant translation
PropertyDefinition propertyDef = dictionaryService.getProperty(qname);
-
+
// convert to the correct type
Serializable value = makeSerializableValue(propertyDef, propertyValue);
// done
@@ -1159,21 +1162,21 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
}
/**
- * Ensures that all required properties are present on the node and copies the
- * property values to the Node
.
+ * 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.
+ * 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.
+ * 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
{
Node node = getNodeNotNull(nodeRef);
-
+
// Invoke policy behaviours
invokeBeforeUpdateNode(nodeRef);
@@ -1181,33 +1184,35 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
Map propertiesBefore = getPropertiesImpl(node);
Map propertiesAfter = setPropertiesImpl(node, properties);
- setChildUniqueName(node); // ensure uniqueness
+ setChildUniqueName(node); // ensure uniqueness
// Invoke policy behaviours
invokeOnUpdateNode(nodeRef);
invokeOnUpdateProperties(nodeRef, propertiesBefore, propertiesAfter);
}
-
+
/**
- * Does the work of setting the property values. Returns a map containing the state of the properties after the set
+ * Does the work of setting the property values. Returns a map containing the state of the properties after the set
* operation is complete.
*
- * @param node the node
- * @param properties the map of property values
- * @return the map of property values after the set operation is complete
+ * @param node
+ * the node
+ * @param properties
+ * the map of property values
+ * @return the map of property values after the set operation is complete
* @throws InvalidNodeRefException
*/
private Map setPropertiesImpl(Node node, Map properties) throws InvalidNodeRefException
{
ParameterCheck.mandatory("properties", properties);
-
+
// remove referencable properties
extractIntrinsicProperties(node, properties);
-
+
// copy properties onto node
Map nodeProperties = node.getProperties();
nodeProperties.clear();
-
+
// check the property type and copy the values across
for (QName propertyQName : properties.keySet())
{
@@ -1219,59 +1224,61 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
PropertyValue propertyValue = makePropertyValue(propertyDef, value);
nodeProperties.put(propertyQNameEntity.getId(), propertyValue);
}
-
+
// update the node status
NodeRef nodeRef = node.getNodeRef();
nodeDaoService.recordChangeId(nodeRef);
-
+
// Return the properties after
return Collections.unmodifiableMap(properties);
}
-
+
/**
- * 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.
*
* @see DbNodeServiceImpl.NullPropertyValue
*/
public void setProperty(NodeRef nodeRef, QName qname, Serializable value) throws InvalidNodeRefException
{
Assert.notNull(qname);
-
+
// get the node
Node node = getNodeNotNull(nodeRef);
-
+
// Invoke policy behaviours
invokeBeforeUpdateNode(nodeRef);
-
+
// Do the set operation
Map propertiesBefore = getPropertiesImpl(node);
Map propertiesAfter = setPropertyImpl(node, qname, value);
-
+
if (qname.equals(ContentModel.PROP_NAME))
{
- setChildUniqueName(node); // ensure uniqueness
+ setChildUniqueName(node); // ensure uniqueness
}
// Invoke policy behaviours
invokeOnUpdateNode(nodeRef);
invokeOnUpdateProperties(nodeRef, propertiesBefore, propertiesAfter);
}
-
+
/**
- * Does the work of setting a property value. Returns the values of the properties after the set operation is
+ * Does the work of setting a property value. Returns the values of the properties after the set operation is
* complete.
*
- * @param node the node
- * @param qname the qname of the property
- * @param value the value of the property
- * @return the values of the properties after the set operation is complete
+ * @param node
+ * the node
+ * @param qname
+ * the qname of the property
+ * @param value
+ * the value of the property
+ * @return the values of the properties after the set operation is complete
* @throws InvalidNodeRefException
*/
private Map setPropertyImpl(Node node, QName qname, Serializable value) throws InvalidNodeRefException
{
NodeRef nodeRef = node.getNodeRef();
-
+
Map properties = node.getProperties();
PropertyDefinition propertyDef = dictionaryService.getProperty(qname);
// Get the persistable key
@@ -1279,26 +1286,26 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// get a persistable value
PropertyValue propertyValue = makePropertyValue(propertyDef, value);
properties.put(qnameEntity.getId(), propertyValue);
-
+
// update the node status
nodeDaoService.recordChangeId(nodeRef);
-
- return getPropertiesImpl(node);
+
+ return getPropertiesImpl(node);
}
-
+
public void removeProperty(NodeRef nodeRef, QName qname) throws InvalidNodeRefException
{
if (qname.equals(ContentModel.PROP_NAME))
{
throw new UnsupportedOperationException("The property " + qname + " may not be removed individually");
}
-
+
// Get the node
Node node = getNodeNotNull(nodeRef);
-
+
// Invoke policy behaviours
invokeBeforeUpdateNode(nodeRef);
-
+
// Get the persistable QNameEntity
QNameEntity qnameEntity = qnameDAO.getOrCreateQNameEntity(qname);
// Get the values before
@@ -1308,7 +1315,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
properties.remove(qnameEntity.getId());
// Get the values afterwards
Map propertiesAfter = getPropertiesImpl(node);
-
+
// Invoke policy behaviours
invokeOnUpdateNode(nodeRef);
invokeOnUpdateProperties(nodeRef, propertiesBefore, propertiesAfter);
@@ -1358,7 +1365,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// no match - ignore
continue;
}
- ChildAssociationRef childAssocRef = tenantService.getBaseName(assoc.getChildAssocRef());
+ ChildAssociationRef childAssocRef = tenantService.getBaseName(assoc.getChildAssocRef());
results.add(childAssocRef);
}
// done
@@ -1371,13 +1378,13 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
public List getChildAssocs(NodeRef nodeRef, QNamePattern typeQNamePattern, QNamePattern qnamePattern)
{
Node node = getNodeNotNull(nodeRef);
-
+
Collection childAssocRefs = null;
// if the type is the wildcard type, and the qname is not a search, then use a shortcut query
if (typeQNamePattern.equals(RegexQNamePattern.MATCH_ALL) && qnamePattern instanceof QName)
{
// get all child associations with the specific qualified name
- childAssocRefs = nodeDaoService.getChildAssocRefs(node, (QName)qnamePattern);
+ childAssocRefs = nodeDaoService.getChildAssocRefs(node, (QName) qnamePattern);
}
else
{
@@ -1401,7 +1408,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// done
return orderedList;
}
-
+
private List reorderChildAssocs(Collection childAssocRefs)
{
// shortcut if there are no assocs
@@ -1412,11 +1419,11 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// sort results
ArrayList orderedList = new ArrayList(childAssocRefs);
Collections.sort(orderedList);
-
+
// list of results
int nthSibling = 0;
Iterator iterator = orderedList.iterator();
- while(iterator.hasNext())
+ while (iterator.hasNext())
{
ChildAssociationRef childAssocRef = iterator.next();
childAssocRef.setNthSibling(nthSibling);
@@ -1459,8 +1466,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
return assocRef;
}
- public AssociationRef createAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName)
- throws InvalidNodeRefException, AssociationExistsException
+ public AssociationRef createAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName) throws InvalidNodeRefException, AssociationExistsException
{
Node sourceNode = getNodeNotNull(sourceRef);
Node targetNode = getNodeNotNull(targetRef);
@@ -1476,12 +1482,11 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// Invoke policy behaviours
invokeOnCreateAssociation(assocRef);
-
+
return assocRef;
}
- public void removeAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName)
- throws InvalidNodeRefException
+ public void removeAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName) throws InvalidNodeRefException
{
Node sourceNode = getNodeNotNull(sourceRef);
Node targetNode = getNodeNotNull(targetRef);
@@ -1493,10 +1498,10 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
return;
}
AssociationRef assocRef = assoc.getNodeAssocRef();
-
+
// delete it
nodeDaoService.deleteNodeAssoc(assoc);
-
+
// Invoke policy behaviours
invokeOnDeleteAssociation(assocRef);
}
@@ -1513,7 +1518,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// check qname pattern
if (!qnamePattern.isMatch(assocTypeQName))
{
- continue; // the assoc name doesn't match the pattern given
+ continue; // the assoc name doesn't match the pattern given
}
nodeAssocRefs.add(assoc.getNodeAssocRef());
}
@@ -1533,37 +1538,36 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// check qname pattern
if (!qnamePattern.isMatch(assocTypeQName))
{
- continue; // the assoc name doesn't match the pattern given
+ continue; // the assoc name doesn't match the pattern given
}
nodeAssocRefs.add(assoc.getNodeAssocRef());
}
// done
return nodeAssocRefs;
}
-
+
/**
* Recursive method used to build up paths from a given node to the root.
*
- * Whilst walking up the hierarchy to the root, some nodes may have a root aspect.
- * Everytime one of these is encountered, a new path is farmed off, but the method
- * continues to walk up the hierarchy.
+ * Whilst walking up the hierarchy to the root, some nodes may have a root aspect. Everytime one of these is
+ * encountered, a new path is farmed off, but the method continues to walk up the hierarchy.
*
- * @param currentNode the node to start from, i.e. the child node to work upwards from
- * @param currentPath the path from the current node to the descendent that we started from
- * @param completedPaths paths that have reached the root are added to this collection
- * @param assocStack the parent-child relationships traversed whilst building the path.
- * Used to detected cyclic relationships.
- * @param primaryOnly true if only the primary parent association must be traversed.
- * If this is true, then the only root is the top level node having no parents.
+ * @param currentNode
+ * the node to start from, i.e. the child node to work upwards from
+ * @param currentPath
+ * the path from the current node to the descendent that we started from
+ * @param completedPaths
+ * paths that have reached the root are added to this collection
+ * @param assocStack
+ * the parent-child relationships traversed whilst building the path. Used to detected cyclic
+ * relationships.
+ * @param primaryOnly
+ * true if only the primary parent association must be traversed. If this is true, then the only root is
+ * the top level node having no parents.
* @throws CyclicChildRelationshipException
*/
- private void prependPaths(
- final Node currentNode,
- final Path currentPath,
- Collection completedPaths,
- Stack assocStack,
- boolean primaryOnly)
- throws CyclicChildRelationshipException
+ private void prependPaths(final Node currentNode, final Path currentPath, Collection completedPaths, Stack assocStack, boolean primaryOnly)
+ throws CyclicChildRelationshipException
{
NodeRef currentNodeRef = currentNode.getNodeRef();
// get the parent associations of the given node
@@ -1573,23 +1577,19 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// does the current node have a root aspect?
boolean isRoot = hasAspect(currentNodeRef, ContentModel.ASPECT_ROOT);
boolean isStoreRoot = currentNode.getTypeQName().getQName().equals(ContentModel.TYPE_STOREROOT);
-
- // look for a root. If we only want the primary root, then ignore all but the top-level root.
- if (isRoot && !(primaryOnly && hasParents)) // exclude primary search with parents present
+
+ // look for a root. If we only want the primary root, then ignore all but the top-level root.
+ if (isRoot && !(primaryOnly && hasParents)) // exclude primary search with parents present
{
// create a one-sided assoc ref for the root node and prepend to the stack
// this effectively spoofs the fact that the current node is not below the root
// - we put this assoc in as the first assoc in the path must be a one-sided
- // reference pointing to the root node
- ChildAssociationRef assocRef = new ChildAssociationRef(
- null,
- null,
- null,
- getRootNode(currentNode.getNodeRef().getStoreRef()));
+ // reference pointing to the root node
+ ChildAssociationRef assocRef = new ChildAssociationRef(null, null, null, getRootNode(currentNode.getNodeRef().getStoreRef()));
// create a path to save and add the 'root' assoc
Path pathToSave = new Path();
Path.ChildAssocElement first = null;
- for (Path.Element element: currentPath)
+ for (Path.Element element : currentPath)
{
if (first == null)
{
@@ -1603,27 +1603,23 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
if (first != null)
{
// mimic an association that would appear if the current node was below the root node
- // or if first beneath the root node it will make the real thing
- ChildAssociationRef updateAssocRef = new ChildAssociationRef(
- isStoreRoot ? ContentModel.ASSOC_CHILDREN : first.getRef().getTypeQName(),
- getRootNode(currentNode.getNodeRef().getStoreRef()),
- first.getRef().getQName(),
- first.getRef().getChildRef());
- Path.Element newFirst = new Path.ChildAssocElement(updateAssocRef);
+ // or if first beneath the root node it will make the real thing
+ ChildAssociationRef updateAssocRef = new ChildAssociationRef(isStoreRoot ? ContentModel.ASSOC_CHILDREN : first.getRef().getTypeQName(), getRootNode(currentNode
+ .getNodeRef().getStoreRef()), first.getRef().getQName(), first.getRef().getChildRef());
+ Path.Element newFirst = new Path.ChildAssocElement(updateAssocRef);
pathToSave.prepend(newFirst);
}
-
+
Path.Element element = new Path.ChildAssocElement(assocRef);
pathToSave.prepend(element);
-
+
// store the path just built
completedPaths.add(pathToSave);
}
if (parentAssocs.size() == 0 && !isRoot)
{
- throw new RuntimeException("Node without parents does not have root aspect: " +
- currentNodeRef);
+ throw new RuntimeException("Node without parents does not have root aspect: " + currentNodeRef);
}
// walk up each parent association
for (ChildAssoc assoc : parentAssocs)
@@ -1632,12 +1628,8 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
if (assocStack.contains(assoc))
{
// the association was present already
- throw new CyclicChildRelationshipException(
- "Cyclic parent-child relationship detected: \n" +
- " current node: " + currentNode + "\n" +
- " current path: " + currentPath + "\n" +
- " next assoc: " + assoc,
- assoc);
+ throw new CyclicChildRelationshipException("Cyclic parent-child relationship detected: \n"
+ + " current node: " + currentNode + "\n" + " current path: " + currentPath + "\n" + " next assoc: " + assoc, assoc);
}
// do we consider only primary assocs?
if (primaryOnly && !assoc.getIsPrimary())
@@ -1645,18 +1637,12 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
continue;
}
// build a path element
- NodeRef parentRef = tenantService.getBaseName(assoc.getParent().getNodeRef());
+ NodeRef parentRef = tenantService.getBaseName(assoc.getParent().getNodeRef());
QName qname = assoc.getQname();
NodeRef childRef = tenantService.getBaseName(assoc.getChild().getNodeRef());
boolean isPrimary = assoc.getIsPrimary();
// build a real association reference
- ChildAssociationRef assocRef = new ChildAssociationRef(
- assoc.getTypeQName().getQName(),
- parentRef,
- qname,
- childRef,
- isPrimary,
- -1);
+ ChildAssociationRef assocRef = new ChildAssociationRef(assoc.getTypeQName().getQName(), parentRef, qname, childRef, isPrimary, -1);
// Ordering is not important here: We are building distinct paths upwards
Path.Element element = new Path.ChildAssocElement(assocRef);
// create a new path that builds on the current path
@@ -1666,7 +1652,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
path.prepend(element);
// get parent node
Node parentNode = assoc.getParent();
-
+
// push the assoc stack, recurse and pop
assocStack.push(assoc);
prependPaths(parentNode, path, completedPaths, assocStack, primaryOnly);
@@ -1681,17 +1667,17 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
*/
public Path getPath(NodeRef nodeRef) throws InvalidNodeRefException
{
- List paths = getPaths(nodeRef, true); // checks primary path count
+ List paths = getPaths(nodeRef, true); // checks primary path count
if (paths.size() == 1)
{
- return paths.get(0); // we know there is only one
+ return paths.get(0); // we know there is only one
}
- throw new RuntimeException("Primary path count not checked"); // checked by getPaths()
+ throw new RuntimeException("Primary path count not checked"); // checked by getPaths()
}
/**
- * When searching for primaryOnly == true
, checks that there is exactly
- * one path.
+ * 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
@@ -1706,13 +1692,13 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
Stack assocStack = new Stack();
// call recursive method to sort it out
prependPaths(node, currentPath, paths, assocStack, primaryOnly);
-
+
// check that for the primary only case we have exactly one path
if (primaryOnly && paths.size() != 1)
{
throw new RuntimeException("Node has " + paths.size() + " primary paths: " + nodeRef);
}
-
+
// done
if (loggerPaths.isDebugEnabled())
{
@@ -1734,7 +1720,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
}
return paths;
}
-
+
private void archiveNode(NodeRef nodeRef, StoreRef archiveStoreRef)
{
QNameEntity aspectQNameEntityArchived = qnameDAO.getOrCreateQNameEntity(ContentModel.ASPECT_ARCHIVED);
@@ -1743,62 +1729,49 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
QNameEntity propQNameArchivedBy = qnameDAO.getOrCreateQNameEntity(ContentModel.PROP_ARCHIVED_BY);
QNameEntity propQNameArchivedDate = qnameDAO.getOrCreateQNameEntity(ContentModel.PROP_ARCHIVED_DATE);
QNameEntity propQNameArchivedOriginalParentAssoc = qnameDAO.getOrCreateQNameEntity(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC);
-
+
NodeStatus nodeStatus = nodeDaoService.getNodeStatus(nodeRef, false);
Node node = nodeStatus.getNode();
ChildAssoc primaryParentAssoc = nodeDaoService.getPrimaryParentAssoc(node);
-
+
// add the aspect
Set aspects = node.getAspects();
aspects.add(aspectQNameEntityArchived.getId());
Map properties = node.getProperties();
- PropertyValue archivedByProperty = makePropertyValue(
- dictionaryService.getProperty(ContentModel.PROP_ARCHIVED_BY),
- AuthenticationUtil.getCurrentUserName());
+ PropertyValue archivedByProperty = makePropertyValue(dictionaryService.getProperty(ContentModel.PROP_ARCHIVED_BY), AuthenticationUtil.getCurrentUserName());
properties.put(propQNameArchivedBy.getId(), archivedByProperty);
- PropertyValue archivedDateProperty = makePropertyValue(
- dictionaryService.getProperty(ContentModel.PROP_ARCHIVED_DATE),
- new Date());
+ PropertyValue archivedDateProperty = makePropertyValue(dictionaryService.getProperty(ContentModel.PROP_ARCHIVED_DATE), new Date());
properties.put(propQNameArchivedDate.getId(), archivedDateProperty);
- PropertyValue archivedPrimaryParentNodeRefProperty = makePropertyValue(
- dictionaryService.getProperty(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC),
- primaryParentAssoc.getChildAssocRef());
+ PropertyValue archivedPrimaryParentNodeRefProperty = makePropertyValue(dictionaryService.getProperty(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC), primaryParentAssoc
+ .getChildAssocRef());
properties.put(propQNameArchivedOriginalParentAssoc.getId(), archivedPrimaryParentNodeRefProperty);
PropertyValue originalOwnerProperty = properties.get(propQNameEntityOwner.getId());
PropertyValue originalCreatorProperty = properties.get(propQNameEntityCreator.getId());
if (originalOwnerProperty != null || originalCreatorProperty != null)
{
QNameEntity propQNameArchivedOriginalOwner = qnameDAO.getOrCreateQNameEntity(ContentModel.PROP_ARCHIVED_ORIGINAL_OWNER);
- properties.put(
- propQNameArchivedOriginalOwner.getId(),
- originalOwnerProperty != null ? originalOwnerProperty : originalCreatorProperty);
+ properties.put(propQNameArchivedOriginalOwner.getId(), originalOwnerProperty != null ? originalOwnerProperty : originalCreatorProperty);
}
-
+
// change the node ownership
QNameEntity ownableAspectQNameEntity = qnameDAO.getOrCreateQNameEntity(ContentModel.ASPECT_OWNABLE);
aspects.add(ownableAspectQNameEntity.getId());
- PropertyValue newOwnerProperty = makePropertyValue(
- dictionaryService.getProperty(ContentModel.PROP_ARCHIVED_ORIGINAL_OWNER),
- AuthenticationUtil.getCurrentUserName());
+ PropertyValue newOwnerProperty = makePropertyValue(dictionaryService.getProperty(ContentModel.PROP_ARCHIVED_ORIGINAL_OWNER), AuthenticationUtil.getCurrentUserName());
QNameEntity propQNameOwner = qnameDAO.getOrCreateQNameEntity(ContentModel.PROP_OWNER);
properties.put(propQNameOwner.getId(), newOwnerProperty);
-
+
// move the node
NodeRef archiveStoreRootNodeRef = getRootNode(archiveStoreRef);
- moveNode(
- nodeRef,
- archiveStoreRootNodeRef,
- ContentModel.ASSOC_CHILDREN,
- QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "archivedItem"));
-
+ moveNode(nodeRef, archiveStoreRootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "archivedItem"));
+
// the node reference has changed due to the store move
nodeRef = node.getNodeRef();
// as has the node status
nodeStatus = nodeDaoService.getNodeStatus(nodeRef, true);
-
+
// get the IDs of all the node's primary children, including its own
Map nodeStatusesById = getNodeHierarchy(nodeStatus, null);
-
+
// Archive all the associations between the archived nodes and non-archived nodes
for (NodeStatus nodeStatusToArchive : nodeStatusesById.values())
{
@@ -1810,14 +1783,15 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
archiveAssocs(nodeToArchive, nodeStatusesById);
}
}
-
+
/**
- * Performs all the necessary housekeeping involved in changing a node's store.
- * This method cascades down through all the primary children of the node as
- * well.
+ * Performs all the necessary housekeeping involved in changing a node's store. This method cascades down through
+ * all the primary children of the node as well.
*
- * @param node the node whose store is changing
- * @param store the new store for the node
+ * @param node
+ * the node whose store is changing
+ * @param store
+ * the new store for the node
*/
private void moveNodeToStore(Node node, Store store)
{
@@ -1825,7 +1799,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
NodeStatus nodeStatus = nodeDaoService.getNodeStatus(nodeRef, true);
// get the IDs of all the node's primary children, including its own
Map nodeStatusesById = getNodeHierarchy(nodeStatus, null);
-
+
// move each node into the archive store
for (NodeStatus oldNodeStatus : nodeStatusesById.values())
{
@@ -1833,46 +1807,47 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
NodeRef targetStoreNodeRef = new NodeRef(store.getStoreRef(), oldNodeStatus.getKey().getGuid());
if (exists(targetStoreNodeRef))
{
- // It is there already. It must be an archive of an earlier version, so just wipe it out
+ // It is there already. It must be an archive of an earlier version, so just wipe it out
Node archivedNode = getNodeNotNull(targetStoreNodeRef);
nodeDaoService.deleteNode(archivedNode, true);
// We need to flush here as the node deletion may not take effect before the node creation
- // is done. As this will only occur during a clash, it is not going to add extra overhead
+ // is done. As this will only occur during a clash, it is not going to add extra overhead
// to the general system performance.
nodeDaoService.flush();
}
-
+
Node nodeToMove = oldNodeStatus.getNode();
if (nodeToMove == null)
{
- // Ignore it. It was moved already.
+ // Ignore it. It was moved already.
continue;
}
NodeRef oldNodeRef = nodeToMove.getNodeRef();
nodeToMove.setStore(store);
NodeRef newNodeRef = nodeToMove.getNodeRef();
-
+
// update old status
oldNodeStatus.setNode(null);
// create the new status
NodeStatus newNodeStatus = nodeDaoService.getNodeStatus(newNodeRef, true);
newNodeStatus.setNode(nodeToMove);
-
+
// Record change IDs
nodeDaoService.recordChangeId(oldNodeRef);
nodeDaoService.recordChangeId(newNodeRef);
-
+
invokeOnUpdateNode(newNodeRef);
}
}
-
+
/**
- * Fill the map of all primary children below the given node.
- * The given node will be added to the map and the method is recursive
- * to all primary children.
+ * Fill the map of all primary children below the given node. The given node will be added to the map and the method
+ * is recursive to all primary children.
*
- * @param nodeStatus the status of the node at the top of the hierarchy
- * @param nodeStatusesById a map of node statuses that will be reused as the return value
+ * @param nodeStatus
+ * the status of the node at the top of the hierarchy
+ * @param nodeStatusesById
+ * a map of node statuses that will be reused as the return value
* @return Returns a map of nodes in the hierarchy keyed by their IDs
*/
private Map getNodeHierarchy(NodeStatus nodeStatus, Map nodeStatusesById)
@@ -1883,7 +1858,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// this is the entry into the hierarchy - flush to ensure we are not stale
nodeDaoService.flush();
}
-
+
Node node = nodeStatus.getNode();
if (node == null)
{
@@ -1908,15 +1883,17 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
}
return nodeStatusesById;
}
-
+
/**
- * Archive all associations to and from the given node, with the
- * exception of associations to or from nodes in the given map.
+ * Archive all associations to and from the given node, with the exception of associations to or from nodes in the
+ * given map.
*
* Primary parent associations are also ignored.
*
- * @param node the node whose associations must be archived
- * @param nodesById a map of nodes partaking in the archival process
+ * @param node
+ * the node whose associations must be archived
+ * @param nodesById
+ * a map of nodes partaking in the archival process
*/
private void archiveAssocs(Node node, Map nodeStatusesById)
{
@@ -1991,13 +1968,13 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
{
nodeDaoService.deleteNodeAssoc(assoc);
}
-
+
// add archived aspect
QNameEntity archivedAssocsAspectQNameEntity = qnameDAO.getOrCreateQNameEntity(ContentModel.ASPECT_ARCHIVED_ASSOCS);
node.getAspects().add(archivedAssocsAspectQNameEntity.getId());
// set properties
Map properties = node.getProperties();
-
+
if (archivedParentAssocRefs.size() > 0)
{
QNameEntity propQNameEntity = qnameDAO.getOrCreateQNameEntity(ContentModel.PROP_ARCHIVED_PARENT_ASSOCS);
@@ -2050,7 +2027,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
QNameEntity propQNameEntityArchivedBy = qnameDAO.getOrCreateQNameEntity(ContentModel.PROP_ARCHIVED_BY);
QNameEntity propQNameEntityArchivedDate = qnameDAO.getOrCreateQNameEntity(ContentModel.PROP_ARCHIVED_DATE);
QNameEntity propQNameEntityOrigOwner = qnameDAO.getOrCreateQNameEntity(ContentModel.PROP_ARCHIVED_ORIGINAL_OWNER);
-
+
NodeStatus archivedNodeStatus = getNodeStatusNotNull(archivedNodeRef);
Node archivedNode = archivedNodeStatus.getNode();
Set aspects = archivedNode.getAspects();
@@ -2060,19 +2037,19 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
{
throw new AlfrescoRuntimeException("The node to archive is not an archive node");
}
- ChildAssociationRef originalPrimaryParentAssocRef = (ChildAssociationRef) makeSerializableValue(
- dictionaryService.getProperty(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC),
- properties.get(propQNameEntityOrigParentAssoc.getId()));
+ ChildAssociationRef originalPrimaryParentAssocRef = (ChildAssociationRef) makeSerializableValue(dictionaryService
+ .getProperty(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC), properties.get(propQNameEntityOrigParentAssoc.getId()));
PropertyValue originalOwnerProperty = properties.get(propQNameEntityOrigOwner.getId());
-
+
// remove the archived aspect
- removeAspect(archivedNodeRef, ContentModel.ASPECT_ARCHIVED); // allow policy to fire, e.g. for DictionaryModelType
-
+ removeAspect(archivedNodeRef, ContentModel.ASPECT_ARCHIVED); // allow policy to fire, e.g. for
+ // DictionaryModelType
+
properties.remove(propQNameEntityOrigParentAssoc.getId());
properties.remove(propQNameEntityArchivedBy.getId());
properties.remove(propQNameEntityArchivedDate.getId());
properties.remove(propQNameEntityOrigOwner.getId());
-
+
// restore the original ownership
if (originalOwnerProperty != null)
{
@@ -2080,7 +2057,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
aspects.add(ownableAspectQNameEntity.getId());
properties.put(propQNameEntityOwner.getId(), originalOwnerProperty);
}
-
+
if (destinationParentNodeRef == null)
{
// we must restore to the original location
@@ -2097,11 +2074,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
}
// move the node to the target parent, which may or may not be the original parent
- ChildAssociationRef newChildAssocRef = moveNode(
- archivedNodeRef,
- destinationParentNodeRef,
- assocTypeQName,
- assocQName);
+ ChildAssociationRef newChildAssocRef = moveNode(archivedNodeRef, destinationParentNodeRef, assocTypeQName, assocQName);
archivedNodeRef = newChildAssocRef.getChildRef();
archivedNodeStatus = nodeDaoService.getNodeStatus(archivedNodeRef, false);
@@ -2113,17 +2086,15 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
Node restoreNode = restoreNodeStatus.getNode();
restoreAssocs(restoreNode, propQNameEntityOrigParentAssoc);
}
-
+
// the node reference has changed due to the store move
NodeRef restoredNodeRef = archivedNode.getNodeRef();
-
+
// done
if (logger.isDebugEnabled())
{
- logger.debug("Restored node: \n" +
- " original noderef: " + archivedNodeRef + "\n" +
- " restored noderef: " + restoredNodeRef + "\n" +
- " new parent: " + destinationParentNodeRef);
+ logger.debug("Restored node: \n"
+ + " original noderef: " + archivedNodeRef + "\n" + " restored noderef: " + restoredNodeRef + "\n" + " new parent: " + destinationParentNodeRef);
}
return restoredNodeRef;
}
@@ -2135,9 +2106,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
Map properties = node.getProperties();
// restore parent associations
- Collection parentAssocRefs = (Collection) getProperty(
- nodeRef,
- ContentModel.PROP_ARCHIVED_PARENT_ASSOCS);
+ Collection parentAssocRefs = (Collection) getProperty(nodeRef, ContentModel.PROP_ARCHIVED_PARENT_ASSOCS);
if (parentAssocRefs != null)
{
for (ChildAssociationRef assocRef : parentAssocRefs)
@@ -2150,23 +2119,16 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
Node parentNode = getNodeNotNull(parentNodeRef);
// get the name to use for the unique child check
QName assocTypeQName = assocRef.getTypeQName();
- nodeDaoService.newChildAssoc(
- parentNode,
- node,
- assocRef.isPrimary(),
- assocTypeQName,
- assocRef.getQName());
+ nodeDaoService.newChildAssoc(parentNode, node, assocRef.isPrimary(), assocTypeQName, assocRef.getQName());
}
properties.remove(propQNameEntityOrigParentAssoc.getId());
}
-
+
// make sure that the node name uniqueness is enforced
setChildUniqueName(node);
-
+
// restore child associations
- Collection childAssocRefs = (Collection) getProperty(
- nodeRef,
- ContentModel.PROP_ARCHIVED_CHILD_ASSOCS);
+ Collection childAssocRefs = (Collection) getProperty(nodeRef, ContentModel.PROP_ARCHIVED_CHILD_ASSOCS);
if (childAssocRefs != null)
{
for (ChildAssociationRef assocRef : childAssocRefs)
@@ -2179,21 +2141,14 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
Node childNode = getNodeNotNull(childNodeRef);
QName assocTypeQName = assocRef.getTypeQName();
// get the name to use for the unique child check
- nodeDaoService.newChildAssoc(
- node,
- childNode,
- assocRef.isPrimary(),
- assocTypeQName,
- assocRef.getQName());
+ nodeDaoService.newChildAssoc(node, childNode, assocRef.isPrimary(), assocTypeQName, assocRef.getQName());
// ensure that the name uniqueness is enforced for the child node
setChildUniqueName(childNode);
}
properties.remove(ContentModel.PROP_ARCHIVED_CHILD_ASSOCS);
}
// restore source associations
- Collection sourceAssocRefs = (Collection) getProperty(
- nodeRef,
- ContentModel.PROP_ARCHIVED_SOURCE_ASSOCS);
+ Collection sourceAssocRefs = (Collection) getProperty(nodeRef, ContentModel.PROP_ARCHIVED_SOURCE_ASSOCS);
if (sourceAssocRefs != null)
{
for (AssociationRef assocRef : sourceAssocRefs)
@@ -2209,9 +2164,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
properties.remove(ContentModel.PROP_ARCHIVED_SOURCE_ASSOCS);
}
// restore target associations
- Collection targetAssocRefs = (Collection) getProperty(
- nodeRef,
- ContentModel.PROP_ARCHIVED_TARGET_ASSOCS);
+ Collection targetAssocRefs = (Collection) getProperty(nodeRef, ContentModel.PROP_ARCHIVED_TARGET_ASSOCS);
if (targetAssocRefs != null)
{
for (AssociationRef assocRef : targetAssocRefs)
@@ -2229,12 +2182,14 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// remove the aspect
node.getAspects().remove(ContentModel.ASPECT_ARCHIVED_ASSOCS);
}
-
+
/**
* Checks the dictionary's definition of the association to assign a unique name to the child node.
*
- * @param assocTypeQName the type of the child association
- * @param childNode the child node being added. The name will be extracted from it, if necessary.
+ * @param assocTypeQName
+ * the type of the child association
+ * @param childNode
+ * the child node being added. The name will be extracted from it, if necessary.
* @return Returns the value to be put on the child association for uniqueness, or null if
*/
private void setChildUniqueName(Node childNode)
@@ -2277,9 +2232,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// done
if (logger.isDebugEnabled())
{
- logger.debug(
- "Unique name set for all " + parentAssocs.size() + " parent associations: \n" +
- " name: " + useName);
+ logger.debug("Unique name set for all " + parentAssocs.size() + " parent associations: \n" + " name: " + useName);
}
}
}