mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Merged V2.2 to HEAD
7575: Permission changes for AVM. 7577: Incorporated most of the feedback provided by Kevin C earlier today 7578: Removed directory not removed by patch 7579: EmailServer bug fixes AR-1902: Double posts when emailing to a document AR-1904: Attachments via email should be allowed on forum posts AR-1903: (Partial Fix) Text attachments should be treated the same way as other attachments 7583: Fixed WCM-961 & WCM-962: Added confirm dialog for 'Delete All Deployment Reports' and 'Release Server' actions git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@8434 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -39,6 +39,8 @@ import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.content.encoding.ContentCharsetFinder;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.email.EmailMessage;
|
||||
import org.alfresco.service.cmr.email.EmailMessagePart;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.MimetypeService;
|
||||
@@ -47,6 +49,7 @@ import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.search.ResultSet;
|
||||
import org.alfresco.service.cmr.search.SearchService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -255,4 +258,113 @@ public abstract class AbstractEmailMessageHandler implements EmailMessageHandler
|
||||
log.debug("Emailed aspect has been added.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new node into Alfresco repository with specified parameters. Node content isn't added.
|
||||
*
|
||||
* @param nodeService Alfresco Node Service
|
||||
* @param parent Parent node
|
||||
* @param name Name of the new node
|
||||
* @param assocType Association type that should be set between parent node and the new one.
|
||||
* @return Reference to created node
|
||||
*/
|
||||
protected NodeRef addContentNode(NodeService nodeService, NodeRef parent, String name, QName assocType)
|
||||
{
|
||||
NodeRef childNodeRef = nodeService.getChildByName(parent, assocType, name);
|
||||
if (childNodeRef != null)
|
||||
{
|
||||
// The node is present already. Make sure the name csae is correct
|
||||
nodeService.setProperty(childNodeRef, ContentModel.PROP_NAME, name);
|
||||
}
|
||||
else
|
||||
{
|
||||
Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();
|
||||
contentProps.put(ContentModel.PROP_NAME, name);
|
||||
ChildAssociationRef associationRef = nodeService.createNode(
|
||||
parent,
|
||||
assocType,
|
||||
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name),
|
||||
ContentModel.TYPE_CONTENT,
|
||||
contentProps);
|
||||
childNodeRef = associationRef.getChildRef();
|
||||
}
|
||||
return childNodeRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new node into Alfresco repository with specified parameters.
|
||||
* Node content isn't added. New node will be created with ContentModel.ASSOC_CONTAINS association with parent.
|
||||
*
|
||||
* @param nodeService Alfresco Node Service
|
||||
* @param parent Parent node
|
||||
* @param name Name of the new node
|
||||
* @return Reference to created node
|
||||
*/
|
||||
protected NodeRef addContentNode(NodeService nodeService, NodeRef parent, String name)
|
||||
{
|
||||
return addContentNode(nodeService, parent, name, ContentModel.ASSOC_CONTAINS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds new node into Alfresco repository and mark its as an attachment.
|
||||
*
|
||||
* @param nodeService Alfresco Node Service.
|
||||
* @param folder Space/Folder to add.
|
||||
* @param mainContentNode Main content node. Any mail is added into Alfresco as one main content node and several its attachments. Each attachment related with its main node.
|
||||
* @param fileName File name for the attachment.
|
||||
* @return Reference to created node.
|
||||
*/
|
||||
protected NodeRef addAttachment(NodeService nodeService, NodeRef folder, NodeRef mainContentNode, String fileName)
|
||||
{
|
||||
if (log.isDebugEnabled())
|
||||
{
|
||||
log.debug("Adding attachment node (name=" + fileName + ").");
|
||||
}
|
||||
|
||||
NodeRef attachmentNode = addContentNode(nodeService, folder, fileName);
|
||||
|
||||
// Remove 'attached' aspect so that we work with the document in its clean form
|
||||
if (nodeService.hasAspect(attachmentNode, EmailServerModel.ASPECT_ATTACHED))
|
||||
{
|
||||
nodeService.removeAspect(attachmentNode, EmailServerModel.ASPECT_ATTACHED);
|
||||
}
|
||||
|
||||
// Add attached aspect
|
||||
nodeService.addAspect(attachmentNode, EmailServerModel.ASPECT_ATTACHED, null);
|
||||
// Recreate the association
|
||||
nodeService.createAssociation(attachmentNode, mainContentNode, EmailServerModel.ASSOC_ATTACHMENT);
|
||||
|
||||
if (log.isDebugEnabled())
|
||||
{
|
||||
log.debug("Attachment has been added.");
|
||||
}
|
||||
return attachmentNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the attachments from the given message and adds them to the space. All attachments
|
||||
* are linked back to the original node that they are attached to.
|
||||
*
|
||||
* @param spaceNodeRef the space to add the documents into
|
||||
* @param nodeRef the node to which the documents will be attached
|
||||
* @param message the email message
|
||||
*/
|
||||
protected void addAttachments(NodeRef spaceNodeRef, NodeRef nodeRef, EmailMessage message)
|
||||
{
|
||||
// Add attachments
|
||||
EmailMessagePart[] attachments = message.getAttachments();
|
||||
for (EmailMessagePart attachment : attachments)
|
||||
{
|
||||
String fileName = attachment.getFileName();
|
||||
|
||||
InputStream contentIs = attachment.getContent();
|
||||
|
||||
MimetypeService mimetypeService = getMimetypeService();
|
||||
String mimetype = mimetypeService.guessMimetype(fileName);
|
||||
String encoding = attachment.getEncoding();
|
||||
|
||||
NodeRef attachmentNode = addAttachment(getNodeService(), spaceNodeRef, nodeRef, fileName);
|
||||
writeContent(attachmentNode, contentIs, mimetype, encoding);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user