From 5dfb8b117f277e67b5169197de399004312fd2f5 Mon Sep 17 00:00:00 2001 From: Kevin Roast Date: Thu, 18 May 2006 18:56:01 +0000 Subject: [PATCH] Enhancement to ScriptFolderPatch to load the example scripts into the Scripts folder once created git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2921 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../alfresco/patch/patch-services-context.xml | 6 ++- .../admin/patch/impl/ScriptsFolderPatch.java | 52 ++++++++++++++++--- 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/config/alfresco/patch/patch-services-context.xml b/config/alfresco/patch/patch-services-context.xml index db0255e93e..56998af2d4 100644 --- a/config/alfresco/patch/patch-services-context.xml +++ b/config/alfresco/patch/patch-services-context.xml @@ -347,13 +347,17 @@ 0 12 13 + alfresco/bootstrap/example_javascripts.acp - + + + + diff --git a/source/java/org/alfresco/repo/admin/patch/impl/ScriptsFolderPatch.java b/source/java/org/alfresco/repo/admin/patch/impl/ScriptsFolderPatch.java index 2c1a688fba..6fea10daa8 100644 --- a/source/java/org/alfresco/repo/admin/patch/impl/ScriptsFolderPatch.java +++ b/source/java/org/alfresco/repo/admin/patch/impl/ScriptsFolderPatch.java @@ -16,6 +16,7 @@ */ package org.alfresco.repo.admin.patch.impl; +import java.io.IOException; import java.io.Serializable; import java.util.HashMap; import java.util.List; @@ -25,13 +26,17 @@ 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.service.cmr.admin.PatchException; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.StoreRef; +import org.alfresco.service.cmr.view.ImporterService; +import org.alfresco.service.cmr.view.Location; import org.alfresco.service.namespace.QName; import org.springframework.context.MessageSource; +import org.springframework.core.io.ClassPathResource; /** * Ensures that the scripts folder is present. @@ -59,32 +64,44 @@ public class ScriptsFolderPatch extends AbstractPatch private static final String PROPERTY_ICON = "space-icon-default"; private ImporterBootstrap importerBootstrap; + private ImporterService importerService; private MessageSource messageSource; protected NodeRef dictionaryNodeRef; protected Properties configuration; protected NodeRef scriptsFolderNodeRef; + private String scriptsACP; + public void setImporterBootstrap(ImporterBootstrap importerBootstrap) { this.importerBootstrap = importerBootstrap; } + + public void setImporterService(ImporterService importerService) + { + this.importerService = importerService; + } public void setMessageSource(MessageSource messageSource) { this.messageSource = messageSource; } - /** + public void setScriptsACP(String scriptsACP) + { + this.scriptsACP = scriptsACP; + } + + /** * Ensure that required common properties have been set */ protected void checkCommonProperties() throws Exception { - if (importerBootstrap == null) - { - throw new PatchException("'importerBootstrap' property has not been set"); - } - else if (namespaceService == null) + checkPropertyNotNull(importerBootstrap, "importerBootstrap"); + checkPropertyNotNull(importerService, "importerService"); + checkPropertyNotNull(messageSource, "messageSource"); + if (namespaceService == null) { throw new PatchException("'namespaceService' property has not been set"); } @@ -96,6 +113,7 @@ public class ScriptsFolderPatch extends AbstractPatch { throw new PatchException("'nodeService' property has not been set"); } + checkPropertyNotNull(scriptsACP, "scriptsACP"); } /** @@ -193,6 +211,19 @@ public class ScriptsFolderPatch extends AbstractPatch { // create it createFolder(); + + // import the content + try + { + authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName()); + + importContent(); + } + finally + { + authenticationComponent.clearCurrentSecurityContext(); + } + msg = I18NUtil.getMessage(MSG_CREATED, scriptsFolderNodeRef); } else @@ -251,4 +282,13 @@ public class ScriptsFolderPatch extends AbstractPatch // done } + + private void importContent() throws IOException + { + // import the content + ClassPathResource acpResource = new ClassPathResource(this.scriptsACP); + ACPImportPackageHandler acpHandler = new ACPImportPackageHandler(acpResource.getFile(), null); + Location importLocation = new Location(this.scriptsFolderNodeRef); + importerService.importView(acpHandler, importLocation, null, null); + } }