Fixed AWC-487: Added patch to grant required permissions to 'Saved Searches' folder

Fixed I18N of SavedSearchFolderPatch
Neatened up patch logging


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2276 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2006-02-01 15:36:03 +00:00
parent 2bdace676d
commit 9be5d15ad1
6 changed files with 219 additions and 49 deletions

View File

@@ -1,14 +1,20 @@
# PatchService messages # PatchService messages
patch.service.not_relevant=Not relevant to schema {0} patch.service.not_relevant=Not relevant to schema {0}
patch.executer.not_executed=Applied patch (not executed): \nID: {0}\nRESULT: \n{1} patch.executer.checking=Checking for patches to apply ...
patch.executer.executed=Applied patch: \nID: {0}\nRESULT: \n{1} patch.executer.no_patches_required=No patches were required.
patch.executer.failed=Failed to apply patch: \nID: {0}\nRESULT: \n{1} patch.executer.not_executed =\n=== Recorded patch (not executed) === \nID: {0}\nRESULT: \n{1}\n=====================================
patch.executer.executed =\n=== Applied patch === \nID: {0}\nRESULT: \n{1}\n=====================================
patch.executer.failed =\n=== Failed to apply patch === \nID: {0}\nRESULT: \n{1}\n=====================================
# Individual patch messages # Individual patch messages
patch.savedSearchesFolder.description=Ensures the existence of the 'Saved Searches' folder. patch.savedSearchesFolder.description=Ensures the existence of the 'Saved Searches' folder.
patch.savedSearchesFolder.result.exists=The saved searches folder already exists: {0} patch.savedSearchesFolder.result.exists=The saved searches folder already exists: {0}
patch.savedSearchesFolder.result.created=The saved searches folder successfully created: {0} patch.savedSearchesFolder.result.created=The saved searches folder was successfully created: {0}
patch.savedSearchesPermission.description=Sets required permissions on 'Saved Searches' folder.
patch.savedSearchesPermission.result.applied=Granted CONTRIBUTOR role to EVERYONE on 'Saved Searches' folder: {0}.
patch.savedSearchesPermission.err.not_found='Saved Searches' folder could not be found.
patch.updatePermissionData.description=Update permission entries from 'folder' to 'cmobject'. patch.updatePermissionData.description=Update permission entries from 'folder' to 'cmobject'.
patch.updatePermissionData.result=Created the following permission reference names: {0}. \nUpdated {1} permission entries. patch.updatePermissionData.result=Created the following permission reference names: {0}. \nUpdated {1} permission entries.

View File

