From 1858509d3a5bc0318772ed9dddf31f0cfc69fb05 Mon Sep 17 00:00:00 2001 From: Kevin Roast Date: Fri, 10 Mar 2006 15:51:17 +0000 Subject: [PATCH] . Patch to load email templates content into older schema (first patch to perform an import) . Updated schema version to 10 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2540 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/bootstrap-context.xml | 4 + .../messages/patch-service.properties | 3 + .../alfresco/patch/patch-services-context.xml | 23 ++ config/alfresco/templates/email_templates.acp | Bin 0 -> 1541 bytes config/alfresco/version.properties | 2 +- .../impl/EmailTemplatesContentPatch.java | 247 ++++++++++++++++++ 6 files changed, 278 insertions(+), 1 deletion(-) create mode 100644 config/alfresco/templates/email_templates.acp create mode 100644 source/java/org/alfresco/repo/admin/patch/impl/EmailTemplatesContentPatch.java diff --git a/config/alfresco/bootstrap-context.xml b/config/alfresco/bootstrap-context.xml index 2540a07b81..699630b290 100644 --- a/config/alfresco/bootstrap-context.xml +++ b/config/alfresco/bootstrap-context.xml @@ -79,6 +79,10 @@ /${spaces.company_home.childname}/${spaces.dictionary.childname}/${spaces.templates.content.childname} alfresco/templates/content_template_examples.xml + + /${spaces.company_home.childname}/${spaces.dictionary.childname}/${spaces.templates.email.childname} + alfresco/templates/email_templates.acp + diff --git a/config/alfresco/messages/patch-service.properties b/config/alfresco/messages/patch-service.properties index 6c01ea98dd..7f2fbac27e 100644 --- a/config/alfresco/messages/patch-service.properties +++ b/config/alfresco/messages/patch-service.properties @@ -47,3 +47,6 @@ patch.forumsIcons.result=Updated {0} icon references patch.emailTemplatesFolder.description=Ensures the existence of the 'Email Templates' folder. patch.emailTemplatesFolder.result.exists=The email templates folder already exists: {0} patch.emailTemplatesFolder.result.created=The email templates folder was successfully created: {0} + +patch.emailTemplatesContent.description=Loads the email templates into the Email Templates folder. +patch.emailTemplatesContent.result=Imported the Email Templates into the default folder. diff --git a/config/alfresco/patch/patch-services-context.xml b/config/alfresco/patch/patch-services-context.xml index 444506f106..2554ad6986 100644 --- a/config/alfresco/patch/patch-services-context.xml +++ b/config/alfresco/patch/patch-services-context.xml @@ -307,5 +307,28 @@ + + patch.emailTemplatesContent + patch.emailTemplatesContent.description + 0 + 9 + 10 + alfresco/templates/email_templates.acp + + + + + + + + + + + + + + + + diff --git a/config/alfresco/templates/email_templates.acp b/config/alfresco/templates/email_templates.acp new file mode 100644 index 0000000000000000000000000000000000000000..75006346e6ffd684374312ff5793eec5b6c11992 GIT binary patch literal 1541 zcmWIWW@Zs#-~dARh%6HZBp?H1r{*SR=ERqz<`(26mZTQPBO#9b30=HgVpTAU5Vr)&u+0L2kB+5_SpaXlHbw=8^X&U)}5bR zoyW_TJ;6-#dxlMq`*QE|JvWk#>)4(;gg9kxyvlK^;rzy@F^WPq&KGQ%UM&=3oGzrA z)2|z*V3{4^XjT%pFnOiY^ZU_vYgPp9VBPX#_WBPC=9GKycwW>v%aUL3v|;yRi(gw* zRSr2Uby~5Z=lscOk#boa3#Z;Z`$*&az8QseTU0HVaAlg!^-+&`G3A2lw(^EaC6{;A z1)S$dtW{IIsFiTA$WG+k$}^}3U=>kV(V_wKwM95=4FYzzoHkz10s0RlyGNO$uuq7I-$f>+j~CnyD_u{g#1uW3$p7(We1FSMV^VYiv5z z^x0EpY4X_|Zgq|`kM^iP+rYMYPv$m{{m#XL8`jU9@-QND`r&`szh$ zAvw;f)rn6S|9{d;wGXU{Z$HFXe#C({z-a#2bg%h~wU$dqXYglv-!NKn^5d*!+|yrM zAC_OU@WPa0ef{0XF4}{F_`tM>I+DO3z752XAZ7rj?n6;oCZEnvxW)|(cx^5Q24T$9 ztyhto^ETvk-(>@lyXV6rZcaYKp%rj7B~0OLo9JfeRXxSV#j5*L?tf|g_3?(E(T=5a zIarb|`^x;BSA5@Y_3ycpa+uF8zF1lqeou^Ni-GQ|<-02We0q7d{n5Uik+}lfPX9<` zTwnWZZFjoT?lr64mPHrcwES>r$}!u}i&2&vjwwrSU%%+~v$l;>1H2PW8kb%4Ul3ao z+%w}_kwR+JgwXCLr(ZQaUyf_~S#r+mJ`sFCdD7O+D%q-Bb*J9!ot^wm?oME)fw!dl zE9b%q!L75B`K37uDTw) z^r$O+%G>mHPIigRTNU4Ydwt`IsYc(XHy+FW@<`A6a3@;eN&D)=Tux7?+iOB9%bpc+1pJjs;k8%(|CWU$a~+kzUBAGoyX3AM3L|qyLZ7OdkJykuvw!_IZbX ztY7?c+Y(t>5v>J#TW2M>hdL~F5M?8B)&-S~ zr~qF{iEa{d3Pm-k8klBrm;}!FFq3elXpoy285DrzJzzRVGYOQw1H4(;K#G`w@G6j& HVg>O4#XFLv literal 0 HcmV?d00001 diff --git a/config/alfresco/version.properties b/config/alfresco/version.properties index e86b455a1f..967997f2b9 100644 --- a/config/alfresco/version.properties +++ b/config/alfresco/version.properties @@ -15,4 +15,4 @@ version.edition=Community Network # Schema number -version.schema=9 +version.schema=10 diff --git a/source/java/org/alfresco/repo/admin/patch/impl/EmailTemplatesContentPatch.java b/source/java/org/alfresco/repo/admin/patch/impl/EmailTemplatesContentPatch.java new file mode 100644 index 0000000000..a475ed692e --- /dev/null +++ b/source/java/org/alfresco/repo/admin/patch/impl/EmailTemplatesContentPatch.java @@ -0,0 +1,247 @@ +/* + * Copyright (C) 2005 Alfresco, Inc. + * + * Licensed under the Mozilla Public License version 1.1 + * with a permitted attribution clause. You may obtain a + * copy of the License at + * + * http://www.alfresco.org/legal/license.txt + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + */ +package org.alfresco.repo.admin.patch.impl; + +import java.io.IOException; +import java.io.Serializable; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.alfresco.i18n.I18NUtil; +import org.alfresco.model.ContentModel; +import org.alfresco.repo.admin.patch.AbstractPatch; +import org.alfresco.repo.importer.ACPImportPackageHandler; +import org.alfresco.repo.importer.ImporterBootstrap; +import org.alfresco.repo.security.authentication.AuthenticationComponent; +import org.alfresco.service.cmr.admin.PatchException; +import org.alfresco.service.cmr.repository.ChildAssociationRef; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.repository.StoreRef; +import org.alfresco.service.cmr.search.SearchService; +import org.alfresco.service.cmr.view.ImporterService; +import org.alfresco.service.cmr.view.Location; +import org.alfresco.service.namespace.NamespaceService; +import org.alfresco.service.namespace.QName; +import org.springframework.context.MessageSource; +import org.springframework.core.io.ClassPathResource; + +/** + * Ensures that the email templates are imported into the default folder. + *

