diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml index 010c2c097e..2497331e5b 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml @@ -116,7 +116,7 @@ abstract="true" class="org.alfresco.module.org_alfresco_module_rm.email.CustomisableEmailMappingKeyBootstrap" init-method="init"> - + - - + + @@ -544,20 +544,20 @@ - + - - - + init-method="init"> + - + org.alfresco.module.org_alfresco_module_rm.model.security.ModelSecurityService @@ -597,13 +597,13 @@ - - - + + @@ -793,10 +793,10 @@ - + + + Thread-Index + messageFrom + messageTo + messageCc + messageSubject + messageSent + + @@ -1069,6 +1078,7 @@ org.alfresco.module.org_alfresco_module_rm.email.CustomEmailMappingService.getCustomMappings=RM_ALLOW org.alfresco.module.org_alfresco_module_rm.email.CustomEmailMappingService.addCustomMapping=RM_ALLOW org.alfresco.module.org_alfresco_module_rm.email.CustomEmailMappingService.deleteCustomMapping=RM_ALLOW + org.alfresco.module.org_alfresco_module_rm.email.CustomEmailMappingService.getEmailMappingKeys=RM_ALLOW org.alfresco.module.org_alfresco_module_rm.email.CustomEmailMappingService.*=RM_DENY ]]> @@ -1094,71 +1104,6 @@ - - - - - - Thread-Index - messageFrom - messageTo - messageCc - messageSubject - messageSent - - - - - - - - - - - ${server.transaction.mode.default} - - - - - - - - - - - - - - - - - - - - - - - - - org.alfresco.module.org_alfresco_module_rm.email.EmailMappingKeyService - - - - emailMappingKeyService - - - - - - - - - - diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml index c7a0086372..269f9daa09 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml @@ -501,6 +501,6 @@ - + \ No newline at end of file diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/email/CustomEmailMappingService.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/email/CustomEmailMappingService.java index c80455da9c..9ae6286a6f 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/email/CustomEmailMappingService.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/email/CustomEmailMappingService.java @@ -18,6 +18,7 @@ */ package org.alfresco.module.org_alfresco_module_rm.email; +import java.util.List; import java.util.Set; /** @@ -27,24 +28,38 @@ public interface CustomEmailMappingService { /** * Get the list of custom mappings - * + * * @return {@link Set}<{@link CustomMapping}> */ public Set getCustomMappings(); /** * Add custom mapping - * + * * @param from * @param to */ public void addCustomMapping(String from, String to); - + /** * Delete custom mapping - * + * * @param from * @param to */ public void deleteCustomMapping(String from, String to); + + /** + * Gets the list of email mapping keys + * + * @return Email mapping keys + */ + public List getEmailMappingKeys(); + + /** + * Registers an email mapping key with the existing list of email mapping keys + * + * @param emailMappingKey emailMappingKey to register + */ + public void registerEMailMappingKey(String emailMappingKey); } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/email/CustomEmailMappingServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/email/CustomEmailMappingServiceImpl.java index a6cf16b61d..c09df857e9 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/email/CustomEmailMappingServiceImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/email/CustomEmailMappingServiceImpl.java @@ -21,6 +21,7 @@ package org.alfresco.module.org_alfresco_module_rm.email; import java.io.Serializable; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; @@ -43,6 +44,7 @@ import org.alfresco.service.namespace.NamespacePrefixResolver; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.service.transaction.TransactionService; +import org.alfresco.util.ParameterCheck; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.json.JSONArray; @@ -58,28 +60,28 @@ import org.springframework.extensions.surf.util.AbstractLifecycleBean; public class CustomEmailMappingServiceImpl extends AbstractLifecycleBean implements CustomEmailMappingService { /** Logger */ - private static Log logger = LogFactory.getLog(CustomEmailMappingServiceImpl.class); - + private static Log logger = LogFactory.getLog(CustomEmailMappingServiceImpl.class); + /** Node reference's to configuration elements */ private static final NodeRef CONFIG_NODE_REF = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, "rm_emailmapping_config"); private static final NodeRef CONFIG_FOLDER_NODE_REF = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, "rm_config_folder"); - + /** Config file name */ private static final String CONFIG_NAME = "imapConfig.json"; - + /** Default custom mappings (TODO move to spring config) */ - private static final CustomMapping[] DEFAULT_MAPPINGS = + private static final CustomMapping[] DEFAULT_MAPPINGS = { new CustomMapping("Date", "rma:dateReceived"), new CustomMapping("messageTo", "rma:address"), new CustomMapping("messageFrom", "rma:originator"), new CustomMapping("messageSent", "rma:publicationDate"), new CustomMapping("messageCc", "rma:otherAddress") - }; - + }; + /** Extractor */ private RFC822MetadataExtracter extracter; - + /** Services */ private NodeService nodeService; private NamespacePrefixResolver nspr; @@ -87,10 +89,13 @@ public class CustomEmailMappingServiceImpl extends AbstractLifecycleBean impleme private PolicyComponent policyComponent; private ContentService contentService; private TransactionService transactionService; - + /** Transient set of custom mappings */ private Set customMappings; - + + /** List of email mapping keys */ + private List emailMappingKeys; + /** * @param policyComponent policy component */ @@ -138,7 +143,15 @@ public class CustomEmailMappingServiceImpl extends AbstractLifecycleBean impleme { this.transactionService = transactionService; } - + + /** + * @param emailMappingKeys email mapping keys + */ + public void setEmailMappingKeys(List emailMappingKeys) + { + this.emailMappingKeys = emailMappingKeys; + } + /** * @see org.alfresco.module.org_alfresco_module_rm.email.CustomEmailMappingService#getCustomMappings() */ @@ -154,24 +167,24 @@ public class CustomEmailMappingServiceImpl extends AbstractLifecycleBean impleme } else { - customMappings = new HashSet(); - + customMappings = new HashSet(); + // load the contents of the extractors property file - Map> currentMapping = extracter.getCurrentMapping(); + Map> currentMapping = extracter.getCurrentMapping(); for(String key : currentMapping.keySet()) { Set set = currentMapping.get(key); - + for(QName qname : set) { CustomMapping value = new CustomMapping(); value.setFrom(key); QName resolvedQname = qname.getPrefixedQName(nspr); - value.setTo(resolvedQname.toPrefixString()); + value.setTo(resolvedQname.toPrefixString()); customMappings.add(value); } } - + // if we have an old config file NodeRef oldConfigNode = getOldConfigNode(); if (oldConfigNode != null) @@ -180,18 +193,18 @@ public class CustomEmailMappingServiceImpl extends AbstractLifecycleBean impleme Set oldMappings = readOldConfig(oldConfigNode); customMappings.addAll(oldMappings); } - + // load the hard coded mappings for(CustomMapping mapping : DEFAULT_MAPPINGS) { - customMappings.add(mapping); - } - + customMappings.add(mapping); + } + // create the config file saveConfig(customMappings); } } - + return customMappings; } @@ -200,23 +213,23 @@ public class CustomEmailMappingServiceImpl extends AbstractLifecycleBean impleme */ public void addCustomMapping(String from, String to) { - // create custom mapping + // create custom mapping CustomMapping customMapping = new CustomMapping(from, to); - + // check whether we already have this mapping or not Set customMappings = getCustomMappings(); if (customMappings.contains(customMapping) == true) { throw new AlfrescoRuntimeException("Can not add custom email mapping, because duplicate mapping already exists."); } - - // else add the custom mapping (since we have already called getCustomMapping we can be sure + + // else add the custom mapping (since we have already called getCustomMapping we can be sure // the member variable is populated) customMappings.add(customMapping); - + // save the changes into the config file saveConfig(customMappings); - + // update the extractors configuration updateExtractor(); } @@ -226,32 +239,52 @@ public class CustomEmailMappingServiceImpl extends AbstractLifecycleBean impleme */ public void deleteCustomMapping(String from, String to) { - // create custom mapping + // create custom mapping CustomMapping customMapping = new CustomMapping(from, to); - + // check whether we already have this mapping or not Set customMappings = getCustomMappings(); if (customMappings.contains(customMapping) == true) - { - // else remove the custom mapping (since we have already called getCustomMapping we can be sure + { + // else remove the custom mapping (since we have already called getCustomMapping we can be sure // the member variable is populated) customMappings.remove(customMapping); - + // save the changes into the config file saveConfig(customMappings); - + // update the extractors configuration updateExtractor(); } } - + + /** + * @see org.alfresco.module.org_alfresco_module_rm.email.CustomEmailMappingService#getEmailMappingKeys() + */ + @Override + public List getEmailMappingKeys() + { + return emailMappingKeys; + } + + /** + * @see org.alfresco.module.org_alfresco_module_rm.email.EmailMappingKeyService#registerEMailMappingKey(java.lang.String) + */ + @Override + public void registerEMailMappingKey(String emailMappingKey) + { + ParameterCheck.mandatoryString("emailMappingKey", emailMappingKey); + + emailMappingKeys.add(emailMappingKey); + } + /** * Updates the extractor with the custom configuration. */ private void updateExtractor() { // convert the mapping information into the form understood by the extractor - Map> newMapping = new HashMap>(17); + Map> newMapping = new HashMap>(17); for(CustomMapping mapping : getCustomMappings()) { QName newQName = QName.createQName(mapping.getTo(), nspr); @@ -265,13 +298,13 @@ public class CustomEmailMappingServiceImpl extends AbstractLifecycleBean impleme } // update the metadata extracter - extracter.setMapping(newMapping); + extracter.setMapping(newMapping); } - + /** * Loads the custom mappings from the configuration file. - * - * @return + * + * @return */ private Set loadConfig() { @@ -280,9 +313,9 @@ public class CustomEmailMappingServiceImpl extends AbstractLifecycleBean impleme if (cr != null) { String text = cr.getContentString(); - + try - { + { JSONArray jsonArray = new JSONArray(new JSONTokener(text)); for(int i = 0 ; i < jsonArray.length(); i++) { @@ -296,14 +329,14 @@ public class CustomEmailMappingServiceImpl extends AbstractLifecycleBean impleme catch (JSONException je) { throw new AlfrescoRuntimeException("Unable to read custom email configuration", je); - } + } } - + return result; } - + /** - * + * * @param customMappingsToSave */ private void saveConfig(Set customMappingsToSave) @@ -315,13 +348,13 @@ public class CustomEmailMappingServiceImpl extends AbstractLifecycleBean impleme properties.put(ContentModel.PROP_NAME, CONFIG_NAME); properties.put(ContentModel.PROP_NODE_UUID, CONFIG_NODE_REF.getId()); nodeService.createNode( - CONFIG_FOLDER_NODE_REF, - ContentModel.ASSOC_CONTAINS, - QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, CONFIG_NAME), - ContentModel.TYPE_CONTENT, + CONFIG_FOLDER_NODE_REF, + ContentModel.ASSOC_CONTAINS, + QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, CONFIG_NAME), + ContentModel.TYPE_CONTENT, properties); } - + // build JSON array of mappings JSONArray jsonMappings = new JSONArray(); try @@ -338,14 +371,14 @@ public class CustomEmailMappingServiceImpl extends AbstractLifecycleBean impleme { throw new AlfrescoRuntimeException("Unable to create JSON email mapping configuration during save.", je); } - + // update the content ContentWriter writer = this.contentService.getWriter(CONFIG_NODE_REF, ContentModel.PROP_CONTENT, true); writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN); writer.setEncoding("UTF-8"); - writer.putContent(jsonMappings.toString()); + writer.putContent(jsonMappings.toString()); } - + /** * @see org.springframework.extensions.surf.util.AbstractLifecycleBean#onBootstrap(org.springframework.context.ApplicationEvent) */ @@ -373,10 +406,10 @@ public class CustomEmailMappingServiceImpl extends AbstractLifecycleBean impleme { logger.warn(e.getMessage()); } - + // reset the mappings customMappings = null; - + // rethrow throw e; } @@ -384,7 +417,7 @@ public class CustomEmailMappingServiceImpl extends AbstractLifecycleBean impleme } }; transactionService.getRetryingTransactionHelper().doInTransaction(callback); - + return null; } }, AuthenticationUtil.getSystemUserName()); @@ -398,13 +431,13 @@ public class CustomEmailMappingServiceImpl extends AbstractLifecycleBean impleme { // No implementation } - + /** * Helper method to get the old configuration node. This is used during the migration * from 1.0 to 2.0. *

* Returns null if it does not exist. - * + * * @return {@link NodeRef} node reference of the old configuration node, null otherwise */ private NodeRef getOldConfigNode() @@ -412,24 +445,24 @@ public class CustomEmailMappingServiceImpl extends AbstractLifecycleBean impleme NodeRef rootNode = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); return nodeService.getChildByName(rootNode, RecordsManagementModel.ASSOC_EMAIL_CONFIG, CONFIG_NAME); } - + /** * Reads the old configuration node. This is used during the migration from 1.0 to 2.0. - * + * * @param nodeRef the old configuration node reference * @return {@link Set}<{@link CustomMapping}> set of the custom mappings stored in the old configuration */ private Set readOldConfig(NodeRef nodeRef) { Set newMappings = new HashSet(); - + ContentReader cr = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT); if (cr != null) { String text = cr.getContentString(); - + try - { + { JSONArray jsonArray = new JSONArray(new JSONTokener(text)); for(int i = 0 ; i < jsonArray.length(); i++) { @@ -446,8 +479,8 @@ public class CustomEmailMappingServiceImpl extends AbstractLifecycleBean impleme logger.warn("unable to read custom email configuration", je); return newMappings; } - + } return newMappings; - } + } } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/email/CustomisableEmailMappingKeyBootstrap.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/email/CustomisableEmailMappingKeyBootstrap.java index a543c70674..79a218ec3e 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/email/CustomisableEmailMappingKeyBootstrap.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/email/CustomisableEmailMappingKeyBootstrap.java @@ -31,8 +31,8 @@ public class CustomisableEmailMappingKeyBootstrap /** List of mappings to register as customisable */ private List customisable; - /** Email mapping key service */ - private EmailMappingKeyService emailMappingKeyService; + /** Custom email mapping service */ + private CustomEmailMappingService customEmailMappingService; /** * @param customizable list of mappings to register as customisable @@ -43,13 +43,13 @@ public class CustomisableEmailMappingKeyBootstrap } /** - * Email mapping key service + * Custom email mapping service * - * @param emailMappingKeyService the email mapping key service + * @param customEmailMappingService the custom email mapping service */ - public void setEmailMappingKeyService(EmailMappingKeyService emailMappingKeyService) + public void setCustomEmailMappingService(CustomEmailMappingService customEmailMappingService) { - this.emailMappingKeyService = emailMappingKeyService; + this.customEmailMappingService = customEmailMappingService; } /** @@ -59,7 +59,7 @@ public class CustomisableEmailMappingKeyBootstrap { for (String customEmailMappingKey : customisable) { - emailMappingKeyService.makeCustomisable(customEmailMappingKey); + customEmailMappingService.registerEMailMappingKey(customEmailMappingKey); } } } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/email/EmailMappingKeyService.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/email/EmailMappingKeyService.java deleted file mode 100644 index 0a63ddfcfe..0000000000 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/email/EmailMappingKeyService.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2005-2012 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.module.org_alfresco_module_rm.email; - -import java.util.List; - -/** - * EMail Mapping Key Service - * - * @author Tuna Aksoy - * @since @2.1 - */ -public interface EmailMappingKeyService -{ - /** - * Gets the list of email mapping keys - * - * @return Email mapping keys - */ - public List getEmailMappingKeys(); - - /** - * Makes a email mapping key customisable. - * - * @param emailMappingKey emailMappingKey to make customisable - */ - public void makeCustomisable(String emailMappingKey); -} diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/email/EmailMappingKeyServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/email/EmailMappingKeyServiceImpl.java deleted file mode 100644 index 2a56189945..0000000000 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/email/EmailMappingKeyServiceImpl.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2005-2012 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.module.org_alfresco_module_rm.email; - -import java.util.List; - -import org.alfresco.util.ParameterCheck; - -/** - * EMail Mapping Key Service - * - * @author Tuna Aksoy - * @since 2.1 - */ -public class EmailMappingKeyServiceImpl implements EmailMappingKeyService -{ - List emailMappingKeys; - - public void setEmailMappingKeys(List emailMappingKeys) - { - this.emailMappingKeys = emailMappingKeys; - } - - /** - * @see org.alfresco.module.org_alfresco_module_rm.email.CustomEmailMappingService#getEmailMappingKeys() - */ - @Override - public List getEmailMappingKeys() - { - return emailMappingKeys; - } - - /** - * @see org.alfresco.module.org_alfresco_module_rm.email.EmailMappingKeyService#makeCustomisable(java.lang.String) - */ - @Override - public void makeCustomisable(String emailMappingKey) - { - ParameterCheck.mandatoryString("emailMappingKey", emailMappingKey); - - emailMappingKeys.add(emailMappingKey); - } -} diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/EmailMapKeysGet.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/EmailMapKeysGet.java index c1831c972f..a7c2069ae5 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/EmailMapKeysGet.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/EmailMapKeysGet.java @@ -21,7 +21,7 @@ package org.alfresco.module.org_alfresco_module_rm.script; import java.util.HashMap; import java.util.Map; -import org.alfresco.module.org_alfresco_module_rm.email.EmailMappingKeyService; +import org.alfresco.module.org_alfresco_module_rm.email.CustomEmailMappingService; import org.springframework.extensions.webscripts.Cache; import org.springframework.extensions.webscripts.DeclarativeWebScript; import org.springframework.extensions.webscripts.Status; @@ -35,17 +35,17 @@ import org.springframework.extensions.webscripts.WebScriptRequest; */ public class EmailMapKeysGet extends DeclarativeWebScript { - /** Email mapping key service */ - private EmailMappingKeyService emailMappingKeyService; + /** Custom email mapping service */ + private CustomEmailMappingService customEmailMappingService; /** - * Email mapping key service + * Custom email mapping service * - * @param emailMappingKeyService the email mapping key service + * @param customEmailMappingService the custom email mapping service */ - public void setEmailMappingKeyService(EmailMappingKeyService emailMappingKeyService) + public void setCustomEmailMappingService(CustomEmailMappingService customEmailMappingService) { - this.emailMappingKeyService = emailMappingKeyService; + this.customEmailMappingService = customEmailMappingService; } @Override @@ -53,7 +53,7 @@ public class EmailMapKeysGet extends DeclarativeWebScript { // Create model object with the lists of email mapping keys Map model = new HashMap(1); - model.put("emailmapkeys", emailMappingKeyService.getEmailMappingKeys()); + model.put("emailmapkeys", customEmailMappingService.getEmailMappingKeys()); return model; } }