@@ -72,14 +72,12 @@
</list> </list>
</property> </property>
</bean> </bean>
<!-- -->
<!-- Helper beans -->
<!-- -->
<!-- patch definitions --> <bean id="patch.savedSearches.Base" abstract="true" parent="basePatch" >
<bean id="patch.savedSearchesFolder" class="org.alfresco.repo.admin.patch.impl.SavedSearchFolderPatch" parent="basePatch" >
<property name="id"><value>patch.savedSearchesFolder</value></property>
<property name="description"><value>patch.savedSearchesFolder.description</value></property>
<property name="fixesFromSchema"><value>0</value></property>
<property name="fixesToSchema"><value>1</value></property>
<property name="targetSchema"><value>2</value></property>
<!-- helper beans for execution --> <!-- helper beans for execution -->
<property name="importerBootstrap"> <property name="importerBootstrap">
<ref bean="importerBootstrap" /> <ref bean="importerBootstrap" />
@@ -95,6 +93,46 @@
</property> </property>
</bean> </bean>
<bean id="bootstrapSpacesMessageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>alfresco/messages/bootstrap-spaces</value>
</list>
</property>
</bean>
<!-- -->
<!-- Patch definitions -->
<!-- -->
<bean id="patch.savedSearchesFolder" class="org.alfresco.repo.admin.patch.impl.SavedSearchFolderPatch" parent="patch.savedSearches.Base" >
<property name="id"><value>patch.savedSearchesFolder</value></property>
<property name="description"><value>patch.savedSearchesFolder.description</value></property>
<property name="fixesFromSchema"><value>0</value></property>
<property name="fixesToSchema"><value>1</value></property>
<property name="targetSchema"><value>2</value></property>
<!-- helper beans for execution -->
<property name="messageSource">
<ref bean="bootstrapSpacesMessageSource" />
</property>
</bean>
<bean id="patch.savedSearchesPermission" class="org.alfresco.repo.admin.patch.impl.SavedSearchPermissionPatch" parent="patch.savedSearches.Base" >
<property name="id"><value>patch.savedSearchesPermission</value></property>
<property name="description"><value>patch.savedSearchesPermission.description</value></property>
<property name="fixesFromSchema"><value>0</value></property>
<property name="fixesToSchema"><value>4</value></property>
<property name="targetSchema"><value>5</value></property>
<!-- helper beans for execution -->
<property name="permissionService">
<ref bean="permissionService"/>
</property>
<!-- dependent on presence of saved searches folder -->
<property name="dependsOn" >
<list>
<ref bean="patch.savedSearchesFolder" />
</list>
</property>
</bean>
<bean id="patch.updatePermissionData" class="org.alfresco.repo.admin.patch.impl.PermissionDataPatch" parent="basePatch" > <bean id="patch.updatePermissionData" class="org.alfresco.repo.admin.patch.impl.PermissionDataPatch" parent="basePatch" >
<property name="id"><value>patch.updatePermissionData</value></property> <property name="id"><value>patch.updatePermissionData</value></property>
<property name="description"><value>patch.updatePermissionData.description</value></property> <property name="description"><value>patch.updatePermissionData.description</value></property>
@@ -132,7 +170,7 @@
<ref bean="namespaceService" /> <ref bean="namespaceService" />
</property> </property>
<property name="messageSource"> <property name="messageSource">
<ref bean="guestMessageSource" /> <ref bean="bootstrapSpacesMessageSource" />
</property> </property>
</bean> </bean>
<bean id="patch.fixNodeSerializableValues" class="org.alfresco.repo.admin.patch.impl.NodePropertySerializablePatch" parent="basePatch" > <bean id="patch.fixNodeSerializableValues" class="org.alfresco.repo.admin.patch.impl.NodePropertySerializablePatch" parent="basePatch" >
@@ -147,14 +185,6 @@
</property> </property>
</bean> </bean>
<bean id="guestMessageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>alfresco/messages/bootstrap-spaces</value>
</list>
</property>
</bean>
<!-- This component ensures that patches get applied on startup --> <!-- This component ensures that patches get applied on startup -->
<!-- The order is important here. All the self-registering patches must be defined before this bean --> <!-- The order is important here. All the self-registering patches must be defined before this bean -->
<bean id="patchExecuter" <bean id="patchExecuter"

View File

