mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-10775 - Thumbnail is not created created for duplicate files uploaded via email
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@31269 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -26,6 +26,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
import javax.mail.Message;
|
import javax.mail.Message;
|
||||||
import javax.mail.Session;
|
import javax.mail.Session;
|
||||||
@@ -512,6 +513,39 @@ public class EmailServiceImplTest extends TestCase
|
|||||||
emailService.importMessage(m);
|
emailService.importMessage(m);
|
||||||
assocs = nodeService.getChildAssocs(testUserHomeFolder, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
|
assocs = nodeService.getChildAssocs(testUserHomeFolder, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
|
||||||
assertEquals("assocs not 5", 5, assocs.size());
|
assertEquals("assocs not 5", 5, assocs.size());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check assoc rename with long names and an extension. So truncation and rename need to
|
||||||
|
* work together and not muck up a .extension.
|
||||||
|
*/
|
||||||
|
logger.debug("Step 4: turn off Overwite Duplicates with long subject name with extension");
|
||||||
|
String EXT_NAME = "Blob.xls";
|
||||||
|
|
||||||
|
msg.setSubject(EXT_NAME);
|
||||||
|
ByteArrayOutputStream bos3 = new ByteArrayOutputStream();
|
||||||
|
msg.writeTo(bos3);
|
||||||
|
is = new StringInputStream(bos3.toString());
|
||||||
|
assertNotNull("is is null", is);
|
||||||
|
m = new SubethaEmailMessage(is);
|
||||||
|
folderEmailMessageHandler.setOverwriteDuplicates(false);
|
||||||
|
emailService.importMessage(m);
|
||||||
|
emailService.importMessage(m);
|
||||||
|
emailService.importMessage(m);
|
||||||
|
assocs = nodeService.getChildAssocs(testUserHomeFolder, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
|
||||||
|
|
||||||
|
List<QName> assocNames = new Vector<QName>();
|
||||||
|
for(ChildAssociationRef assoc : assocs)
|
||||||
|
{
|
||||||
|
logger.debug("assocName: " + assoc.getQName());
|
||||||
|
System.out.println(assoc.getQName());
|
||||||
|
assocNames.add(assoc.getQName());
|
||||||
|
}
|
||||||
|
assertTrue(EXT_NAME + "not found", assocNames.contains(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Blob.xls")));
|
||||||
|
assertTrue("Blob(1).xls not found", assocNames.contains(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Blob(1).xls")));
|
||||||
|
assertTrue("Blob(2).xls not found", assocNames.contains(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Blob(2).xls")));
|
||||||
|
assertTrue(TEST_SUBJECT + "not found", assocNames.contains(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, TEST_SUBJECT)));
|
||||||
|
assertTrue(TEST_SUBJECT+"(1) not found", assocNames.contains(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Practical Bee Keeping(1)")));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -27,9 +27,9 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.alfresco.email.server.EmailServiceImpl;
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.repo.content.MimetypeMap;
|
|
||||||
import org.alfresco.repo.content.encoding.ContentCharsetFinder;
|
import org.alfresco.repo.content.encoding.ContentCharsetFinder;
|
||||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||||
import org.alfresco.service.cmr.email.EmailMessage;
|
import org.alfresco.service.cmr.email.EmailMessage;
|
||||||
@@ -42,10 +42,10 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
|||||||
import org.alfresco.service.cmr.repository.NodeService;
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
import org.alfresco.service.namespace.NamespaceService;
|
import org.alfresco.service.namespace.NamespaceService;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import com.sun.star.auth.InvalidArgumentException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract class implements common logic for processing email messages.
|
* Abstract class implements common logic for processing email messages.
|
||||||
@@ -62,6 +62,8 @@ public abstract class AbstractEmailMessageHandler implements EmailMessageHandler
|
|||||||
private ContentService contentService;
|
private ContentService contentService;
|
||||||
private MimetypeService mimetypeService;
|
private MimetypeService mimetypeService;
|
||||||
|
|
||||||
|
private static Log logger = LogFactory.getLog(AbstractEmailMessageHandler.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Alfresco Content Service.
|
* @return Alfresco Content Service.
|
||||||
*/
|
*/
|
||||||
@@ -277,7 +279,16 @@ public abstract class AbstractEmailMessageHandler implements EmailMessageHandler
|
|||||||
|
|
||||||
String workingName = name;
|
String workingName = name;
|
||||||
|
|
||||||
for(int counter = 0; counter < 10000; counter++)
|
// Need to work out a new safe name.
|
||||||
|
String baseName = FilenameUtils.getBaseName(name);
|
||||||
|
String extension = FilenameUtils.getExtension(name);
|
||||||
|
|
||||||
|
if(logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("addContentNode name:" + name);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int counter = 1; counter < 10000; counter++)
|
||||||
{
|
{
|
||||||
QName safeQName = QName.createQNameWithValidLocalName(NamespaceService.CONTENT_MODEL_1_0_URI, workingName);
|
QName safeQName = QName.createQNameWithValidLocalName(NamespaceService.CONTENT_MODEL_1_0_URI, workingName);
|
||||||
|
|
||||||
@@ -287,31 +298,42 @@ public abstract class AbstractEmailMessageHandler implements EmailMessageHandler
|
|||||||
{
|
{
|
||||||
if(overwrite)
|
if(overwrite)
|
||||||
{
|
{
|
||||||
|
if(logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("overwriting existing node :" + name);
|
||||||
|
}
|
||||||
childNodeRef=childNodeRefs.get(0).getChildRef();
|
childNodeRef=childNodeRefs.get(0).getChildRef();
|
||||||
|
|
||||||
// Node already exists
|
// Node already exists
|
||||||
// The node is present already. Make sure the name case is correct
|
// The node is present already. Make sure the name case is correct
|
||||||
nodeService.setProperty(childNodeRef, ContentModel.PROP_NAME, name);
|
nodeService.setProperty(childNodeRef, ContentModel.PROP_NAME, baseName);
|
||||||
return childNodeRef;
|
return childNodeRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to work out a new safe name.
|
// Node already exists and not overwrite
|
||||||
|
|
||||||
String postFix = "(" + counter + ")";
|
String postFix = "(" + counter + ")";
|
||||||
|
|
||||||
if(name.length() + postFix.length() > QName.MAX_LENGTH )
|
if(baseName.length() + extension.length() + postFix.length() > QName.MAX_LENGTH )
|
||||||
{
|
{
|
||||||
workingName = name.substring(0, QName.MAX_LENGTH-postFix.length()) + postFix;
|
// Need to truncate base name
|
||||||
// Need to truncate name
|
workingName = baseName.substring(0, QName.MAX_LENGTH - postFix.length() - extension.length() -1) + postFix;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
workingName = name + postFix;
|
workingName = baseName + postFix ;
|
||||||
|
}
|
||||||
|
if(extension.length() > 0)
|
||||||
|
{
|
||||||
|
workingName = workingName + "." + extension;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Here if child node ref does not already exist
|
// Here if child node ref does not already exist
|
||||||
|
if(logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("child node ref does not already exist :" + workingName);
|
||||||
|
}
|
||||||
Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();
|
Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();
|
||||||
contentProps.put(ContentModel.PROP_NAME, workingName);
|
contentProps.put(ContentModel.PROP_NAME, workingName);
|
||||||
|
|
||||||
@@ -338,7 +360,10 @@ public abstract class AbstractEmailMessageHandler implements EmailMessageHandler
|
|||||||
* @param nodeService Alfresco Node Service
|
* @param nodeService Alfresco Node Service
|
||||||
* @param parent Parent node
|
* @param parent Parent node
|
||||||
* @param name Name of the new node
|
* @param name Name of the new node
|
||||||
|
* @param overwrite whether a new node should overwrite an existing node with the same name or have its name
|
||||||
|
* mangled to be alongside the existing node.
|
||||||
* @return Reference to created node
|
* @return Reference to created node
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
protected NodeRef addContentNode(NodeService nodeService, NodeRef parent, String name, boolean overwrite)
|
protected NodeRef addContentNode(NodeService nodeService, NodeRef parent, String name, boolean overwrite)
|
||||||
{
|
{
|
||||||
|
@@ -465,11 +465,12 @@ public class SubethaEmailMessage implements EmailMessage
|
|||||||
* @param subject String representing subject
|
* @param subject String representing subject
|
||||||
* @return Encoded string
|
* @return Encoded string
|
||||||
*/
|
*/
|
||||||
|
// MER Removed . * , { ".", "%2e" }
|
||||||
static private String encodeSubject(String subject)
|
static private String encodeSubject(String subject)
|
||||||
{
|
{
|
||||||
String result = subject.trim();
|
String result = subject.trim();
|
||||||
String[][] s = new String[][] { { "\\", "%5c" }, { "/", "%2f" }, { "*", "%2a" }, { "|", "%7c" }, { ":", "%3a" }, { "\"", "%22" }, { "<", "%3c" }, { ">", "%3e" },
|
String[][] s = new String[][] { { "\\", "%5c" }, { "/", "%2f" }, { "*", "%2a" }, { "|", "%7c" }, { ":", "%3a" }, { "\"", "%22" }, { "<", "%3c" }, { ">", "%3e" },
|
||||||
{ "?", "%3f" }, { ".", "%2e" } };
|
{ "?", "%3f" }};
|
||||||
|
|
||||||
for (int i = 0; i < s.length; i++)
|
for (int i = 0; i < s.length; i++)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user