+ * This uses the bootstrap importer to get the paths to look for. If not present, + * the required structures are created. + *

+ * This class should be replaced with a more generic ImporterPatch + * that can do conditional importing into given locations. + *

+ * JIRA: {@link http://www.alfresco.org/jira/browse/AR-342 AR-342} + * + * @author Kevin Roast + */ +public class EmailTemplatesContentPatch extends AbstractPatch +{ + private static final String MSG_CREATED = "patch.emailTemplatesContent.result"; + + public static final String PROPERTY_COMPANY_HOME_CHILDNAME = "spaces.company_home.childname"; + public static final String PROPERTY_DICTIONARY_CHILDNAME = "spaces.dictionary.childname"; + public static final String PROPERTY_EMAIL_TEMPLATES_CHILDNAME = "spaces.templates.email.childname"; + + private ImporterBootstrap importerBootstrap; + private NamespaceService namespaceService; + private SearchService searchService; + private ImporterService importerService; + private AuthenticationComponent authComponent; + private NodeService nodeService; + private MessageSource messageSource; + + protected Properties configuration; + protected NodeRef emailTemplatesNodeRef; + + private String templatesACP; + + public void setImporterBootstrap(ImporterBootstrap importerBootstrap) + { + this.importerBootstrap = importerBootstrap; + } + + public void setNamespaceService(NamespaceService namespaceService) + { + this.namespaceService = namespaceService; + } + + public void setSearchService(SearchService searchService) + { + this.searchService = searchService; + } + + public void setImporterService(ImporterService importerService) + { + this.importerService = importerService; + } + + public void setNodeService(NodeService nodeService) + { + this.nodeService = nodeService; + } + + public void setAuthenticationComponent(AuthenticationComponent authComponent) + { + this.authComponent = authComponent; + } + + public void setMessageSource(MessageSource messageSource) + { + this.messageSource = messageSource; + } + + /** + * @param templatesACP The templates ACP file to import. + */ + public void setTemplatesACP(String templatesACP) + { + this.templatesACP = templatesACP; + } + + /** + * Ensure that required properties have been set + */ + protected void checkRequiredProperties() throws Exception + { + if (importerBootstrap == null) + { + throw new PatchException("'importerBootstrap' property has not been set"); + } + if (namespaceService == null) + { + throw new PatchException("'namespaceService' property has not been set"); + } + if (searchService == null) + { + throw new PatchException("'searchService' property has not been set"); + } + if (nodeService == null) + { + throw new PatchException("'nodeService' property has not been set"); + } + if (importerService == null) + { + throw new PatchException("'importerService' property has not been set"); + } + if (messageSource == null) + { + throw new PatchException("'messageSource' property has not been set"); + } + if (templatesACP == null || templatesACP.length() == 0) + { + throw new PatchException("'templatesACP' property has not been set"); + } + } + + /** + * Extracts pertinent references and properties that are common to execution + * of this and derived patches. + */ + protected void setUp() throws Exception + { + // get the node store that we must work against + StoreRef storeRef = importerBootstrap.getStoreRef(); + if (storeRef == null) + { + throw new PatchException("Bootstrap store has not been set"); + } + NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef); + + this.configuration = importerBootstrap.getConfiguration(); + + // get the association names that form the path + String companyHomeChildName = configuration.getProperty(PROPERTY_COMPANY_HOME_CHILDNAME); + if (companyHomeChildName == null || companyHomeChildName.length() == 0) + { + throw new PatchException("Bootstrap property '" + PROPERTY_COMPANY_HOME_CHILDNAME + "' is not present"); + } + String dictionaryChildName = configuration.getProperty(PROPERTY_DICTIONARY_CHILDNAME); + if (dictionaryChildName == null || dictionaryChildName.length() == 0) + { + throw new PatchException("Bootstrap property '" + PROPERTY_DICTIONARY_CHILDNAME + "' is not present"); + } + String emailTemplatesChildName = configuration.getProperty(PROPERTY_EMAIL_TEMPLATES_CHILDNAME); + if (emailTemplatesChildName == null || emailTemplatesChildName.length() == 0) + { + throw new PatchException("Bootstrap property '" + PROPERTY_EMAIL_TEMPLATES_CHILDNAME + "' is not present"); + } + + // build the search string to get the email templates node + StringBuilder sb = new StringBuilder(128); + sb.append("/").append(companyHomeChildName) + .append("/").append(dictionaryChildName) + .append("/").append(emailTemplatesChildName); + String xpath = sb.toString(); + + // get the templates node + List nodeRefs = searchService.selectNodes(storeRootNodeRef, xpath, null, namespaceService, false); + if (nodeRefs.size() == 0) + { + throw new PatchException("Unable to locate Email Templates folder: \n" + + " root: " + storeRootNodeRef + "\n" + + " xpath: " + xpath); + } + else if (nodeRefs.size() > 1) + { + throw new PatchException("Found too many Email Templates folder results: \n" + + " root: " + storeRootNodeRef + "\n" + + " xpath: " + xpath + "\n" + + " results: " + nodeRefs); + } + this.emailTemplatesNodeRef = nodeRefs.get(0); + } + + @Override + protected String applyInternal() throws Exception + { + // common properties must be set before we can continue + checkRequiredProperties(); + + setUp(); + + // import the content + try + { + authComponent.setCurrentUser(authComponent.getSystemUserName()); + + importContent(); + } + finally + { + authComponent.clearCurrentSecurityContext(); + } + + // output a message to describe the result + return I18NUtil.getMessage(MSG_CREATED); + } + + private void importContent() throws IOException + { + // import the content + ClassPathResource acpResource = new ClassPathResource(this.templatesACP); + ACPImportPackageHandler acpHandler = new ACPImportPackageHandler(acpResource.getFile(), null); + Location importLocation = new Location(this.emailTemplatesNodeRef); + importerService.importView(acpHandler, importLocation, null, null); + } +}