@@ -32,6 +32,8 @@ import org.apache.commons.logging.LogFactory;
*/ */
public class PatchExecuter public class PatchExecuter
{ {
private static final String MSG_CHECKING = "patch.executer.checking";
private static final String MSG_NO_PATCHES_REQUIRED = "patch.executer.no_patches_required";
private static final String MSG_NOT_EXECUTED = "patch.executer.not_executed"; private static final String MSG_NOT_EXECUTED = "patch.executer.not_executed";
private static final String MSG_EXECUTED = "patch.executer.executed"; private static final String MSG_EXECUTED = "patch.executer.executed";
private static final String MSG_FAILED = "patch.executer.failed"; private static final String MSG_FAILED = "patch.executer.failed";
@@ -53,6 +55,8 @@ public class PatchExecuter
*/ */
public void applyOutstandingPatches() public void applyOutstandingPatches()
{ {
logger.info(I18NUtil.getMessage(MSG_CHECKING));
Date before = new Date(System.currentTimeMillis() - 20000L); // 20 seconds ago Date before = new Date(System.currentTimeMillis() - 20000L); // 20 seconds ago
patchService.applyOutstandingPatches(); patchService.applyOutstandingPatches();
Date after = new Date(System .currentTimeMillis() + 20000L); // 20 seconds ahead Date after = new Date(System .currentTimeMillis() + 20000L); // 20 seconds ahead
@@ -63,10 +67,7 @@ public class PatchExecuter
// don't report anything if nothing was done // don't report anything if nothing was done
if (appliedPatches.size() == 0) if (appliedPatches.size() == 0)
{ {
if (logger.isDebugEnabled()) logger.info(I18NUtil.getMessage(MSG_NO_PATCHES_REQUIRED));
{
logger.debug("No patches applied");
}
} }
else else
{ {

View File

@@ -36,7 +36,6 @@ import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.NamespaceService;
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.context.support.ResourceBundleMessageSource;
/** /**
* Ensures that the <b>guest</b> user homespace exists.<br/> A guest user homespace is now created during bootstrap. It is required for guest user access, but in older databases * Ensures that the <b>guest</b> user homespace exists.<br/> A guest user homespace is now created during bootstrap. It is required for guest user access, but in older databases

View File

@@ -34,6 +34,7 @@ import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.SearchService; import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.springframework.context.MessageSource;
/** /**
* Ensures that the <b>savedsearches</b> folder is present. * Ensures that the <b>savedsearches</b> folder is present.
@@ -53,9 +54,9 @@ public class SavedSearchFolderPatch extends AbstractPatch
private static final String MSG_EXISTS = "patch.savedSearchesFolder.result.exists"; private static final String MSG_EXISTS = "patch.savedSearchesFolder.result.exists";
private static final String MSG_CREATED = "patch.savedSearchesFolder.result.created"; private static final String MSG_CREATED = "patch.savedSearchesFolder.result.created";
private static final String PROPERTY_COMPANY_HOME_CHILDNAME = "spaces.company_home.childname"; public 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_DICTIONARY_CHILDNAME = "spaces.dictionary.childname";
private static final String PROPERTY_SAVED_SEARCHES_FOLDER_CHILDNAME = "spaces.savedsearches.childname"; public static final String PROPERTY_SAVED_SEARCHES_FOLDER_CHILDNAME = "spaces.savedsearches.childname";
private static final String PROPERTY_SAVED_SEARCHES_FOLDER_NAME = "spaces.savedsearches.name"; private static final String PROPERTY_SAVED_SEARCHES_FOLDER_NAME = "spaces.savedsearches.name";
private static final String PROPERTY_SAVED_SEARCHES_FOLDER_DESCRIPTION = "spaces.savedsearches.description"; private static final String PROPERTY_SAVED_SEARCHES_FOLDER_DESCRIPTION = "spaces.savedsearches.description";
private static final String PROPERTY_ICON = "space-icon-default"; private static final String PROPERTY_ICON = "space-icon-default";
@@ -64,6 +65,11 @@ public class SavedSearchFolderPatch extends AbstractPatch
private NamespaceService namespaceService; private NamespaceService namespaceService;
private SearchService searchService; private SearchService searchService;
private NodeService nodeService; private NodeService nodeService;
private MessageSource messageSource;
protected NodeRef dictionaryNodeRef;
protected Properties configuration;
protected NodeRef savedSearchesFolderNodeRef;
public void setImporterBootstrap(ImporterBootstrap importerBootstrap) public void setImporterBootstrap(ImporterBootstrap importerBootstrap)
{ {
@@ -85,8 +91,15 @@ public class SavedSearchFolderPatch extends AbstractPatch
this.nodeService = nodeService; this.nodeService = nodeService;
} }
@Override public void setMessageSource(MessageSource messageSource)
protected String applyInternal() throws Exception {
this.messageSource = messageSource;
}
/**
* Ensure that required common properties have been set
*/
protected void checkCommonProperties() throws Exception
{ {
if (importerBootstrap == null) if (importerBootstrap == null)
{ {
@@ -104,7 +117,14 @@ public class SavedSearchFolderPatch extends AbstractPatch
{ {
throw new PatchException("'nodeService' property has not been set"); 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 // get the node store that we must work against
StoreRef storeRef = importerBootstrap.getStoreRef(); StoreRef storeRef = importerBootstrap.getStoreRef();
if (storeRef == null) if (storeRef == null)
@@ -113,7 +133,7 @@ public class SavedSearchFolderPatch extends AbstractPatch
} }
NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef); NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef);
Properties configuration = importerBootstrap.getConfiguration(); this.configuration = importerBootstrap.getConfiguration();
// get the association names that form the path // get the association names that form the path
String companyHomeChildName = configuration.getProperty(PROPERTY_COMPANY_HOME_CHILDNAME); String companyHomeChildName = configuration.getProperty(PROPERTY_COMPANY_HOME_CHILDNAME);
if (companyHomeChildName == null || companyHomeChildName.length() == 0) if (companyHomeChildName == null || companyHomeChildName.length() == 0)
@@ -151,7 +171,7 @@ public class SavedSearchFolderPatch extends AbstractPatch
" xpath: " + xpath + "\n" + " xpath: " + xpath + "\n" +
" results: " + nodeRefs); " results: " + nodeRefs);
} }
NodeRef dictionaryNodeRef = nodeRefs.get(0); this.dictionaryNodeRef = nodeRefs.get(0);
// Now we have the optional part. Check for the existence of the saved searches folder // Now we have the optional part. Check for the existence of the saved searches folder
xpath = savedSearchesChildName; xpath = savedSearchesChildName;
@@ -163,34 +183,74 @@ public class SavedSearchFolderPatch extends AbstractPatch
" xpath: " + xpath + "\n" + " xpath: " + xpath + "\n" +
" results: " + nodeRefs); " results: " + nodeRefs);
} }
String msg = null; else if (nodeRefs.size() == 0)
if (nodeRefs.size() == 1)
{ {
// it already exists // the node does not exist
msg = I18NUtil.getMessage(MSG_EXISTS, nodeRefs.get(0)); this.savedSearchesFolderNodeRef = null;
} }
else else
{
// we have the saved searches folder noderef
this.savedSearchesFolderNodeRef = 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 (savedSearchesFolderNodeRef == null)
{ {
// create it // create it
NodeRef savedSearchesFolderNodeRef = createFolder(dictionaryNodeRef, configuration); createFolder();
msg = I18NUtil.getMessage(MSG_CREATED, savedSearchesFolderNodeRef); msg = I18NUtil.getMessage(MSG_CREATED, savedSearchesFolderNodeRef);
} }
else
{
// it already exists
msg = I18NUtil.getMessage(MSG_EXISTS, savedSearchesFolderNodeRef);
}
// done // done
return msg; return msg;
} }
private NodeRef createFolder(NodeRef dictionaryNodeRef, Properties configuration) private void createFolder()
{ {
// get required properties // get required properties
String savedSearchesChildName = configuration.getProperty( String savedSearchesChildName = configuration.getProperty(PROPERTY_SAVED_SEARCHES_FOLDER_CHILDNAME);
PROPERTY_SAVED_SEARCHES_FOLDER_CHILDNAME, if (savedSearchesChildName == null)
"app:saved_searches"); {
String savedSearchesName = configuration.getProperty( throw new PatchException("Bootstrap property '" + PROPERTY_SAVED_SEARCHES_FOLDER_CHILDNAME + "' is not present");
}
String savedSearchesName = messageSource.getMessage(
PROPERTY_SAVED_SEARCHES_FOLDER_NAME, PROPERTY_SAVED_SEARCHES_FOLDER_NAME,
"Saved Searches"); null,
String savedSearchesDescription = configuration.getProperty( I18NUtil.getLocale());
if (savedSearchesName == null || savedSearchesName.length() == 0)
{
throw new PatchException("Bootstrap property '" + PROPERTY_SAVED_SEARCHES_FOLDER_NAME + "' is not present");
}
String savedSearchesDescription = messageSource.getMessage(
PROPERTY_SAVED_SEARCHES_FOLDER_DESCRIPTION, PROPERTY_SAVED_SEARCHES_FOLDER_DESCRIPTION,
"Saved searches"); null,
I18NUtil.getLocale());
if (savedSearchesDescription == null || savedSearchesDescription.length() == 0)
{
throw new PatchException("Bootstrap property '" + PROPERTY_SAVED_SEARCHES_FOLDER_DESCRIPTION + "' is not present");
}
Map<QName, Serializable> properties = new HashMap<QName, Serializable>(7); Map<QName, Serializable> properties = new HashMap<QName, Serializable>(7);
properties.put(ContentModel.PROP_NAME, savedSearchesName); properties.put(ContentModel.PROP_NAME, savedSearchesName);
properties.put(ContentModel.PROP_TITLE, savedSearchesName); properties.put(ContentModel.PROP_TITLE, savedSearchesName);
@@ -203,11 +263,10 @@ public class SavedSearchFolderPatch extends AbstractPatch
QName.resolveToQName(namespaceService, savedSearchesChildName), QName.resolveToQName(namespaceService, savedSearchesChildName),
ContentModel.TYPE_FOLDER, ContentModel.TYPE_FOLDER,
properties); properties);
NodeRef nodeRef = childAssocRef.getChildRef(); savedSearchesFolderNodeRef = childAssocRef.getChildRef();
// add the required aspects // add the required aspects
nodeService.addAspect(nodeRef, ContentModel.ASPECT_UIFACETS, null); nodeService.addAspect(savedSearchesFolderNodeRef, ContentModel.ASPECT_UIFACETS, null);
// done // done
return nodeRef;
} }
} }

