mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-104: Split email attachments doesn't work
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/BRANCHES/V2.0@36847 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -726,7 +726,7 @@
|
|||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<!-- Split Email -->
|
<!-- Split Email -->
|
||||||
<bean id="splitEmail" class="org.alfresco.module.org_alfresco_module_rm.action.impl.SplitEmailAction" parent="rmAction" >
|
<bean id="splitEmail" class="org.alfresco.module.org_alfresco_module_rm.action.impl.SplitEmailAction" parent="rmAction">
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="splitEmail_proxy" class="org.alfresco.module.org_alfresco_module_rm.capability.RMActionProxyFactoryBean" parent="rmProxyAction" init-method="registerAction">
|
<bean id="splitEmail_proxy" class="org.alfresco.module.org_alfresco_module_rm.capability.RMActionProxyFactoryBean" parent="rmProxyAction" init-method="registerAction">
|
||||||
|
@@ -945,8 +945,7 @@ public class RecordsManagementAdminServiceImpl implements RecordsManagementAdmin
|
|||||||
*/
|
*/
|
||||||
public Map<QName, AssociationDefinition> getCustomReferenceDefinitions()
|
public Map<QName, AssociationDefinition> getCustomReferenceDefinitions()
|
||||||
{
|
{
|
||||||
QName relevantAspectQName = QName.createQName(RMC_CUSTOM_ASSOCS, namespaceService);
|
AspectDefinition aspectDefn = dictionaryService.getAspect(ASPECT_CUSTOM_ASSOCIATIONS);
|
||||||
AspectDefinition aspectDefn = dictionaryService.getAspect(relevantAspectQName);
|
|
||||||
Map<QName, AssociationDefinition> assocDefns = aspectDefn.getAssociations();
|
Map<QName, AssociationDefinition> assocDefns = aspectDefn.getAssociations();
|
||||||
|
|
||||||
return assocDefns;
|
return assocDefns;
|
||||||
|
@@ -33,14 +33,13 @@ import javax.mail.Part;
|
|||||||
import javax.mail.internet.ContentType;
|
import javax.mail.internet.ContentType;
|
||||||
import javax.mail.internet.MimeMessage;
|
import javax.mail.internet.MimeMessage;
|
||||||
import javax.mail.internet.MimeUtility;
|
import javax.mail.internet.MimeUtility;
|
||||||
import javax.transaction.UserTransaction;
|
|
||||||
|
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.model.ImapModel;
|
import org.alfresco.model.ImapModel;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.action.RMActionExecuterAbstractBase;
|
import org.alfresco.module.org_alfresco_module_rm.action.RMActionExecuterAbstractBase;
|
||||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||||
import org.alfresco.service.cmr.action.Action;
|
import org.alfresco.service.cmr.action.Action;
|
||||||
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
|
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
|
||||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||||
@@ -68,11 +67,36 @@ public class SplitEmailAction extends RMActionExecuterAbstractBase
|
|||||||
private static final String MSG_NO_READ_MIME_MESSAGE = "rm.action.no-read-mime-message";
|
private static final String MSG_NO_READ_MIME_MESSAGE = "rm.action.no-read-mime-message";
|
||||||
private static final String MSG_EMAIL_DECLARED = "rm.action.email-declared";
|
private static final String MSG_EMAIL_DECLARED = "rm.action.email-declared";
|
||||||
private static final String MSG_EMAIL_NOT_RECORD = "rm.action.email-not-record";
|
private static final String MSG_EMAIL_NOT_RECORD = "rm.action.email-not-record";
|
||||||
private static final String MSG_EMAIL_CREATE_CHILD_ASSOC = "rm.action.email-create-child-assoc";
|
|
||||||
|
/** Relationship Labels */
|
||||||
|
private static final String REL_FROM = "Message";
|
||||||
|
private static final String REL_TO = "Attachment";
|
||||||
|
|
||||||
/** Logger */
|
/** Logger */
|
||||||
private static Log logger = LogFactory.getLog(SplitEmailAction.class);
|
private static Log logger = LogFactory.getLog(SplitEmailAction.class);
|
||||||
|
|
||||||
|
private QName relationshipQName;
|
||||||
|
|
||||||
|
public void bootstrap()
|
||||||
|
{
|
||||||
|
String compoundId = recordsManagementAdminService.getCompoundIdFor(REL_FROM, REL_TO);
|
||||||
|
|
||||||
|
Map<QName, AssociationDefinition> map = recordsManagementAdminService.getCustomReferenceDefinitions();
|
||||||
|
for (Map.Entry<QName, AssociationDefinition> entry : map.entrySet())
|
||||||
|
{
|
||||||
|
if (compoundId.equals(entry.getValue().getTitle()) == true)
|
||||||
|
{
|
||||||
|
relationshipQName = entry.getKey();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (relationshipQName == null)
|
||||||
|
{
|
||||||
|
relationshipQName = recordsManagementAdminService.addCustomChildAssocDefinition(REL_FROM, REL_TO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action,
|
* @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action,
|
||||||
* org.alfresco.service.cmr.repository.NodeRef)
|
* org.alfresco.service.cmr.repository.NodeRef)
|
||||||
@@ -242,85 +266,27 @@ public class SplitEmailAction extends RMActionExecuterAbstractBase
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QName assocDef = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a link from the message to the attachment
|
* Create a link from the message to the attachment
|
||||||
*/
|
*/
|
||||||
private void createRMReference(NodeRef parentRef, NodeRef childRef)
|
private void createRMReference(final NodeRef parentRef, final NodeRef childRef)
|
||||||
{
|
{
|
||||||
String sourceId = "message";
|
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
|
||||||
String targetId = "attachment";
|
|
||||||
|
|
||||||
String compoundId = recordsManagementAdminService.getCompoundIdFor(sourceId, targetId);
|
|
||||||
|
|
||||||
Map<QName, AssociationDefinition> refs = recordsManagementAdminService.getCustomReferenceDefinitions();
|
|
||||||
for(QName name : refs.keySet())
|
|
||||||
{
|
{
|
||||||
// TODO how to find assocDef?
|
@Override
|
||||||
// Refs seems to be null
|
public Void doWork() throws Exception
|
||||||
}
|
|
||||||
|
|
||||||
if(assocDef == null)
|
|
||||||
{
|
|
||||||
assocDef = createReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
recordsManagementAdminService.addCustomReference(parentRef, childRef, assocDef);
|
|
||||||
|
|
||||||
// add the IMAP attachment aspect
|
|
||||||
nodeService.createAssociation(
|
|
||||||
parentRef,
|
|
||||||
childRef,
|
|
||||||
ImapModel.ASSOC_IMAP_ATTACHMENT);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the custom reference - need to jump through hoops with the transaction handling here
|
|
||||||
* since the association is created in the post commit phase, so it can't be used within the
|
|
||||||
* current transaction.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private QName createReference()
|
|
||||||
{
|
|
||||||
UserTransaction txn = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
txn = transactionService.getNonPropagatingUserTransaction();
|
|
||||||
txn.begin();
|
|
||||||
RetryingTransactionHelper helper = transactionService.getRetryingTransactionHelper();
|
|
||||||
RetryingTransactionCallback<QName> addCustomChildAssocDefinitionCallback = new RetryingTransactionCallback<QName>()
|
|
||||||
{
|
{
|
||||||
public QName execute() throws Throwable
|
// add the relationship
|
||||||
{
|
recordsManagementAdminService.addCustomReference(parentRef, childRef, relationshipQName);
|
||||||
String sourceId = "message";
|
|
||||||
String targetId = "attachment";
|
// add the IMAP attachment aspect
|
||||||
QName assocDef = recordsManagementAdminService.addCustomChildAssocDefinition(sourceId, targetId);
|
nodeService.createAssociation(
|
||||||
return assocDef;
|
parentRef,
|
||||||
}
|
childRef,
|
||||||
};
|
ImapModel.ASSOC_IMAP_ATTACHMENT);
|
||||||
QName ret = helper.doInTransaction(addCustomChildAssocDefinitionCallback);
|
|
||||||
|
return null;
|
||||||
txn.commit();
|
}
|
||||||
return ret;
|
});
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
if(txn != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
txn.rollback();
|
|
||||||
}
|
|
||||||
catch (Exception se)
|
|
||||||
{
|
|
||||||
logger.error("error during creation of custom child association", se);
|
|
||||||
// we can do nothing with this rollback exception.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_EMAIL_CREATE_CHILD_ASSOC), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
package org.alfresco.module.org_alfresco_module_rm.bootstrap;
|
package org.alfresco.module.org_alfresco_module_rm.bootstrap;
|
||||||
|
|
||||||
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService;
|
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.action.impl.SplitEmailAction;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.caveat.RMCaveatConfigService;
|
import org.alfresco.module.org_alfresco_module_rm.caveat.RMCaveatConfigService;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.email.CustomEmailMappingService;
|
import org.alfresco.module.org_alfresco_module_rm.email.CustomEmailMappingService;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
@@ -81,12 +82,13 @@ public class RecordsManagementBootstrap extends AbstractLifecycleBean
|
|||||||
// initialise caveat config
|
// initialise caveat config
|
||||||
caveatConfigService.init();
|
caveatConfigService.init();
|
||||||
|
|
||||||
// initialise custom email mapping
|
|
||||||
//customEmailMappingService.init();
|
|
||||||
|
|
||||||
// Initialise the custom model
|
// Initialise the custom model
|
||||||
adminService.initialiseCustomModel();
|
adminService.initialiseCustomModel();
|
||||||
|
|
||||||
|
// Initialise the SplitEmailAction
|
||||||
|
SplitEmailAction action = (SplitEmailAction)getApplicationContext().getBean("splitEmail");
|
||||||
|
action.bootstrap();
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user