Big honkin' merge from head. Sheesh!

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3617 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-08-27 01:01:30 +00:00
parent e2c66899cc
commit 8031cc6574
322 changed files with 20776 additions and 6550 deletions

View File

@@ -0,0 +1,115 @@
/*
* 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.Map;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ActionModel;
import org.alfresco.repo.admin.patch.AbstractPatch;
import org.alfresco.repo.rule.RuleModel;
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.search.ResultSet;
import org.alfresco.service.namespace.QName;
/**
* Patch to apply the model changes made when decoupling actions from rules.
*
* @author Roy Wetherall
*/
public class ActionRuleDecouplingPatch extends AbstractPatch
{
private static final String MSG_RESULT = "patch.actionRuleDecouplingPatch.result";
/**
* @see org.alfresco.repo.admin.patch.AbstractPatch#applyInternal()
*/
@Override
protected String applyInternal() throws Exception
{
// Get a reference to the spaces store
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
// Get all the node's of type rule in the store
int updateCount = 0;
ResultSet resultSet = this.searchService.query(storeRef, "lucene", "TYPE:\"" + RuleModel.TYPE_RULE + "\"");
for (NodeRef origRuleNodeRef : resultSet.getNodeRefs())
{
// Check that this rule need updated
Map<QName, Serializable> origProperties = this.nodeService.getProperties(origRuleNodeRef);
if (origProperties.containsKey(RuleModel.PROP_EXECUTE_ASYNC) == false)
{
// 1) Change the type of the rule to be a composite action
this.nodeService.setType(origRuleNodeRef, ActionModel.TYPE_COMPOSITE_ACTION);
// 2) Create a new rule node
ChildAssociationRef parentRef = this.nodeService.getPrimaryParent(origRuleNodeRef);
NodeRef newRuleNodeRef = this.nodeService.createNode(
parentRef.getParentRef(),
parentRef.getTypeQName(),
parentRef.getQName(),
RuleModel.TYPE_RULE).getChildRef();
// 3) Move the origional rule under the new rule
this.nodeService.moveNode(
origRuleNodeRef,
newRuleNodeRef,
RuleModel.ASSOC_ACTION,
RuleModel.ASSOC_ACTION);
// 4) Move the various properties from the origional, onto the new rule
Map<QName, Serializable> newProperties = this.nodeService.getProperties(newRuleNodeRef);
// Set the rule type, execute async and applyToChildren properties on the rule
String ruleType = (String)origProperties.get(RuleModel.PROP_RULE_TYPE);
origProperties.remove(RuleModel.PROP_RULE_TYPE);
newProperties.put(RuleModel.PROP_RULE_TYPE, ruleType);
Boolean executeAsync = (Boolean)origProperties.get(ActionModel.PROP_EXECUTE_ASYNCHRONOUSLY);
origProperties.remove(ActionModel.PROP_EXECUTE_ASYNCHRONOUSLY);
newProperties.put(RuleModel.PROP_EXECUTE_ASYNC, executeAsync);
Boolean applyToChildren = (Boolean)origProperties.get(RuleModel.PROP_APPLY_TO_CHILDREN);
origProperties.remove(RuleModel.PROP_APPLY_TO_CHILDREN);
newProperties.put(RuleModel.PROP_APPLY_TO_CHILDREN, applyToChildren);
origProperties.remove(QName.createQName(RuleModel.RULE_MODEL_URI, "owningNodeRef"));
// Move the action and description values from the composite action onto the rule
String title = (String)origProperties.get(ActionModel.PROP_ACTION_TITLE);
origProperties.remove(ActionModel.PROP_ACTION_TITLE);
String description = (String)origProperties.get(ActionModel.PROP_ACTION_DESCRIPTION);
origProperties.remove(ActionModel.PROP_ACTION_DESCRIPTION);
newProperties.put(ContentModel.PROP_TITLE, title);
newProperties.put(ContentModel.PROP_DESCRIPTION, description);
// Set the updated property values
this.nodeService.setProperties(origRuleNodeRef, origProperties);
this.nodeService.setProperties(newRuleNodeRef, newProperties);
// Increment the update count
updateCount++;
}
}
// Done
String msg = I18NUtil.getMessage(MSG_RESULT, updateCount);
return msg;
}
}