View File

@@ -0,0 +1,75 @@
/*
* 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.service.cmr.admin.PatchException;
import org.alfresco.service.cmr.security.PermissionService;
/**
* Grant <b>CONTRIBUTOR</b> role to <b>EVERYONE</b> in <b>savedsearches</b> folder.
* <p>
* This patch expects the folder to be present.
* <p>
* JIRA: {@link http://www.alfresco.org/jira/browse/AWC-487 AR-487}
*
* @see org.alfresco.repo.admin.patch.impl.SavedSearchFolderPatch
* @author Derek Hulley
*/
public class SavedSearchPermissionPatch extends SavedSearchFolderPatch
{
private static final String MSG_CREATED = "patch.savedSearchesPermission.result.applied";
private static final String ERR_NOT_FOUND = "patch.savedSearchesPermission.err.not_found";
private PermissionService permissionService;
public void setPermissionService(PermissionService permissionService)
{
this.permissionService = permissionService;
}
@Override
protected String applyInternal() throws Exception
{
// properties must be set
checkCommonProperties();
if (permissionService == null)
{
throw new PatchException("'permissionService' property has not been set");
}
// get useful values
setUp();
if (savedSearchesFolderNodeRef == null)
{
// it doesn't exist
String msg = I18NUtil.getMessage(ERR_NOT_FOUND);
throw new PatchException(msg);
}
// apply permission
permissionService.setPermission(
savedSearchesFolderNodeRef,
PermissionService.ALL_AUTHORITIES,
PermissionService.CONTRIBUTOR,
true);
String msg = I18NUtil.getMessage(MSG_CREATED, savedSearchesFolderNodeRef);
// done
return msg;
}
}