Merge RM-3227 from V2.3 to V2.4

This commit is contained in:
Roy Wetherall
2016-06-29 10:15:13 +10:00
9 changed files with 450 additions and 185 deletions

View File

@@ -195,7 +195,6 @@
<!-- init caveatConfig behaviours --> <!-- init caveatConfig behaviours -->
<property name="caveatConfigService" ref="caveatConfigService"/> <property name="caveatConfigService" ref="caveatConfigService"/>
<property name="customEmailMappingService" ref="customEmailMappingService"/> <property name="customEmailMappingService" ref="customEmailMappingService"/>
<property name="recordsManagementAdminService" ref="RecordsManagementAdminService"/>
<property name="suggesterBootstrap" ref="nodeParameterSuggesterBootstrap"/> <property name="suggesterBootstrap" ref="nodeParameterSuggesterBootstrap"/>
</bean> </bean>

View File

@@ -775,6 +775,7 @@
<bean id="recordsManagementAdminService" class="org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminServiceImpl" parent="recordsManagementAdminBase"> <bean id="recordsManagementAdminService" class="org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminServiceImpl" parent="recordsManagementAdminBase">
<property name="relationshipService" ref="RelationshipService" /> <property name="relationshipService" ref="RelationshipService" />
<property name="transactionService" ref="transactionService"/>
<property name="customisableTypes"> <property name="customisableTypes">
<list> <list>
<value>rma:recordCategory</value> <value>rma:recordCategory</value>
@@ -817,7 +818,6 @@
<property name="objectDefinitionSource"> <property name="objectDefinitionSource">
<value> <value>
<![CDATA[ <![CDATA[
org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService.initialiseCustomModel=RM_ALLOW
org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService.getCustomisable=RM_ALLOW org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService.getCustomisable=RM_ALLOW
org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService.isCustomisable=RM_ALLOW org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService.isCustomisable=RM_ALLOW
org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService.makeCustomisable=RM_ALLOW org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService.makeCustomisable=RM_ALLOW

View File

@@ -54,11 +54,6 @@ import org.alfresco.service.namespace.RegexQNamePattern;
*/ */
public interface RecordsManagementAdminService public interface RecordsManagementAdminService
{ {
/**
* Initialise the custom model
*/
void initialiseCustomModel();
/** /**
* Get a list of all registered customisable types and aspects. * Get a list of all registered customisable types and aspects.
* *

View File

@@ -24,7 +24,6 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.module.org_alfresco_module_rm.admin; package org.alfresco.module.org_alfresco_module_rm.admin;
import static org.springframework.extensions.surf.util.ParameterCheck.mandatory; import static org.springframework.extensions.surf.util.ParameterCheck.mandatory;
@@ -61,6 +60,7 @@ import org.alfresco.repo.policy.annotation.BehaviourBean;
import org.alfresco.repo.policy.annotation.BehaviourKind; import org.alfresco.repo.policy.annotation.BehaviourKind;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.cmr.dictionary.AspectDefinition; import org.alfresco.service.cmr.dictionary.AspectDefinition;
import org.alfresco.service.cmr.dictionary.AssociationDefinition; import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.Constraint; import org.alfresco.service.cmr.dictionary.Constraint;
@@ -73,7 +73,11 @@ 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.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern; import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.GUID; import org.alfresco.util.GUID;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.core.Ordered;
import org.springframework.extensions.surf.util.I18NUtil; import org.springframework.extensions.surf.util.I18NUtil;
import org.springframework.extensions.surf.util.URLDecoder; import org.springframework.extensions.surf.util.URLDecoder;
@@ -83,10 +87,14 @@ import org.springframework.extensions.surf.util.URLDecoder;
* @author Neil McErlean, janv * @author Neil McErlean, janv
*/ */
@BehaviourBean @BehaviourBean
public class RecordsManagementAdminServiceImpl extends RecordsManagementAdminBase implements RecordsManagementAdminService, public class RecordsManagementAdminServiceImpl extends RecordsManagementAdminBase
implements RecordsManagementAdminService,
RecordsManagementCustomModel,
NodeServicePolicies.OnAddAspectPolicy, NodeServicePolicies.OnAddAspectPolicy,
NodeServicePolicies.OnRemoveAspectPolicy, NodeServicePolicies.OnRemoveAspectPolicy,
NodeServicePolicies.OnCreateNodePolicy NodeServicePolicies.OnCreateNodePolicy,
ApplicationListener<ContextRefreshedEvent>,
Ordered
{ {
/** I18N messages*/ /** I18N messages*/
private static final String MSG_SERVICE_NOT_INIT = "rm.admin.service-not-init"; private static final String MSG_SERVICE_NOT_INIT = "rm.admin.service-not-init";
@@ -108,13 +116,25 @@ public class RecordsManagementAdminServiceImpl extends RecordsManagementAdminBas
/** Relationship service */ /** Relationship service */
private RelationshipService relationshipService; private RelationshipService relationshipService;
/** Transaction service */
private TransactionService transactionService;
/** List of types that can be customisable */ /** List of types that can be customisable */
private List<QName> pendingCustomisableTypes; private List<QName> pendingCustomisableTypes;
private Map<QName, QName> customisableTypes; private Map<QName, QName> customisableTypes;
/** indicates whether the custom map has been initialised or not */
private boolean isCustomMapInit = false;
/**
* @param transactionService transaction service
*/
public void setTransactionService(TransactionService transactionService)
{
this.transactionService = transactionService;
}
/** /**
* Sets the relationship instance
*
* @param relationshipService The relationship service instance * @param relationshipService The relationship service instance
*/ */
public void setRelationshipService(RelationshipService relationshipService) public void setRelationshipService(RelationshipService relationshipService)
@@ -132,6 +152,48 @@ public class RecordsManagementAdminServiceImpl extends RecordsManagementAdminBas
return this.relationshipService; return this.relationshipService;
} }
/**
* Indicate that this application content listener must be executed with the lowest
* precedence. (ie last)
*
* @see Ordered#getOrder()
*/
@Override
public int getOrder()
{
return Ordered.LOWEST_PRECEDENCE;
}
/**
* Load the custom properties map
*
* @see ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
*/
@Override
public void onApplicationEvent(ContextRefreshedEvent event)
{
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
// initialise custom properties
initCustomMap();
return null;
}
});
}
/**
* Helper method to indicate whether the custom map is initialised or not.
*
* @return boolean true if initialised, false otherwise
*/
public boolean isCustomMapInit()
{
return isCustomMapInit;
}
/** /**
* @see org.alfresco.repo.node.NodeServicePolicies.OnAddAspectPolicy#onAddAspect(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName) * @see org.alfresco.repo.node.NodeServicePolicies.OnAddAspectPolicy#onAddAspect(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
*/ */
@@ -144,9 +206,8 @@ public class RecordsManagementAdminServiceImpl extends RecordsManagementAdminBas
) )
public void onAddAspect(final NodeRef nodeRef, final QName aspectTypeQName) public void onAddAspect(final NodeRef nodeRef, final QName aspectTypeQName)
{ {
mandatory("nodeRef", nodeRef); if (isCustomMapInit)
mandatory("aspectTypeQName", aspectTypeQName); {
AuthenticationUtil.runAs(new RunAsWork<Void>() AuthenticationUtil.runAs(new RunAsWork<Void>()
{ {
@Override @Override
@@ -164,6 +225,7 @@ public class RecordsManagementAdminServiceImpl extends RecordsManagementAdminBas
} }
}, AuthenticationUtil.getSystemUserName()); }, AuthenticationUtil.getSystemUserName());
} }
}
/** /**
* @see org.alfresco.repo.node.NodeServicePolicies.OnRemoveAspectPolicy#onRemoveAspect(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName) * @see org.alfresco.repo.node.NodeServicePolicies.OnRemoveAspectPolicy#onRemoveAspect(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
@@ -177,9 +239,8 @@ public class RecordsManagementAdminServiceImpl extends RecordsManagementAdminBas
) )
public void onRemoveAspect(final NodeRef nodeRef, final QName aspectTypeQName) public void onRemoveAspect(final NodeRef nodeRef, final QName aspectTypeQName)
{ {
mandatory("nodeRef", nodeRef); if (isCustomMapInit)
mandatory("aspectTypeQName", aspectTypeQName); {
AuthenticationUtil.runAs(new RunAsWork<Void>() AuthenticationUtil.runAs(new RunAsWork<Void>()
{ {
@Override @Override
@@ -196,6 +257,7 @@ public class RecordsManagementAdminServiceImpl extends RecordsManagementAdminBas
} }
}, AuthenticationUtil.getSystemUserName()); }, AuthenticationUtil.getSystemUserName());
} }
}
/** /**
* Make sure any custom property aspects are applied to newly created nodes. * Make sure any custom property aspects are applied to newly created nodes.
@@ -211,8 +273,8 @@ public class RecordsManagementAdminServiceImpl extends RecordsManagementAdminBas
) )
public void onCreateNode(final ChildAssociationRef childAssocRef) public void onCreateNode(final ChildAssociationRef childAssocRef)
{ {
mandatory("nodeRef", childAssocRef); if (isCustomMapInit)
{
AuthenticationUtil.runAs(new RunAsWork<Void>() AuthenticationUtil.runAs(new RunAsWork<Void>()
{ {
@Override @Override
@@ -246,14 +308,6 @@ public class RecordsManagementAdminServiceImpl extends RecordsManagementAdminBas
} }
}, AuthenticationUtil.getSystemUserName()); }, AuthenticationUtil.getSystemUserName());
} }
/**
* @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#initialiseCustomModel()
*/
public void initialiseCustomModel()
{
// Initialise the map
getCustomisableMap();
} }
/** /**
@@ -340,13 +394,9 @@ public class RecordsManagementAdminServiceImpl extends RecordsManagementAdminBas
} }
/** /**
* Gets a map containing all the customisable types * Initialise custom type map
*
* @return map from the customisable type to its custom aspect
*/ */
private Map<QName, QName> getCustomisableMap() private void initCustomMap()
{
if (customisableTypes == null)
{ {
customisableTypes = new HashMap<QName, QName>(7); customisableTypes = new HashMap<QName, QName>(7);
Collection<QName> aspects = getDictionaryService().getAspects(RM_CUSTOM_MODEL); Collection<QName> aspects = getDictionaryService().getAspects(RM_CUSTOM_MODEL);
@@ -424,6 +474,21 @@ public class RecordsManagementAdminServiceImpl extends RecordsManagementAdminBas
writeCustomContentModel(modelRef, model); writeCustomContentModel(modelRef, model);
} }
} }
// indicate map is initialised
isCustomMapInit = true;
}
/**
* Gets a map containing all the customisable types
*
* @return map from the customisable type to its custom aspect
*/
private Map<QName, QName> getCustomisableMap()
{
if (customisableTypes == null)
{
throw AlfrescoRuntimeException.create("Customisable map has not been initialised correctly.");
} }
return customisableTypes; return customisableTypes;
} }