View File

@@ -0,0 +1,72 @@
/*
* 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 org.alfresco.i18n.I18NUtil;
import org.alfresco.repo.admin.patch.AbstractPatch;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.security.PersonService;
/**
* Change Guest Person permission to make visible to all users as 'Consumer'.
*
* This allows users other than admin to select the Guest user for Invite to a Space.
*/
public class GuestPersonPermissionPatch2 extends AbstractPatch
{
private static final String MSG_SUCCESS = "patch.guestPersonPermission2.result";
private PersonService personService;
private PermissionService permissionService;
private String guestId = "guest";
public GuestPersonPermissionPatch2()
{
super();
}
public void setGuestId(String guestId)
{
this.guestId = guestId;
}
public void setPermissionService(PermissionService permissionService)
{
this.permissionService = permissionService;
}
public void setPersonService(PersonService personService)
{
this.personService = personService;
}
@Override
protected String applyInternal() throws Exception
{
if (personService.personExists(guestId))
{
NodeRef personRef = personService.getPerson(guestId);
permissionService.setInheritParentPermissions(personRef, true);
}
return I18NUtil.getMessage(MSG_SUCCESS);
}
}

View File

@@ -0,0 +1,306 @@
/*
* 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.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.security.PermissionService;
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 <b>RSS Templates</b> folder is present.
* <p>
* This uses the bootstrap importer to get the paths to look for. If not present,
* the required structures are created.
* <p>
* This class should be replaced with a more generic <code>ImporterPatch</code>
* that can do conditional importing into given locations.
* <p>
* JIRA: {@link http://www.alfresco.org/jira/browse/AR-342 AR-342}
*
* @author Kevin Roast
*/
public class RSSTemplatesFolderPatch extends AbstractPatch
{
private static final String MSG_EXISTS = "patch.rssTemplatesFolder.result.exists";
private static final String MSG_CREATED = "patch.rssTemplatesFolder.result.created";
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_RSS_FOLDER_CHILDNAME = "spaces.templates.rss.childname";
private static final String PROPERTY_RSS_FOLDER_NAME = "spaces.templates.rss.name";
private static final String PROPERTY_RSS_FOLDER_DESCRIPTION = "spaces.templates.rss.description";
private static final String PROPERTY_ICON = "space-icon-default";
private ImporterBootstrap importerBootstrap;
private ImporterService importerService;
private MessageSource messageSource;
private PermissionService permissionService;
protected NodeRef dictionaryNodeRef;
protected Properties configuration;
protected NodeRef rssFolderNodeRef;
private String rssTemplatesACP;
public void setPermissionService(PermissionService permissionService)
{
this.permissionService = permissionService;
}
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 setRssTemplatesACP(String rssTemplatesACP)
{
this.rssTemplatesACP = rssTemplatesACP;
}
/**
* Ensure that required common properties have been set
*/
protected void checkCommonProperties() throws Exception
{
checkPropertyNotNull(importerBootstrap, "importerBootstrap");
checkPropertyNotNull(importerService, "importerService");
checkPropertyNotNull(messageSource, "messageSource");
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");
}
checkPropertyNotNull(rssTemplatesACP, "rssTemplatesACP");
}
/**
* 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 rssChildName = configuration.getProperty(PROPERTY_RSS_FOLDER_CHILDNAME);
if (rssChildName == null || rssChildName.length() == 0)
{
throw new PatchException("Bootstrap property '" + PROPERTY_RSS_FOLDER_CHILDNAME + "' is not present");
}
// build the search string to get the dictionary node
StringBuilder sb = new StringBuilder(256);
sb.append("/").append(companyHomeChildName)
.append("/").append(dictionaryChildName);
String xpath = sb.toString();
// get the dictionary node
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.dictionaryNodeRef = nodeRefs.get(0);
// Now we have the optional part - check for the existence of the RSS Templates folder
xpath = rssChildName;
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.rssFolderNodeRef = null;
}
else
{
// we have the RSS Templates folder noderef
this.rssFolderNodeRef = 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 (rssFolderNodeRef == null)
{
// create it
createFolder();
// apply Guest permission to the folder
permissionService.setPermission(
rssFolderNodeRef,
PermissionService.GUEST_AUTHORITY,
PermissionService.CONSUMER,
true);
// import the content
try
{
authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
importContent();
}
finally
{
authenticationComponent.clearCurrentSecurityContext();
}
msg = I18NUtil.getMessage(MSG_CREATED, rssFolderNodeRef);
}
else
{
// it already exists
msg = I18NUtil.getMessage(MSG_EXISTS, rssFolderNodeRef);
}
// done
return msg;
}
private void createFolder()
{
// get required properties
String rssChildName = configuration.getProperty(PROPERTY_RSS_FOLDER_CHILDNAME);
if (rssChildName == null)
{
throw new PatchException("Bootstrap property '" + PROPERTY_RSS_FOLDER_CHILDNAME + "' is not present");
}
String folderName = messageSource.getMessage(
PROPERTY_RSS_FOLDER_NAME,
null,
I18NUtil.getLocale());
if (folderName == null || folderName.length() == 0)
{
throw new PatchException("Bootstrap property '" + PROPERTY_RSS_FOLDER_NAME + "' is not present");
}
String folderDescription = messageSource.getMessage(
PROPERTY_RSS_FOLDER_DESCRIPTION,
null,
I18NUtil.getLocale());
if (folderDescription == null || folderDescription.length() == 0)
{
throw new PatchException("Bootstrap property '" + PROPERTY_RSS_FOLDER_DESCRIPTION + "' is not present");
}
Map<QName, Serializable> properties = new HashMap<QName, Serializable>(7);
properties.put(ContentModel.PROP_NAME, folderName);
properties.put(ContentModel.PROP_TITLE, folderName);
properties.put(ContentModel.PROP_DESCRIPTION, folderDescription);
properties.put(ContentModel.PROP_ICON, PROPERTY_ICON);
// create the node
ChildAssociationRef childAssocRef = nodeService.createNode(
dictionaryNodeRef,
ContentModel.ASSOC_CONTAINS,
QName.resolveToQName(namespaceService, rssChildName),
ContentModel.TYPE_FOLDER,
properties);
this.rssFolderNodeRef = childAssocRef.getChildRef();
// finally add the required aspects
nodeService.addAspect(rssFolderNodeRef, ContentModel.ASPECT_UIFACETS, null);
}
private void importContent() throws IOException
{
// import the content
ClassPathResource acpResource = new ClassPathResource(this.rssTemplatesACP);
ACPImportPackageHandler acpHandler = new ACPImportPackageHandler(acpResource.getFile(), null);
Location importLocation = new Location(this.rssFolderNodeRef);
importerService.importView(acpHandler, importLocation, null, null);
}
}

View File

@@ -0,0 +1,64 @@
/*
* 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 org.alfresco.repo.admin.patch.AbstractPatch;
import org.alfresco.service.cmr.admin.PatchException;
/**
* This patch ensures that an upgrade script has been executed. Upgrade scripts
* should create an entry for the patch with the required ID and execution status
* so that the code in this class is never called. If called, an exception message
* is always generated.
*
* @author Derek Hulley
*/
public class SchemaUpgradeScriptPatch extends AbstractPatch
{
private static final String MSG_NOT_EXECUTED = "patch.schemaUpgradeScript.err.not_executed";
private String scriptName;
public SchemaUpgradeScriptPatch()
{
}
/**
* Set the name of the upgrade script to execute.
*
* @param scriptName the script filename
*/
public void setScriptName(String scriptName)
{
this.scriptName = scriptName;
}
protected void checkProperties()
{
super.checkProperties();
checkPropertyNotNull(scriptName, "scriptName");
}
/**
* @see #MSG_NOT_EXECUTED
*/
@Override
protected String applyInternal() throws Exception
{
throw new PatchException(MSG_NOT_EXECUTED, scriptName);
}
}

