mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
. WCM folders patch for pre-existing Alfresco installations
- Creates the "/Company Home/Web Projects" dir if it does not already exist - Creates the "/Company Home/Data Dictionary/Web Forms" dir if it does not already exist - Updates current schema version to 32 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4895 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -309,7 +309,7 @@
|
|||||||
<prop key="spaces.scripts.childname">${spaces.scripts.childname}</prop>
|
<prop key="spaces.scripts.childname">${spaces.scripts.childname}</prop>
|
||||||
<prop key="spaces.wcm.childname">${spaces.wcm.childname}</prop>
|
<prop key="spaces.wcm.childname">${spaces.wcm.childname}</prop>
|
||||||
<prop key="spaces.content_forms.childname">${spaces.content_forms.childname}</prop>
|
<prop key="spaces.content_forms.childname">${spaces.content_forms.childname}</prop>
|
||||||
<prop key="spaces.user_homes.childname">${spaces.user_homes.childname}</prop>
|
<prop key="spaces.user_homes.childname">${spaces.user_homes.childname}</prop>
|
||||||
</props>
|
</props>
|
||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
@@ -115,3 +115,9 @@ patch.multilingualBootstrap.description=Bootstraps the node that will hold the m
|
|||||||
patch.userHomesFolder.description=Ensures the existence of the 'User Homes' folder.
|
patch.userHomesFolder.description=Ensures the existence of the 'User Homes' folder.
|
||||||
patch.userHomesFolder.result.exists=The user homes folder already exists: {0}
|
patch.userHomesFolder.result.exists=The user homes folder already exists: {0}
|
||||||
patch.userHomesFolder.result.created=The user homes folder was successfully created: {0}
|
patch.userHomesFolder.result.created=The user homes folder was successfully created: {0}
|
||||||
|
|
||||||
|
patch.wcmFolders.description=Ensures the existance of the WCM specific 'Web Projects' and 'Web Forms' folders.
|
||||||
|
patch.wcmFolders.webprojects.result.exists=The Web Projects folder already exists: {0}
|
||||||
|
patch.wcmFolders.webprojects.result.created=The Web Projects folder was successfully created: {0}
|
||||||
|
patch.wcmFolders.webforms.result.exists=The Web Forms folder already exists: {0}
|
||||||
|
patch.wcmFolders.webforms.result.created=The Web Forms folder was successfully created: {0}
|
||||||
|
@@ -552,5 +552,20 @@
|
|||||||
<ref bean="spacesBootstrap" />
|
<ref bean="spacesBootstrap" />
|
||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<bean id="patch.wcmFolders" class="org.alfresco.repo.admin.patch.impl.WCMFoldersPatch" parent="basePatch" >
|
||||||
|
<property name="id"><value>patch.wcmFolders</value></property>
|
||||||
|
<property name="description"><value>patch.wcmFolders.description</value></property>
|
||||||
|
<property name="fixesFromSchema"><value>0</value></property>
|
||||||
|
<property name="fixesToSchema"><value>31</value></property>
|
||||||
|
<property name="targetSchema"><value>32</value></property>
|
||||||
|
<!-- helper beans for execution -->
|
||||||
|
<property name="messageSource">
|
||||||
|
<ref bean="bootstrapSpacesMessageSource" />
|
||||||
|
</property>
|
||||||
|
<property name="importerBootstrap">
|
||||||
|
<ref bean="spacesBootstrap" />
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
@@ -19,4 +19,4 @@ version.build=@build-number@
|
|||||||
|
|
||||||
# Schema number
|
# Schema number
|
||||||
|
|
||||||
version.schema=31
|
version.schema=32
|
||||||
|
@@ -0,0 +1,358 @@
|
|||||||
|
/*
|
||||||
|
* 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.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.ApplicationModel;
|
||||||
|
import org.alfresco.model.ContentModel;
|
||||||
|
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||||
|
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.namespace.QName;
|
||||||
|
import org.springframework.context.MessageSource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensures that the <b>Web Projects</b> and <b>Web Forms</b>folders are present.
|
||||||
|
* <p>
|
||||||
|
* This uses the bootstrap importer to get the paths to look for. If not present,
|
||||||
|
* the required structures are created.
|
||||||
|
* <p>
|
||||||
|
*
|
||||||
|
* @author Kevin Roast
|
||||||
|
*/
|
||||||
|
public class WCMFoldersPatch extends AbstractPatch
|
||||||
|
{
|
||||||
|
private static final String MSG_WEBPROJECTS_EXISTS = "patch.wcmFolders.webprojects.result.exists";
|
||||||
|
private static final String MSG_WEBPROJECTS_CREATED = "patch.wcmFolders.webprojects.result.created";
|
||||||
|
private static final String MSG_WEBFORMS_EXISTS = "patch.wcmFolders.webforms.result.exists";
|
||||||
|
private static final String MSG_WEBFORMS_CREATED = "patch.wcmFolders.webforms.result.created";
|
||||||
|
|
||||||
|
private static final String PROPERTY_COMPANY_HOME_CHILDNAME = "spaces.company_home.childname";
|
||||||
|
private static final String PROPERTY_DICTIONARY_CHILDNAME = "spaces.dictionary.childname";
|
||||||
|
public static final String PROPERTY_WEBPROJECTS_FOLDER_CHILDNAME = "spaces.wcm.childname";
|
||||||
|
private static final String MSG_WEBPROJECTS_FOLDER_NAME = "spaces.wcm.name";
|
||||||
|
private static final String MSG_WEBPROJECTS_FOLDER_DESCRIPTION = "spaces.wcm.description";
|
||||||
|
public static final String PROPERTY_WEBFORMS_FOLDER_CHILDNAME = "spaces.content_forms.childname";
|
||||||
|
private static final String MSG_WEBFORMS_FOLDER_NAME = "spaces.content_forms.name";
|
||||||
|
private static final String MSG_WEBFORMS_FOLDER_DESCRIPTION = "spaces.content_forms.description";
|
||||||
|
|
||||||
|
private static final String PROPERTY_ICON = "space-icon-default";
|
||||||
|
|
||||||
|
private ImporterBootstrap importerBootstrap;
|
||||||
|
private MessageSource messageSource;
|
||||||
|
|
||||||
|
protected NodeRef companyHomeNodeRef;
|
||||||
|
protected NodeRef dictionaryNodeRef;
|
||||||
|
protected Properties configuration;
|
||||||
|
protected NodeRef wcmProjectsFolderNodeRef;
|
||||||
|
protected NodeRef wcmFormsFolderNodeRef;
|
||||||
|
|
||||||
|
public void setImporterBootstrap(ImporterBootstrap importerBootstrap)
|
||||||
|
{
|
||||||
|
this.importerBootstrap = importerBootstrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessageSource(MessageSource messageSource)
|
||||||
|
{
|
||||||
|
this.messageSource = messageSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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)
|
||||||
|
{
|
||||||
|
throw new PatchException("'namespaceService' property has not been set");
|
||||||
|
}
|
||||||
|
else if (searchService == null)
|
||||||
|
{
|
||||||
|
throw new PatchException("'searchService' property has not been set");
|
||||||
|
}
|
||||||
|
else if (nodeService == null)
|
||||||
|
{
|
||||||
|
throw new PatchException("'nodeService' 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 wcmProjectsChildName = configuration.getProperty(PROPERTY_WEBPROJECTS_FOLDER_CHILDNAME);
|
||||||
|
if (wcmProjectsChildName == null || wcmProjectsChildName.length() == 0)
|
||||||
|
{
|
||||||
|
throw new PatchException("Bootstrap property '" + PROPERTY_WEBPROJECTS_FOLDER_CHILDNAME + "' is not present");
|
||||||
|
}
|
||||||
|
String wcmFormsChildName = configuration.getProperty(PROPERTY_WEBFORMS_FOLDER_CHILDNAME);
|
||||||
|
if (wcmFormsChildName == null || wcmFormsChildName.length() == 0)
|
||||||
|
{
|
||||||
|
throw new PatchException("Bootstrap property '" + PROPERTY_WEBFORMS_FOLDER_CHILDNAME + "' is not present");
|
||||||
|
}
|
||||||
|
|
||||||
|
// build the search string to get the company home node
|
||||||
|
StringBuilder sb = new StringBuilder(256);
|
||||||
|
sb.append("/").append(companyHomeChildName);
|
||||||
|
String xpath = sb.toString();
|
||||||
|
// get the company home
|
||||||
|
List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, xpath, null, namespaceService, false);
|
||||||
|
if (nodeRefs.size() == 0)
|
||||||
|
{
|
||||||
|
throw new PatchException("XPath didn't return any results: \n" +
|
||||||
|
" root: " + storeRootNodeRef + "\n" +
|
||||||
|
" xpath: " + xpath);
|
||||||
|
}
|
||||||
|
else if (nodeRefs.size() > 1)
|
||||||
|
{
|
||||||
|
throw new PatchException("XPath returned too many results: \n" +
|
||||||
|
" root: " + storeRootNodeRef + "\n" +
|
||||||
|
" xpath: " + xpath + "\n" +
|
||||||
|
" results: " + nodeRefs);
|
||||||
|
}
|
||||||
|
this.companyHomeNodeRef = nodeRefs.get(0);
|
||||||
|
|
||||||
|
// build the search string to get the dictionary node
|
||||||
|
sb.append("/").append(dictionaryChildName);
|
||||||
|
xpath = sb.toString();
|
||||||
|
// get the dictionary node
|
||||||
|
nodeRefs = searchService.selectNodes(storeRootNodeRef, xpath, null, namespaceService, false);
|
||||||
|
if (nodeRefs.size() == 0)
|
||||||
|
{
|
||||||
|
throw new PatchException("XPath didn't return any results: \n" +
|
||||||
|
" root: " + storeRootNodeRef + "\n" +
|
||||||
|
" xpath: " + xpath);
|
||||||
|
}
|
||||||
|
else if (nodeRefs.size() > 1)
|
||||||
|
{
|
||||||
|
throw new PatchException("XPath returned too many results: \n" +
|
||||||
|
" root: " + storeRootNodeRef + "\n" +
|
||||||
|
" xpath: " + xpath + "\n" +
|
||||||
|
" results: " + nodeRefs);
|
||||||
|
}
|
||||||
|
this.dictionaryNodeRef = nodeRefs.get(0);
|
||||||
|
|
||||||
|
// Check for the existence of the 'Web Projects' folder
|
||||||
|
xpath = wcmProjectsChildName;
|
||||||
|
nodeRefs = searchService.selectNodes(companyHomeNodeRef, xpath, null, namespaceService, false);
|
||||||
|
if (nodeRefs.size() > 1)
|
||||||
|
{
|
||||||
|
throw new PatchException("XPath returned too many results: \n" +
|
||||||
|
" company home node: " + companyHomeNodeRef + "\n" +
|
||||||
|
" xpath: " + xpath + "\n" +
|
||||||
|
" results: " + nodeRefs);
|
||||||
|
}
|
||||||
|
else if (nodeRefs.size() == 0)
|
||||||
|
{
|
||||||
|
// the node does not exist
|
||||||
|
this.wcmProjectsFolderNodeRef = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// we have the 'Web Projects' folder noderef
|
||||||
|
this.wcmProjectsFolderNodeRef = nodeRefs.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for the existence of the 'Web Forms' folder
|
||||||
|
xpath = wcmFormsChildName;
|
||||||
|
nodeRefs = searchService.selectNodes(dictionaryNodeRef, xpath, null, namespaceService, false);
|
||||||
|
if (nodeRefs.size() > 1)
|
||||||
|
{
|
||||||
|
throw new PatchException("XPath returned too many results: \n" +
|
||||||
|
" dictionary node: " + dictionaryNodeRef + "\n" +
|
||||||
|
" xpath: " + xpath + "\n" +
|
||||||
|
" results: " + nodeRefs);
|
||||||
|
}
|
||||||
|
else if (nodeRefs.size() == 0)
|
||||||
|
{
|
||||||
|
// the node does not exist
|
||||||
|
this.wcmFormsFolderNodeRef = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// we have the 'Web Forms' folder noderef
|
||||||
|
this.wcmFormsFolderNodeRef = nodeRefs.get(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String applyInternal() throws Exception
|
||||||
|
{
|
||||||
|
// properties must be set
|
||||||
|
checkCommonProperties();
|
||||||
|
if (messageSource == null)
|
||||||
|
{
|
||||||
|
throw new PatchException("'messageSource' property has not been set");
|
||||||
|
}
|
||||||
|
|
||||||
|
// get useful values
|
||||||
|
setUp();
|
||||||
|
|
||||||
|
String msg = null;
|
||||||
|
if (wcmProjectsFolderNodeRef == null)
|
||||||
|
{
|
||||||
|
// create it
|
||||||
|
createWebProjectsFolder();
|
||||||
|
msg = I18NUtil.getMessage(MSG_WEBPROJECTS_CREATED, wcmProjectsFolderNodeRef);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// it already exists
|
||||||
|
msg = I18NUtil.getMessage(MSG_WEBPROJECTS_EXISTS, wcmProjectsFolderNodeRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wcmFormsFolderNodeRef == null)
|
||||||
|
{
|
||||||
|
// create it
|
||||||
|
createWebFormsFolder();
|
||||||
|
msg = msg + "\r\n" + I18NUtil.getMessage(MSG_WEBFORMS_CREATED, wcmProjectsFolderNodeRef);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// it already exists
|
||||||
|
msg = msg + "\r\n" + I18NUtil.getMessage(MSG_WEBFORMS_EXISTS, wcmProjectsFolderNodeRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
// done
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createWebProjectsFolder()
|
||||||
|
{
|
||||||
|
// get required properties
|
||||||
|
String wcmProjectsChildName = configuration.getProperty(PROPERTY_WEBPROJECTS_FOLDER_CHILDNAME);
|
||||||
|
if (wcmProjectsChildName == null)
|
||||||
|
{
|
||||||
|
throw new PatchException("Bootstrap property '" + PROPERTY_WEBPROJECTS_FOLDER_CHILDNAME + "' is not present");
|
||||||
|
}
|
||||||
|
|
||||||
|
String name = messageSource.getMessage(
|
||||||
|
MSG_WEBPROJECTS_FOLDER_NAME,
|
||||||
|
null,
|
||||||
|
I18NUtil.getLocale());
|
||||||
|
if (name == null || name.length() == 0)
|
||||||
|
{
|
||||||
|
throw new PatchException("Bootstrap property '" + MSG_WEBPROJECTS_FOLDER_NAME + "' is not present");
|
||||||
|
}
|
||||||
|
|
||||||
|
String description = messageSource.getMessage(
|
||||||
|
MSG_WEBPROJECTS_FOLDER_DESCRIPTION,
|
||||||
|
null,
|
||||||
|
I18NUtil.getLocale());
|
||||||
|
if (description == null || description.length() == 0)
|
||||||
|
{
|
||||||
|
throw new PatchException("Bootstrap property '" + MSG_WEBPROJECTS_FOLDER_DESCRIPTION + "' is not present");
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<QName, Serializable> properties = new HashMap<QName, Serializable>(7);
|
||||||
|
properties.put(ContentModel.PROP_NAME, name);
|
||||||
|
properties.put(ContentModel.PROP_TITLE, name);
|
||||||
|
properties.put(ContentModel.PROP_DESCRIPTION, description);
|
||||||
|
properties.put(ApplicationModel.PROP_ICON, PROPERTY_ICON);
|
||||||
|
// create the node
|
||||||
|
ChildAssociationRef childAssocRef = nodeService.createNode(
|
||||||
|
companyHomeNodeRef,
|
||||||
|
ContentModel.ASSOC_CONTAINS,
|
||||||
|
QName.resolveToQName(namespaceService, wcmProjectsChildName),
|
||||||
|
ContentModel.TYPE_FOLDER,
|
||||||
|
properties);
|
||||||
|
wcmProjectsFolderNodeRef = childAssocRef.getChildRef();
|
||||||
|
|
||||||
|
// add the required aspects
|
||||||
|
nodeService.addAspect(wcmProjectsFolderNodeRef, ApplicationModel.ASPECT_UIFACETS, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createWebFormsFolder()
|
||||||
|
{
|
||||||
|
// get required properties
|
||||||
|
String wcmFormsChildName = configuration.getProperty(PROPERTY_WEBFORMS_FOLDER_CHILDNAME);
|
||||||
|
if (wcmFormsChildName == null)
|
||||||
|
{
|
||||||
|
throw new PatchException("Bootstrap property '" + PROPERTY_WEBFORMS_FOLDER_CHILDNAME + "' is not present");
|
||||||
|
}
|
||||||
|
|
||||||
|
String name = messageSource.getMessage(
|
||||||
|
MSG_WEBFORMS_FOLDER_NAME,
|
||||||
|
null,
|
||||||
|
I18NUtil.getLocale());
|
||||||
|
if (name == null || name.length() == 0)
|
||||||
|
{
|
||||||
|
throw new PatchException("Bootstrap property '" + MSG_WEBFORMS_FOLDER_NAME + "' is not present");
|
||||||
|
}
|
||||||
|
|
||||||
|
String description = messageSource.getMessage(
|
||||||
|
MSG_WEBFORMS_FOLDER_DESCRIPTION,
|
||||||
|
null,
|
||||||
|
I18NUtil.getLocale());
|
||||||
|
if (description == null || description.length() == 0)
|
||||||
|
{
|
||||||
|
throw new PatchException("Bootstrap property '" + MSG_WEBFORMS_FOLDER_DESCRIPTION + "' is not present");
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<QName, Serializable> properties = new HashMap<QName, Serializable>(7);
|
||||||
|
properties.put(ContentModel.PROP_NAME, name);
|
||||||
|
properties.put(ContentModel.PROP_TITLE, name);
|
||||||
|
properties.put(ContentModel.PROP_DESCRIPTION, description);
|
||||||
|
properties.put(ApplicationModel.PROP_ICON, PROPERTY_ICON);
|
||||||
|
// create the node
|
||||||
|
ChildAssociationRef childAssocRef = nodeService.createNode(
|
||||||
|
dictionaryNodeRef,
|
||||||
|
ContentModel.ASSOC_CONTAINS,
|
||||||
|
QName.resolveToQName(namespaceService, wcmFormsChildName),
|
||||||
|
ContentModel.TYPE_FOLDER,
|
||||||
|
properties);
|
||||||
|
wcmFormsFolderNodeRef = childAssocRef.getChildRef();
|
||||||
|
|
||||||
|
// add the required aspects
|
||||||
|
nodeService.addAspect(wcmFormsFolderNodeRef, ApplicationModel.ASPECT_UIFACETS, null);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user