RM-902: 13 workflows are started if move record when outbound rule to Request info is set

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@54957 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Roy Wetherall
2013-09-05 05:19:49 +00:00
parent 4b5dd96449
commit 3921147ec3
3 changed files with 185 additions and 49 deletions

View File

@@ -268,5 +268,11 @@
<value>${spaces.store}</value>
</property>
</bean>
<bean id="on-delete-child-association-trigger" class="org.alfresco.repo.rule.ruletrigger.ExtendedBeforeDeleteChildAssociationRuleTrigger" parent="rule-trigger-base">
<property name="executeRuleImmediately">
<value>true</value>
</property>
</bean>
</beans>

View File

@@ -48,6 +48,7 @@ import org.alfresco.module.org_alfresco_module_rm.role.Role;
import org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService;
import org.alfresco.module.org_alfresco_module_rm.vital.VitalRecordServiceImpl;
import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.policy.BehaviourFilter;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
@@ -180,6 +181,10 @@ public class RecordServiceImpl implements RecordService,
/** File folder service */
private FileFolderService fileFolderService;
/** Behaviour filter */
@SuppressWarnings("unused")
private BehaviourFilter behaviourFilter;
/** List of available record meta-data aspects */
private Set<QName> recordMetaDataAspects;
@@ -311,6 +316,14 @@ public class RecordServiceImpl implements RecordService,
{
this.fileFolderService = fileFolderService;
}
/**
* @param behaviourFilter behaviour filter
*/
public void setBehaviourFilter(BehaviourFilter behaviourFilter)
{
this.behaviourFilter = behaviourFilter;
}
/**
* Init method
@@ -522,61 +535,70 @@ public class RecordServiceImpl implements RecordService,
@Override
public Void doWork() throws Exception
{
// get the new record container for the file plan
NodeRef newRecordContainer = filePlanService.getUnfiledContainer(filePlan);
if (newRecordContainer == null)
// disable delete rules
ruleService.disableRuleType("outbound");
try
{
throw new AlfrescoRuntimeException("Unable to create record, because new record container could not be found.");
}
// get the documents readers
Long aclId = nodeService.getNodeAclId(nodeRef);
Set<String> readers = permissionService.getReaders(aclId);
Set<String> writers = permissionService.getWriters(aclId);
// add the current owner to the list of extended writers
String owner = ownableService.getOwner(nodeRef);
// remove the owner
ownableService.setOwner(nodeRef, OwnableService.NO_OWNER);
// get the documents primary parent assoc
ChildAssociationRef parentAssoc = nodeService.getPrimaryParent(nodeRef);
// move the document into the file plan
nodeService.moveNode(nodeRef, newRecordContainer, ContentModel.ASSOC_CONTAINS, parentAssoc.getQName());
// save the information about the originating details
Map<QName, Serializable> aspectProperties = new HashMap<QName, Serializable>(3);
aspectProperties.put(PROP_RECORD_ORIGINATING_LOCATION, (Serializable) parentAssoc.getParentRef());
aspectProperties.put(PROP_RECORD_ORIGINATING_USER_ID, userId);
aspectProperties.put(PROP_RECORD_ORIGINATING_CREATION_DATE, new Date());
nodeService.addAspect(nodeRef, ASPECT_RECORD_ORIGINATING_DETAILS, aspectProperties);
// make the document a record
makeRecord(nodeRef);
if (isLinked == true)
{
// turn off rules
ruleService.disableRules();
try
// get the new record container for the file plan
NodeRef newRecordContainer = filePlanService.getUnfiledContainer(filePlan);
if (newRecordContainer == null)
{
// maintain the original primary location
nodeService.addChild(parentAssoc.getParentRef(), nodeRef, parentAssoc.getTypeQName(), parentAssoc.getQName());
throw new AlfrescoRuntimeException("Unable to create record, because new record container could not be found.");
}
// set the extended security
Set<String> combinedWriters = new HashSet<String>(writers);
combinedWriters.add(owner);
combinedWriters.add(AuthenticationUtil.getFullyAuthenticatedUser());
extendedSecurityService.addExtendedSecurity(nodeRef, readers, combinedWriters);
}
finally
// get the documents readers
Long aclId = nodeService.getNodeAclId(nodeRef);
Set<String> readers = permissionService.getReaders(aclId);
Set<String> writers = permissionService.getWriters(aclId);
// add the current owner to the list of extended writers
String owner = ownableService.getOwner(nodeRef);
// remove the owner
ownableService.setOwner(nodeRef, OwnableService.NO_OWNER);
// get the documents primary parent assoc
ChildAssociationRef parentAssoc = nodeService.getPrimaryParent(nodeRef);
// move the document into the file plan
nodeService.moveNode(nodeRef, newRecordContainer, ContentModel.ASSOC_CONTAINS, parentAssoc.getQName());
// save the information about the originating details
Map<QName, Serializable> aspectProperties = new HashMap<QName, Serializable>(3);
aspectProperties.put(PROP_RECORD_ORIGINATING_LOCATION, (Serializable) parentAssoc.getParentRef());
aspectProperties.put(PROP_RECORD_ORIGINATING_USER_ID, userId);
aspectProperties.put(PROP_RECORD_ORIGINATING_CREATION_DATE, new Date());
nodeService.addAspect(nodeRef, ASPECT_RECORD_ORIGINATING_DETAILS, aspectProperties);
// make the document a record
makeRecord(nodeRef);
if (isLinked == true)
{
ruleService.enableRules();
// turn off rules
ruleService.disableRules();
try
{
// maintain the original primary location
nodeService.addChild(parentAssoc.getParentRef(), nodeRef, parentAssoc.getTypeQName(), parentAssoc.getQName());
// set the extended security
Set<String> combinedWriters = new HashSet<String>(writers);
combinedWriters.add(owner);
combinedWriters.add(AuthenticationUtil.getFullyAuthenticatedUser());
extendedSecurityService.addExtendedSecurity(nodeRef, readers, combinedWriters);
}
finally
{
ruleService.enableRules();
}
}
}
finally
{
ruleService.enableRuleType("outbound");
}
return null;
}
@@ -638,6 +660,7 @@ public class RecordServiceImpl implements RecordService,
*/
private void makeRecord(NodeRef document)
{
ruleService.disableRules();
try
{
// get the record id
@@ -674,6 +697,10 @@ public class RecordServiceImpl implements RecordService,
{
throw new AlfrescoRuntimeException("Unable to make record, because rename failed.", e);
}
finally
{
ruleService.enableRules();
}
}

View File

@@ -0,0 +1,103 @@
/*
* Copyright (C) 2005-2013 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.repo.rule.ruletrigger;
import java.util.Set;
import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
import org.alfresco.repo.transaction.TransactionalResourceHelper;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Prevent multiple triggering of outbound rules when moving records.
*
* @author Roy Wetherall
*/
public class ExtendedBeforeDeleteChildAssociationRuleTrigger
extends RuleTriggerAbstractBase
implements NodeServicePolicies.BeforeDeleteChildAssociationPolicy
{
/**
* The logger
*/
private static Log logger = LogFactory.getLog(BeforeDeleteChildAssociationRuleTrigger.class);
private static final String POLICY = "beforeDeleteChildAssociation";
private boolean isClassBehaviour = false;
public void setIsClassBehaviour(boolean isClassBehaviour)
{
this.isClassBehaviour = isClassBehaviour;
}
/**
* @see org.alfresco.repo.rule.ruletrigger.RuleTrigger#registerRuleTrigger()
*/
public void registerRuleTrigger()
{
if (isClassBehaviour == true)
{
this.policyComponent.bindClassBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, POLICY),
this,
new JavaBehaviour(this, POLICY, NotificationFrequency.FIRST_EVENT));
}
else
{
this.policyComponent.bindAssociationBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, POLICY),
this,
new JavaBehaviour(this, POLICY, NotificationFrequency.FIRST_EVENT));
}
}
public void beforeDeleteChildAssociation(ChildAssociationRef childAssocRef)
{
// Break out early if rules are not enabled
if (!areRulesEnabled())
{
return;
}
NodeRef childNodeRef = childAssocRef.getChildRef();
// Avoid renamed nodes
Set<NodeRef> renamedNodeRefSet = TransactionalResourceHelper.getSet(RULE_TRIGGER_RENAMED_NODES);
if (renamedNodeRefSet.contains(childNodeRef))
{
return;
}
if (logger.isDebugEnabled() == true)
{
logger.debug("Single child assoc trigger (policy = " + POLICY + ") fired for parent node " + childAssocRef.getParentRef() + " and child node " + childAssocRef.getChildRef());
}
triggerRules(childAssocRef.getParentRef(), childNodeRef);
}
}