use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-repository by Alfresco.
the class CopyServiceImplTest method checkCopiedNode.
/**
* Check that the copied node contains the state we are expecting
*
* @param sourceNodeRef the source node reference
* @param destinationNodeRef the destination node reference
*/
private void checkCopiedNode(NodeRef sourceNodeRef, NodeRef destinationNodeRef, boolean newCopy, boolean sameStore, boolean copyChildren) {
if (newCopy == true) {
if (sameStore == true) {
// Check that the copy aspect has been applied to the copy
boolean hasCopyAspect = nodeService.hasAspect(destinationNodeRef, ContentModel.ASPECT_COPIEDFROM);
assertTrue("Missing aspect: " + ContentModel.ASPECT_COPIEDFROM, hasCopyAspect);
List<AssociationRef> assocs = nodeService.getTargetAssocs(destinationNodeRef, ContentModel.ASSOC_ORIGINAL);
assertEquals("Expectd exactly one reference back to original", 1, assocs.size());
NodeRef checkSourceNodeRef = assocs.get(0).getTargetRef();
assertEquals("Copy refers to incorrect original source", sourceNodeRef, checkSourceNodeRef);
} else {
// Check that destiantion has the same id as the source
assertEquals(sourceNodeRef.getId(), destinationNodeRef.getId());
}
}
boolean hasTestAspect = nodeService.hasAspect(destinationNodeRef, TEST_ASPECT_QNAME);
assertTrue(hasTestAspect);
// Check that all the correct properties have been copied
Map<QName, Serializable> destinationProperties = nodeService.getProperties(destinationNodeRef);
assertNotNull(destinationProperties);
String value1 = (String) destinationProperties.get(PROP1_QNAME_MANDATORY);
assertNotNull(value1);
assertEquals(TEST_VALUE_1, value1);
String value2 = (String) destinationProperties.get(PROP2_QNAME_OPTIONAL);
assertNotNull(value2);
assertEquals(TEST_VALUE_2, value2);
String value3 = (String) destinationProperties.get(PROP3_QNAME_MANDATORY);
assertNotNull(value3);
assertEquals(TEST_VALUE_1, value3);
String value4 = (String) destinationProperties.get(PROP4_QNAME_OPTIONAL);
assertNotNull(value4);
assertEquals(TEST_VALUE_2, value4);
// Check all the target associations have been copied
List<AssociationRef> destinationTargets = nodeService.getTargetAssocs(destinationNodeRef, TEST_ASSOC_TYPE_QNAME);
assertNotNull(destinationTargets);
assertEquals(1, destinationTargets.size());
AssociationRef nodeAssocRef = destinationTargets.get(0);
assertNotNull(nodeAssocRef);
assertEquals(targetNodeRef, nodeAssocRef.getTargetRef());
// Check all the child associations have been copied
List<ChildAssociationRef> childAssocRefs = nodeService.getChildAssocs(destinationNodeRef);
assertNotNull(childAssocRefs);
int expectedSize = copyChildren ? 2 : 0;
if (nodeService.hasAspect(destinationNodeRef, RuleModel.ASPECT_RULES) == true) {
expectedSize = expectedSize + 1;
}
assertEquals(expectedSize, childAssocRefs.size());
for (ChildAssociationRef ref : childAssocRefs) {
if (ref.getQName().equals(TEST_CHILD_ASSOC_QNAME2) == true) {
// Since this child is non-primary in the source it will always be non-primary in the destination
assertFalse(ref.isPrimary());
assertEquals(nonPrimaryChildNodeRef, ref.getChildRef());
} else {
if (copyChildren == false) {
if (ref.getTypeQName().equals(RuleModel.ASSOC_RULE_FOLDER) == true) {
assertTrue(ref.isPrimary());
assertTrue(childNodeRef.equals(ref.getChildRef()) == false);
} else {
assertFalse(ref.isPrimary());
assertEquals(childNodeRef, ref.getChildRef());
}
} else {
assertTrue(ref.isPrimary());
assertTrue(childNodeRef.equals(ref.getChildRef()) == false);
// TODO need to check that the copied child has all the correct details ..
}
}
}
}
use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-repository by Alfresco.
the class ContentDiskDriver method cloneNodeAspects.
/**
* Clone/move aspects/properties between nodes
*
* @param newName new name of the file
* @param fromNode NodeRef the node to copy from
* @param toNode NodeRef the node to copy to
* @param ctx Filesystem Context
*/
private void cloneNodeAspects(String newName, NodeRef fromNode, NodeRef toNode, ContentContext ctx) {
if (nodeService.hasAspect(fromNode, ContentModel.ASPECT_LOCKABLE)) {
// Remove the lockable aspect from the old working copy, add it to the new file
nodeService.removeAspect(fromNode, ContentModel.ASPECT_LOCKABLE);
nodeService.addAspect(toNode, ContentModel.ASPECT_LOCKABLE, null);
if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_RENAME))
logger.debug(" Moved aspect " + ContentModel.ASPECT_LOCKABLE + " to new document");
}
if (nodeService.hasAspect(fromNode, ContentModel.ASPECT_WORKING_COPY)) {
// Add the working copy aspect to the new file
Map<QName, Serializable> workingCopyProperties = new HashMap<QName, Serializable>(1);
workingCopyProperties.put(ContentModel.PROP_WORKING_COPY_OWNER, nodeService.getProperty(fromNode, ContentModel.PROP_WORKING_COPY_OWNER));
nodeService.addAspect(toNode, ContentModel.ASPECT_WORKING_COPY, workingCopyProperties);
// Remove the working copy aspect from old working copy file
nodeService.removeAspect(fromNode, ContentModel.ASPECT_WORKING_COPY);
if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_RENAME))
logger.debug(" Moved aspect " + ContentModel.ASPECT_WORKING_COPY + " to new document");
}
if (nodeService.hasAspect(fromNode, ContentModel.ASPECT_COPIEDFROM)) {
// Add the copied from aspect to the new file
List<AssociationRef> assocs = nodeService.getSourceAssocs(fromNode, ContentModel.ASSOC_ORIGINAL);
if (assocs.size() > 0) {
AssociationRef assoc = assocs.get(0);
NodeRef originalNodeRef = assoc.getTargetRef();
nodeService.createAssociation(toNode, originalNodeRef, ContentModel.ASSOC_ORIGINAL);
}
// Remove the copied from aspect from old working copy file
nodeService.removeAspect(fromNode, ContentModel.ASPECT_COPIEDFROM);
if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_RENAME))
logger.debug(" Moved aspect " + ContentModel.ASPECT_COPIEDFROM + " to new document");
// // Check if the original node is locked
//
// if ( lockService.getLockType( copiedFromNode) == null) {
//
// // Add the lock back onto the original file
//
// lockService.lock( copiedFromNode, LockType.READ_ONLY_LOCK);
//
// // DEBUG
//
// if ( logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_RENAME))
// logger.debug(" Re-locked copied from node " + copiedFromNode);
// }
}
for (QName aspectName : nodeService.getAspects(fromNode)) {
if (!_excludedNamespaces.contains(aspectName.getNamespaceURI())) {
nodeService.addAspect(toNode, aspectName, null);
}
}
// Copy over all other properties from non system namespaces
Map<QName, Serializable> fromProps = nodeService.getProperties(fromNode);
for (Map.Entry<QName, Serializable> entry : fromProps.entrySet()) {
QName propName = entry.getKey();
if (!_excludedNamespaces.contains(propName.getNamespaceURI())) {
nodeService.setProperty(toNode, propName, entry.getValue());
}
}
// Check if the new file name is a temporary file, remove any versionable aspect from it
String newNameNorm = newName.toLowerCase();
if (newNameNorm.endsWith(".tmp") || newNameNorm.endsWith(".temp")) {
if (nodeService.hasAspect(toNode, ContentModel.ASPECT_VERSIONABLE))
nodeService.removeAspect(toNode, ContentModel.ASPECT_VERSIONABLE);
// Add the temporary aspect, also prevents versioning
nodeService.addAspect(toNode, ContentModel.ASPECT_TEMPORARY, null);
if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_RENAME))
logger.debug(" Removed versionable aspect from temp file");
}
for (QName propName : _copyProperties) {
Serializable nodeProp = nodeService.getProperty(fromNode, propName);
if (nodeProp != null)
nodeService.setProperty(toNode, propName, nodeProp);
}
}
use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-repository by Alfresco.
the class RepoSecondaryManifestProcessorImpl method processPeerAssociations.
/**
* Process the peer associations
*
* @param requiredAssocs List<AssociationRef>
* @param currentAssocs List<AssociationRef>
* @param nodeRef NodeRef
* @param isSource boolean
*/
private void processPeerAssociations(List<AssociationRef> requiredAssocs, List<AssociationRef> currentAssocs, NodeRef nodeRef, boolean isSource) {
if (requiredAssocs == null) {
requiredAssocs = new ArrayList<AssociationRef>();
}
if (currentAssocs == null) {
currentAssocs = new ArrayList<AssociationRef>();
}
List<AssociationRefKey> keysRequired = new ArrayList<AssociationRefKey>();
List<AssociationRefKey> keysCurrent = new ArrayList<AssociationRefKey>();
/**
* Which assocs do we need to add ?
*
* Need to compare on sourceNodeRef, targetNodeRef and qname but ignore, irrelevant id property
* which is why we need to introduce AssociationRefKey
*/
for (AssociationRef ref : requiredAssocs) {
keysRequired.add(new AssociationRefKey(ref));
}
for (AssociationRef ref : currentAssocs) {
keysCurrent.add(new AssociationRefKey(ref));
}
/**
* Which assocs do we need to add?
*/
for (AssociationRefKey ref : keysRequired) {
if (!keysCurrent.contains(ref)) {
// We don't have an existing association with this required node
NodeRef otherNode = isSource ? ref.targetRef : ref.sourceRef;
if (nodeService.exists(otherNode)) {
// the other node exists in this repo
NodeRef parent = isSource ? nodeRef : ref.sourceRef;
NodeRef child = isSource ? ref.targetRef : nodeRef;
if (log.isDebugEnabled()) {
log.debug("need to add peer assoc from:" + parent + ", to:" + child + ", qname:" + ref.assocTypeQName);
}
nodeService.createAssociation(parent, child, ref.assocTypeQName);
}
}
}
// {
for (AssociationRefKey ref : keysCurrent) {
if (!keysRequired.contains(ref)) {
if (log.isDebugEnabled()) {
log.debug("need to remove peer assoc from:" + ref.sourceRef + ", to:" + ref.targetRef + ", qname:" + ref.assocTypeQName);
}
nodeService.removeAssociation(ref.sourceRef, ref.targetRef, ref.assocTypeQName);
}
}
// }
}
use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-repository by Alfresco.
the class PeerAssociatedNodeFinder method processExcludedSet.
/**
* @param thisNode NodeRef
* @return Set<NodeRef>
*/
private Set<NodeRef> processExcludedSet(NodeRef thisNode) {
Set<NodeRef> results = new HashSet<NodeRef>(89);
NodeService nodeService = serviceRegistry.getNodeService();
// Find any peer nodes (filtering as necessary)
List<AssociationRef> targets = nodeService.getTargetAssocs(thisNode, RegexQNamePattern.MATCH_ALL);
boolean filterPeers = !peerAssociationTypes.isEmpty();
for (AssociationRef target : targets) {
if (!filterPeers || !peerAssociationTypes.contains(target.getTypeQName())) {
results.add(target.getTargetRef());
}
}
return results;
}
use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-repository by Alfresco.
the class XMLTransferManifestReader method startElement.
/**
* Start Element
*/
public void startElement(String uri, String localName, String prefixName, Attributes atts) throws SAXException {
QName elementQName = QName.resolveToQName(this, prefixName);
HashMap<String, String> namespace = new HashMap<String, String>();
namespaces.addFirst(namespace);
/**
* Look for any namespace attributes
*/
for (int i = 0; i < atts.getLength(); i++) {
QName attributeQName = QName.resolveToQName(this, atts.getQName(i));
if (attributeQName.getNamespaceURI().equals(XMLNS_URI)) {
namespace.put(attributeQName.getLocalName(), atts.getValue(i));
}
}
if (elementQName == null) {
return;
}
if (elementQName.getNamespaceURI().equals(TRANSFER_URI))
;
{
// This is one of the transfer manifest elements
String elementName = elementQName.getLocalName();
// Simple and stupid parser for now
if (elementName.equals(ManifestModel.LOCALNAME_TRANSFER_MAINIFEST)) {
// Good we got this
} else if (elementName.equals(ManifestModel.LOCALNAME_TRANSFER_HEADER)) {
TransferManifestHeader header = new TransferManifestHeader();
props.put("header", header);
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_DELETED_NODE)) {
TransferManifestDeletedNode node = new TransferManifestDeletedNode();
NodeRef nodeRef = new NodeRef(atts.getValue("", "nodeRef"));
node.setNodeRef(nodeRef);
props.put("node", node);
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_NODE)) {
TransferManifestNormalNode node = new TransferManifestNormalNode();
NodeRef nodeRef = new NodeRef(atts.getValue("", "nodeRef"));
QName type = QName.createQName(atts.getValue("", "nodeType"));
node.setNodeRef(nodeRef);
node.setType(type);
QName ancestorType = QName.createQName(atts.getValue("", "ancestorType"));
node.setAncestorType(ancestorType);
props.put("node", node);
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_ASPECTS)) {
TransferManifestNormalNode node = (TransferManifestNormalNode) props.get("node");
node.setAspects(new HashSet<QName>());
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_ASPECT)) {
buffer = new StringBuffer();
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_PROPERTIES)) {
TransferManifestNormalNode node = (TransferManifestNormalNode) props.get("node");
HashMap<QName, Serializable> properties = new HashMap<QName, Serializable>();
node.setProperties(properties);
props.put("properties", properties);
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_PROPERTY)) {
QName name = QName.createQName(atts.getValue("", "name"));
props.put("name", name);
props.remove("values");
props.remove("mlvalues");
} else if (elementName.equals(ManifestModel.LOCALNAME_HEADER_CREATED_DATE)) {
buffer = new StringBuffer();
} else if (elementName.equals(ManifestModel.LOCALNAME_HEADER_NODE_COUNT)) {
buffer = new StringBuffer();
} else if (elementName.equals(ManifestModel.LOCALNAME_HEADER_REPOSITORY_ID)) {
buffer = new StringBuffer();
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_PARENT_ASSOCS)) {
TransferManifestNormalNode node = (TransferManifestNormalNode) props.get("node");
ArrayList<ChildAssociationRef> parentAssocs = new ArrayList<ChildAssociationRef>();
node.setParentAssocs(parentAssocs);
// To receive the primary parent assoc.
props.put("parentAssocs", parentAssocs);
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_CHILD_ASSOCS)) {
TransferManifestNormalNode node = (TransferManifestNormalNode) props.get("node");
node.setChildAssocs(new ArrayList<ChildAssociationRef>());
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_CHILD_ASSOC)) {
buffer = new StringBuffer();
NodeRef to = new NodeRef(atts.getValue("", "to"));
QName type = QName.createQName(atts.getValue("", "type"));
Boolean isPrimary = Boolean.parseBoolean(atts.getValue("", "isPrimary"));
props.put("to", to);
props.put("type", type);
props.put("isPrimary", isPrimary);
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_PARENT_ASSOC)) {
buffer = new StringBuffer();
NodeRef from = new NodeRef(atts.getValue("", "from"));
QName type = QName.createQName(atts.getValue("", "type"));
Boolean isPrimary = Boolean.parseBoolean(atts.getValue("", "isPrimary"));
props.put("from", from);
props.put("type", type);
props.put("isPrimary", isPrimary);
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_TARGET_ASSOCS)) {
TransferManifestNormalNode node = (TransferManifestNormalNode) props.get("node");
List<AssociationRef> assocs = new ArrayList<AssociationRef>();
node.setTargetAssocs(assocs);
props.put("assocs", assocs);
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_SOURCE_ASSOCS)) {
TransferManifestNormalNode node = (TransferManifestNormalNode) props.get("node");
List<AssociationRef> assocs = new ArrayList<AssociationRef>();
node.setSourceAssocs(assocs);
props.put("assocs", assocs);
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_ASSOC)) {
NodeRef source = new NodeRef(atts.getValue("", "source"));
NodeRef target = new NodeRef(atts.getValue("", "target"));
QName type = QName.createQName(atts.getValue("", "type"));
props.put("source", source);
props.put("target", target);
props.put("type", type);
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_PRIMARY_PARENT)) {
buffer = new StringBuffer();
ArrayList<ChildAssociationRef> parentAssocs = new ArrayList<ChildAssociationRef>();
// Synthetic element - To receive the primary parent assoc.
props.put("parentAssocs", parentAssocs);
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_VALUES)) {
Collection<Serializable> values = new ArrayList<Serializable>();
props.put("values", values);
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_VALUE_STRING)) {
props.put("className", atts.getValue("", "className"));
buffer = new StringBuffer();
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_VALUE_NULL)) {
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_VALUE_SERIALIZED)) {
props.put("encoding", atts.getValue("", "encoding"));
buffer = new StringBuffer();
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_MLVALUE)) {
MLText mltext = (MLText) props.get("mlvalues");
if (mltext == null) {
mltext = new MLText();
props.put("mlvalues", mltext);
}
String strLocale = (String) atts.getValue("", "locale");
Locale locale = I18NUtil.parseLocale(strLocale);
props.put("locale", locale);
buffer = new StringBuffer();
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_CONTENT_HEADER)) {
String contentURL = (String) atts.getValue("", "contentURL");
String mimetype = (String) atts.getValue("", "mimetype");
String strLocale = (String) atts.getValue("", "locale");
Locale locale = I18NUtil.parseLocale(strLocale);
String encoding = (String) atts.getValue("", "encoding");
String sizeStr = (String) atts.getValue("", "size");
Long size = Long.valueOf(sizeStr);
ContentData contentHeader = new ContentData(contentURL, mimetype, size.longValue(), encoding, locale);
props.put("contentHeader", contentHeader);
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_ACL)) {
String isInherited = (String) atts.getValue("", "isInherited");
ManifestAccessControl acl = new ManifestAccessControl();
if ("TRUE".equalsIgnoreCase(isInherited)) {
acl.setInherited(true);
}
props.put("acl", acl);
} else if (elementName.equals(ManifestModel.LOCALNAME_HEADER_VERSION)) {
String versionMajor = (String) atts.getValue("", "versionMajor");
String versionMinor = (String) atts.getValue("", "versionMinor");
String versionRevision = (String) atts.getValue("", "versionRevision");
String edition = (String) atts.getValue("", "edition");
props.put("headerVersion", new TransferVersionImpl(versionMajor, versionMinor, versionRevision, edition));
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_ACL_PERMISSION)) {
String authority = (String) atts.getValue("", "authority");
String permission = (String) atts.getValue("", "permission");
String status = (String) atts.getValue("", "status");
ManifestPermission perm = new ManifestPermission();
perm.setAuthority(authority);
perm.setPermission(permission);
perm.setStatus(status);
props.put("permission", perm);
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_CATEGORIES)) {
props.put("categories", new HashMap<NodeRef, ManifestCategory>());
} else if (elementName.equals(ManifestModel.LOCALNAME_ELEMENT_CATEGORY)) {
ManifestCategory cat = new ManifestCategory();
String path = (String) atts.getValue("", "path");
cat.setPath(path);
props.put("category", cat);
}
}
// if transfer URI
}
Aggregations