From 5de4783dee27332d3755164385c21aec20439a75 Mon Sep 17 00:00:00 2001 From: Dave Ward Date: Thu, 30 Sep 2010 18:45:02 +0000 Subject: [PATCH] Merged V3.3-BUG-FIX to HEAD 22796: Merged V3.3 to V3.3-BUG-FIX 22728: (RECORD ONLY) Undoing (reverse-merging) change 22715 as it should not have been committed on this branch. 22715 was a fix for ALF-4946 Possible NullPointerException during creation of thumbnails whose names are null-valued. 22757: Fix for ALF-4984 - Removed obsolete bean defs from custom-slingshot-application-context.xml.sample file for Share 22794: ALF-3858: Handle creation of custom subtypes and copying of their properties and aspects during the "MS Word Shuffle" 22795: Merged DEV/TEMPORARY to V3.3 22743: ALF-4949 : Impossible to import fileplan 1. Incorrect import url generation was fixed. 2. Manual testing was preformed. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@22797 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../org/alfresco/filesys/repo/CifsHelper.java | 6 +- .../filesys/repo/ContentDiskDriver.java | 77 ++++++++++++++++--- 2 files changed, 68 insertions(+), 15 deletions(-) diff --git a/source/java/org/alfresco/filesys/repo/CifsHelper.java b/source/java/org/alfresco/filesys/repo/CifsHelper.java index bae42dd366..d8fdf4c81d 100644 --- a/source/java/org/alfresco/filesys/repo/CifsHelper.java +++ b/source/java/org/alfresco/filesys/repo/CifsHelper.java @@ -324,7 +324,7 @@ public class CifsHelper * @return Returns a newly created file or folder node * @throws FileExistsException if the file or folder already exists */ - public NodeRef createNode(NodeRef rootNodeRef, String path, boolean isFile) throws FileExistsException + public NodeRef createNode(NodeRef rootNodeRef, String path, QName typeQName) throws FileExistsException { // split the path up into its constituents StringTokenizer tokenizer = new StringTokenizer(path, FileName.DOS_SEPERATOR_STR, false); @@ -355,8 +355,6 @@ public class CifsHelper folderPathElements, ContentModel.TYPE_FOLDER).getNodeRef(); } - // add the file or folder - QName typeQName = isFile ? ContentModel.TYPE_CONTENT : ContentModel.TYPE_FOLDER; try { NodeRef nodeRef = fileFolderService.create(parentFolderNodeRef, name, typeQName).getNodeRef(); @@ -367,7 +365,7 @@ public class CifsHelper logger.debug("Created node: \n" + " device root: " + rootNodeRef + "\n" + " path: " + path + "\n" + - " is file: " + isFile + "\n" + + " type: " + typeQName + "\n" + " new node: " + nodeRef); } return nodeRef; diff --git a/source/java/org/alfresco/filesys/repo/ContentDiskDriver.java b/source/java/org/alfresco/filesys/repo/ContentDiskDriver.java index aacad50f0c..a4eaf4bfef 100644 --- a/source/java/org/alfresco/filesys/repo/ContentDiskDriver.java +++ b/source/java/org/alfresco/filesys/repo/ContentDiskDriver.java @@ -22,11 +22,14 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.Serializable; import java.net.InetAddress; +import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.TreeSet; import java.util.concurrent.Callable; import javax.transaction.UserTransaction; @@ -133,10 +136,17 @@ public class ContentDiskDriver extends AlfrescoDiskDriver implements DiskInterfa // File state attributes public static final String AttrLinkNode = "ContentLinkNode"; - - // List of properties to copy during rename + + // List of content properties to copy during rename private static QName[] _copyProperties = { ContentModel.PROP_AUTHOR, ContentModel.PROP_TITLE, ContentModel.PROP_DESCRIPTION }; + + // List of property namespaces to exclude from copy during rename + + private static Set _excludedNamespaces = new TreeSet(Arrays.asList(new String[] + { + NamespaceService.CONTENT_MODEL_1_0_URI, NamespaceService.SYSTEM_MODEL_1_0_URI + })); // Services and helpers @@ -1957,7 +1967,7 @@ public class ContentDiskDriver extends AlfrescoDiskDriver implements DiskInterfa // Create it - the path will be created, if necessary - NodeRef nodeRef = cifsHelper.createNode(deviceRootNodeRef, path, true); + NodeRef nodeRef = cifsHelper.createNode(deviceRootNodeRef, path, ContentModel.TYPE_CONTENT); nodeService.addAspect(nodeRef, ContentModel.ASPECT_NO_CONTENT, null); return new Pair(parentPath, nodeRef); @@ -2135,7 +2145,7 @@ public class ContentDiskDriver extends AlfrescoDiskDriver implements DiskInterfa // Create it - the path will be created, if necessary - NodeRef nodeRef = cifsHelper.createNode(deviceRootNodeRef, path, false); + NodeRef nodeRef = cifsHelper.createNode(deviceRootNodeRef, path, ContentModel.TYPE_FOLDER); return new Pair(parentPath, nodeRef); } @@ -2882,6 +2892,7 @@ public class ContentDiskDriver extends AlfrescoDiskDriver implements DiskInterfa NodeRef targetNodeRef = null; boolean isFromVersionable = nodeService.hasAspect( nodeToMoveRef, ContentModel.ASPECT_VERSIONABLE); + boolean typesCompatible = true; if ( newExists == FileStatus.FileExists) { @@ -2900,9 +2911,33 @@ public class ContentDiskDriver extends AlfrescoDiskDriver implements DiskInterfa if ( logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_RENAME)) logger.debug(" Using renamed node, " + newState); - // Use the renamed node to clone aspects/state - - cloneNodeAspects( name, (NodeRef) newState.getFilesystemObject(), nodeToMoveRef, ctx); + NodeRef newStateNode = (NodeRef)newState.getFilesystemObject(); + QName oldType = nodeService.getType(nodeToMoveRef); + QName newType = nodeService.getType(newStateNode); + if (oldType.equals(newType)) { + + // Use the renamed node to clone aspects/state if it is of the correct type + + cloneNodeAspects(name, newStateNode, nodeToMoveRef, ctx); + } + else + { + // Otherwise we must create a node of the correct type + targetNodeRef = cifsHelper.createNode(ctx.getRootNode(), newName, newType); + + // Force a copy to this target + typesCompatible = false; + + // DEBUG + + if ( logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_RENAME)) + logger.debug(" Created new node for " + newName + " type " + newType); + + // Copy aspects from the original state + + cloneNodeAspects( name, newStateNode, targetNodeRef, ctx); + + } } else if ( newState.getFileStatus() == DeleteOnClose) { @@ -2920,7 +2955,7 @@ public class ContentDiskDriver extends AlfrescoDiskDriver implements DiskInterfa if ( logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_RENAME)) logger.debug(" Found archived node " + archivedNode); - if ( archivedNode != null && getNodeService().exists( archivedNode)) + if ( archivedNode != null ) { // Restore the node @@ -2969,7 +3004,7 @@ public class ContentDiskDriver extends AlfrescoDiskDriver implements DiskInterfa // Create a new node for the target - targetNodeRef = cifsHelper.createNode(ctx.getRootNode(), newName, true); + targetNodeRef = cifsHelper.createNode(ctx.getRootNode(), newName, nodeService.getType(nodeToMoveRef)); // DEBUG @@ -2982,9 +3017,9 @@ public class ContentDiskDriver extends AlfrescoDiskDriver implements DiskInterfa } } - // If the original or target nodes are not versionable then just use a standard rename of the + // If the original or target nodes are not versionable and types are compatible then just use a standard rename of the // node - if ( isFromVersionable == false && + if ( isFromVersionable == false && typesCompatible && ( targetNodeRef == null || nodeService.hasAspect( targetNodeRef, ContentModel.ASPECT_VERSIONABLE) == false)) { // Rename the file/folder @@ -3819,6 +3854,26 @@ public class ContentDiskDriver extends AlfrescoDiskDriver implements DiskInterfa } } + // Copy over all aspects from non-system namespaces (we will copy their properties later) + + 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 + + for ( Map.Entry entry : nodeService.getProperties(fromNode).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();