View File

@@ -188,7 +188,7 @@ public class ScriptsFolderPatch extends AbstractPatch
}
else
{
// we have the saved searches folder noderef
// we have the scripts folder noderef
this.scriptsFolderNodeRef = nodeRefs.get(0);
}
}
@@ -238,49 +238,47 @@ public class ScriptsFolderPatch extends AbstractPatch
private void createFolder()
{
// get required properties
String savedSearchesChildName = configuration.getProperty(PROPERTY_SCRIPTS_FOLDER_CHILDNAME);
if (savedSearchesChildName == null)
String scriptsChildName = configuration.getProperty(PROPERTY_SCRIPTS_FOLDER_CHILDNAME);
if (scriptsChildName == null)
{
throw new PatchException("Bootstrap property '" + PROPERTY_SCRIPTS_FOLDER_CHILDNAME + "' is not present");
}
String savedSearchesName = messageSource.getMessage(
String folderName = messageSource.getMessage(
PROPERTY_SCRIPTS_FOLDER_NAME,
null,
I18NUtil.getLocale());
if (savedSearchesName == null || savedSearchesName.length() == 0)
if (folderName == null || folderName.length() == 0)
{
throw new PatchException("Bootstrap property '" + PROPERTY_SCRIPTS_FOLDER_NAME + "' is not present");
}
String savedSearchesDescription = messageSource.getMessage(
String folderDescription = messageSource.getMessage(
PROPERTY_SCRIPTS_FOLDER_DESCRIPTION,
null,
I18NUtil.getLocale());
if (savedSearchesDescription == null || savedSearchesDescription.length() == 0)
if (folderDescription == null || folderDescription.length() == 0)
{
throw new PatchException("Bootstrap property '" + PROPERTY_SCRIPTS_FOLDER_DESCRIPTION + "' is not present");
}
Map<QName, Serializable> properties = new HashMap<QName, Serializable>(7);
properties.put(ContentModel.PROP_NAME, savedSearchesName);
properties.put(ContentModel.PROP_TITLE, savedSearchesName);
properties.put(ContentModel.PROP_DESCRIPTION, savedSearchesDescription);
properties.put(ContentModel.PROP_NAME, folderName);
properties.put(ContentModel.PROP_TITLE, folderName);
properties.put(ContentModel.PROP_DESCRIPTION, folderDescription);
properties.put(ContentModel.PROP_ICON, PROPERTY_ICON);
// create the node
ChildAssociationRef childAssocRef = nodeService.createNode(
dictionaryNodeRef,
ContentModel.ASSOC_CONTAINS,
QName.resolveToQName(namespaceService, savedSearchesChildName),
QName.resolveToQName(namespaceService, scriptsChildName),
ContentModel.TYPE_FOLDER,
properties);
scriptsFolderNodeRef = childAssocRef.getChildRef();
// add the required aspects
// finally add the required aspects
nodeService.addAspect(scriptsFolderNodeRef, ContentModel.ASPECT_UIFACETS, null);
// done
}
private void importContent() throws IOException

View File

@@ -0,0 +1,51 @@
/*
* 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 org.alfresco.i18n.I18NUtil;
import org.alfresco.repo.admin.patch.AbstractPatch;
import org.alfresco.repo.workflow.WorkflowPackageImpl;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Ensures the system folder for Workflows is created.
*
* @author davidc
*/
public class SystemWorkflowFolderPatch extends AbstractPatch
{
private static final String MSG_CREATED = "patch.systemWorkflowFolder.result.created";
private WorkflowPackageImpl workflowPackageImpl;
public void setWorkflowPackageImpl(WorkflowPackageImpl workflowPackageImpl)
{
this.workflowPackageImpl = workflowPackageImpl;
}
/* (non-Javadoc)
* @see org.alfresco.repo.admin.patch.AbstractPatch#applyInternal()
*/
@Override
protected String applyInternal() throws Exception
{
NodeRef systemContainer = workflowPackageImpl.createSystemWorkflowContainer();
return I18NUtil.getMessage(MSG_CREATED, systemContainer);
}
}

View File

@@ -0,0 +1,148 @@
/*
* 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.util.List;
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.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.view.ImporterService;
import org.alfresco.service.cmr.view.Location;
import org.springframework.context.MessageSource;
import org.springframework.core.io.ClassPathResource;
/**
* Removes the <b>uifacets</b> aspect incorrectly applied to the default set of Presentation
* Templates loaded during bootstrap. For new installs the bootstrap XML file has been modified
* to no longer apply the aspect.
* <p>
* This uses the bootstrap importer to get the paths to look for.
*
* @author Kevin Roast
*/
public class UIFacetsAspectRemovalPatch extends AbstractPatch
{
private static final String MSG_UPDATED = "patch.uifacetsAspectRemovalPatch.updated";
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_TEMPLATES_CHILDNAME = "spaces.templates.content.childname";
private ImporterBootstrap importerBootstrap;
private MessageSource messageSource;
protected Properties configuration;
protected NodeRef templatesNodeRef;
public void setImporterBootstrap(ImporterBootstrap importerBootstrap)
{
this.importerBootstrap = importerBootstrap;
}
public void setMessageSource(MessageSource messageSource)
{
this.messageSource = messageSource;
}
/**
* Ensure that required properties have been set
*/
protected void checkRequiredProperties() throws Exception
{
checkPropertyNotNull(importerBootstrap, "importerBootstrap");
checkPropertyNotNull(messageSource, "messageSource");
}
/**
* Extracts pertinent references and properties that are common to execution
* of this and derived patches.
*
* @return the number of updated template files
*/
protected int removeAspectFromTemplates() 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 templatesChildName = configuration.getProperty(PROPERTY_TEMPLATES_CHILDNAME);
if (templatesChildName == null || templatesChildName.length() == 0)
{
throw new PatchException("Bootstrap property '" + PROPERTY_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(templatesChildName)
.append("//*[subtypeOf('cm:content')]");
String xpath = sb.toString();
// get the template content nodes
int updated = 0;
List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, xpath, null, namespaceService, false);
for (NodeRef ref : nodeRefs)
{
// if the content has the uifacets aspect, then remove it and meaningless icon reference
if (nodeService.hasAspect(ref, ContentModel.ASPECT_UIFACETS))
{
nodeService.removeAspect(ref, ContentModel.ASPECT_UIFACETS);
nodeService.setProperty(ref, ContentModel.PROP_ICON, null);
updated++;
}
}
return updated;
}
@Override
protected String applyInternal() throws Exception
{
// common properties must be set before we can continue
checkRequiredProperties();
int updated = removeAspectFromTemplates();
// output a message to describe the result
return I18NUtil.getMessage(MSG_UPDATED, updated);
}
}

View File

@@ -0,0 +1,268 @@
/*
* 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.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.Date;
import java.util.List;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.admin.patch.AbstractPatch;
import org.alfresco.repo.domain.ChildAssoc;
import org.alfresco.repo.domain.Node;
import org.alfresco.repo.node.db.NodeDaoService;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.ChildAssociationDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.DuplicateChildNodeNameException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.Path;
import org.alfresco.service.namespace.QName;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
* Checks that all child node names are unique for the associations that require it.
*
* @author Derek Hulley
*/
public class UniqueChildNamePatch extends AbstractPatch
{
private static final String MSG_SUCCESS = "patch.uniqueChildName.result";
private static final String MSG_COPY_OF = "patch.uniqueChildName.copyOf";
/** the number of associations to process at a time */
private static final int MAX_RESULTS = 1000;
private SessionFactory sessionFactory;
private DictionaryService dictionaryService;
private NodeDaoService nodeDaoService;
public UniqueChildNamePatch()
{
}
public void setSessionFactory(SessionFactory sessionFactory)
{
this.sessionFactory = sessionFactory;
}
/**
* @param dictionaryService The service used to sort out the associations
* that require duplicate checks
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* @param nodeDaoService The service that generates the CRC values
*/
public void setNodeDaoService(NodeDaoService nodeDaoService)
{
this.nodeDaoService = nodeDaoService;
}
@Override
protected void checkProperties()
{
super.checkProperties();
checkPropertyNotNull(sessionFactory, "sessionFactory");
checkPropertyNotNull(dictionaryService, "dictionaryService");
checkPropertyNotNull(nodeDaoService, "nodeDaoService");
}
@Override
protected String applyInternal() throws Exception
{
// initialise the helper
HibernateHelper helper = new HibernateHelper();
helper.setSessionFactory(sessionFactory);
String msg = helper.assignCrc();
// done
return msg;
}
private class HibernateHelper extends HibernateDaoSupport
{
private File logFile;
private FileChannel channel;
private HibernateHelper() throws IOException
{
logFile = new File("./UniqueChildNamePatch.log");
// open the file for appending
RandomAccessFile outputFile = new RandomAccessFile(logFile, "rw");
channel = outputFile.getChannel();
// move to the end of the file
channel.position(channel.size());
// add a newline and it's ready
writeLine("").writeLine("");
writeLine("UniqueChildNamePatch executing on " + new Date());
}
private HibernateHelper write(Object obj) throws IOException
{
channel.write(ByteBuffer.wrap(obj.toString().getBytes()));
return this;
}
private HibernateHelper writeLine(Object obj) throws IOException
{
write(obj);
write("\n");
return this;
}
public String assignCrc() throws Exception
{
// get the association types to check
@SuppressWarnings("unused")
List<QName> assocTypeQNames = getUsedAssocQNames();
int fixed = 0;
int processed = 0;
// check loop through all associations, looking for duplicates
for (QName assocTypeQName : assocTypeQNames)
{
AssociationDefinition assocDef = dictionaryService.getAssociation(assocTypeQName);
if (!(assocDef instanceof ChildAssociationDefinition))
{
String msg = "WARNING: Non-child association used to link a child node: " + assocTypeQName;
writeLine(msg);
logger.warn(msg);
continue;
}
ChildAssociationDefinition childAssocDef = (ChildAssociationDefinition) assocDef;
if (childAssocDef.getDuplicateChildNamesAllowed())
{
continue;
}
write("Checking for name duplicates on association type ").writeLine(assocTypeQName);
// get all child associations until there are no more results
long lastAssocId = Long.MIN_VALUE;
int lastResultCount = 1;
while(lastResultCount > 0)
{
writeLine(String.format("...Processed %7d associations with %3d duplicates found...", processed, fixed));
List<Object[]> results = getAssociations(assocTypeQName, lastAssocId) ;
lastResultCount = results.size();
for (Object[] objects : results)
{
ChildAssoc childAssoc = (ChildAssoc) objects[0];
Node childNode = (Node) objects[1];
NodeRef childNodeRef = childNode.getNodeRef();
// get the current name
String childName = (String) nodeService.getProperty(childNodeRef, ContentModel.PROP_NAME);
lastAssocId = childAssoc.getId();
String usedChildName = childName;
processed++;
boolean duplicate = false;
while(true)
{
try
{
// push the name back to the node
nodeService.setProperty(childNodeRef, ContentModel.PROP_NAME, usedChildName);
break; // no issues - no duplicate
}
catch (DuplicateChildNodeNameException e)
{
// there was a duplicate, so adjust the name and change the node property
duplicate = true;
// assign a new name
usedChildName = childName + I18NUtil.getMessage(MSG_COPY_OF, processed);
// try again
}
}
// if duplicated, report it
if (duplicate)
{
fixed++;
// get the node path
NodeRef parentNodeRef = childAssoc.getParent().getNodeRef();
Path path = nodeService.getPath(parentNodeRef);
writeLine(" Changed duplicated child name:");
writeLine(" Parent: " + parentNodeRef);
writeLine(" Parent path: " + path);
writeLine(" Duplicate name: " + childName);
writeLine(" Replaced with: " + usedChildName);
}
}
}
}
// build the result message
String msg = I18NUtil.getMessage(MSG_SUCCESS, processed, fixed, logFile);
return msg;
}
@SuppressWarnings("unchecked")
private List<QName> getUsedAssocQNames()
{
HibernateCallback callback = new HibernateCallback()
{
public Object doInHibernate(Session session)
{
Query query = session
.createQuery(
"select distinct assoc.typeQName " +
"from org.alfresco.repo.domain.hibernate.ChildAssocImpl as assoc");
return query.list();
}
};
List<QName> results = (List<QName>) getHibernateTemplate().execute(callback);
return results;
}
/**
* @return Returns a list of <tt>ChildAssoc</tt> and <tt>String</tt> instances
*/
@SuppressWarnings("unchecked")
private List<Object[]> getAssociations(final QName assocTypeQName, final long lastAssocId)
{
HibernateCallback callback = new HibernateCallback()
{
public Object doInHibernate(Session session)
{
Query query = session
.getNamedQuery("node.patch.GetAssocsAndChildNames")
.setLong("lastAssocId", lastAssocId)
.setParameter("assocTypeQName", assocTypeQName)
.setMaxResults(MAX_RESULTS);
return query.list();
}
};
List<Object[]> results = (List<Object[]>) getHibernateTemplate().execute(callback);
return results;
}
}
}