mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
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
This commit is contained in:
@@ -347,6 +347,7 @@
|
|||||||
<property name="fixesFromSchema"><value>0</value></property>
|
<property name="fixesFromSchema"><value>0</value></property>
|
||||||
<property name="fixesToSchema"><value>12</value></property>
|
<property name="fixesToSchema"><value>12</value></property>
|
||||||
<property name="targetSchema"><value>13</value></property>
|
<property name="targetSchema"><value>13</value></property>
|
||||||
|
<property name="scriptsACP"><value>alfresco/bootstrap/example_javascripts.acp</value></property>
|
||||||
<!-- helper beans for execution -->
|
<!-- helper beans for execution -->
|
||||||
<property name="importerBootstrap">
|
<property name="importerBootstrap">
|
||||||
<ref bean="spacesBootstrap" />
|
<ref bean="spacesBootstrap" />
|
||||||
@@ -354,6 +355,9 @@
|
|||||||
<property name="messageSource">
|
<property name="messageSource">
|
||||||
<ref bean="bootstrapSpacesMessageSource" />
|
<ref bean="bootstrapSpacesMessageSource" />
|
||||||
</property>
|
</property>
|
||||||
|
<property name="importerService">
|
||||||
|
<ref bean="importerComponent" />
|
||||||
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.admin.patch.impl;
|
package org.alfresco.repo.admin.patch.impl;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -25,13 +26,17 @@ import java.util.Properties;
|
|||||||
import org.alfresco.i18n.I18NUtil;
|
import org.alfresco.i18n.I18NUtil;
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||||
|
import org.alfresco.repo.importer.ACPImportPackageHandler;
|
||||||
import org.alfresco.repo.importer.ImporterBootstrap;
|
import org.alfresco.repo.importer.ImporterBootstrap;
|
||||||
import org.alfresco.service.cmr.admin.PatchException;
|
import org.alfresco.service.cmr.admin.PatchException;
|
||||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.StoreRef;
|
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.alfresco.service.namespace.QName;
|
||||||
import org.springframework.context.MessageSource;
|
import org.springframework.context.MessageSource;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures that the <b>scripts</b> folder is present.
|
* Ensures that the <b>scripts</b> folder is present.
|
||||||
@@ -59,32 +64,44 @@ public class ScriptsFolderPatch extends AbstractPatch
|
|||||||
private static final String PROPERTY_ICON = "space-icon-default";
|
private static final String PROPERTY_ICON = "space-icon-default";
|
||||||
|
|
||||||
private ImporterBootstrap importerBootstrap;
|
private ImporterBootstrap importerBootstrap;
|
||||||
|
private ImporterService importerService;
|
||||||
private MessageSource messageSource;
|
private MessageSource messageSource;
|
||||||
|
|
||||||
protected NodeRef dictionaryNodeRef;
|
protected NodeRef dictionaryNodeRef;
|
||||||
protected Properties configuration;
|
protected Properties configuration;
|
||||||
protected NodeRef scriptsFolderNodeRef;
|
protected NodeRef scriptsFolderNodeRef;
|
||||||
|
|
||||||
|
private String scriptsACP;
|
||||||
|
|
||||||
public void setImporterBootstrap(ImporterBootstrap importerBootstrap)
|
public void setImporterBootstrap(ImporterBootstrap importerBootstrap)
|
||||||
{
|
{
|
||||||
this.importerBootstrap = importerBootstrap;
|
this.importerBootstrap = importerBootstrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setImporterService(ImporterService importerService)
|
||||||
|
{
|
||||||
|
this.importerService = importerService;
|
||||||
|
}
|
||||||
|
|
||||||
public void setMessageSource(MessageSource messageSource)
|
public void setMessageSource(MessageSource messageSource)
|
||||||
{
|
{
|
||||||
this.messageSource = messageSource;
|
this.messageSource = messageSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void setScriptsACP(String scriptsACP)
|
||||||
|
{
|
||||||
|
this.scriptsACP = scriptsACP;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
* Ensure that required common properties have been set
|
* Ensure that required common properties have been set
|
||||||
*/
|
*/
|
||||||
protected void checkCommonProperties() throws Exception
|
protected void checkCommonProperties() throws Exception
|
||||||
{
|
{
|
||||||
if (importerBootstrap == null)
|
checkPropertyNotNull(importerBootstrap, "importerBootstrap");
|
||||||
{
|
checkPropertyNotNull(importerService, "importerService");
|
||||||
throw new PatchException("'importerBootstrap' property has not been set");
|
checkPropertyNotNull(messageSource, "messageSource");
|
||||||
}
|
if (namespaceService == null)
|
||||||
else if (namespaceService == null)
|
|
||||||
{
|
{
|
||||||
throw new PatchException("'namespaceService' property has not been set");
|
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");
|
throw new PatchException("'nodeService' property has not been set");
|
||||||
}
|
}
|
||||||
|
checkPropertyNotNull(scriptsACP, "scriptsACP");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -193,6 +211,19 @@ public class ScriptsFolderPatch extends AbstractPatch
|
|||||||
{
|
{
|
||||||
// create it
|
// create it
|
||||||
createFolder();
|
createFolder();
|
||||||
|
|
||||||
|
// import the content
|
||||||
|
try
|
||||||
|
{
|
||||||
|
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
|
||||||
|
|
||||||
|
importContent();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
authenticationComponent.clearCurrentSecurityContext();
|
||||||
|
}
|
||||||
|
|
||||||
msg = I18NUtil.getMessage(MSG_CREATED, scriptsFolderNodeRef);
|
msg = I18NUtil.getMessage(MSG_CREATED, scriptsFolderNodeRef);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -251,4 +282,13 @@ public class ScriptsFolderPatch extends AbstractPatch
|
|||||||
|
|
||||||
// done
|
// 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user