View File

@@ -28,7 +28,6 @@
package org.alfresco.module.org_alfresco_module_rm.bootstrap; package org.alfresco.module.org_alfresco_module_rm.bootstrap;
import org.alfresco.module.org_alfresco_module_rm.action.impl.SplitEmailAction; import org.alfresco.module.org_alfresco_module_rm.action.impl.SplitEmailAction;
import org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService;
import org.alfresco.module.org_alfresco_module_rm.caveat.RMCaveatConfigService; import org.alfresco.module.org_alfresco_module_rm.caveat.RMCaveatConfigService;
import org.alfresco.module.org_alfresco_module_rm.email.CustomEmailMappingService; import org.alfresco.module.org_alfresco_module_rm.email.CustomEmailMappingService;
import org.alfresco.repo.action.parameter.NodeParameterSuggesterBootstrap; import org.alfresco.repo.action.parameter.NodeParameterSuggesterBootstrap;
@@ -50,7 +49,6 @@ public class RecordsManagementBootstrap extends AbstractLifecycleBean
private TransactionService transactionService; private TransactionService transactionService;
private RMCaveatConfigService caveatConfigService; private RMCaveatConfigService caveatConfigService;
private CustomEmailMappingService customEmailMappingService; private CustomEmailMappingService customEmailMappingService;
private RecordsManagementAdminService adminService;
private NodeParameterSuggesterBootstrap suggesterBootstrap; private NodeParameterSuggesterBootstrap suggesterBootstrap;
public NodeParameterSuggesterBootstrap getSuggesterBootstrap() public NodeParameterSuggesterBootstrap getSuggesterBootstrap()
@@ -78,11 +76,6 @@ public class RecordsManagementBootstrap extends AbstractLifecycleBean
this.customEmailMappingService = customEmailMappingService; this.customEmailMappingService = customEmailMappingService;
} }
public void setRecordsManagementAdminService(RecordsManagementAdminService adminService)
{
this.adminService = adminService;
}
public CustomEmailMappingService getCustomEmailMappingService() public CustomEmailMappingService getCustomEmailMappingService()
{ {
return customEmailMappingService; return customEmailMappingService;
@@ -103,9 +96,6 @@ public class RecordsManagementBootstrap extends AbstractLifecycleBean
// initialise caveat config // initialise caveat config
caveatConfigService.init(); caveatConfigService.init();
// Initialise the custom model
adminService.initialiseCustomModel();
// Initialize the suggester after the model // Initialize the suggester after the model
// in case it contains namespaces from custom models // in case it contains namespaces from custom models
suggesterBootstrap.init(); suggesterBootstrap.init();

View File

@@ -0,0 +1,61 @@
/*
* Copyright (C) 2005-2016 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.module.org_alfresco_module_rm.test.integration.issue.rm3314;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
/**
* Test for https://issues.alfresco.com/jira/browse/RM-3114
*
* @author Roy Wetherall
* @since 2.2.1.5
*/
public class RM3314Test extends BaseRMTestCase
{
/** registry to record callback from test beans "test.rm3114.1" and "test.rm3114.2" */
public static Map<String, Boolean> callback = new HashMap<String, Boolean>(2);
/**
* Given that the custom model hasn't been initialised
* When an aspect is added
* Then nothing happens
*
* Given that the custom model has been initialised
* When an aspect is added
* Then something happens
*/
public void testListenersExecutedInTheCorrectOrder()
{
/**
* The related test beans will call back into the callback map showing
* whether at the end of their execution whether the custom model has been
* initialised or not. Given the order in which these test beans are executed
* on spring context load, we would expect that .1 executes with the custom
* map unloaded, and the .2 with it loaded.
*/
assertFalse(callback.isEmpty());
assertFalse(callback.get("test.rm3314.1"));
assertTrue(callback.get("test.rm3314.2"));
}
}

View File

@@ -0,0 +1,134 @@
/*
* Copyright (C) 2005-2014 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.module.org_alfresco_module_rm.test.integration.issue.rm3314;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminServiceImpl;
import org.alfresco.repo.model.Repository;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.core.Ordered;
import org.springframework.jdbc.BadSqlGrammarException;
/**
* Simple bean used to test RM-3314
*
* @author rwetherall
* @since 2.2.1.5
*/
public class RM3314TestListener implements ApplicationListener<ContextRefreshedEvent>,
Ordered,
BeanNameAware
{
private RecordsManagementAdminServiceImpl recordsManagementAdminService;
private NodeService nodeService;
private FileFolderService fileFolderService;
private Repository repository;
private String name;
private int order = Ordered.LOWEST_PRECEDENCE;
public void setRecordsManagementAdminService(RecordsManagementAdminServiceImpl recordsManagementAdminService)
{
this.recordsManagementAdminService = recordsManagementAdminService;
}
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void setFileFolderService(FileFolderService fileFolderService)
{
this.fileFolderService = fileFolderService;
}
public void setRepository(Repository repository)
{
this.repository = repository;
}
@Override
public void setBeanName(String name)
{
this.name = name;
}
public void setOrder(int order)
{
this.order = order;
}
@Override
public void onApplicationEvent(ContextRefreshedEvent event)
{
// call back to show whether the custom map is initialised or not
RM3314Test.callback.put(name, recordsManagementAdminService.isCustomMapInit());
// Do some work on a node to show that reguardless of whether the custom map is
// init or not, things still work.
// Note: using public services to ensure new transaction for each service call
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
{
public Void doWork() throws Exception
{
try
{
// create node
NodeRef folder = fileFolderService.create(
repository.getCompanyHome(),
name,
ContentModel.TYPE_FOLDER).getNodeRef();
try
{
// add aspect
nodeService.addAspect(folder, ContentModel.ASPECT_CLASSIFIABLE, null);
// remove aspect
nodeService.removeAspect(folder, ContentModel.ASPECT_CLASSIFIABLE);
}
finally
{
// delete node
nodeService.deleteNode(folder);
}
}
catch (BadSqlGrammarException e)
{
// ignore and carry on
}
return null;
}
});
}
@Override
public int getOrder()
{
return order;
}
}

View File

@@ -246,4 +246,25 @@
<bean id="contentCleanser.test" class="org.alfresco.module.org_alfresco_module_rm.test.util.TestContentCleanser"/> <bean id="contentCleanser.test" class="org.alfresco.module.org_alfresco_module_rm.test.util.TestContentCleanser"/>
<!-- Test listeners -->
<!-- Executed with '0' order. This is default order and as such the application event will be executed relative to the other
beans in the order in which they appear in the spring context -->
<bean id="test.rm3314.1" class="org.alfresco.module.org_alfresco_module_rm.test.integration.issue.rm3314.RM3314TestListener">
<property name="order" value="0"/>
<property name="recordsManagementAdminService" ref="recordsManagementAdminService"/>
<property name="nodeService" ref="NodeService"/>
<property name="fileFolderService" ref="FileFolderService" />
<property name="repository" ref="repositoryHelper" />
</bean>
<!-- The default order has this bean executing its application event with the lowest precendence, ie after all the other
beans set to '0' precendence by default -->
<bean id="test.rm3314.2" class="org.alfresco.module.org_alfresco_module_rm.test.integration.issue.rm3314.RM3314TestListener">
<property name="recordsManagementAdminService" ref="recordsManagementAdminService"/>
<property name="nodeService" ref="NodeService"/>
<property name="fileFolderService" ref="FileFolderService" />
<property name="repository" ref="repositoryHelper" />
</bean>
</beans> </beans>