Kevin Roast 34cc24aad6 Merged BRANCHES/DEV/V4.1-BUG-FIX to HEAD
44359: Fix for ALF-15236 - JSF - Edit online of html files does not keep the formatting
   44365: Fix for ALF-14653 - Share - Page link created wrongly in wiki
   44366: Fix for ALF-15435 - Incorrect behavior while managing groups via Explorer
   44370: Completion of existing fix for ALF-14568. Also a build fix.
   44372: Fix for ALF-13192 Rules from first folder move to second when delete first folder.
          This bug was caused because up to now, all rules have been firing for system folders, which they shouldn't have been.
   44381: ALF-17094: Merged V4.1.1  (4.1.1.14) to V4.1-BUG-FIX (4.1.3)
          << Code is actually as suggested by Derek rather than code on V4.1.1 >>
      44291: MNT-222 InvalidNodeRefException on user deletion in Share UI 
   44385: Fix for ALF-16006 - MT: Document Library is absent after upgrade from 3.4.x to 4.1.x (eg. 3.4.10 -> 4.1.1)
          Offshore team identified that patches running outside of a TXN were returning an empty list of tenants for MT upgrades
          - fixed after chat to Derek – added a new "big" TenantAdminService with a TXN wrapper interceptor so the AbstractPatch method that generates the list of tenants will also have a txn support regardless of the config set for a particularly patch
          - merged in fix to AVMToADM store patch to respect tenant named objects in paths
   44395: Fix for ALF-17061 Search is failing with Node does not exist: missing://missing/missing(null)
   44402: Merged DEV to V4.1-BUG-FIX
      44347: ALF-16866 : Failure when trying to login as tenant created on 3.4.0 after the upgrade from 3.4.0 to 4.1.2
         The immutableEntityTransactionalCache was made not tenant aware, and fixUserQNames patch now runs after migrateTenantsFromAttrsToTable to fix tenant users, too.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@44521 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2012-12-09 21:26:09 +00:00

204 lines
6.7 KiB
Java

/*
* Copyright (C) 2005-2010 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.HashSet;
import java.util.Set;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ActionModel;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.rule.RuleModel;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.rule.RuleService;
import org.alfresco.service.cmr.rule.RuleType;
import org.alfresco.service.namespace.QName;
/**
* Rule trigger abstract base
*
* @author Roy Wetherall
*/
public abstract class RuleTriggerAbstractBase implements RuleTrigger
{
/** the types (hardcoded) to ignore generally */
private static final Set<QName> IGNORE_TYPES;
/** the aspects (hardcoded) to ignore generally */
private static final Set<QName> IGNORE_ASPECTS;
static
{
IGNORE_TYPES = new HashSet<QName>(13);
IGNORE_TYPES.add(RuleModel.TYPE_RULE);
IGNORE_TYPES.add(ActionModel.TYPE_ACTION);
IGNORE_TYPES.add(ContentModel.TYPE_THUMBNAIL);
// Workaround to prevent rules running on cm:rating nodes (which happened for 'liked' folders ALF-8308 & ALF-8382)
IGNORE_TYPES.add(ContentModel.TYPE_RATING);
IGNORE_TYPES.add(ContentModel.TYPE_SYSTEM_FOLDER);
IGNORE_ASPECTS = new HashSet<QName>(13);
IGNORE_ASPECTS.add(ContentModel.ASPECT_TEMPORARY);
}
/**
* A list of the rule types that are interested in this trigger
*/
private Set<RuleType> ruleTypes = new HashSet<RuleType>();
protected PolicyComponent policyComponent;
protected NodeService nodeService;
protected ContentService contentService;
protected AuthenticationComponent authenticationComponent;
protected DictionaryService dictionaryService;
protected RuleService ruleService;
/**
* Indicates whether the rule should be executed immediately or at the end of the transaction.
* By default this is false as all rules are executed at the end of the transaction.
*/
protected boolean executeRuleImmediately = false;
/**
* Set the policy component
*/
public void setPolicyComponent(PolicyComponent policyComponent)
{
this.policyComponent = policyComponent;
}
/**
* Set the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Set the content service
*/
public void setContentService(ContentService contentService)
{
this.contentService = contentService;
}
/**
* Set the authenticationComponent
*/
public void setAuthenticationComponent(AuthenticationComponent authenticationComponent)
{
this.authenticationComponent = authenticationComponent;
}
/**
* Set the dictionary service
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* Set the RuleService to assist with enabled/disabled check
*/
public void setRuleService(RuleService ruleService)
{
this.ruleService = ruleService;
}
/**
* Sets the values that indicates whether the rule should be executed immediately or not.
*
* @param executeRuleImmediately true execute the rule immediaely, false otherwise
*/
public void setExecuteRuleImmediately(boolean executeRuleImmediately)
{
this.executeRuleImmediately = executeRuleImmediately;
}
/**
* Registration of an interested rule type
*
*/
public void registerRuleType(RuleType ruleType)
{
this.ruleTypes.add(ruleType);
}
/**
* Trigger the rules that relate to any interested rule types for the node
* references passed.
*
* @param nodeRef the node reference who rules are to be triggered
* @param actionedUponNodeRef the node reference that will be actioned upon by the rules
*/
protected void triggerRules(NodeRef nodeRef, NodeRef actionedUponNodeRef)
{
// Break out early if rules are off
if (!areRulesEnabled())
{
return;
}
// Do not trigger rules for rule and action type nodes
if (ignoreTrigger(actionedUponNodeRef) == false)
{
for (RuleType ruleType : this.ruleTypes)
{
ruleType.triggerRuleType(nodeRef, actionedUponNodeRef, this.executeRuleImmediately);
}
}
}
/**
* Helper method to allow triggers to check if rules are enabled or disabled
* (ALF-10839: Eliminate rule discovery overhead on property update when rules have been disabled)
* @return <tt>true</tt> if rules are enabled
*/
protected boolean areRulesEnabled()
{
return ruleService.isEnabled();
}
/**
* Indicate whether the trigger should be ignored or not
* @param actionedUponNodeRef actioned upon node reference
* @return boolean true if the trigger should be ignored, false otherwise
*/
private boolean ignoreTrigger(NodeRef actionedUponNodeRef)
{
boolean result = false;
QName typeQName = nodeService.getType(actionedUponNodeRef);
if (IGNORE_TYPES.contains(typeQName))
{
result = true;
}
for (QName aspectToIgnore : IGNORE_ASPECTS)
{
if (nodeService.hasAspect(actionedUponNodeRef, aspectToIgnore))
{
return true;
}
}
return result;
}
}