Moving to root below branch label

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2005 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2005-12-08 07:13:07 +00:00
commit e1e6508fec
1095 changed files with 230566 additions and 0 deletions

View File

@@ -0,0 +1,68 @@
/*
* 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.action;
import org.alfresco.service.cmr.action.ActionConditionDefinition;
/**
* Rule condition implementation class.
*
* @author Roy Wetherall
*/
public class ActionConditionDefinitionImpl extends ParameterizedItemDefinitionImpl
implements ActionConditionDefinition
{
/**
* Serial version UID
*/
private static final long serialVersionUID = 3688505493618177331L;
/**
* ActionCondition evaluator
*/
private String conditionEvaluator;
/**
* Constructor
*
* @param name the name
*/
public ActionConditionDefinitionImpl(String name)
{
super(name);
}
/**
* Set the condition evaluator
*
* @param conditionEvaluator the condition evaluator
*/
public void setConditionEvaluator(String conditionEvaluator)
{
this.conditionEvaluator = conditionEvaluator;
}
/**
* Get the condition evaluator
*
* @return the condition evaluator
*/
public String getConditionEvaluator()
{
return conditionEvaluator;
}
}

View File

@@ -0,0 +1,67 @@
/*
* 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.action;
import org.alfresco.service.cmr.rule.RuleServiceException;
/**
* @author Roy Wetherall
*/
public class ActionConditionDefinitionImplTest extends BaseParameterizedItemDefinitionImplTest
{
/**
* Constants used during tests
*/
private static final String CONDITION_EVALUATOR = "conditionEvaluator";
/**
* @see org.alfresco.repo.rule.common.RuleItemDefinitionImplTest#create()
*/
protected ParameterizedItemDefinitionImpl create()
{
// Test duplicate param name
try
{
ActionConditionDefinitionImpl temp = new ActionConditionDefinitionImpl(NAME);
temp.setParameterDefinitions(this.duplicateParamDefs);
fail("Duplicate param names are not allowed.");
}
catch (RuleServiceException exception)
{
// Indicates that there are duplicate param names
}
// Create a good one
ActionConditionDefinitionImpl temp = new ActionConditionDefinitionImpl(NAME);
assertNotNull(temp);
//temp.setTitle(TITLE);
//temp.setDescription(DESCRIPTION);
temp.setParameterDefinitions(this.paramDefs);
temp.setConditionEvaluator(CONDITION_EVALUATOR);
return temp;
}
/**
* Test getConditionEvaluator
*/
public void testGetConditionEvaluator()
{
ActionConditionDefinitionImpl cond = (ActionConditionDefinitionImpl)create();
assertEquals(CONDITION_EVALUATOR, cond.getConditionEvaluator());
}
}

View File

@@ -0,0 +1,89 @@
/*
* 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.action;
import java.io.Serializable;
import java.util.Map;
import org.alfresco.service.cmr.action.ActionCondition;
/**
* @author Roy Wetherall
*/
public class ActionConditionImpl extends ParameterizedItemImpl implements Serializable,
ActionCondition
{
/**
* Serial version UID
*/
private static final long serialVersionUID = 3257288015402644020L;
/**
* Rule condition defintion
*/
private String actionConditionDefinitionName;
/**
* Indicates whether the result of the condition should have the NOT logical operator applied
* to it.
*/
private boolean invertCondition = false;
/**
* Constructor
*/
public ActionConditionImpl(String id, String actionConditionDefinitionName)
{
this(id, actionConditionDefinitionName, null);
}
/**
* @param parameterValues
*/
public ActionConditionImpl(
String id,
String actionConditionDefinitionName,
Map<String, Serializable> parameterValues)
{
super(id, parameterValues);
this.actionConditionDefinitionName = actionConditionDefinitionName;
}
/**
* @see org.alfresco.service.cmr.action.ActionCondition#getActionConditionDefinitionName()
*/
public String getActionConditionDefinitionName()
{
return this.actionConditionDefinitionName;
}
/**
* @see org.alfresco.service.cmr.action.ActionCondition#setInvertCondition(boolean)
*/
public void setInvertCondition(boolean invertCondition)
{
this.invertCondition = invertCondition;
}
/**
* @see org.alfresco.service.cmr.action.ActionCondition#getInvertCondition()
*/
public boolean getInvertCondition()
{
return this.invertCondition;
}
}

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.action;
import org.alfresco.service.cmr.action.ActionCondition;
/**
* @author Roy Wetherall
*/
public class ActionConditionImplTest extends BaseParameterizedItemImplTest
{
/**
* @see org.alfresco.repo.rule.common.RuleItemImplTest#create()
*/
@Override
protected ParameterizedItemImpl create()
{
return new ActionConditionImpl(
ID,
NAME,
this.paramValues);
}
public void testGetRuleConditionDefintion()
{
ActionCondition temp = (ActionCondition)create();
assertEquals(NAME, temp.getActionConditionDefinitionName());
}
public void testSetGetInvertCondition()
{
ActionCondition temp = (ActionCondition)create();
assertFalse(temp.getInvertCondition());
temp.setInvertCondition(true);
assertTrue(temp.getInvertCondition());
}
}

View File

@@ -0,0 +1,68 @@
/*
* 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.action;
import org.alfresco.service.cmr.action.ActionDefinition;
/**
* Rule action implementation class
*
* @author Roy Wetherall
*/
public class ActionDefinitionImpl extends ParameterizedItemDefinitionImpl
implements ActionDefinition
{
/**
* Serial version UID
*/
private static final long serialVersionUID = 4048797883396863026L;
/**
* The rule action executor
*/
private String ruleActionExecutor;
/**
* Constructor
*
* @param name the name
*/
public ActionDefinitionImpl(String name)
{
super(name);
}
/**
* Set the rule action executor
*
* @param ruleActionExecutor the rule action executor
*/
public void setRuleActionExecutor(String ruleActionExecutor)
{
this.ruleActionExecutor = ruleActionExecutor;
}
/**
* Get the rule aciton executor
*
* @return the rule action executor
*/
public String getRuleActionExecutor()
{
return ruleActionExecutor;
}
}

View File

@@ -0,0 +1,61 @@
/*
* 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.action;
import org.alfresco.service.cmr.rule.RuleServiceException;
/**
* @author Roy Wetherall
*/
public class ActionDefinitionImplTest extends BaseParameterizedItemDefinitionImplTest
{
private static final String RULE_ACTION_EXECUTOR = "ruleActionExector";
protected ParameterizedItemDefinitionImpl create()
{
// Test duplicate param name
try
{
ActionDefinitionImpl temp = new ActionDefinitionImpl(NAME);
temp.setParameterDefinitions(duplicateParamDefs);
fail("Duplicate param names are not allowed.");
}
catch (RuleServiceException exception)
{
// Indicates that there are duplicate param names
}
// Create a good one
ActionDefinitionImpl temp = new ActionDefinitionImpl(NAME);
assertNotNull(temp);
//temp.setTitle(TITLE);
// temp.setDescription(DESCRIPTION);
temp.setParameterDefinitions(paramDefs);
temp.setRuleActionExecutor(RULE_ACTION_EXECUTOR);
return temp;
}
/**
* Test getRuleActionExecutor
*/
public void testGetRuleActionExecutor()
{
ActionDefinitionImpl temp = (ActionDefinitionImpl)create();
assertEquals(RULE_ACTION_EXECUTOR, temp.getRuleActionExecutor());
}
}

View File

@@ -0,0 +1,380 @@
/*
* 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.action;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ActionCondition;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Action implementation
*
* @author Roy Wetherall
*/
public class ActionImpl extends ParameterizedItemImpl
implements Serializable, Action
{
/**
* Serial version UID
*/
private static final long serialVersionUID = 3258135760426186548L;
/**
* The title
*/
private String title;
/**
* The description
*/
private String description;
/**
* Inidcates whether the action should be executed asynchronously or not
*/
private boolean executeAsynchronously = false;
/**
* The compensating action
*/
private Action compensatingAction;
/**
* The created date
*/
private Date createdDate;
/**
* The creator
*/
private String creator;
/**
* The modified date
*/
private Date modifiedDate;
/**
* The modifier
*/
private String modifier;
/**
* Rule action definition name
*/
private String actionDefinitionName;
/**
* The owning node reference
*/
private NodeRef owningNodeRef;
/**
* The chain of actions that have lead to this action
*/
private Set<String> actionChain;
/**
* Action conditions
*/
private List<ActionCondition> actionConditions = new ArrayList<ActionCondition>();
/**
* Constructor
*
* @param id the action id
* @param actionDefinitionName the name of the action definition
*/
public ActionImpl(String id, String actionDefinitionName, NodeRef owningNodeRef)
{
this(id, actionDefinitionName, owningNodeRef, null);
}
/**
* Constructor
*
* @param id the action id
* @param actionDefinitionName the action definition name
* @param parameterValues the parameter values
*/
public ActionImpl(
String id,
String actionDefinitionName,
NodeRef owningNodeRef,
Map<String, Serializable> parameterValues)
{
super(id, parameterValues);
this.actionDefinitionName = actionDefinitionName;
this.owningNodeRef = owningNodeRef;
}
/**
* @see org.alfresco.service.cmr.action.Action#getTitle()
*/
public String getTitle()
{
return this.title;
}
/**
* @see org.alfresco.service.cmr.action.Action#setTitle(java.lang.String)
*/
public void setTitle(String title)
{
this.title = title;
}
/**
* @see org.alfresco.service.cmr.action.Action#getDescription()
*/
public String getDescription()
{
return this.description;
}
/**
* @see org.alfresco.service.cmr.action.Action#setDescription(java.lang.String)
*/
public void setDescription(String description)
{
this.description = description;
}
/**
* @see org.alfresco.service.cmr.action.Action#getOwningNodeRef()
*/
public NodeRef getOwningNodeRef()
{
return this.owningNodeRef;
}
public void setOwningNodeRef(NodeRef owningNodeRef)
{
this.owningNodeRef = owningNodeRef;
}
/**
* @see org.alfresco.service.cmr.action.Action#getExecuteAsychronously()
*/
public boolean getExecuteAsychronously()
{
return this.executeAsynchronously ;
}
/**
* @see org.alfresco.service.cmr.action.Action#setExecuteAsynchronously(boolean)
*/
public void setExecuteAsynchronously(boolean executeAsynchronously)
{
this.executeAsynchronously = executeAsynchronously;
}
/**
* @see org.alfresco.service.cmr.action.Action#getCompensatingAction()
*/
public Action getCompensatingAction()
{
return this.compensatingAction;
}
/**
* @see org.alfresco.service.cmr.action.Action#setCompensatingAction(org.alfresco.service.cmr.action.Action)
*/
public void setCompensatingAction(Action action)
{
this.compensatingAction = action;
}
/**
* @see org.alfresco.service.cmr.action.Action#getCreatedDate()
*/
public Date getCreatedDate()
{
return this.createdDate;
}
/**
* Set the created date
*
* @param createdDate the created date
*/
public void setCreatedDate(Date createdDate)
{
this.createdDate = createdDate;
}
/**
* @see org.alfresco.service.cmr.action.Action#getCreator()
*/
public String getCreator()
{
return this.creator;
}
/**
* Set the creator
*
* @param creator the creator
*/
public void setCreator(String creator)
{
this.creator = creator;
}
/**
* @see org.alfresco.service.cmr.action.Action#getModifiedDate()
*/
public Date getModifiedDate()
{
return this.modifiedDate;
}
/**
* Set the modified date
*
* @param modifiedDate the modified date
*/
public void setModifiedDate(Date modifiedDate)
{
this.modifiedDate = modifiedDate;
}
/**
* @see org.alfresco.service.cmr.action.Action#getModifier()
*/
public String getModifier()
{
return this.modifier;
}
/**
* Set the modifier
*
* @param modifier the modifier
*/
public void setModifier(String modifier)
{
this.modifier = modifier;
}
/**
* @see org.alfresco.service.cmr.action.Action#getActionDefinitionName()
*/
public String getActionDefinitionName()
{
return this.actionDefinitionName;
}
/**
* @see org.alfresco.service.cmr.action.Action#hasActionConditions()
*/
public boolean hasActionConditions()
{
return (this.actionConditions.isEmpty() == false);
}
/**
* @see org.alfresco.service.cmr.action.Action#indexOfActionCondition(org.alfresco.service.cmr.action.ActionCondition)
*/
public int indexOfActionCondition(ActionCondition actionCondition)
{
return this.actionConditions.indexOf(actionCondition);
}
/**
* @see org.alfresco.service.cmr.action.Action#getActionConditions()
*/
public List<ActionCondition> getActionConditions()
{
return this.actionConditions;
}
/**
* @see org.alfresco.service.cmr.action.Action#getActionCondition(int)
*/
public ActionCondition getActionCondition(int index)
{
return this.actionConditions.get(index);
}
/**
* @see org.alfresco.service.cmr.action.Action#addActionCondition(org.alfresco.service.cmr.action.ActionCondition)
*/
public void addActionCondition(ActionCondition actionCondition)
{
this.actionConditions.add(actionCondition);
}
/**
* @see org.alfresco.service.cmr.action.Action#addActionCondition(int, org.alfresco.service.cmr.action.ActionCondition)
*/
public void addActionCondition(int index, ActionCondition actionCondition)
{
this.actionConditions.add(index, actionCondition);
}
/**
* @see org.alfresco.service.cmr.action.Action#setActionCondition(int, org.alfresco.service.cmr.action.ActionCondition)
*/
public void setActionCondition(int index, ActionCondition actionCondition)
{
this.actionConditions.set(index, actionCondition);
}
/**
* @see org.alfresco.service.cmr.action.Action#removeActionCondition(org.alfresco.service.cmr.action.ActionCondition)
*/
public void removeActionCondition(ActionCondition actionCondition)
{
this.actionConditions.remove(actionCondition);
}
/**
* @see org.alfresco.service.cmr.action.Action#removeAllActionConditions()
*/
public void removeAllActionConditions()
{
this.actionConditions.clear();
}
/**
* Set the action chain
*
* @param actionChain the list of actions that lead to this action
*/
public void setActionChain(Set<String> actionChain)
{
this.actionChain = actionChain;
}
/**
* Get the action chain
*
* @return the list of actions that lead to this action
*/
public Set<String> getActionChain()
{
return actionChain;
}
}

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.action;
import java.util.List;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ActionCondition;
import org.alfresco.util.GUID;
/**
* @author Roy Wetherall
*/
public class ActionImplTest extends BaseParameterizedItemImplTest
{
private static final String ID_COND1 = "idCond1";
private static final String ID_COND2 = "idCond2";
private static final String ID_COND3 = "idCond3";
private static final String NAME_COND1 = "nameCond1";
private static final String NAME_COND2 = "nameCond2";
private static final String NAME_COND3 = "nameCond3";
/**
* @see org.alfresco.repo.rule.common.RuleItemImplTest#create()
*/
@Override
protected ParameterizedItemImpl create()
{
return new ActionImpl(
ID,
NAME,
null,
this.paramValues);
}
public void testGetRuleActionDefintion()
{
Action temp = (Action)create();
assertEquals(NAME, temp.getActionDefinitionName());
}
public void testSimpleProperties()
{
Action action = (Action)create();
// Check the default values
assertFalse(action.getExecuteAsychronously());
assertNull(action.getCompensatingAction());
// Set some values
action.setTitle("title");
action.setDescription("description");
action.setExecuteAsynchronously(true);
Action compensatingAction = new ActionImpl(GUID.generate(), "actionDefintionName", null);
action.setCompensatingAction(compensatingAction);
// Check the values have been set
assertEquals("title", action.getTitle());
assertEquals("description", action.getDescription());
assertTrue(action.getExecuteAsychronously());
assertEquals(compensatingAction, action.getCompensatingAction());
}
public void testActionConditions()
{
ActionCondition cond1 = new ActionConditionImpl(ID_COND1, NAME_COND1, this.paramValues);
ActionCondition cond2 = new ActionConditionImpl(ID_COND2, NAME_COND2, this.paramValues);
ActionCondition cond3 = new ActionConditionImpl(ID_COND3, NAME_COND3, this.paramValues);
Action action = (Action)create();
// Check has no conditions
assertFalse(action.hasActionConditions());
List<ActionCondition> noConditions = action.getActionConditions();
assertNotNull(noConditions);
assertEquals(0, noConditions.size());
// Add the conditions to the action
action.addActionCondition(cond1);
action.addActionCondition(cond2);
action.addActionCondition(cond3);
// Check that the conditions are there and in the correct order
assertTrue(action.hasActionConditions());
List<ActionCondition> actionConditions = action.getActionConditions();
assertNotNull(actionConditions);
assertEquals(3, actionConditions.size());
int counter = 0;
for (ActionCondition condition : actionConditions)
{
if (counter == 0)
{
assertEquals(cond1, condition);
}
else if (counter == 1)
{
assertEquals(cond2, condition);
}
else if (counter == 2)
{
assertEquals(cond3, condition);
}
counter+=1;
}
assertEquals(cond1, action.getActionCondition(0));
assertEquals(cond2, action.getActionCondition(1));
assertEquals(cond3, action.getActionCondition(2));
// Check remove
action.removeActionCondition(cond3);
assertEquals(2, action.getActionConditions().size());
// Check set
action.setActionCondition(1, cond3);
assertEquals(cond1, action.getActionCondition(0));
assertEquals(cond3, action.getActionCondition(1));
// Check index of
assertEquals(0, action.indexOfActionCondition(cond1));
assertEquals(1, action.indexOfActionCondition(cond3));
// Test insert
action.addActionCondition(1, cond2);
assertEquals(3, action.getActionConditions().size());
assertEquals(cond1, action.getActionCondition(0));
assertEquals(cond2, action.getActionCondition(1));
assertEquals(cond3, action.getActionCondition(2));
// Check remote all
action.removeAllActionConditions();
assertFalse(action.hasActionConditions());
assertEquals(0, action.getActionConditions().size());
}
}

View File

@@ -0,0 +1,34 @@
package org.alfresco.repo.action;
import org.alfresco.service.namespace.QName;
public interface ActionModel
{
static final String ACTION_MODEL_URI = "http://www.alfresco.org/model/action/1.0";
static final String ACTION_MODEL_PREFIX = "act";
static final QName TYPE_ACTION = QName.createQName(ACTION_MODEL_URI, "action");
static final QName PROP_DEFINITION_NAME = QName.createQName(ACTION_MODEL_URI, "definitionName");
static final QName PROP_ACTION_TITLE = QName.createQName(ACTION_MODEL_URI, "actionTitle");
static final QName PROP_ACTION_DESCRIPTION = QName.createQName(ACTION_MODEL_URI, "actionDescription");
static final QName PROP_EXECUTE_ASYNCHRONOUSLY = QName.createQName(ACTION_MODEL_URI, "executeAsynchronously");
static final QName ASSOC_CONDITIONS = QName.createQName(ACTION_MODEL_URI, "conditions");
static final QName ASSOC_COMPENSATING_ACTION = QName.createQName(ACTION_MODEL_URI, "compensatingAction");
static final QName ASSOC_PARAMETERS = QName.createQName(ACTION_MODEL_URI, "parameters");
static final QName TYPE_ACTION_CONDITION = QName.createQName(ACTION_MODEL_URI, "actioncondition");
static final QName TYPE_ACTION_PARAMETER = QName.createQName(ACTION_MODEL_URI, "actionparameter");
static final QName PROP_PARAMETER_NAME = QName.createQName(ACTION_MODEL_URI, "parameterName");
static final QName PROP_PARAMETER_VALUE = QName.createQName(ACTION_MODEL_URI, "parameterValue");
static final QName TYPE_COMPOSITE_ACTION = QName.createQName(ACTION_MODEL_URI, "compositeaction");
static final QName ASSOC_ACTIONS = QName.createQName(ACTION_MODEL_URI, "actions");
static final QName ASPECT_ACTIONS = QName.createQName(ACTION_MODEL_URI, "actions");
static final QName ASSOC_ACTION_FOLDER = QName.createQName(ACTION_MODEL_URI, "actionFolder");
//static final QName ASPECT_ACTIONABLE = QName.createQName(ACTION_MODEL_URI, "actionable");
//static final QName ASSOC_SAVED_ACTION_FOLDERS = QName.createQName(ACTION_MODEL_URI, "savedActionFolders");
//static final QName TYPE_SAVED_ACTION_FOLDER = QName.createQName(ACTION_MODEL_URI, "savedactionfolder");
//static final QName ASSOC_SAVED_ACTIONS = QName.createQName(ACTION_MODEL_URI, "savedActions");
static final QName PROP_CONDITION_INVERT = QName.createQName(ACTION_MODEL_URI, "invert");
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,938 @@
/*
* 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.action;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.evaluator.ComparePropertyValueEvaluator;
import org.alfresco.repo.action.evaluator.InCategoryEvaluator;
import org.alfresco.repo.action.evaluator.NoConditionEvaluator;
import org.alfresco.repo.action.evaluator.compare.ComparePropertyValueOperation;
import org.alfresco.repo.action.executer.AddFeaturesActionExecuter;
import org.alfresco.repo.action.executer.CheckInActionExecuter;
import org.alfresco.repo.action.executer.CheckOutActionExecuter;
import org.alfresco.repo.action.executer.CompositeActionExecuter;
import org.alfresco.repo.action.executer.MoveActionExecuter;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.transaction.TransactionUtil;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ActionCondition;
import org.alfresco.service.cmr.action.ActionConditionDefinition;
import org.alfresco.service.cmr.action.ActionDefinition;
import org.alfresco.service.cmr.action.ActionService;
import org.alfresco.service.cmr.action.CompositeAction;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.BaseAlfrescoSpringTest;
import org.alfresco.util.BaseSpringTest;
/**
* Action service test
*
* @author Roy Wetherall
*/
public class ActionServiceImplTest extends BaseAlfrescoSpringTest
{
private static final String BAD_NAME = "badName";
private NodeRef nodeRef;
@Override
protected void onSetUpInTransaction() throws Exception
{
super.onSetUpInTransaction();
// Create the node used for tests
this.nodeRef = this.nodeService.createNode(
this.rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}testnode"),
ContentModel.TYPE_CONTENT).getChildRef();
this.nodeService.setProperty(
this.nodeRef,
ContentModel.PROP_CONTENT,
new ContentData(null, MimetypeMap.MIMETYPE_TEXT_PLAIN, 0L, null));
}
/**
* Test getActionDefinition
*/
public void testGetActionDefinition()
{
ActionDefinition action = actionService.getActionDefinition(AddFeaturesActionExecuter.NAME);
assertNotNull(action);
assertEquals(AddFeaturesActionExecuter.NAME, action.getName());
ActionConditionDefinition nullCondition = this.actionService.getActionConditionDefinition(BAD_NAME);
assertNull(nullCondition);
}
/**
* Test getActionDefintions
*/
public void testGetActionDefinitions()
{
List<ActionDefinition> defintions = this.actionService.getActionDefinitions();
assertNotNull(defintions);
assertFalse(defintions.isEmpty());
for (ActionDefinition definition : defintions)
{
System.out.println(definition.getTitle());
}
}
/**
* Test getActionConditionDefinition
*/
public void testGetActionConditionDefinition()
{
ActionConditionDefinition condition = this.actionService.getActionConditionDefinition(NoConditionEvaluator.NAME);
assertNotNull(condition);
assertEquals(NoConditionEvaluator.NAME, condition.getName());
ActionConditionDefinition nullCondition = this.actionService.getActionConditionDefinition(BAD_NAME);
assertNull(nullCondition);
}
/**
* Test getActionConditionDefinitions
*
*/
public void testGetActionConditionDefinitions()
{
List<ActionConditionDefinition> defintions = this.actionService.getActionConditionDefinitions();
assertNotNull(defintions);
assertFalse(defintions.isEmpty());
for (ActionConditionDefinition definition : defintions)
{
System.out.println(definition.getTitle());
}
}
/**
* Test create action condition
*/
public void testCreateActionCondition()
{
ActionCondition condition = this.actionService.createActionCondition(NoConditionEvaluator.NAME);
assertNotNull(condition);
assertEquals(NoConditionEvaluator.NAME, condition.getActionConditionDefinitionName());
}
/**
* Test createAction
*/
public void testCreateAction()
{
Action action = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
assertNotNull(action);
assertEquals(AddFeaturesActionExecuter.NAME, action.getActionDefinitionName());
}
/**
* Test createCompositeAction
*/
public void testCreateCompositeAction()
{
CompositeAction action = this.actionService.createCompositeAction();
assertNotNull(action);
assertEquals(CompositeActionExecuter.NAME, action.getActionDefinitionName());
}
/**
* Evaluate action
*/
public void testEvaluateAction()
{
Action action = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
assertTrue(this.actionService.evaluateAction(action, this.nodeRef));
ActionCondition condition = this.actionService.createActionCondition(ComparePropertyValueEvaluator.NAME);
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "*.doc");
action.addActionCondition(condition);
assertFalse(this.actionService.evaluateAction(action, this.nodeRef));
this.nodeService.setProperty(this.nodeRef, ContentModel.PROP_NAME, "myDocument.doc");
assertTrue(this.actionService.evaluateAction(action, this.nodeRef));
ActionCondition condition2 = this.actionService.createActionCondition(ComparePropertyValueEvaluator.NAME);
condition2.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "my");
action.addActionCondition(condition2);
assertTrue(this.actionService.evaluateAction(action, this.nodeRef));
this.nodeService.setProperty(this.nodeRef, ContentModel.PROP_NAME, "document.doc");
assertFalse(this.actionService.evaluateAction(action, this.nodeRef));
}
/**
* Test evaluate action condition
*/
public void testEvaluateActionCondition()
{
ActionCondition condition = this.actionService.createActionCondition(ComparePropertyValueEvaluator.NAME);
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "*.doc");
assertFalse(this.actionService.evaluateActionCondition(condition, this.nodeRef));
this.nodeService.setProperty(this.nodeRef, ContentModel.PROP_NAME, "myDocument.doc");
assertTrue(this.actionService.evaluateActionCondition(condition, this.nodeRef));
// Check that inverting the condition has the correct effect
condition.setInvertCondition(true);
assertFalse(this.actionService.evaluateActionCondition(condition, this.nodeRef));
}
/**
* Test execute action
*/
public void testExecuteAction()
{
assertFalse(this.nodeService.hasAspect(this.nodeRef, ContentModel.ASPECT_VERSIONABLE));
Action action = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
action.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_VERSIONABLE);
this.actionService.executeAction(action, this.nodeRef);
assertTrue(this.nodeService.hasAspect(this.nodeRef, ContentModel.ASPECT_VERSIONABLE));
this.nodeService.removeAspect(this.nodeRef, ContentModel.ASPECT_VERSIONABLE);
assertFalse(this.nodeService.hasAspect(this.nodeRef, ContentModel.ASPECT_VERSIONABLE));
ActionCondition condition = this.actionService.createActionCondition(ComparePropertyValueEvaluator.NAME);
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "*.doc");
action.addActionCondition(condition);
this.actionService.executeAction(action, this.nodeRef);
assertFalse(this.nodeService.hasAspect(this.nodeRef, ContentModel.ASPECT_VERSIONABLE));
this.actionService.executeAction(action, this.nodeRef, true);
assertFalse(this.nodeService.hasAspect(this.nodeRef, ContentModel.ASPECT_VERSIONABLE));
this.actionService.executeAction(action, this.nodeRef, false);
assertTrue(this.nodeService.hasAspect(this.nodeRef, ContentModel.ASPECT_VERSIONABLE));
this.nodeService.removeAspect(this.nodeRef, ContentModel.ASPECT_VERSIONABLE);
assertFalse(this.nodeService.hasAspect(this.nodeRef, ContentModel.ASPECT_VERSIONABLE));
this.nodeService.setProperty(this.nodeRef, ContentModel.PROP_NAME, "myDocument.doc");
this.actionService.executeAction(action, this.nodeRef);
assertTrue(this.nodeService.hasAspect(this.nodeRef, ContentModel.ASPECT_VERSIONABLE));
this.nodeService.removeAspect(this.nodeRef, ContentModel.ASPECT_VERSIONABLE);
assertFalse(this.nodeService.hasAspect(this.nodeRef, ContentModel.ASPECT_VERSIONABLE));
this.nodeService.removeAspect(this.nodeRef, ContentModel.ASPECT_VERSIONABLE);
assertFalse(this.nodeService.hasAspect(this.nodeRef, ContentModel.ASPECT_VERSIONABLE));
// Create the composite action
Action action1 = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
action1.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_LOCKABLE);
Action action2 = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
action2.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_VERSIONABLE);
CompositeAction compAction = this.actionService.createCompositeAction();
compAction.setTitle("title");
compAction.setDescription("description");
compAction.addAction(action1);
compAction.addAction(action2);
// Execute the composite action
this.actionService.executeAction(compAction, this.nodeRef);
assertTrue(this.nodeService.hasAspect(this.nodeRef, ContentModel.ASPECT_LOCKABLE));
assertTrue(this.nodeService.hasAspect(this.nodeRef, ContentModel.ASPECT_VERSIONABLE));
}
public void testGetAndGetAllWithNoActions()
{
assertNull(this.actionService.getAction(this.nodeRef, AddFeaturesActionExecuter.NAME));
List<Action> actions = this.actionService.getActions(this.nodeRef);
assertNotNull(actions);
assertEquals(0, actions.size());
}
/**
* Test saving an action with no conditions. Includes testing storage and retrieval
* of compensating actions.
*/
public void testSaveActionNoCondition()
{
// Create the action
Action action = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
String actionId = action.getId();
// Set the parameters of the action
action.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_VERSIONABLE);
// Set the title and description of the action
action.setTitle("title");
action.setDescription("description");
action.setExecuteAsynchronously(true);
// Save the action
this.actionService.saveAction(this.nodeRef, action);
// Get the action
Action savedAction = this.actionService.getAction(this.nodeRef, actionId);
// Check the action
assertEquals(action.getId(), savedAction.getId());
assertEquals(action.getActionDefinitionName(), savedAction.getActionDefinitionName());
// Check the properties
assertEquals("title", savedAction.getTitle());
assertEquals("description", savedAction.getDescription());
assertTrue(savedAction.getExecuteAsychronously());
// Check that the compensating action has not been set
assertNull(savedAction.getCompensatingAction());
// Check the properties
assertEquals(1, savedAction.getParameterValues().size());
assertEquals(ContentModel.ASPECT_VERSIONABLE, savedAction.getParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME));
// Check the conditions
assertNotNull(savedAction.getActionConditions());
assertEquals(0, savedAction.getActionConditions().size());
// Edit the properties of the action
Map<QName, Serializable> properties = new HashMap<QName, Serializable>(1);
properties.put(ContentModel.PROP_NAME, "testName");
action.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_PROPERTIES, (Serializable)properties);
action.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_AUDITABLE);
// Set the compensating action
Action compensatingAction = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
compensatingAction.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_VERSIONABLE);
action.setCompensatingAction(compensatingAction);
this.actionService.saveAction(this.nodeRef, action);
Action savedAction2 = this.actionService.getAction(this.nodeRef, actionId);
// Check the updated properties
assertEquals(2, savedAction2.getParameterValues().size());
assertEquals(ContentModel.ASPECT_AUDITABLE, savedAction2.getParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME));
Map<QName, Serializable> temp = (Map<QName, Serializable>)savedAction2.getParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_PROPERTIES);
assertNotNull(temp);
assertEquals(1, temp.size());
assertEquals("testName", temp.get(ContentModel.PROP_NAME));
// Check the compensating action
Action savedCompensatingAction = savedAction2.getCompensatingAction();
assertNotNull(savedCompensatingAction);
assertEquals(compensatingAction, savedCompensatingAction);
assertEquals(AddFeaturesActionExecuter.NAME, savedCompensatingAction.getActionDefinitionName());
assertEquals(ContentModel.ASPECT_VERSIONABLE, savedCompensatingAction.getParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME));
// Change the details of the compensating action (edit and remove)
compensatingAction.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_CLASSIFIABLE);
this.actionService.saveAction(this.nodeRef, action);
Action savedAction3 = this.actionService.getAction(this.nodeRef, actionId);
Action savedCompensatingAction2 = savedAction3.getCompensatingAction();
assertNotNull(savedCompensatingAction2);
assertEquals(compensatingAction, savedCompensatingAction2);
assertEquals(AddFeaturesActionExecuter.NAME, savedCompensatingAction2.getActionDefinitionName());
assertEquals(ContentModel.ASPECT_CLASSIFIABLE, savedCompensatingAction2.getParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME));
action.setCompensatingAction(null);
this.actionService.saveAction(this.nodeRef, action);
Action savedAction4 = this.actionService.getAction(this.nodeRef, actionId);
assertNull(savedAction4.getCompensatingAction());
//System.out.println(NodeStoreInspector.dumpNodeStore(this.nodeService, this.testStoreRef));
}
public void testOwningNodeRef()
{
// Create the action
Action action = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
String actionId = action.getId();
// Set the parameters of the action
action.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_VERSIONABLE);
// Set the title and description of the action
action.setTitle("title");
action.setDescription("description");
action.setExecuteAsynchronously(true);
// Check the owning node ref
assertNull(action.getOwningNodeRef());
// Save the action
this.actionService.saveAction(this.nodeRef, action);
// Check the owning node ref
assertEquals(this.nodeRef, action.getOwningNodeRef());
// Get the action
Action savedAction = this.actionService.getAction(this.nodeRef, actionId);
// Check the owning node ref
assertEquals(this.nodeRef, savedAction.getOwningNodeRef());;
}
/**
* Test saving an action with conditions
*/
public void testSaveActionWithConditions()
{
// Create the action
Action action = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
String actionId = action.getId();
// Set the parameters of the action
action.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_VERSIONABLE);
Map<QName, Serializable> properties = new HashMap<QName, Serializable>(1);
properties.put(ContentModel.PROP_NAME, "testName");
action.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_PROPERTIES, (Serializable)properties);
// Set the conditions of the action
ActionCondition actionCondition = this.actionService.createActionCondition(NoConditionEvaluator.NAME);
actionCondition.setInvertCondition(true);
ActionCondition actionCondition2 = this.actionService.createActionCondition(ComparePropertyValueEvaluator.NAME);
actionCondition2.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "*.doc");
action.addActionCondition(actionCondition);
action.addActionCondition(actionCondition2);
// Save the action
this.actionService.saveAction(this.nodeRef, action);
// Get the action
Action savedAction = this.actionService.getAction(this.nodeRef, actionId);
// Check the action
assertEquals(action.getId(), savedAction.getId());
assertEquals(action.getActionDefinitionName(), savedAction.getActionDefinitionName());
// Check the properties
assertEquals(action.getParameterValues().size(), savedAction.getParameterValues().size());
assertEquals(ContentModel.ASPECT_VERSIONABLE, savedAction.getParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME));
Map<QName, Serializable> temp = (Map<QName, Serializable>)savedAction.getParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_PROPERTIES);
assertNotNull(temp);
assertEquals(1, temp.size());
assertEquals("testName", temp.get(ContentModel.PROP_NAME));
// Check the conditions
assertNotNull(savedAction.getActionConditions());
assertEquals(2, savedAction.getActionConditions().size());
for (ActionCondition savedCondition : savedAction.getActionConditions())
{
if (savedCondition.getActionConditionDefinitionName().equals(NoConditionEvaluator.NAME) == true)
{
assertEquals(0, savedCondition.getParameterValues().size());
assertTrue(savedCondition.getInvertCondition());
}
else if (savedCondition.getActionConditionDefinitionName().equals(ComparePropertyValueEvaluator.NAME) == true)
{
assertEquals(1, savedCondition.getParameterValues().size());
assertEquals("*.doc", savedCondition.getParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE));
assertFalse(savedCondition.getInvertCondition());
}
else
{
fail("There is a condition here that we are not expecting.");
}
}
// Modify the conditions of the action
ActionCondition actionCondition3 = this.actionService.createActionCondition(InCategoryEvaluator.NAME);
actionCondition3.setParameterValue(InCategoryEvaluator.PARAM_CATEGORY_ASPECT, ContentModel.ASPECT_OWNABLE);
action.addActionCondition(actionCondition3);
action.removeActionCondition(actionCondition);
actionCondition2.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "*.exe");
actionCondition2.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.EQUALS);
this.actionService.saveAction(this.nodeRef, action);
Action savedAction2 = this.actionService.getAction(this.nodeRef, actionId);
// Check that the conditions have been updated correctly
assertNotNull(savedAction2.getActionConditions());
assertEquals(2, savedAction2.getActionConditions().size());
for (ActionCondition savedCondition : savedAction2.getActionConditions())
{
if (savedCondition.getActionConditionDefinitionName().equals(InCategoryEvaluator.NAME) == true)
{
assertEquals(1, savedCondition.getParameterValues().size());
assertEquals(ContentModel.ASPECT_OWNABLE, savedCondition.getParameterValue(InCategoryEvaluator.PARAM_CATEGORY_ASPECT));
}
else if (savedCondition.getActionConditionDefinitionName().equals(ComparePropertyValueEvaluator.NAME) == true)
{
assertEquals(2, savedCondition.getParameterValues().size());
assertEquals("*.exe", savedCondition.getParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE));
assertEquals(ComparePropertyValueOperation.EQUALS, savedCondition.getParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION));
}
else
{
fail("There is a condition here that we are not expecting.");
}
}
//System.out.println(NodeStoreInspector.dumpNodeStore(this.nodeService, this.testStoreRef));
}
/**
* Test saving a composite action
*/
public void testSaveCompositeAction()
{
Action action1 = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
Action action2 = this.actionService.createAction(CheckInActionExecuter.NAME);
CompositeAction compositeAction = this.actionService.createCompositeAction();
String actionId = compositeAction.getId();
compositeAction.addAction(action1);
compositeAction.addAction(action2);
this.actionService.saveAction(this.nodeRef, compositeAction);
assertEquals(1, this.actionService.getActions(this.nodeRef).size());
CompositeAction savedCompositeAction = (CompositeAction)this.actionService.getAction(this.nodeRef, actionId);
// Check the saved composite action
assertEquals(2, savedCompositeAction.getActions().size());
for (Action action : savedCompositeAction.getActions())
{
if (action.getActionDefinitionName().equals(AddFeaturesActionExecuter.NAME) == true)
{
assertEquals(action, action1);
}
else if (action.getActionDefinitionName().equals(CheckInActionExecuter.NAME) == true)
{
assertEquals(action, action2);
}
else
{
fail("We have an action here we are not expecting.");
}
}
// Change the actions and re-save
compositeAction.removeAction(action1);
Action action3 = this.actionService.createAction(CheckOutActionExecuter.NAME);
compositeAction.addAction(action3);
action2.setParameterValue(CheckInActionExecuter.PARAM_DESCRIPTION, "description");
this.actionService.saveAction(this.nodeRef, compositeAction);
assertEquals(1, this.actionService.getActions(this.nodeRef).size());
CompositeAction savedCompositeAction2 = (CompositeAction)this.actionService.getAction(this.nodeRef, actionId);
assertEquals(2, savedCompositeAction2.getActions().size());
for (Action action : savedCompositeAction2.getActions())
{
if (action.getActionDefinitionName().equals(CheckOutActionExecuter.NAME) == true)
{
assertEquals(action, action3);
}
else if (action.getActionDefinitionName().equals(CheckInActionExecuter.NAME) == true)
{
assertEquals(action, action2);
assertEquals("description", action2.getParameterValue(CheckInActionExecuter.PARAM_DESCRIPTION));
}
else
{
fail("We have an action here we are not expecting.");
}
}
}
/**
* Test remove action
*/
public void testRemove()
{
assertEquals(0, this.actionService.getActions(this.nodeRef).size());
Action action1 = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
this.actionService.saveAction(this.nodeRef, action1);
Action action2 = this.actionService.createAction(CheckInActionExecuter.NAME);
this.actionService.saveAction(this.nodeRef, action2);
assertEquals(2, this.actionService.getActions(this.nodeRef).size());
this.actionService.removeAction(this.nodeRef, action1);
assertEquals(1, this.actionService.getActions(this.nodeRef).size());
this.actionService.removeAllActions(this.nodeRef);
assertEquals(0, this.actionService.getActions(this.nodeRef).size());
}
public void testConditionOrder()
{
Action action = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
String actionId = action.getId();
ActionCondition condition1 = this.actionService.createActionCondition(NoConditionEvaluator.NAME);
ActionCondition condition2 = this.actionService.createActionCondition(NoConditionEvaluator.NAME);
action.addActionCondition(condition1);
action.addActionCondition(condition2);
this.actionService.saveAction(this.nodeRef, action);
Action savedAction = this.actionService.getAction(this.nodeRef, actionId);
// Check that the conditions have been retrieved in the correct order
assertNotNull(savedAction);
assertEquals(condition1, savedAction.getActionCondition(0));
assertEquals(condition2, savedAction.getActionCondition(1));
ActionCondition condition3 = this.actionService.createActionCondition(NoConditionEvaluator.NAME);
ActionCondition condition4 = this.actionService.createActionCondition(NoConditionEvaluator.NAME);
// Update the conditions on the action
savedAction.removeActionCondition(condition1);
savedAction.addActionCondition(condition3);
savedAction.addActionCondition(condition4);
this.actionService.saveAction(this.nodeRef, savedAction);
Action savedAction2 = this.actionService.getAction(this.nodeRef, actionId);
// Check that the conditions are still in the correct order
assertNotNull(savedAction2);
assertEquals(condition2, savedAction2.getActionCondition(0));
assertEquals(condition3, savedAction2.getActionCondition(1));
assertEquals(condition4, savedAction2.getActionCondition(2));
}
public void testActionOrder()
{
CompositeAction action = this.actionService.createCompositeAction();
String actionId = action.getId();
Action action1 = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
Action action2 = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
action.addAction(action1);
action.addAction(action2);
this.actionService.saveAction(this.nodeRef, action);
CompositeAction savedAction = (CompositeAction)this.actionService.getAction(this.nodeRef, actionId);
// Check that the conditions have been retrieved in the correct order
assertNotNull(savedAction);
assertEquals(action1, savedAction.getAction(0));
assertEquals(action2, savedAction.getAction(1));
Action action3 = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
Action action4 = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
// Update the conditions on the action
savedAction.removeAction(action1);
savedAction.addAction(action3);
savedAction.addAction(action4);
this.actionService.saveAction(this.nodeRef, savedAction);
CompositeAction savedAction2 = (CompositeAction)this.actionService.getAction(this.nodeRef, actionId);
// Check that the conditions are still in the correct order
assertNotNull(savedAction2);
assertEquals(action2, savedAction2.getAction(0));
assertEquals(action3, savedAction2.getAction(1));
assertEquals(action4, savedAction2.getAction(2));
}
/** ===================================================================================
* Test asynchronous actions
*/
/**
* Test asynchronous execute action
*/
public void testAsyncExecuteAction()
{
assertFalse(this.nodeService.hasAspect(this.nodeRef, ContentModel.ASPECT_VERSIONABLE));
Action action = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
action.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_VERSIONABLE);
action.setExecuteAsynchronously(true);
this.actionService.executeAction(action, this.nodeRef);
setComplete();
endTransaction();
final NodeService finalNodeService = this.nodeService;
final NodeRef finalNodeRef = this.nodeRef;
postAsyncActionTest(
this.transactionService,
1000,
10,
new AsyncTest()
{
public boolean executeTest()
{
return (
finalNodeService.hasAspect(finalNodeRef, ContentModel.ASPECT_VERSIONABLE));
};
});
}
/**
* Test async composite action execution
*/
public void testAsyncCompositeActionExecute()
{
// Create the composite action
Action action1 = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
action1.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_LOCKABLE);
Action action2 = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
action2.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_VERSIONABLE);
CompositeAction compAction = this.actionService.createCompositeAction();
compAction.setTitle("title");
compAction.setDescription("description");
compAction.addAction(action1);
compAction.addAction(action2);
compAction.setExecuteAsynchronously(true);
// Execute the composite action
this.actionService.executeAction(compAction, this.nodeRef);
setComplete();
endTransaction();
final NodeService finalNodeService = this.nodeService;
final NodeRef finalNodeRef = this.nodeRef;
postAsyncActionTest(
this.transactionService,
1000,
10,
new AsyncTest()
{
public boolean executeTest()
{
return (
finalNodeService.hasAspect(finalNodeRef, ContentModel.ASPECT_VERSIONABLE) &&
finalNodeService.hasAspect(finalNodeRef, ContentModel.ASPECT_LOCKABLE));
};
});
}
public void xtestAsyncLoadTest()
{
// TODO this is very weak .. how do we improve this ???
Action action = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
action.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_VERSIONABLE);
action.setExecuteAsynchronously(true);
for (int i = 0; i < 1000; i++)
{
this.actionService.executeAction(action, this.nodeRef);
}
setComplete();
endTransaction();
// TODO how do we assess whether the large number of actions stacked cause a problem ??
}
/**
*
* @param sleepTime
* @param maxTries
* @param test
* @param context
*/
public static void postAsyncActionTest(
TransactionService transactionService,
final long sleepTime,
final int maxTries,
final AsyncTest test)
{
try
{
int tries = 0;
boolean done = false;
while (done == false && tries < maxTries)
{
try
{
// Increment the tries counter
tries++;
// Sleep for a bit
Thread.sleep(sleepTime);
done = (TransactionUtil.executeInUserTransaction(
transactionService,
new TransactionUtil.TransactionWork<Boolean>()
{
public Boolean doWork()
{
// See if the action has been performed
boolean done = test.executeTest();
return done;
}
})).booleanValue();
}
catch (InterruptedException e)
{
// Do nothing
e.printStackTrace();
}
}
if (done == false)
{
throw new RuntimeException("Asynchronous action was not executed.");
}
}
catch (Throwable exception)
{
exception.printStackTrace();
fail("An exception was encountered whilst checking the async action was executed: " + exception.getMessage());
}
}
/**
* Async test interface
*/
public interface AsyncTest
{
boolean executeTest();
}
/** ===================================================================================
* Test failure behaviour
*/
/**
* Test sync failure behaviour
*/
public void testSyncFailureBehaviour()
{
// Create an action that is going to fail
Action action = this.actionService.createAction(MoveActionExecuter.NAME);
action.setParameterValue(MoveActionExecuter.PARAM_ASSOC_TYPE_QNAME, ContentModel.ASSOC_CHILDREN);
action.setParameterValue(MoveActionExecuter.PARAM_ASSOC_QNAME, ContentModel.ASSOC_CHILDREN);
// Create a bad node ref
NodeRef badNodeRef = new NodeRef(this.storeRef, "123123");
action.setParameterValue(MoveActionExecuter.PARAM_DESTINATION_FOLDER, badNodeRef);
try
{
this.actionService.executeAction(action, this.nodeRef);
// Fail if we get there since the exception should have been raised
fail("An exception should have been raised.");
}
catch (RuntimeException exception)
{
// Good! The exception was raised correctly
}
// Test what happens when a element of a composite action fails (should raise and bubble up to parent bahviour)
// Create the composite action
Action action1 = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
action1.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_LOCKABLE);
Action action2 = this.actionService.createAction(AddFeaturesActionExecuter.NAME);
action2.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, QName.createQName("{test}badDogAspect"));
CompositeAction compAction = this.actionService.createCompositeAction();
compAction.setTitle("title");
compAction.setDescription("description");
compAction.addAction(action1);
compAction.addAction(action2);
try
{
// Execute the composite action
this.actionService.executeAction(compAction, this.nodeRef);
fail("An exception should have been raised here !!");
}
catch (RuntimeException runtimeException)
{
// Good! The exception was raised
}
}
/**
* Test the compensating action
*/
public void testCompensatingAction()
{
// Create an action that is going to fail
final Action action = this.actionService.createAction(MoveActionExecuter.NAME);
action.setParameterValue(MoveActionExecuter.PARAM_ASSOC_TYPE_QNAME, ContentModel.ASSOC_CHILDREN);
action.setParameterValue(MoveActionExecuter.PARAM_ASSOC_QNAME, ContentModel.ASSOC_CHILDREN);
// Create a bad node ref
NodeRef badNodeRef = new NodeRef(this.storeRef, "123123");
action.setParameterValue(MoveActionExecuter.PARAM_DESTINATION_FOLDER, badNodeRef);
action.setTitle("title");
// Create the compensating action
Action compensatingAction = actionService.createAction(AddFeaturesActionExecuter.NAME);
compensatingAction.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_CLASSIFIABLE);
compensatingAction.setTitle("title");
action.setCompensatingAction(compensatingAction);
// Set the action to execute asynchronously
action.setExecuteAsynchronously(true);
this.actionService.executeAction(action, this.nodeRef);
setComplete();
endTransaction();
postAsyncActionTest(
this.transactionService,
1000,
10,
new AsyncTest()
{
public boolean executeTest()
{
return (
ActionServiceImplTest.this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_CLASSIFIABLE));
};
});
// Modify the compensating action so that it will also fail
compensatingAction.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, QName.createQName("{test}badAspect"));
TransactionUtil.executeInUserTransaction(
this.transactionService,
new TransactionUtil.TransactionWork<Object>()
{
public Object doWork()
{
try
{
ActionServiceImplTest.this.actionService.executeAction(action, ActionServiceImplTest.this.nodeRef);
}
catch (RuntimeException exception)
{
// The exception should have been ignored and execution continued
exception.printStackTrace();
fail("An exception should not have been raised here.");
}
return null;
}
});
}
}

View File

@@ -0,0 +1,69 @@
/*
* 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.action;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.alfresco.repo.action.evaluator.CompareMimeTypeEvaluatorTest;
import org.alfresco.repo.action.evaluator.ComparePropertyValueEvaluatorTest;
import org.alfresco.repo.action.evaluator.HasAspectEvaluatorTest;
import org.alfresco.repo.action.evaluator.IsSubTypeEvaluatorTest;
import org.alfresco.repo.action.executer.AddFeaturesActionExecuterTest;
import org.alfresco.repo.action.executer.ContentMetadataExtracterTest;
import org.alfresco.repo.action.executer.SetPropertyValueActionExecuterTest;
import org.alfresco.repo.action.executer.SpecialiseTypeActionExecuterTest;
/**
* Version test suite
*
* @author Roy Wetherall
*/
public class ActionTestSuite extends TestSuite
{
/**
* Creates the test suite
*
* @return the test suite
*/
public static Test suite()
{
TestSuite suite = new TestSuite();
suite.addTestSuite(ParameterDefinitionImplTest.class);
suite.addTestSuite(ActionDefinitionImplTest.class);
suite.addTestSuite(ActionConditionDefinitionImplTest.class);
suite.addTestSuite(ActionImplTest.class);
suite.addTestSuite(ActionConditionImplTest.class);
suite.addTestSuite(CompositeActionImplTest.class);
suite.addTestSuite(ActionServiceImplTest.class);
// Test evaluators
suite.addTestSuite(IsSubTypeEvaluatorTest.class);
suite.addTestSuite(ComparePropertyValueEvaluatorTest.class);
suite.addTestSuite(CompareMimeTypeEvaluatorTest.class);
suite.addTestSuite(HasAspectEvaluatorTest.class);
// Test executors
suite.addTestSuite(SetPropertyValueActionExecuterTest.class);
suite.addTestSuite(AddFeaturesActionExecuterTest.class);
suite.addTestSuite(ContentMetadataExtracterTest.class);
suite.addTestSuite(SpecialiseTypeActionExecuterTest.class);
return suite;
}
}

View File

@@ -0,0 +1,124 @@
/*
* 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.action;
import org.alfresco.repo.action.ActionServiceImpl.PendingAction;
import org.alfresco.repo.transaction.TransactionListener;
import org.alfresco.util.GUID;
/**
* The action service transaction listener
*
* @author Roy Wetherall
*/
public class ActionTransactionListener implements TransactionListener
{
/**
* Id used in equals and hash
*/
private String id = GUID.generate();
/**
* The action service (runtime interface)
*/
private RuntimeActionService actionService;
/**
* Constructor
*
* @param actionService the action service
*/
public ActionTransactionListener(RuntimeActionService actionService)
{
this.actionService = actionService;
}
/**
* @see org.alfresco.repo.transaction.TransactionListener#flush()
*/
public void flush()
{
}
/**
* @see org.alfresco.repo.transaction.TransactionListener#beforeCommit(boolean)
*/
public void beforeCommit(boolean readOnly)
{
}
/**
* @see org.alfresco.repo.transaction.TransactionListener#beforeCompletion()
*/
public void beforeCompletion()
{
}
/**
* @see org.alfresco.repo.transaction.TransactionListener#afterCommit()
*/
public void afterCommit()
{
for (PendingAction pendingAction : this.actionService.getPostTransactionPendingActions())
{
this.actionService.getAsynchronousActionExecutionQueue().executeAction(
actionService,
pendingAction.getAction(),
pendingAction.getActionedUponNodeRef(),
pendingAction.getCheckConditions(),
pendingAction.getActionChain());
}
}
/**
* @see org.alfresco.repo.transaction.TransactionListener#afterRollback()
*/
public void afterRollback()
{
}
/**
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode()
{
return this.id.hashCode();
}
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj)
{
if (this == obj)
{
return true;
}
if (obj instanceof ActionTransactionListener)
{
ActionTransactionListener that = (ActionTransactionListener) obj;
return (this.id.equals(that.id));
}
else
{
return false;
}
}
}

View File

@@ -0,0 +1,161 @@
/*
* 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.action;
import java.util.List;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.policy.Behaviour;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.policy.PolicyScope;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.rule.RuleService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
/**
* Class containing behaviour for the actions aspect
*
* @author Roy Wetherall
*/
public class ActionsAspect
{
private Behaviour onAddAspectBehaviour;
private PolicyComponent policyComponent;
private RuleService ruleService;
private NodeService nodeService;
public void setPolicyComponent(PolicyComponent policyComponent)
{
this.policyComponent = policyComponent;
}
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void setRuleService(RuleService ruleService)
{
this.ruleService = ruleService;
}
public void init()
{
this.policyComponent.bindClassBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, "onCopyNode"),
ActionModel.ASPECT_ACTIONS,
new JavaBehaviour(this, "onCopyNode"));
this.policyComponent.bindClassBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, "onCopyComplete"),
ActionModel.ASPECT_ACTIONS,
new JavaBehaviour(this, "onCopyComplete"));
this.onAddAspectBehaviour = new JavaBehaviour(this, "onAddAspect");
this.policyComponent.bindClassBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, "onAddAspect"),
ActionModel.ASPECT_ACTIONS,
onAddAspectBehaviour);
}
/**
* Helper to diable the on add aspect policy behaviour. Helpful when importing,
* copying and other bulk respstorative operations.
*
* TODO will eventually be redundant when policies can be enabled/diabled in the
* policy componenet
*/
public void disbleOnAddAspect()
{
this.onAddAspectBehaviour.disable();
}
/**
* Helper to enable the on add aspect policy behaviour. Helpful when importing,
* copying and other bulk respstorative operations.
*
* TODO will eventually be redundant when policies can be enabled/diabled in the
* policy componenet
*/
public void enableOnAddAspect()
{
this.onAddAspectBehaviour.enable();
}
/**
* On add aspect policy behaviour
* @param nodeRef
* @param aspectTypeQName
*/
public void onAddAspect(NodeRef nodeRef, QName aspectTypeQName)
{
this.ruleService.disableRules(nodeRef);
try
{
this.nodeService.createNode(
nodeRef,
ActionModel.ASSOC_ACTION_FOLDER,
ActionModel.ASSOC_ACTION_FOLDER,
ContentModel.TYPE_SYSTEM_FOLDER);
}
finally
{
this.ruleService.enableRules(nodeRef);
}
}
public void onCopyNode(
QName classRef,
NodeRef sourceNodeRef,
StoreRef destinationStoreRef,
boolean copyToNewNode,
PolicyScope copyDetails)
{
copyDetails.addAspect(ActionModel.ASPECT_ACTIONS);
List<ChildAssociationRef> assocs = this.nodeService.getChildAssocs(
sourceNodeRef,
RegexQNamePattern.MATCH_ALL,
ActionModel.ASSOC_ACTION_FOLDER);
for (ChildAssociationRef assoc : assocs)
{
copyDetails.addChildAssociation(classRef, assoc, true);
}
this.onAddAspectBehaviour.disable();
}
public void onCopyComplete(
QName classRef,
NodeRef sourceNodeRef,
NodeRef destinationRef,
Map<NodeRef, NodeRef> copyMap)
{
this.onAddAspectBehaviour.enable();
}
}

View File

@@ -0,0 +1,44 @@
/*
* 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.action;
import java.util.Set;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Asynchronous action execution queue
*
* @author Roy Wetherall
*/
public interface AsynchronousActionExecutionQueue
{
/**
*
* @param actionedUponNodeRef
* @param action
* @param checkConditions
*/
void executeAction(
RuntimeActionService actionService,
Action action,
NodeRef actionedUponNodeRef,
boolean checkConditions,
Set<String> actionChain);
}

View File

@@ -0,0 +1,297 @@
/*
* 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.action;
import java.util.Set;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.transaction.TransactionUtil;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.transaction.TransactionService;
/**
* The asynchronous action execution queue implementation
*
* @author Roy Wetherall
*/
public class AsynchronousActionExecutionQueueImpl extends ThreadPoolExecutor implements
AsynchronousActionExecutionQueue
{
/**
* Default pool values
*/
private static final int CORE_POOL_SIZE = 2;
private static final int MAX_POOL_SIZE = 5;
private static final long KEEP_ALIVE = 30;
private static final TimeUnit TIME_UNIT = TimeUnit.SECONDS;
private static final int MAX_QUEUE_SIZE = 500;
/**
* The transaction service
*/
private TransactionService transactionService;
/**
* The authentication component
*/
private AuthenticationComponent authenticationComponent;
/**
* Default constructor
*/
public AsynchronousActionExecutionQueueImpl()
{
super(CORE_POOL_SIZE, MAX_POOL_SIZE, KEEP_ALIVE, TIME_UNIT, new ArrayBlockingQueue<Runnable>(MAX_QUEUE_SIZE,
true));
}
/**
* Set the transaction service
*
* @param transactionService
* the transaction service
*/
public void setTransactionService(TransactionService transactionService)
{
this.transactionService = transactionService;
}
/**
* Set the authentication component
*
* @param authenticationComponent
* the authentication component
*/
public void setAuthenticationComponent(AuthenticationComponent authenticationComponent)
{
this.authenticationComponent = authenticationComponent;
}
/**
* @see org.alfresco.repo.action.AsynchronousActionExecutionQueue#executeAction(org.alfresco.service.cmr.repository.NodeRef,
* org.alfresco.service.cmr.action.Action, boolean)
*/
public void executeAction(RuntimeActionService actionService, Action action, NodeRef actionedUponNodeRef,
boolean checkConditions, Set<String> actionChain)
{
executeAction(actionService, action, actionedUponNodeRef, checkConditions, actionChain, null);
}
/**
* @see org.alfresco.repo.action.AsynchronousActionExecutionQueue#executeAction(org.alfresco.service.cmr.repository.NodeRef,
* org.alfresco.service.cmr.action.Action, boolean,
* org.alfresco.service.cmr.repository.NodeRef)
*/
public void executeAction(RuntimeActionService actionService, Action action, NodeRef actionedUponNodeRef,
boolean checkConditions, Set<String> actionChain, NodeRef actionExecutionHistoryNodeRef)
{
execute(new ActionExecutionWrapper(actionService, transactionService, authenticationComponent, action,
actionedUponNodeRef, checkConditions, actionExecutionHistoryNodeRef, actionChain));
}
/**
* @see java.util.concurrent.ThreadPoolExecutor#beforeExecute(java.lang.Thread,
* java.lang.Runnable)
*/
@Override
protected void beforeExecute(Thread thread, Runnable runnable)
{
super.beforeExecute(thread, runnable);
}
/**
* @see java.util.concurrent.ThreadPoolExecutor#afterExecute(java.lang.Runnable,
* java.lang.Throwable)
*/
@Override
protected void afterExecute(Runnable thread, Throwable runnable)
{
super.afterExecute(thread, runnable);
}
/**
* Runnable class to wrap the execution of the action.
*/
private class ActionExecutionWrapper implements Runnable
{
/**
* Runtime action service
*/
private RuntimeActionService actionService;
/**
* The transaction service
*/
private TransactionService transactionService;
/**
* The authentication component
*/
private AuthenticationComponent authenticationComponent;
/**
* The action
*/
private Action action;
/**
* The actioned upon node reference
*/
private NodeRef actionedUponNodeRef;
/**
* The check conditions value
*/
private boolean checkConditions;
/**
* The action execution history node reference
*/
private NodeRef actionExecutionHistoryNodeRef;
/**
* The action chain
*/
private Set<String> actionChain;
/**
* Constructor
*
* @param actionService
* @param transactionService
* @param authenticationComponent
* @param action
* @param actionedUponNodeRef
* @param checkConditions
* @param actionExecutionHistoryNodeRef
*/
public ActionExecutionWrapper(RuntimeActionService actionService, TransactionService transactionService,
AuthenticationComponent authenticationComponent, Action action, NodeRef actionedUponNodeRef,
boolean checkConditions, NodeRef actionExecutionHistoryNodeRef, Set<String> actionChain)
{
this.actionService = actionService;
this.transactionService = transactionService;
this.authenticationComponent = authenticationComponent;
this.actionedUponNodeRef = actionedUponNodeRef;
this.action = action;
this.checkConditions = checkConditions;
this.actionExecutionHistoryNodeRef = actionExecutionHistoryNodeRef;
this.actionChain = actionChain;
}
/**
* Get the action
*
* @return the action
*/
public Action getAction()
{
return this.action;
}
/**
* Get the actioned upon node reference
*
* @return the actioned upon node reference
*/
public NodeRef getActionedUponNodeRef()
{
return this.actionedUponNodeRef;
}
/**
* Get the check conditions value
*
* @return the check conditions value
*/
public boolean getCheckCondtions()
{
return this.checkConditions;
}
/**
* Get the action execution history node reference
*
* @return the action execution history node reference
*/
public NodeRef getActionExecutionHistoryNodeRef()
{
return this.actionExecutionHistoryNodeRef;
}
/**
* Get the action chain
*
* @return the action chain
*/
public Set<String> getActionChain()
{
return actionChain;
}
/**
* Executes the action via the action runtime service
*
* @see java.lang.Runnable#run()
*/
@SuppressWarnings("unchecked")
public void run()
{
try
{
// For now run all actions in the background as the system user
ActionExecutionWrapper.this.authenticationComponent
.setCurrentUser(ActionExecutionWrapper.this.authenticationComponent.getSystemUserName());
try
{
TransactionUtil.executeInNonPropagatingUserTransaction(this.transactionService,
new TransactionUtil.TransactionWork()
{
public Object doWork()
{
ActionExecutionWrapper.this.actionService.executeActionImpl(
ActionExecutionWrapper.this.action,
ActionExecutionWrapper.this.actionedUponNodeRef,
ActionExecutionWrapper.this.checkConditions, true,
ActionExecutionWrapper.this.actionChain);
return null;
}
});
}
finally
{
ActionExecutionWrapper.this.authenticationComponent.clearCurrentSecurityContext();
}
}
catch (Throwable exception)
{
exception.printStackTrace();
}
}
}
}

View File

@@ -0,0 +1,106 @@
/*
* 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.action;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.namespace.QName;
/**
* @author Roy Wetherall
*/
public abstract class BaseParameterizedItemDefinitionImplTest extends TestCase
{
protected static final String NAME = "name";
protected static final String TITLE = "title";
protected static final String DESCRIPTION = "description";
protected List<ParameterDefinition> paramDefs = new ArrayList<ParameterDefinition>();
protected List<ParameterDefinition> duplicateParamDefs = new ArrayList<ParameterDefinition>();
private static final String PARAM1_DISPLAYNAME = "param1-displayname";
private static final String PARAM1_NAME = "param1-name";
private static final QName PARAM1_TYPE = DataTypeDefinition.TEXT;
private static final QName PARAM2_TYPE = DataTypeDefinition.TEXT;
private static final String PARAM2_DISPLAYNAME = "param2-displaname";
private static final String PARAM2_NAME = "param2-name";
@Override
protected void setUp() throws Exception
{
// Create param def lists
this.paramDefs.add(new ParameterDefinitionImpl(PARAM1_NAME, PARAM1_TYPE, false, PARAM1_DISPLAYNAME));
this.paramDefs.add(new ParameterDefinitionImpl(PARAM2_NAME, PARAM2_TYPE, false, PARAM2_DISPLAYNAME));
this.duplicateParamDefs.add(new ParameterDefinitionImpl(PARAM1_NAME, PARAM1_TYPE, false, PARAM1_DISPLAYNAME));
this.duplicateParamDefs.add(new ParameterDefinitionImpl(PARAM1_NAME, PARAM1_TYPE, false, PARAM1_DISPLAYNAME));
}
public void testConstructor()
{
create();
}
protected abstract ParameterizedItemDefinitionImpl create();
public void testGetName()
{
ParameterizedItemDefinitionImpl temp = create();
assertEquals(NAME, temp.getName());
}
public void testGetParameterDefintions()
{
ParameterizedItemDefinitionImpl temp = create();
List<ParameterDefinition> params = temp.getParameterDefinitions();
assertNotNull(params);
assertEquals(2, params.size());
int i = 0;
for (ParameterDefinition definition : params)
{
if (i == 0)
{
assertEquals(PARAM1_NAME, definition.getName());
assertEquals(PARAM1_TYPE, definition.getType());
assertEquals(PARAM1_DISPLAYNAME, definition.getDisplayLabel());
}
else
{
assertEquals(PARAM2_NAME, definition.getName());
assertEquals(PARAM2_TYPE, definition.getType());
assertEquals(PARAM2_DISPLAYNAME, definition.getDisplayLabel());
}
i++;
}
}
public void testGetParameterDefinition()
{
ParameterizedItemDefinitionImpl temp = create();
ParameterDefinition definition = temp.getParameterDefintion(PARAM1_NAME);
assertNotNull(definition);
assertEquals(PARAM1_NAME, definition.getName());
assertEquals(PARAM1_TYPE, definition.getType());
assertEquals(PARAM1_DISPLAYNAME, definition.getDisplayLabel());
ParameterDefinition nullDef = temp.getParameterDefintion("bobbins");
assertNull(nullDef);
}
}

View File

@@ -0,0 +1,110 @@
/*
* 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.action;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import junit.framework.TestCase;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
/**
* @author Roy Wetherall
*/
public abstract class BaseParameterizedItemImplTest extends TestCase
{
protected List<ParameterDefinition> paramDefs = new ArrayList<ParameterDefinition>();
protected Map<String, Serializable> paramValues = new HashMap<String, Serializable>();
protected static final String ID = "id";
protected static final String NAME = "name";
protected static final String TITLE = "title";
protected static final String DESCRIPTION = "description";
private static final String PARAM_1 = "param1";
private static final String VALUE_1 = "value1";
private static final String PARAM_2 = "param2";
private static final String VALUE_2 = "value2";
private static final String PARAM_DISPLAYLABEL = "displayLabel";
@Override
protected void setUp() throws Exception
{
// Create param defs
paramDefs.add(new ParameterDefinitionImpl(PARAM_1, DataTypeDefinition.TEXT, false, PARAM_DISPLAYLABEL));
paramDefs.add(new ParameterDefinitionImpl(PARAM_2, DataTypeDefinition.TEXT, false, PARAM_DISPLAYLABEL));
// Create param values
paramValues.put(PARAM_1, VALUE_1);
paramValues.put(PARAM_2, VALUE_2);
}
public void testConstructor()
{
create();
}
protected abstract ParameterizedItemImpl create();
public void testGetParameterValues()
{
ParameterizedItemImpl temp = create();
Map<String, Serializable> tempParamValues = temp.getParameterValues();
assertNotNull(tempParamValues);
assertEquals(2, tempParamValues.size());
for (Map.Entry entry : tempParamValues.entrySet())
{
if (entry.getKey() == PARAM_1)
{
assertEquals(VALUE_1, entry.getValue());
}
else if (entry.getKey() == PARAM_2)
{
assertEquals(VALUE_2, entry.getValue());
}
else
{
fail("There is an unexpected entry here.");
}
}
}
public void testGetParameterValue()
{
ParameterizedItemImpl temp = create();
assertNull(temp.getParameterValue("bobbins"));
assertEquals(VALUE_1, temp.getParameterValue(PARAM_1));
}
public void testSetParameterValue()
{
ParameterizedItemImpl temp = create();
temp.setParameterValue("bobbins", "value");
assertEquals("value", temp.getParameterValue("bobbins"));
}
public void testGetId()
{
ParameterizedItemImpl temp = create();
assertEquals(ID, temp.getId());
}
}

View File

@@ -0,0 +1,45 @@
/*
* 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.action;
import org.springframework.beans.factory.BeanNameAware;
// TODO this is no longer required
/**
* Common resouce abstract base class.
*
* @author Roy Wetherall
*/
public abstract class CommonResourceAbstractBase implements BeanNameAware
{
/**
* The bean name
*/
protected String name;
/**
* Set the bean name
*
* @param name
* the bean name
*/
public void setBeanName(String name)
{
this.name = name;
}
}

View File

@@ -0,0 +1,126 @@
/*
* 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.action;
import java.util.ArrayList;
import java.util.List;
import org.alfresco.repo.action.executer.CompositeActionExecuter;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.CompositeAction;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Composite action implementation
*
* @author Roy Wetherall
*/
public class CompositeActionImpl extends ActionImpl implements CompositeAction
{
/**
* Serial version UID
*/
private static final long serialVersionUID = -5348203599304776812L;
/**
* The action list
*/
private List<Action> actions = new ArrayList<Action>();
/**
* Constructor
*
* @param id the action id
*/
public CompositeActionImpl(String id, NodeRef owningNodeRef)
{
super(id, CompositeActionExecuter.NAME, owningNodeRef);
}
/**
* @see org.alfresco.service.cmr.action.CompositeAction#hasActions()
*/
public boolean hasActions()
{
return (this.actions.isEmpty() == false);
}
/**
* @see org.alfresco.service.cmr.action.CompositeAction#addAction(org.alfresco.service.cmr.action.Action)
*/
public void addAction(Action action)
{
this.actions.add(action);
}
/**
* @see org.alfresco.service.cmr.action.CompositeAction#addAction(int, org.alfresco.service.cmr.action.Action)
*/
public void addAction(int index, Action action)
{
this.actions.add(index, action);
}
/**
* @see org.alfresco.service.cmr.action.CompositeAction#setAction(int, org.alfresco.service.cmr.action.Action)
*/
public void setAction(int index, Action action)
{
this.actions.set(index, action);
}
/**
* @see org.alfresco.service.cmr.action.CompositeAction#indexOfAction(org.alfresco.service.cmr.action.Action)
*/
public int indexOfAction(Action action)
{
return this.actions.indexOf(action);
}
/**
* @see org.alfresco.service.cmr.action.CompositeAction#getActions()
*/
public List<Action> getActions()
{
return this.actions;
}
/**
* @see org.alfresco.service.cmr.action.CompositeAction#getAction(int)
*/
public Action getAction(int index)
{
return this.actions.get(index);
}
/**
* @see org.alfresco.service.cmr.action.CompositeAction#removeAction(org.alfresco.service.cmr.action.Action)
*/
public void removeAction(Action action)
{
this.actions.remove(action);
}
/**
* @see org.alfresco.service.cmr.action.CompositeAction#removeAllActions()
*/
public void removeAllActions()
{
this.actions.clear();
}
}

View File

@@ -0,0 +1,108 @@
/*
* 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.action;
import java.util.List;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.CompositeAction;
/**
* Composite action test
*
* @author Roy Wetherall
*/
public class CompositeActionImplTest extends ActionImplTest
{
private static final String ACTION1_ID = "action1Id";
private static final String ACTION2_ID = "action2Id";
private static final String ACTION3_ID = "action3Id";
private static final String ACTION1_NAME = "actionName1";
private static final String ACTION2_NAME = "actionName1";
private static final String ACTION3_NAME = "actionName3";
public void testActions()
{
Action action1 = new ActionImpl(ACTION1_ID, ACTION1_NAME, null);
Action action2 = new ActionImpl(ACTION2_ID, ACTION2_NAME, null);
Action action3 = new ActionImpl(ACTION3_ID, ACTION3_NAME, null);
CompositeAction compositeAction = new CompositeActionImpl(ID, null);
// Check has no action
assertFalse(compositeAction.hasActions());
List<Action> noActions = compositeAction.getActions();
assertNotNull(noActions);
assertEquals(0, noActions.size());
// Add actions
compositeAction.addAction(action1);
compositeAction.addAction(action2);
compositeAction.addAction(action3);
// Check that the actions that are there and in the correct order
assertTrue(compositeAction.hasActions());
List<Action> actions = compositeAction.getActions();
assertNotNull(actions);
assertEquals(3, actions.size());
int counter = 0;
for (Action action : actions)
{
if (counter == 0)
{
assertEquals(action1, action);
}
else if (counter == 1)
{
assertEquals(action2, action);
}
else if (counter == 2)
{
assertEquals(action3, action);
}
counter+=1;
}
assertEquals(action1, compositeAction.getAction(0));
assertEquals(action2, compositeAction.getAction(1));
assertEquals(action3, compositeAction.getAction(2));
// Check remove
compositeAction.removeAction(action3);
assertEquals(2, compositeAction.getActions().size());
// Check set
compositeAction.setAction(1, action3);
assertEquals(action1, compositeAction.getAction(0));
assertEquals(action3, compositeAction.getAction(1));
// Check index of
assertEquals(0, compositeAction.indexOfAction(action1));
assertEquals(1, compositeAction.indexOfAction(action3));
// Test insert
compositeAction.addAction(1, action2);
assertEquals(3, compositeAction.getActions().size());
assertEquals(action1, compositeAction.getAction(0));
assertEquals(action2, compositeAction.getAction(1));
assertEquals(action3, compositeAction.getAction(2));
// Check remote all
compositeAction.removeAllActions();
assertFalse(compositeAction.hasActions());
assertEquals(0, compositeAction.getActions().size());
}
}

View File

@@ -0,0 +1,106 @@
/*
* 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.action;
import java.io.Serializable;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.namespace.QName;
/**
* Parameter definition implementation class.
*
* @author Roy Wetherall
*/
public class ParameterDefinitionImpl implements ParameterDefinition, Serializable
{
/**
* Serial version UID
*/
private static final long serialVersionUID = 3976741384558751799L;
/**
* The name of the parameter
*/
private String name;
/**
* The type of the parameter
*/
private QName type;
/**
* The display label
*/
private String displayLabel;
/**
* Indicates whether it is mandatory for the parameter to be set
*/
private boolean isMandatory = false;
/**
* Constructor
*
* @param name the name of the parameter
* @param type the type of the parameter
* @param displayLabel the display label
*/
public ParameterDefinitionImpl(
String name,
QName type,
boolean isMandatory,
String displayLabel)
{
this.name = name;
this.type = type;
this.displayLabel = displayLabel;
this.isMandatory = isMandatory;
}
/**
* @see org.alfresco.service.cmr.action.ParameterDefinition#getName()
*/
public String getName()
{
return this.name;
}
/**
* @see org.alfresco.service.cmr.action.ParameterDefinition#getType()
*/
public QName getType()
{
return this.type;
}
/**
* @see org.alfresco.service.cmr.action.ParameterDefinition#isMandatory()
*/
public boolean isMandatory()
{
return this.isMandatory;
}
/**
* @see org.alfresco.service.cmr.action.ParameterDefinition#getDisplayLabel()
*/
public String getDisplayLabel()
{
return this.displayLabel;
}
}

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.action;
import junit.framework.TestCase;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
/**
* Parameter definition implementation unit test.
*
* @author Roy Wetherall
*/
public class ParameterDefinitionImplTest extends TestCase
{
private static final String NAME = "param-name";
private static final String DISPLAY_LABEL = "The display label.";
public void testConstructor()
{
create();
}
private ParameterDefinitionImpl create()
{
ParameterDefinitionImpl paramDef = new ParameterDefinitionImpl(
NAME,
DataTypeDefinition.TEXT,
true,
DISPLAY_LABEL);
assertNotNull(paramDef);
return paramDef;
}
public void testGetName()
{
ParameterDefinitionImpl temp = create();
assertEquals(NAME, temp.getName());
}
public void testGetClass()
{
ParameterDefinitionImpl temp = create();
assertEquals(DataTypeDefinition.TEXT, temp.getType());
}
public void testIsMandatory()
{
ParameterDefinitionImpl temp = create();
assertTrue(temp.isMandatory());
}
public void testGetDisplayLabel()
{
ParameterDefinitionImpl temp = create();
assertEquals(DISPLAY_LABEL, temp.getDisplayLabel());
}
}

View File

@@ -0,0 +1,163 @@
/*
* 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.action;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.action.ParameterizedItem;
import org.alfresco.service.cmr.action.ParameterizedItemDefinition;
import org.alfresco.service.cmr.rule.RuleServiceException;
/**
* Rule item abstract base.
* <p>
* Helper base class used by the action exector and condition evaluator implementations.
*
* @author Roy Wetherall
*/
public abstract class ParameterizedItemAbstractBase extends CommonResourceAbstractBase
{
/**
* Error messages
*/
private static final String ERR_MAND_PROP = "A value for the mandatory parameter {0} has not been set on the rule item {1}";
/**
* Look-up constants
*/
private static final String TITLE = "title";
private static final String DESCRIPTION = "description";
private static final String DISPLAY_LABEL = "display-label";
/**
* Action service
*/
protected RuntimeActionService runtimeActionService;
/**
* @return Return a short title and description string
*/
public String toString()
{
StringBuilder sb = new StringBuilder(60);
sb.append("ParameterizedItem")
.append("[ title='").append(getTitleKey()).append("'")
.append(", description='").append(getDescriptionKey()).append("'")
.append("]");
return sb.toString();
}
/**
* Gets a list containing the parameter definitions for this rule item.
*
* @return the list of parameter definitions
*/
protected List<ParameterDefinition> getParameterDefintions()
{
List<ParameterDefinition> result = new ArrayList<ParameterDefinition>();
addParameterDefintions(result);
return result;
}
/**
* Adds the parameter definitions to the list
*
* @param paramList the parameter definitions list
*/
protected abstract void addParameterDefintions(List<ParameterDefinition> paramList);
/**
* Sets the action service
*
* @param actionRegistration the action service
*/
public void setRuntimeActionService(RuntimeActionService runtimeActionService)
{
this.runtimeActionService = runtimeActionService;
}
/**
* Gets the title I18N key
*
* @return the title key
*/
protected String getTitleKey()
{
return this.name + "." + TITLE;
}
/**
* Gets the description I18N key
*
* @return the description key
*/
protected String getDescriptionKey()
{
return this.name + "." + DESCRIPTION;
}
/**
* Indicates whether adhoc property definitions are allowed or not
*
* @return true if they are, by default false
*/
protected boolean getAdhocPropertiesAllowed()
{
// By default adhoc properties are not allowed
return false;
}
/**
* Gets the parameter definition display label from the properties file.
*
* @param paramName the name of the parameter
* @return the diaplay label of the parameter
*/
protected String getParamDisplayLabel(String paramName)
{
return I18NUtil.getMessage(this.name + "." + paramName + "." + DISPLAY_LABEL);
}
/**
* Checked whether all the mandatory parameters for the rule item have been assigned.
*
* @param ruleItem the rule item
* @param ruleItemDefinition the rule item definition
*/
protected void checkMandatoryProperties(ParameterizedItem ruleItem, ParameterizedItemDefinition ruleItemDefinition)
{
List<ParameterDefinition> definitions = ruleItemDefinition.getParameterDefinitions();
for (ParameterDefinition definition : definitions)
{
if (definition.isMandatory() == true)
{
// Check that a value has been set for the mandatory parameter
if (ruleItem.getParameterValue(definition.getName()) == null)
{
// Error since a mandatory parameter has a null value
throw new RuleServiceException(
MessageFormat.format(ERR_MAND_PROP, new Object[]{definition.getName(), ruleItemDefinition.getName()}));
}
}
}
}
}

View File

@@ -0,0 +1,213 @@
/*
* 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.action;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.action.ParameterizedItemDefinition;
import org.alfresco.service.cmr.rule.RuleServiceException;
/**
* Rule item implementation class
*
* @author Roy Wetherall
*/
public abstract class ParameterizedItemDefinitionImpl implements ParameterizedItemDefinition, Serializable
{
/**
* The name of the rule item
*/
private String name;
/**
* The title I18N key
*/
private String titleKey;
/**
* The description I18N key
*/
private String descriptionKey;
/**
* Indicates whether adHocProperties are allowed
*/
private boolean adhocPropertiesAllowed = false;
/**
* The list of parameters associated with the rule item
*/
private List<ParameterDefinition> parameterDefinitions = new ArrayList<ParameterDefinition>();
/**
* A map of the parameter definitions by name
*/
private Map<String, ParameterDefinition> paramDefinitionsByName;
/**
* Error messages
*/
private static final String ERR_NAME_DUPLICATION = "The names " +
"given to parameter definitions must be unique within the " +
"scope of the rule item definition.";
/**
* Constructor
*
* @param name the name
*/
public ParameterizedItemDefinitionImpl(String name)
{
this.name = name;
}
/**
* @see org.alfresco.service.cmr.action.ParameterizedItemDefinition#getName()
*/
public String getName()
{
return this.name;
}
/**
* Set the title of the rule item
*
* @param title the title
*/
public void setTitleKey(String title)
{
this.titleKey = title;
}
/**
* @see org.alfresco.service.cmr.action.ParameterizedItemDefinition#getTitle()
*/
public String getTitle()
{
return I18NUtil.getMessage(this.titleKey);
}
/**
* Set the description I18N key
*
* @param descriptionKey the description key
*/
public void setDescriptionKey(String descriptionKey)
{
this.descriptionKey = descriptionKey;
}
/**
* @see org.alfresco.service.cmr.action.ParameterizedItemDefinition#getDescription()
*/
public String getDescription()
{
return I18NUtil.getMessage(this.descriptionKey);
}
/**
* @see org.alfresco.service.cmr.action.ParameterizedItemDefinition#getAdhocPropertiesAllowed()
*/
public boolean getAdhocPropertiesAllowed()
{
return this.adhocPropertiesAllowed;
}
/**
* Set whether adhoc properties are allowed
*
* @param adhocPropertiesAllowed true is adhoc properties are allowed, false otherwise
*/
public void setAdhocPropertiesAllowed(boolean adhocPropertiesAllowed)
{
this.adhocPropertiesAllowed = adhocPropertiesAllowed;
}
/**
* Set the parameter definitions for the rule item
*
* @param parameterDefinitions the parameter definitions
*/
public void setParameterDefinitions(
List<ParameterDefinition> parameterDefinitions)
{
if (hasDuplicateNames(parameterDefinitions) == true)
{
throw new RuleServiceException(ERR_NAME_DUPLICATION);
}
this.parameterDefinitions = parameterDefinitions;
// Create a map of the definitions to use for subsequent calls
this.paramDefinitionsByName = new HashMap<String, ParameterDefinition>(this.parameterDefinitions.size());
for (ParameterDefinition definition : this.parameterDefinitions)
{
this.paramDefinitionsByName.put(definition.getName(), definition);
}
}
/**
* Determines whether the list of parameter defintions contains duplicate
* names of not.
*
* @param parameterDefinitions a list of parmeter definitions
* @return true if there are name duplications, false
* otherwise
*/
private boolean hasDuplicateNames(List<ParameterDefinition> parameterDefinitions)
{
boolean result = false;
if (parameterDefinitions != null)
{
HashSet<String> temp = new HashSet<String>(parameterDefinitions.size());
for (ParameterDefinition definition : parameterDefinitions)
{
temp.add(definition.getName());
}
result = (parameterDefinitions.size() != temp.size());
}
return result;
}
/**
* @see org.alfresco.service.cmr.action.ParameterizedItemDefinition#getParameterDefinitions()
*/
public List<ParameterDefinition> getParameterDefinitions()
{
return this.parameterDefinitions;
}
/**
* @see org.alfresco.service.cmr.action.ParameterizedItemDefinition#getParameterDefintion(java.lang.String)
*/
public ParameterDefinition getParameterDefintion(String name)
{
ParameterDefinition result = null;
if (paramDefinitionsByName != null)
{
result = this.paramDefinitionsByName.get(name);
}
return result;
}
}

View File

@@ -0,0 +1,150 @@
/*
* 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.action;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.cmr.action.ParameterizedItem;
/**
* Rule item instance implementation class.
*
* @author Roy Wetherall
*/
public abstract class ParameterizedItemImpl implements ParameterizedItem, Serializable
{
/**
* The id
*/
private String id;
/**
* The parameter values
*/
private Map<String, Serializable> parameterValues = new HashMap<String, Serializable>();
/**
* Constructor
*
* @param ruleItem the rule item
*/
public ParameterizedItemImpl(String id)
{
this(id, null);
}
/**
* Constructor
*
* @param ruleItem the rule item
* @param parameterValues the parameter values
*/
public ParameterizedItemImpl(String id, Map<String, Serializable> parameterValues)
{
// Set the action id
this.id = id;
if (parameterValues != null)
{
// TODO need to check that the parameter values being set correspond
// correctly to the parameter definions on the rule item defintion
this.parameterValues = parameterValues;
}
}
/**
* @see org.alfresco.service.cmr.action.ParameterizedItem#getId()
*/
public String getId()
{
return this.id;
}
/**
* @see org.alfresco.service.cmr.action.ParameterizedItem#getParameterValues()
*/
public Map<String, Serializable> getParameterValues()
{
Map<String, Serializable> result = this.parameterValues;
if (result == null)
{
result = new HashMap<String, Serializable>();
}
return result;
}
/**
* @see org.alfresco.service.cmr.action.ParameterizedItem#getParameterValue(String)
*/
public Serializable getParameterValue(String name)
{
return this.parameterValues.get(name);
}
/**
* @see org.alfresco.service.cmr.action.ParameterizedItem#setParameterValues(java.util.Map)
*/
public void setParameterValues(Map<String, Serializable> parameterValues)
{
if (parameterValues != null)
{
// TODO need to check that the parameter values being set correspond
// correctly to the parameter definions on the rule item defintion
this.parameterValues = parameterValues;
}
}
/**
* @see org.alfresco.service.cmr.action.ParameterizedItem#setParameterValue(String, Serializable)
*/
public void setParameterValue(String name, Serializable value)
{
this.parameterValues.put(name, value);
}
/**
* Hash code implementation
*/
@Override
public int hashCode()
{
return this.id.hashCode();
}
/**
* Equals implementation
*/
@Override
public boolean equals(Object obj)
{
if (this == obj)
{
return true;
}
if (obj instanceof ParameterizedItemImpl)
{
ParameterizedItemImpl that = (ParameterizedItemImpl) obj;
return (this.id.equals(that.id));
}
else
{
return false;
}
}
}

View File

@@ -0,0 +1,66 @@
/*
* 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.action;
import java.util.List;
import java.util.Set;
import org.alfresco.repo.action.ActionServiceImpl.PendingAction;
import org.alfresco.repo.action.evaluator.ActionConditionEvaluator;
import org.alfresco.repo.action.executer.ActionExecuter;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.CompositeAction;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* @author Roy Wetherall
*/
public interface RuntimeActionService
{
AsynchronousActionExecutionQueue getAsynchronousActionExecutionQueue();
void registerActionConditionEvaluator(ActionConditionEvaluator actionConditionEvaluator);
void registerActionExecuter(ActionExecuter actionExecuter);
void populateCompositeAction(NodeRef compositeNodeRef, CompositeAction compositeAction);
/**
* Save action, used internally to store the details of an action on the aciton node.
*
* @param actionNodeRef the action node reference
* @param action the action
*/
void saveActionImpl(NodeRef owningNodeRef, NodeRef actionNodeRef, Action action);
/**
*
* @param action
* @param actionedUponNodeRef
* @param checkConditions
*/
public void executeActionImpl(
Action action,
NodeRef actionedUponNodeRef,
boolean checkConditions,
boolean executedAsynchronously,
Set<String> actionChain);
public void directActionExecution(Action action, NodeRef actionedUponNodeRef);
public List<PendingAction> getPostTransactionPendingActions();
}

View File

@@ -0,0 +1,199 @@
<model name="act:actionmodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
<description>Alfresco Action Model</description>
<author>Alfresco</author>
<published>2005-08-16</published>
<version>0.1</version>
<imports>
<import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
<import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
<import uri="http://www.alfresco.org/model/application/1.0" prefix="app"/>
</imports>
<namespaces>
<namespace uri="http://www.alfresco.org/model/action/1.0" prefix="act"/>
</namespaces>
<types>
<!-- Action, conditions and rules -->
<type name="act:actionbase">
<title>Action Base Type</title>
<parent>cm:cmobject</parent>
<properties>
<property name="act:definitionName">
<type>d:text</type>
<mandatory>true</mandatory>
</property>
</properties>
<associations>
<child-association name="act:parameters">
<target>
<class>act:actionparameter</class>
<mandatory>false</mandatory>
<many>true</many>
</target>
</child-association>
</associations>
</type>
<type name="act:action">
<title>Action</title>
<parent>act:actionbase</parent>
<properties>
<property name="act:actionTitle">
<type>d:text</type>
<mandatory>false</mandatory>
</property>
<property name="act:actionDescription">
<type>d:text</type>
<mandatory>false</mandatory>
</property>
<property name="act:executeAsynchronously">
<type>d:boolean</type>
<mandatory>true</mandatory>
</property>
<property name="act:runAsUser">
<type>d:text</type>
<mandatory>false</mandatory>
</property>
<property name="act:runAsPassword">
<type>d:text</type>
<mandatory>false</mandatory>
</property>
</properties>
<associations>
<child-association name="act:conditions">
<target>
<class>act:actioncondition</class>
<mandatory>false</mandatory>
<many>true</many>
</target>
</child-association>
<child-association name="act:compensatingAction">
<target>
<class>act:action</class>
<mandatory>false</mandatory>
<many>false</many>
</target>
</child-association>
</associations>
</type>
<type name="act:actioncondition">
<title>Action Condition</title>
<parent>act:actionbase</parent>
<properties>
<property name="act:invert">
<type>d:boolean</type>
<mandatory>true</mandatory>
</property>
</properties>
</type>
<type name="act:actionparameter">
<title>Action/Condition Parameter</title>
<parent>cm:cmobject</parent>
<properties>
<property name="act:parameterName">
<type>d:text</type>
<mandatory>true</mandatory>
</property>
<property name="act:parameterValue">
<type>d:any</type>
<mandatory>true</mandatory>
</property>
</properties>
</type>
<type name="act:compositeaction">
<title>Composite Action</title>
<parent>act:action</parent>
<associations>
<child-association name="act:actions">
<target>
<class>act:action</class>
<mandatory>true</mandatory>
<many>true</many>
</target>
</child-association>
</associations>
</type>
<type name="act:savedactionfolder">
<title>Saved Action Folder</title>
<parent>cm:systemfolder</parent>
<associations>
<child-association name="act:savedActions">
<target>
<class>act:action</class>
<mandatory>true</mandatory>
<many>true</many>
</target>
</child-association>
</associations>
</type>
<!-- This type has been deprecated: for backwards compatibility only -->
<type name="act:actionexecutiondetails">
<title>Action Execution Details</title>
<parent>cm:cmobject</parent>
<properties>
<property name="act:actionExecutionTitle">
<type>d:text</type>
<mandatory>false</mandatory>
</property>
<property name="act:executionStatus">
<type>d:text</type>
<mandatory>true</mandatory>
</property>
<property name="act:errorMessage">
<type>d:text</type>
<mandatory>false</mandatory>
</property>
<property name="act:errorDetails">
<type>d:text</type>
<mandatory>false</mandatory>
</property>
</properties>
</type>
</types>
<aspects>
<aspect name="act:actions">
<title>Rules</title>
<associations>
<child-association name="act:actionFolder">
<target>
<class>cm:systemfolder</class>
<mandatory>false</mandatory>
<many>false</many>
</target>
</child-association>
</associations>
</aspect>
<!-- This type has been deprecated: for backwards compatibility only -->
<aspect name="act:actionexecutionhistory">
<title>Action Execution History</title>
<associations>
<child-association name="act:actionExecutionDetails">
<target>
<class>act:actionexecutiondetails</class>
<mandatory>false</mandatory>
<many>true</many>
</target>
</child-association>
</associations>
</aspect>
</aspects>
</model>

View File

@@ -0,0 +1,47 @@
/*
* 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.action.evaluator;
import org.alfresco.service.cmr.action.ActionCondition;
import org.alfresco.service.cmr.action.ActionConditionDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Action Condition Evaluator
*
* @author Roy Wetherall
*/
public interface ActionConditionEvaluator
{
/**
* Get the action condition deinfinition
*
* @return the action condition definition
*/
public ActionConditionDefinition getActionConditionDefintion();
/**
* Evaluate the action condition
*
* @param actionCondition the action condition
* @param actionedUponNodeRef the actioned upon node
* @return true if the condition passes, false otherwise
*/
public boolean evaluate(
ActionCondition actionCondition,
NodeRef actionedUponNodeRef);
}

View File

@@ -0,0 +1,105 @@
/*
* 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.action.evaluator;
import org.alfresco.repo.action.ActionConditionDefinitionImpl;
import org.alfresco.repo.action.ParameterizedItemAbstractBase;
import org.alfresco.service.cmr.action.ActionCondition;
import org.alfresco.service.cmr.action.ActionConditionDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Rule condition evaluator abstract base implementation.
*
* @author Roy Wetherall
*/
public abstract class ActionConditionEvaluatorAbstractBase extends ParameterizedItemAbstractBase implements ActionConditionEvaluator
{
/**
* Indicates whether the condition is public or not
*/
private boolean publicCondition = true;
/**
* The action condition definition
*/
protected ActionConditionDefinition actionConditionDefinition;
/**
* Initialise method
*/
public void init()
{
if (this.publicCondition == true)
{
// Call back to the action service to register the condition
this.runtimeActionService.registerActionConditionEvaluator(this);
}
}
/**
* Set the value that indicates whether a condition is public or not
*
* @param publicCondition true if the condition is public, false otherwise
*/
public void setPublicCondition(boolean publicCondition)
{
this.publicCondition = publicCondition;
}
/**
* Get the action condition definition.
*
* @return the action condition definition
*/
public ActionConditionDefinition getActionConditionDefintion()
{
if (this.actionConditionDefinition == null)
{
this.actionConditionDefinition = new ActionConditionDefinitionImpl(this.name);
((ActionConditionDefinitionImpl)this.actionConditionDefinition).setTitleKey(getTitleKey());
((ActionConditionDefinitionImpl)this.actionConditionDefinition).setDescriptionKey(getDescriptionKey());
((ActionConditionDefinitionImpl)this.actionConditionDefinition).setAdhocPropertiesAllowed(getAdhocPropertiesAllowed());
((ActionConditionDefinitionImpl)this.actionConditionDefinition).setConditionEvaluator(this.name);
((ActionConditionDefinitionImpl)this.actionConditionDefinition).setParameterDefinitions(getParameterDefintions());
}
return this.actionConditionDefinition;
}
/**
* @see org.alfresco.repo.action.evaluator.ActionConditionEvaluator#evaluate(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
*/
public boolean evaluate(ActionCondition actionCondition, NodeRef actionedUponNodeRef)
{
checkMandatoryProperties(actionCondition, getActionConditionDefintion());
boolean result = evaluateImpl(actionCondition, actionedUponNodeRef);
if (actionCondition.getInvertCondition() == true)
{
result = !result;
}
return result;
}
/**
* Evaluation implementation
*
* @param actionCondition the action condition
* @param actionedUponNodeRef the actioned upon node reference
* @return the result of the condition evaluation
*/
protected abstract boolean evaluateImpl(ActionCondition actionCondition, NodeRef actionedUponNodeRef);
}

View File

@@ -0,0 +1,93 @@
/*
* 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.action.evaluator;
import java.util.List;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.evaluator.compare.ContentPropertyName;
import org.alfresco.service.cmr.action.ActionCondition;
import org.alfresco.service.cmr.action.ActionServiceException;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
/**
* Compare mime type evaluator
*
* @author Roy Wetherall
*/
public class CompareMimeTypeEvaluator extends ComparePropertyValueEvaluator
{
/**
* Evaluator constants
*/
public static final String NAME = "compare-mime-type";
/**
*
*/
private static final String ERRID_NOT_A_CONTENT_TYPE = "compare_mime_type_evaluator.not_a_content_type";
private static final String ERRID_NO_PROPERTY_DEFINTION_FOUND = "compare_mime_type_evaluator.no_property_definition_found";
/**
* @see org.alfresco.repo.action.evaluator.ActionConditionEvaluatorAbstractBase#evaluateImpl(org.alfresco.service.cmr.action.ActionCondition, org.alfresco.service.cmr.repository.NodeRef)
*/
public boolean evaluateImpl(ActionCondition actionCondition, NodeRef actionedUponNodeRef)
{
QName propertyQName = (QName)actionCondition.getParameterValue(ComparePropertyValueEvaluator.PARAM_PROPERTY);
if (propertyQName == null)
{
// Default to the standard content property
actionCondition.setParameterValue(ComparePropertyValueEvaluator.PARAM_PROPERTY, ContentModel.PROP_CONTENT);
}
else
{
// Ensure that we are dealing with a content property
QName propertyTypeQName = null;
PropertyDefinition propertyDefintion = this.dictionaryService.getProperty(propertyQName);
if (propertyDefintion != null)
{
propertyTypeQName = propertyDefintion.getDataType().getName();
if (DataTypeDefinition.CONTENT.equals(propertyTypeQName) == false)
{
throw new ActionServiceException(ERRID_NOT_A_CONTENT_TYPE);
}
}
else
{
throw new ActionServiceException(ERRID_NO_PROPERTY_DEFINTION_FOUND);
}
}
// Set the content property to be MIMETYPE
actionCondition.setParameterValue(ComparePropertyValueEvaluator.PARAM_CONTENT_PROPERTY, ContentPropertyName.MIME_TYPE.toString());
return super.evaluateImpl(actionCondition, actionedUponNodeRef);
}
/**
* @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefintions(java.util.List)
*/
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
super.addParameterDefintions(paramList);
}
}

View File

@@ -0,0 +1,89 @@
/*
* 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.action.evaluator;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ActionConditionImpl;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.GUID;
/**
* Compare property value evaluator test
*
* @author Roy Wetherall
*/
public class CompareMimeTypeEvaluatorTest extends BaseSpringTest
{
private NodeService nodeService;
private ContentService contentService;
private StoreRef testStoreRef;
private NodeRef rootNodeRef;
private NodeRef nodeRef;
private CompareMimeTypeEvaluator evaluator;
/**
* @see org.springframework.test.AbstractTransactionalSpringContextTests#onSetUpInTransaction()
*/
@Override
protected void onSetUpInTransaction() throws Exception
{
this.nodeService = (NodeService)this.applicationContext.getBean("nodeService");
this.contentService = (ContentService)this.applicationContext.getBean("contentService");
// Create the store and get the root node
this.testStoreRef = this.nodeService.createStore(
StoreRef.PROTOCOL_WORKSPACE, "Test_"
+ System.currentTimeMillis());
this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef);
// Create the node used for tests
this.nodeRef = this.nodeService.createNode(
this.rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}testnode"),
ContentModel.TYPE_CONTENT).getChildRef();
this.evaluator = (CompareMimeTypeEvaluator)this.applicationContext.getBean(CompareMimeTypeEvaluator.NAME);
}
public void testContentPropertyComparisons()
{
ActionConditionImpl condition = new ActionConditionImpl(GUID.generate(), ComparePropertyValueEvaluator.NAME);
// What happens if you do this and the node has no content set yet !!
// Add some content to the node reference
ContentWriter contentWriter = this.contentService.getWriter(this.nodeRef, ContentModel.PROP_CONTENT, true);
contentWriter.setEncoding("UTF-8");
contentWriter.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
contentWriter.putContent("This is some test content.");
// Test matching the mimetype
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, MimetypeMap.MIMETYPE_TEXT_PLAIN);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, MimetypeMap.MIMETYPE_HTML);
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
}
}

View File

@@ -0,0 +1,266 @@
/*
* 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.action.evaluator;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.action.evaluator.compare.ComparePropertyValueOperation;
import org.alfresco.repo.action.evaluator.compare.ContentPropertyName;
import org.alfresco.repo.action.evaluator.compare.PropertyValueComparator;
import org.alfresco.service.cmr.action.ActionCondition;
import org.alfresco.service.cmr.action.ActionServiceException;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.ContentReader;
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.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.namespace.QName;
/**
* Compare property value evaluator
*
* @author Roy Wetherall
*/
public class ComparePropertyValueEvaluator extends ActionConditionEvaluatorAbstractBase
{
/**
* Evaluator constants
*/
public final static String NAME = "compare-property-value";
public final static String PARAM_PROPERTY = "property";
public final static String PARAM_CONTENT_PROPERTY = "content-property";
public final static String PARAM_VALUE = "value";
public final static String PARAM_OPERATION = "operation";
/**
* The default property to check if none is specified in the properties
*/
private final static QName DEFAULT_PROPERTY = ContentModel.PROP_NAME;
/**
* I18N message ID's
*/
private static final String MSGID_INVALID_OPERATION = "compare_property_value_evaluator.invalid_operation";
private static final String MSGID_NO_CONTENT_PROPERTY = "compare_property_value_evaluator.no_content_property";
/**
* Map of comparators used by different property types
*/
private Map<QName, PropertyValueComparator> comparators = new HashMap<QName, PropertyValueComparator>();
/**
* The node service
*/
protected NodeService nodeService;
/**
* The content service
*/
protected ContentService contentService;
/**
* The dictionary service
*/
protected DictionaryService dictionaryService;
/**
* Set node service
*
* @param nodeService the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Set the content service
*
* @param contentService the content service
*/
public void setContentService(ContentService contentService)
{
this.contentService = contentService;
}
/**
* Set the dictionary service
*
* @param dictionaryService the dictionary service
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* Set the list of property value comparators
*
* @param comparators the list of property value comparators
*/
public void setPropertyValueComparators(List<PropertyValueComparator> comparators)
{
for (PropertyValueComparator comparator : comparators)
{
comparator.registerComparator(this);
}
}
/**
* Registers a comparator for a given property data type.
*
* @param dataType property data type
* @param comparator property value comparator
*/
public void registerComparator(QName dataType, PropertyValueComparator comparator)
{
this.comparators.put(dataType, comparator);
}
/**
* Add paremeter defintions
*/
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_PROPERTY, DataTypeDefinition.QNAME, false, getParamDisplayLabel(PARAM_PROPERTY)));
paramList.add(new ParameterDefinitionImpl(PARAM_CONTENT_PROPERTY, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_CONTENT_PROPERTY)));
paramList.add(new ParameterDefinitionImpl(PARAM_VALUE, DataTypeDefinition.ANY, true, getParamDisplayLabel(PARAM_VALUE)));
paramList.add(new ParameterDefinitionImpl(PARAM_OPERATION, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_OPERATION)));
}
/**
* @see ActionConditionEvaluatorAbstractBase#evaluateImpl(ActionCondition, NodeRef)
*/
public boolean evaluateImpl(
ActionCondition ruleCondition,
NodeRef actionedUponNodeRef)
{
boolean result = false;
if (this.nodeService.exists(actionedUponNodeRef) == true)
{
// Get the name value of the node
QName propertyQName = (QName)ruleCondition.getParameterValue(PARAM_PROPERTY);
if (propertyQName == null)
{
propertyQName = DEFAULT_PROPERTY;
}
// Get the origional value and the value to match
Serializable propertyValue = this.nodeService.getProperty(actionedUponNodeRef, propertyQName);
Serializable compareValue = ruleCondition.getParameterValue(PARAM_VALUE);
// Get the operation
ComparePropertyValueOperation operation = null;
String operationString = (String)ruleCondition.getParameterValue(PARAM_OPERATION);
if (operationString != null)
{
operation = ComparePropertyValueOperation.valueOf(operationString);
}
// Look at the type of the property (assume to be ANY if none found in dicitionary)
QName propertyTypeQName = DataTypeDefinition.ANY;
PropertyDefinition propertyDefintion = this.dictionaryService.getProperty(propertyQName);
if (propertyDefintion != null)
{
propertyTypeQName = propertyDefintion.getDataType().getName();
}
// Sort out what to do if the property is a content property
if (DataTypeDefinition.CONTENT.equals(propertyTypeQName) == true)
{
// Get the content property name
ContentPropertyName contentProperty = null;
String contentPropertyString = (String)ruleCondition.getParameterValue(PARAM_CONTENT_PROPERTY);
if (contentPropertyString == null)
{
// Error if no content property has been set
throw new ActionServiceException(MSGID_NO_CONTENT_PROPERTY);
}
else
{
contentProperty = ContentPropertyName.valueOf(contentPropertyString);
}
// Get the content data
if (propertyValue != null)
{
ContentData contentData = DefaultTypeConverter.INSTANCE.convert(ContentData.class, propertyValue);
switch (contentProperty)
{
case ENCODING:
{
propertyTypeQName = DataTypeDefinition.TEXT;
propertyValue = contentData.getEncoding();
break;
}
case SIZE:
{
propertyTypeQName = DataTypeDefinition.LONG;
propertyValue = contentData.getSize();
break;
}
case MIME_TYPE:
{
propertyTypeQName = DataTypeDefinition.TEXT;
propertyValue = contentData.getMimetype();
break;
}
}
}
}
if (propertyValue != null)
{
// Try and get a matching comparator
PropertyValueComparator comparator = this.comparators.get(propertyTypeQName);
if (comparator != null)
{
// Call the comparator for the property type
result = comparator.compare(propertyValue, compareValue, operation);
}
else
{
// The default behaviour is to assume the property can only be compared using equals
if (operation != null && operation != ComparePropertyValueOperation.EQUALS)
{
// Error since only the equals operation is valid
throw new ActionServiceException(
MSGID_INVALID_OPERATION,
new Object[]{operation.toString(), propertyTypeQName.toString()});
}
// Use equals to compare the values
result = compareValue.equals(propertyValue);
}
}
}
return result;
}
}

View File

@@ -0,0 +1,507 @@
/*
* 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.action.evaluator;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ActionConditionImpl;
import org.alfresco.repo.action.evaluator.compare.ComparePropertyValueOperation;
import org.alfresco.repo.action.evaluator.compare.ContentPropertyName;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.dictionary.DictionaryDAO;
import org.alfresco.repo.dictionary.M2Model;
import org.alfresco.repo.dictionary.M2Property;
import org.alfresco.repo.dictionary.M2Type;
import org.alfresco.service.cmr.action.ActionServiceException;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.GUID;
/**
* Compare property value evaluator test
*
* @author Roy Wetherall
*/
public class ComparePropertyValueEvaluatorTest extends BaseSpringTest
{
private static final String TEST_TYPE_NAMESPACE = "testNamespace";
private static final QName TEST_TYPE_QNAME = QName.createQName(TEST_TYPE_NAMESPACE, "testType");
private static final QName PROP_TEXT = QName.createQName(TEST_TYPE_NAMESPACE, "propText");
private static final QName PROP_INT = QName.createQName(TEST_TYPE_NAMESPACE, "propInt");
private static final QName PROP_DATETIME = QName.createQName(TEST_TYPE_NAMESPACE, "propDatetime");
private static final QName PROP_NODEREF = QName.createQName(TEST_TYPE_NAMESPACE, "propNodeRef");
private static final String TEXT_VALUE = "myDocument.doc";
private static final int INT_VALUE = 100;
private Date beforeDateValue;
private Date dateValue;
private Date afterDateValue;
private NodeRef nodeValue;
private DictionaryDAO dictionaryDAO;
private NodeService nodeService;
private ContentService contentService;
private StoreRef testStoreRef;
private NodeRef rootNodeRef;
private NodeRef nodeRef;
private ComparePropertyValueEvaluator evaluator;
/**
* Sets the meta model DAO
*
* @param dictionaryDAO the meta model DAO
*/
public void setDictionaryDAO(DictionaryDAO dictionaryDAO)
{
this.dictionaryDAO = dictionaryDAO;
}
/**
* @see org.springframework.test.AbstractTransactionalSpringContextTests#onSetUpInTransaction()
*/
@Override
protected void onSetUpInTransaction() throws Exception
{
// Need to create model to contain our custom type
createTestModel();
this.nodeService = (NodeService)this.applicationContext.getBean("nodeService");
this.contentService = (ContentService)this.applicationContext.getBean("contentService");
// Create the store and get the root node
this.testStoreRef = this.nodeService.createStore(
StoreRef.PROTOCOL_WORKSPACE, "Test_"
+ System.currentTimeMillis());
this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef);
this.nodeValue = new NodeRef(this.testStoreRef, "1234");
this.beforeDateValue = new Date();
Thread.sleep(2000);
this.dateValue = new Date();
Thread.sleep(2000);
this.afterDateValue = new Date();
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
props.put(PROP_TEXT, TEXT_VALUE);
props.put(PROP_INT, INT_VALUE);
props.put(PROP_DATETIME, this.dateValue);
props.put(PROP_NODEREF, this.nodeValue);
// Create the node used for tests
this.nodeRef = this.nodeService.createNode(
this.rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}testnode"),
TEST_TYPE_QNAME,
props).getChildRef();
this.evaluator = (ComparePropertyValueEvaluator)this.applicationContext.getBean(ComparePropertyValueEvaluator.NAME);
}
/**
* Test numeric comparisions
*/
public void testNumericComparison()
{
ActionConditionImpl condition = new ActionConditionImpl(GUID.generate(), ComparePropertyValueEvaluator.NAME);
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_PROPERTY, PROP_INT);
// Test the default operation
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, INT_VALUE);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, 101);
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Test equals operation
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.EQUALS.toString());
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, INT_VALUE);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, 101);
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Test equals greater than operation
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.GREATER_THAN.toString());
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, 99);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, 101);
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Test equals greater than operation
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.GREATER_THAN_EQUAL.toString());
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, 99);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, 100);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, 101);
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Test equals less than operation
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.LESS_THAN.toString());
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, 101);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, 99);
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Test equals less than equals operation
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.LESS_THAN_EQUAL.toString());
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, 101);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, 100);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, 99);
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Ensure other operators are invalid
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.BEGINS.toString());
try { this.evaluator.evaluate(condition, this.nodeRef); fail("An exception should have been raised here."); } catch (ActionServiceException exception) {exception.printStackTrace();};
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.ENDS.toString());
try { this.evaluator.evaluate(condition, this.nodeRef); fail("An exception should have been raised here."); } catch (ActionServiceException exception) {};
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.CONTAINS.toString());
try { this.evaluator.evaluate(condition, this.nodeRef); fail("An exception should have been raised here."); } catch (ActionServiceException exception) {};
}
/**
* Test date comparison
*/
public void testDateComparison()
{
ActionConditionImpl condition = new ActionConditionImpl(GUID.generate(), ComparePropertyValueEvaluator.NAME);
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_PROPERTY, PROP_DATETIME);
// Test the default operation
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.dateValue);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, new Date());
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Test the equals operation
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.EQUALS.toString());
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.dateValue);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, new Date());
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Test equals greater than operation
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.GREATER_THAN.toString());
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.beforeDateValue);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.afterDateValue);
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Test equals greater than operation
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.GREATER_THAN_EQUAL.toString());
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.beforeDateValue);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.dateValue);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.afterDateValue);
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Test equals less than operation
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.LESS_THAN.toString());
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.afterDateValue);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.beforeDateValue);
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Test equals less than equals operation
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.LESS_THAN_EQUAL.toString());
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.afterDateValue);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.dateValue);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.beforeDateValue);
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Ensure other operators are invalid
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.BEGINS.toString());
try { this.evaluator.evaluate(condition, this.nodeRef); fail("An exception should have been raised here."); } catch (ActionServiceException exception) {exception.printStackTrace();};
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.ENDS.toString());
try { this.evaluator.evaluate(condition, this.nodeRef); fail("An exception should have been raised here."); } catch (ActionServiceException exception) {};
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.CONTAINS.toString());
try { this.evaluator.evaluate(condition, this.nodeRef); fail("An exception should have been raised here."); } catch (ActionServiceException exception) {};
}
/**
* Test text comparison
*/
public void testTextComparison()
{
ActionConditionImpl condition = new ActionConditionImpl(GUID.generate(), ComparePropertyValueEvaluator.NAME);
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_PROPERTY, PROP_TEXT);
// Test default operations implied by presence and position of *
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "*.doc");
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "*.xls");
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "my*");
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "bad*");
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "Document");
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "bobbins");
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Test equals operator
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.EQUALS.toString());
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, TEXT_VALUE);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "bobbins");
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Test contains operator
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.CONTAINS.toString());
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "Document");
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "bobbins");
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Test begins operator
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.BEGINS.toString());
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "my");
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "bobbins");
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Test ends operator
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.ENDS.toString());
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "doc");
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "bobbins");
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Ensure other operators are invalid
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.GREATER_THAN.toString());
try { this.evaluator.evaluate(condition, this.nodeRef); fail("An exception should have been raised here."); } catch (ActionServiceException exception) {exception.printStackTrace();};
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.GREATER_THAN_EQUAL.toString());
try { this.evaluator.evaluate(condition, this.nodeRef); fail("An exception should have been raised here."); } catch (ActionServiceException exception) {};
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.LESS_THAN.toString());
try { this.evaluator.evaluate(condition, this.nodeRef); fail("An exception should have been raised here."); } catch (ActionServiceException exception) {};
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.LESS_THAN_EQUAL.toString());
try { this.evaluator.evaluate(condition, this.nodeRef); fail("An exception should have been raised here."); } catch (ActionServiceException exception) {};
}
/**
* Test some combinations of test file names that had been failing
*/
public void testTempFileNames()
{
ActionConditionImpl condition = new ActionConditionImpl(GUID.generate(), ComparePropertyValueEvaluator.NAME);
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_PROPERTY, PROP_TEXT);
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "~*.doc");
this.nodeService.setProperty(this.nodeRef, PROP_TEXT, "~1234.doc");
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
}
/**
* Test comparison of properties that do not have a registered comparitor
*/
public void testOtherComparison()
{
NodeRef badNodeRef = new NodeRef(this.testStoreRef, "badId");
ActionConditionImpl condition = new ActionConditionImpl(GUID.generate(), ComparePropertyValueEvaluator.NAME);
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_PROPERTY, PROP_NODEREF);
// Test default operation
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.nodeValue);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, badNodeRef);
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "this isn't even the correct type!");
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Test equals operation
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.EQUALS.toString());
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.nodeValue);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, badNodeRef);
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Ensure other operators are invalid
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.BEGINS.toString());
try { this.evaluator.evaluate(condition, this.nodeRef); fail("An exception should have been raised here."); } catch (ActionServiceException exception) { exception.printStackTrace();};
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.ENDS.toString());
try { this.evaluator.evaluate(condition, this.nodeRef); fail("An exception should have been raised here."); } catch (ActionServiceException exception) {};
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.CONTAINS.toString());
try { this.evaluator.evaluate(condition, this.nodeRef); fail("An exception should have been raised here."); } catch (ActionServiceException exception) {};
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.GREATER_THAN.toString());
try { this.evaluator.evaluate(condition, this.nodeRef); fail("An exception should have been raised here."); } catch (ActionServiceException exception) {};
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.GREATER_THAN_EQUAL.toString());
try { this.evaluator.evaluate(condition, this.nodeRef); fail("An exception should have been raised here."); } catch (ActionServiceException exception) {};
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.LESS_THAN.toString());
try { this.evaluator.evaluate(condition, this.nodeRef); fail("An exception should have been raised here."); } catch (ActionServiceException exception) {};
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.LESS_THAN_EQUAL.toString());
try { this.evaluator.evaluate(condition, this.nodeRef); fail("An exception should have been raised here."); } catch (ActionServiceException exception) {};
}
public void testContentPropertyComparisons()
{
ActionConditionImpl condition = new ActionConditionImpl(GUID.generate(), ComparePropertyValueEvaluator.NAME);
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_PROPERTY, ContentModel.PROP_CONTENT);
// What happens if you do this and the node has no content set yet !!
// Add some content to the node reference
ContentWriter contentWriter = this.contentService.getWriter(this.nodeRef, ContentModel.PROP_CONTENT, true);
contentWriter.setEncoding("UTF-8");
contentWriter.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
contentWriter.putContent("This is some test content.");
// Test matching the mimetype
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_CONTENT_PROPERTY, ContentPropertyName.MIME_TYPE.toString());
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, MimetypeMap.MIMETYPE_TEXT_PLAIN);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, MimetypeMap.MIMETYPE_HTML);
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Test matching the encoding
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_CONTENT_PROPERTY, ContentPropertyName.ENCODING.toString());
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "UTF-8");
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "UTF-16");
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
// Test comparision to the size of the content
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_CONTENT_PROPERTY, ContentPropertyName.SIZE.toString());
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.LESS_THAN.toString());
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, 50);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, 2);
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
}
private void createTestModel()
{
M2Model model = M2Model.createModel("test:comparepropertyvalueevaluatortest");
model.createNamespace(TEST_TYPE_NAMESPACE, "test");
model.createImport(NamespaceService.DICTIONARY_MODEL_1_0_URI, NamespaceService.DICTIONARY_MODEL_PREFIX);
model.createImport(NamespaceService.SYSTEM_MODEL_1_0_URI, NamespaceService.SYSTEM_MODEL_PREFIX);
model.createImport(NamespaceService.CONTENT_MODEL_1_0_URI, NamespaceService.CONTENT_MODEL_PREFIX);
M2Type testType = model.createType("test:" + TEST_TYPE_QNAME.getLocalName());
testType.setParentName("cm:" + ContentModel.TYPE_CONTENT.getLocalName());
M2Property prop1 = testType.createProperty("test:" + PROP_TEXT.getLocalName());
prop1.setMandatory(false);
prop1.setType("d:" + DataTypeDefinition.TEXT.getLocalName());
prop1.setMultiValued(false);
M2Property prop2 = testType.createProperty("test:" + PROP_INT.getLocalName());
prop2.setMandatory(false);
prop2.setType("d:" + DataTypeDefinition.INT.getLocalName());
prop2.setMultiValued(false);
M2Property prop3 = testType.createProperty("test:" + PROP_DATETIME.getLocalName());
prop3.setMandatory(false);
prop3.setType("d:" + DataTypeDefinition.DATETIME.getLocalName());
prop3.setMultiValued(false);
M2Property prop4 = testType.createProperty("test:" + PROP_NODEREF.getLocalName());
prop4.setMandatory(false);
prop4.setType("d:" + DataTypeDefinition.NODE_REF.getLocalName());
prop4.setMultiValued(false);
dictionaryDAO.putModel(model);
}
}

View File

@@ -0,0 +1,84 @@
/*
* 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.action.evaluator;
import java.util.List;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.service.cmr.action.ActionCondition;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
/**
* Has aspect evaluator
*
* @author Roy Wetherall
*/
public class HasAspectEvaluator extends ActionConditionEvaluatorAbstractBase
{
/**
* Evaluator constants
*/
public static final String NAME = "has-aspect";
public static final String PARAM_ASPECT = "aspect";
/**
* The node service
*/
private NodeService nodeService;
/**
* Set node service
*
* @param nodeService the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @see org.alfresco.repo.action.evaluator.ActionConditionEvaluatorAbstractBase#evaluateImpl(org.alfresco.service.cmr.action.ActionCondition, org.alfresco.service.cmr.repository.NodeRef)
*/
public boolean evaluateImpl(ActionCondition ruleCondition, NodeRef actionedUponNodeRef)
{
boolean result = false;
if (this.nodeService.exists(actionedUponNodeRef) == true)
{
if (this.nodeService.hasAspect(actionedUponNodeRef, (QName)ruleCondition.getParameterValue(PARAM_ASPECT)) == true)
{
result = true;
}
}
return result;
}
/**
* @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefintions(java.util.List)
*/
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_ASPECT, DataTypeDefinition.QNAME, true, getParamDisplayLabel(PARAM_ASPECT)));
}
}

View File

@@ -0,0 +1,94 @@
/*
* 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.action.evaluator;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ActionConditionImpl;
import org.alfresco.service.cmr.action.ActionCondition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.GUID;
/**
* Is sub class evaluator test
*
* @author Roy Wetherall
*/
public class HasAspectEvaluatorTest extends BaseSpringTest
{
private NodeService nodeService;
private StoreRef testStoreRef;
private NodeRef rootNodeRef;
private NodeRef nodeRef;
private HasAspectEvaluator evaluator;
private final static String ID = GUID.generate();
@Override
protected void onSetUpInTransaction() throws Exception
{
this.nodeService = (NodeService)this.applicationContext.getBean("nodeService");
// Create the store and get the root node
this.testStoreRef = this.nodeService.createStore(
StoreRef.PROTOCOL_WORKSPACE, "Test_"
+ System.currentTimeMillis());
this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef);
// Create the node used for tests
this.nodeRef = this.nodeService.createNode(
this.rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}testnode"),
ContentModel.TYPE_CONTENT).getChildRef();
this.evaluator = (HasAspectEvaluator)this.applicationContext.getBean(HasAspectEvaluator.NAME);
}
public void testMandatoryParamsMissing()
{
ActionCondition condition = new ActionConditionImpl(ID, HasAspectEvaluator.NAME, null);
try
{
this.evaluator.evaluate(condition, this.nodeRef);
fail("The fact that a mandatory parameter has not been set should have been detected.");
}
catch (Throwable exception)
{
// Do nothing since this is correct
}
}
public void testPass()
{
this.nodeService.addAspect(this.nodeRef, ContentModel.ASPECT_VERSIONABLE, null);
ActionCondition condition = new ActionConditionImpl(ID, HasAspectEvaluator.NAME, null);
condition.setParameterValue(HasAspectEvaluator.PARAM_ASPECT, ContentModel.ASPECT_VERSIONABLE);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
}
public void testFail()
{
ActionCondition condition = new ActionConditionImpl(ID, HasAspectEvaluator.NAME, null);
condition.setParameterValue(HasAspectEvaluator.PARAM_ASPECT, ContentModel.ASPECT_VERSIONABLE);
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
}
}

View File

@@ -0,0 +1,91 @@
/*
* 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.action.evaluator;
import java.util.List;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.action.ActionCondition;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.version.VersionHistory;
import org.alfresco.service.cmr.version.VersionService;
/**
* Has version history evaluator
*
* @author Roy Wetherall
*/
public class HasVersionHistoryEvaluator extends ActionConditionEvaluatorAbstractBase
{
/**
* Evaluator constants
*/
public static final String NAME = "has-version-history";
/**
* The node service
*/
private NodeService nodeService;
private VersionService versionService;
/**
* Set node service
*
* @param nodeService the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void setVersionService(VersionService versionService)
{
this.versionService = versionService;
}
/**
* @see org.alfresco.repo.action.evaluator.ActionConditionEvaluatorAbstractBase#evaluateImpl(org.alfresco.service.cmr.action.ActionCondition, org.alfresco.service.cmr.repository.NodeRef)
*/
public boolean evaluateImpl(ActionCondition ruleCondition, NodeRef actionedUponNodeRef)
{
boolean result = false;
if (this.nodeService.exists(actionedUponNodeRef) == true &&
this.nodeService.hasAspect(actionedUponNodeRef, ContentModel.ASPECT_VERSIONABLE) == true)
{
VersionHistory versionHistory = this.versionService.getVersionHistory(actionedUponNodeRef);
if (versionHistory != null && versionHistory.getAllVersions().size() != 0)
{
result = true;
}
}
return result;
}
/**
* @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefintions(java.util.List)
*/
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
}
}

View File

@@ -0,0 +1,144 @@
/*
* 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.action.evaluator;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.service.cmr.action.ActionCondition;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.namespace.QName;
/**
* In category evaluator implementation.
*
* @author Roy Wetherall
*/
public class InCategoryEvaluator extends ActionConditionEvaluatorAbstractBase
{
/**
* Rule constants
*/
public static final String NAME = "in-category";
public static final String PARAM_CATEGORY_ASPECT = "category-aspect";
public static final String PARAM_CATEGORY_VALUE = "category-value";
/**
* The node service
*/
private NodeService nodeService;
/**
* The dictionary service
*/
private DictionaryService dictionaryService;
/**
* Sets the node service
*
* @param nodeService the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Sets the dictionary service
*
* @param dictionaryService the dictionary service
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* Add the parameter definitions
*/
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_CATEGORY_ASPECT, DataTypeDefinition.QNAME, true, getParamDisplayLabel(PARAM_CATEGORY_ASPECT)));
paramList.add(new ParameterDefinitionImpl(PARAM_CATEGORY_VALUE, DataTypeDefinition.NODE_REF, true, getParamDisplayLabel(PARAM_CATEGORY_VALUE)));
}
/**
* @see org.alfresco.repo.action.evaluator.ActionConditionEvaluatorAbstractBase#evaluateImpl(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
protected boolean evaluateImpl(
ActionCondition ruleCondition,
NodeRef actionedUponNodeRef)
{
boolean result = false;
// Double check that the node still exists
if (this.nodeService.exists(actionedUponNodeRef) == true)
{
// Get the rule parameter values
QName categoryAspect = (QName)ruleCondition.getParameterValue(PARAM_CATEGORY_ASPECT);
NodeRef categoryValue = (NodeRef)ruleCondition.getParameterValue(PARAM_CATEGORY_VALUE);
// Check that the apect is classifiable and is currently applied to the node
if (this.dictionaryService.isSubClass(categoryAspect, ContentModel.ASPECT_CLASSIFIABLE) == true &&
this.nodeService.hasAspect(actionedUponNodeRef, categoryAspect) == true)
{
// Get the category property qname
QName categoryProperty = null;
Map<QName, PropertyDefinition> propertyDefs = this.dictionaryService.getAspect(categoryAspect).getProperties();
for (Map.Entry<QName, PropertyDefinition> entry : propertyDefs.entrySet())
{
if (DataTypeDefinition.CATEGORY.equals(entry.getValue().getDataType().getName()) == true)
{
// Found the category property
categoryProperty = entry.getKey();
break;
}
}
if (categoryProperty != null)
{
// Check to see if the category value is in the list of currently set category values
Serializable value = this.nodeService.getProperty(actionedUponNodeRef, categoryProperty);
Collection<NodeRef> actualCategories = DefaultTypeConverter.INSTANCE.getCollection(NodeRef.class, value);
for (NodeRef nodeRef : actualCategories)
{
if (nodeRef.equals(categoryValue) == true)
{
result = true;
break;
}
}
}
}
}
return result;
}
}

View File

@@ -0,0 +1,102 @@
/*
* 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.action.evaluator;
import java.util.List;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.service.cmr.action.ActionCondition;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
/**
* No condition evaluator implmentation.
*
* @author Roy Wetherall
*/
public class IsSubTypeEvaluator extends ActionConditionEvaluatorAbstractBase
{
/**
* Evaluator constants
*/
public static final String NAME = "is-subtype";
public static final String PARAM_TYPE = "type";
/**
* The node service
*/
private NodeService nodeService;
/**
* The dictionary service
*/
private DictionaryService dictionaryService;
/**
* Set node service
*
* @param nodeService the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Set dictionary service
*
* @param dictionaryService the dictionary service
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* @see org.alfresco.repo.action.evaluator.ActionConditionEvaluatorAbstractBase#evaluateImpl(org.alfresco.service.cmr.action.ActionCondition, org.alfresco.service.cmr.repository.NodeRef)
*/
public boolean evaluateImpl(ActionCondition ruleCondition, NodeRef actionedUponNodeRef)
{
boolean result = false;
if (this.nodeService.exists(actionedUponNodeRef) == true)
{
// TODO: Move this type check into its own Class Evaluator
QName nodeType = nodeService.getType(actionedUponNodeRef);
if (dictionaryService.isSubClass(nodeType, (QName)ruleCondition.getParameterValue(PARAM_TYPE)))
{
result = true;
}
}
return result;
}
/**
* @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefintions(java.util.List)
*/
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_TYPE, DataTypeDefinition.QNAME, true, getParamDisplayLabel(PARAM_TYPE)));
}
}

View File

@@ -0,0 +1,95 @@
/*
* 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.action.evaluator;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ActionConditionImpl;
import org.alfresco.service.cmr.action.ActionCondition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.GUID;
/**
* Is sub class evaluator test
*
* @author Roy Wetherall
*/
public class IsSubTypeEvaluatorTest extends BaseSpringTest
{
private NodeService nodeService;
private StoreRef testStoreRef;
private NodeRef rootNodeRef;
private NodeRef nodeRef;
private IsSubTypeEvaluator evaluator;
private final static String ID = GUID.generate();
@Override
protected void onSetUpInTransaction() throws Exception
{
this.nodeService = (NodeService)this.applicationContext.getBean("nodeService");
// Create the store and get the root node
this.testStoreRef = this.nodeService.createStore(
StoreRef.PROTOCOL_WORKSPACE, "Test_"
+ System.currentTimeMillis());
this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef);
// Create the node used for tests
this.nodeRef = this.nodeService.createNode(
this.rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}testnode"),
ContentModel.TYPE_CONTENT).getChildRef();
this.evaluator = (IsSubTypeEvaluator)this.applicationContext.getBean(IsSubTypeEvaluator.NAME);
}
public void testMandatoryParamsMissing()
{
ActionCondition condition = new ActionConditionImpl(ID, IsSubTypeEvaluator.NAME, null);
try
{
this.evaluator.evaluate(condition, this.nodeRef);
fail("The fact that a mandatory parameter has not been set should have been detected.");
}
catch (Throwable exception)
{
// Do nothing since this is correct
}
}
public void testPass()
{
ActionCondition condition = new ActionConditionImpl(ID, IsSubTypeEvaluator.NAME, null);
condition.setParameterValue(IsSubTypeEvaluator.PARAM_TYPE, ContentModel.TYPE_CONTENT);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
condition.setParameterValue(IsSubTypeEvaluator.PARAM_TYPE, ContentModel.TYPE_CMOBJECT);
assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
}
public void testFail()
{
ActionCondition condition = new ActionConditionImpl(ID, IsSubTypeEvaluator.NAME, null);
condition.setParameterValue(IsSubTypeEvaluator.PARAM_TYPE, ContentModel.TYPE_FOLDER);
assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
}
}

View File

@@ -0,0 +1,54 @@
/*
* 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.action.evaluator;
import java.util.List;
import org.alfresco.service.cmr.action.ActionCondition;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* No condition evaluator implmentation.
*
* @author Roy Wetherall
*/
public class NoConditionEvaluator extends ActionConditionEvaluatorAbstractBase
{
/**
* Evaluator constants
*/
public static final String NAME = "no-condition";
/**
* @see org.alfresco.repo.action.evaluator.ActionConditionEvaluatorAbstractBase#evaluateImpl(org.alfresco.service.cmr.action.ActionCondition, org.alfresco.service.cmr.repository.NodeRef)
*/
public boolean evaluateImpl(ActionCondition ruleCondition, NodeRef actionedUponNodeRef)
{
return true;
}
/**
* @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefintions(java.util.List)
*/
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
// No parameters to add
}
}

View File

@@ -0,0 +1,22 @@
package org.alfresco.repo.action.evaluator.compare;
/**
* ComparePropertyValueOperation enum.
* <p>
* Contains the operations that can be used when evaluating whether the value of a property
* matches the value set.
* <p>
* Some operations can only be used with specific types. If a mismatch is encountered an error will
* be raised.
*/
public enum ComparePropertyValueOperation
{
EQUALS, // All property types
CONTAINS, // String properties only
BEGINS, // String properties only
ENDS, // String properties only
GREATER_THAN, // Numeric and date properties only
GREATER_THAN_EQUAL, // Numeric and date properties only
LESS_THAN, // Numeric and date properties only
LESS_THAN_EQUAL // Numeric and date properties only
}

View File

@@ -0,0 +1,27 @@
/*
* 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.action.evaluator.compare;
/**
* @author Roy Wetherall
*/
public enum ContentPropertyName
{
MIME_TYPE,
ENCODING,
SIZE
}

View File

@@ -0,0 +1,102 @@
/*
* 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.action.evaluator.compare;
import java.io.Serializable;
import java.util.Date;
import org.alfresco.repo.action.evaluator.ComparePropertyValueEvaluator;
import org.alfresco.service.cmr.action.ActionServiceException;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
/**
* Date property value comparator
*
* @author Roy Wetherall
*/
public class DatePropertyValueComparator implements PropertyValueComparator
{
/**
* I18N message ids
*/
private static final String MSGID_INVALID_OPERATION = "date_property_value_comparator.invalid_operation";
/**
* @see org.alfresco.repo.action.evaluator.compare.PropertyValueComparator#compare(java.io.Serializable, java.io.Serializable, org.alfresco.repo.action.evaluator.compare.ComparePropertyValueOperation)
*/
public boolean compare(Serializable propertyValue,
Serializable compareValue, ComparePropertyValueOperation operation)
{
boolean result = false;
if (operation == null)
{
operation = ComparePropertyValueOperation.EQUALS;
}
Date propertyDate = (Date)propertyValue;
Date compareDate = (Date)compareValue;
switch (operation)
{
case EQUALS:
{
result = propertyDate.equals(compareDate);
break;
}
case LESS_THAN:
{
result = propertyDate.before(compareDate);
break;
}
case LESS_THAN_EQUAL:
{
result = (propertyDate.equals(compareDate) || propertyDate.before(compareDate));
break;
}
case GREATER_THAN:
{
result = propertyDate.after(compareDate);
break;
}
case GREATER_THAN_EQUAL:
{
result = (propertyDate.equals(compareDate) || propertyDate.after(compareDate));
break;
}
default:
{
// Raise an invalid operation exception
throw new ActionServiceException(
MSGID_INVALID_OPERATION,
new Object[]{operation.toString()});
}
}
return result;
}
/**
* @see org.alfresco.repo.action.evaluator.compare.PropertyValueComparator#registerComparator(org.alfresco.repo.action.evaluator.ComparePropertyValueEvaluator)
*/
public void registerComparator(ComparePropertyValueEvaluator evaluator)
{
evaluator.registerComparator(DataTypeDefinition.DATE, this);
evaluator.registerComparator(DataTypeDefinition.DATETIME, this);
}
}

View File

@@ -0,0 +1,106 @@
/*
* 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.action.evaluator.compare;
import java.io.Serializable;
import org.alfresco.repo.action.evaluator.ComparePropertyValueEvaluator;
import org.alfresco.service.cmr.action.ActionServiceException;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
/**
* Numeric property value comparator.
*
* @author Roy Wetherall
*/
public class NumericPropertyValueComparator implements PropertyValueComparator
{
/**
* I18N message ids
*/
private static final String MSGID_INVALID_OPERATION = "numeric_property_value_comparator.invalid_operation";
/**
* @see org.alfresco.repo.action.evaluator.compare.PropertyValueComparator#compare(java.io.Serializable, java.io.Serializable, org.alfresco.repo.action.evaluator.compare.ComparePropertyValueOperation)
*/
public boolean compare(
Serializable propertyValue,
Serializable compareValue,
ComparePropertyValueOperation operation)
{
boolean result = false;
if (operation == null)
{
operation = ComparePropertyValueOperation.EQUALS;
}
// TODO need to check that doing this potential conversion does not cause a problem
double property = ((Number)propertyValue).doubleValue();
double compare = ((Number)compareValue).doubleValue();
switch (operation)
{
case EQUALS:
{
result = (property == compare);
break;
}
case GREATER_THAN:
{
result = (property > compare);
break;
}
case GREATER_THAN_EQUAL:
{
result = (property >= compare);
break;
}
case LESS_THAN:
{
result = (property < compare);
break;
}
case LESS_THAN_EQUAL:
{
result = (property <= compare);
break;
}
default:
{
// Raise an invalid operation exception
throw new ActionServiceException(
MSGID_INVALID_OPERATION,
new Object[]{operation.toString()});
}
}
return result;
}
/**
* @see org.alfresco.repo.action.evaluator.compare.PropertyValueComparator#registerComparator(org.alfresco.repo.action.evaluator.ComparePropertyValueEvaluator)
*/
public void registerComparator(ComparePropertyValueEvaluator evaluator)
{
evaluator.registerComparator(DataTypeDefinition.DOUBLE, this);
evaluator.registerComparator(DataTypeDefinition.FLOAT, this);
evaluator.registerComparator(DataTypeDefinition.INT, this);
evaluator.registerComparator(DataTypeDefinition.LONG, this);
}
}

View File

@@ -0,0 +1,49 @@
/*
* 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.action.evaluator.compare;
import java.io.Serializable;
import org.alfresco.repo.action.evaluator.ComparePropertyValueEvaluator;
/**
* Property value comparator interface
*
* @author Roy Wetherall
*/
public interface PropertyValueComparator
{
/**
* Callback method to register this comparator with the evaluator.
*
* @param evaluator the compare property value evaluator
*/
void registerComparator(ComparePropertyValueEvaluator evaluator);
/**
* Compares the value of a property with the compare value, using the operator passed.
*
* @param propertyValue the property value
* @param compareValue the compare value
* @param operation the operation used to compare the two values
* @return the result of the comparision, true if successful false otherwise
*/
boolean compare(
Serializable propertyValue,
Serializable compareValue,
ComparePropertyValueOperation operation);
}

View File

@@ -0,0 +1,183 @@
/*
* 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.action.evaluator.compare;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.alfresco.repo.action.evaluator.ComparePropertyValueEvaluator;
import org.alfresco.service.cmr.action.ActionServiceException;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
/**
* Test property value comparator
*
* @author Roy Wetherall
*/
public class TextPropertyValueComparator implements PropertyValueComparator
{
/**
* I18N message ids
*/
private static final String MSGID_INVALID_OPERATION = "text_property_value_comparator.invalid_operation";
/**
* Special star string
*/
private static final String STAR = "*";
/**
* @see org.alfresco.repo.action.evaluator.compare.PropertyValueComparator#compare(java.io.Serializable, java.io.Serializable, org.alfresco.repo.action.evaluator.compare.ComparePropertyValueOperation)
*/
public boolean compare(
Serializable propertyValue,
Serializable compareValue,
ComparePropertyValueOperation operation)
{
String compareText = (String)compareValue;
boolean result = false;
if (operation == null)
{
// Check for a trailing or leading star since it implies special behaviour when no default operation is specified
if (compareText.startsWith(STAR) == true)
{
// Remove the star and set the operation to endsWith
operation = ComparePropertyValueOperation.ENDS;
compareText = compareText.substring(1);
}
else if (compareText.endsWith(STAR) == true)
{
// Remove the star and set the operation to startsWith
operation = ComparePropertyValueOperation.BEGINS;
compareText = compareText.substring(0, (compareText.length()-2));
}
else
{
operation = ComparePropertyValueOperation.CONTAINS;
}
}
// Build the reg ex
String regEx = buildRegEx(compareText, operation);
// Do the match
if (propertyValue != null)
{
result = ((String)propertyValue).toLowerCase().matches(regEx);
}
return result;
}
/**
* Builds the regular expressin that it used to make the match
*
* @param matchText the raw text to be matched
* @param operation the operation
* @return the regular expression string
*/
private String buildRegEx(String matchText, ComparePropertyValueOperation operation)
{
String result = escapeText(matchText.toLowerCase());
switch (operation)
{
case CONTAINS:
result = "^.*" + result + ".*$";
break;
case BEGINS:
result = "^" + result + ".*$";
break;
case ENDS:
result = "^.*" + result + "$";
break;
case EQUALS:
break;
default:
// Raise an invalid operation exception
throw new ActionServiceException(
MSGID_INVALID_OPERATION,
new Object[]{operation.toString()});
}
return result;
}
/**
* Escapes the text before it is turned into a regualr expression
*
* @param matchText the raw text
* @return the escaped text
*/
private String escapeText(String matchText)
{
StringBuilder builder = new StringBuilder(matchText.length());
for (char charValue : matchText.toCharArray())
{
if (charValue == '*')
{
builder.append(".");
}
else if (getEscapeCharList().contains(charValue) == true)
{
builder.append("\\");
}
builder.append(charValue);
}
return builder.toString();
}
/**
* List of escape characters
*/
private static List<Character> ESCAPE_CHAR_LIST = null;
/**
* Get the list of escape chars
*
* @return list of excape chars
*/
private List<Character> getEscapeCharList()
{
if (ESCAPE_CHAR_LIST == null)
{
//([{\^$|)?*+.
ESCAPE_CHAR_LIST = new ArrayList<Character>(4);
ESCAPE_CHAR_LIST.add('.');
ESCAPE_CHAR_LIST.add('^');
ESCAPE_CHAR_LIST.add('$');
ESCAPE_CHAR_LIST.add('(');
ESCAPE_CHAR_LIST.add('[');
ESCAPE_CHAR_LIST.add('{');
ESCAPE_CHAR_LIST.add('\\');
ESCAPE_CHAR_LIST.add('|');
ESCAPE_CHAR_LIST.add(')');
ESCAPE_CHAR_LIST.add('?');
ESCAPE_CHAR_LIST.add('+');
}
return ESCAPE_CHAR_LIST;
}
/**
* @see org.alfresco.repo.action.evaluator.compare.PropertyValueComparator#registerComparator(org.alfresco.repo.action.evaluator.ComparePropertyValueEvaluator)
*/
public void registerComparator(ComparePropertyValueEvaluator evaluator)
{
evaluator.registerComparator(DataTypeDefinition.TEXT, this);
}
}

View File

@@ -0,0 +1,44 @@
/*
* 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.action.executer;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ActionDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* @author Roy Wetherall
*/
public interface ActionExecuter
{
/**
* Get the action definition for the action
*
* @return the action definition
*/
public ActionDefinition getActionDefinition();
/**
* Execute the action executer
*
* @param action the action
* @param actionedUponNodeRef the actioned upon node reference
*/
public void execute(
Action action,
NodeRef actionedUponNodeRef);
}

View File

@@ -0,0 +1,103 @@
/*
* 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.action.executer;
import org.alfresco.repo.action.ActionDefinitionImpl;
import org.alfresco.repo.action.ParameterizedItemAbstractBase;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ActionDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Rule action executor abstract base.
*
* @author Roy Wetherall
*/
public abstract class ActionExecuterAbstractBase extends ParameterizedItemAbstractBase implements ActionExecuter
{
/**
* Action definition
*/
protected ActionDefinition actionDefinition;
/**
* Indicated whether the action is public or internal
*/
protected boolean publicAction = true;
/**
* Init method
*/
public void init()
{
if (this.publicAction == true)
{
this.runtimeActionService.registerActionExecuter(this);
}
}
/**
* Set whether the action is public or not.
*
* @param publicAction true if the action is public, false otherwise
*/
public void setPublicAction(boolean publicAction)
{
this.publicAction = publicAction;
}
/**
* Get rule action definition
*
* @return the action definition object
*/
public ActionDefinition getActionDefinition()
{
if (this.actionDefinition == null)
{
this.actionDefinition = new ActionDefinitionImpl(this.name);
((ActionDefinitionImpl)this.actionDefinition).setTitleKey(getTitleKey());
((ActionDefinitionImpl)this.actionDefinition).setDescriptionKey(getDescriptionKey());
((ActionDefinitionImpl)this.actionDefinition).setAdhocPropertiesAllowed(getAdhocPropertiesAllowed());
((ActionDefinitionImpl)this.actionDefinition).setRuleActionExecutor(this.name);
((ActionDefinitionImpl)this.actionDefinition).setParameterDefinitions(getParameterDefintions());
}
return this.actionDefinition;
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
*/
public void execute(Action action, NodeRef actionedUponNodeRef)
{
// Check the mandatory properties
checkMandatoryProperties(action, getActionDefinition());
// Execute the implementation
executeImpl(action, actionedUponNodeRef);
}
/**
* Execute the action implementation
*
* @param action the action
* @param actionedUponNodeRef the actioned upon node
*/
protected abstract void executeImpl(Action action, NodeRef actionedUponNodeRef);
}

View File

@@ -0,0 +1,110 @@
/*
* 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.action.executer;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
/**
* Add features action executor implementation.
*
* @author Roy Wetherall
*/
public class AddFeaturesActionExecuter extends ActionExecuterAbstractBase
{
/**
* Action constants
*/
public static final String NAME = "add-features";
public static final String PARAM_ASPECT_NAME = "aspect-name";
public static final String PARAM_ASPECT_PROPERTIES = "aspect_properties";
/**
* The node service
*/
private NodeService nodeService;
/**
* Set the node service
*
* @param nodeService the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Adhoc properties are allowed for this executor
*/
@Override
protected boolean getAdhocPropertiesAllowed()
{
return true;
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.service.cmr.repository.NodeRef, NodeRef)
*/
public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef)
{
if (this.nodeService.exists(actionedUponNodeRef) == true)
{
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
QName aspectQName = null;
Map<String, Serializable> paramValues = ruleAction.getParameterValues();
for (Map.Entry<String, Serializable> entry : paramValues.entrySet())
{
if (entry.getKey().equals(PARAM_ASPECT_NAME) == true)
{
aspectQName = (QName)entry.getValue();
}
else
{
// Must be an adhoc property
QName propertyQName = QName.createQName(entry.getKey());
Serializable propertyValue = entry.getValue();
properties.put(propertyQName, propertyValue);
}
}
// Add the aspect
this.nodeService.addAspect(actionedUponNodeRef, aspectQName, properties);
}
}
/**
* @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefintions(java.util.List)
*/
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_ASPECT_NAME, DataTypeDefinition.QNAME, true, getParamDisplayLabel(PARAM_ASPECT_NAME)));
}
}

View File

@@ -0,0 +1,106 @@
/*
* 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.action.executer;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ActionImpl;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.GUID;
/**
* Add features action execution test
*
* @author Roy Wetherall
*/
public class AddFeaturesActionExecuterTest extends BaseSpringTest
{
/**
* The node service
*/
private NodeService nodeService;
/**
* The store reference
*/
private StoreRef testStoreRef;
/**
* The root node reference
*/
private NodeRef rootNodeRef;
/**
* The test node reference
*/
private NodeRef nodeRef;
/**
* The add features action executer
*/
private AddFeaturesActionExecuter executer;
/**
* Id used to identify the test action created
*/
private final static String ID = GUID.generate();
/**
* Called at the begining of all tests
*/
@Override
protected void onSetUpInTransaction() throws Exception
{
this.nodeService = (NodeService)this.applicationContext.getBean("nodeService");
// Create the store and get the root node
this.testStoreRef = this.nodeService.createStore(
StoreRef.PROTOCOL_WORKSPACE, "Test_"
+ System.currentTimeMillis());
this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef);
// Create the node used for tests
this.nodeRef = this.nodeService.createNode(
this.rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}testnode"),
ContentModel.TYPE_CONTENT).getChildRef();
// Get the executer instance
this.executer = (AddFeaturesActionExecuter)this.applicationContext.getBean(AddFeaturesActionExecuter.NAME);
}
/**
* Test execution
*/
public void testExecution()
{
// Check that the node does not have the classifiable aspect
assertFalse(this.nodeService.hasAspect(this.nodeRef, ContentModel.ASPECT_CLASSIFIABLE));
// Execute the action
ActionImpl action = new ActionImpl(ID, AddFeaturesActionExecuter.NAME, null);
action.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_CLASSIFIABLE);
this.executer.execute(action, this.nodeRef);
// Check that the node now has the classifiable aspect applied
assertTrue(this.nodeService.hasAspect(this.nodeRef, ContentModel.ASPECT_CLASSIFIABLE));
}
}

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.action.executer;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.version.VersionModel;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionType;
/**
* Check in action executor
*
* @author Roy Wetherall
*/
public class CheckInActionExecuter extends ActionExecuterAbstractBase
{
public static final String NAME = "check-in";
public static final String PARAM_DESCRIPTION = "description";
public static final String PARAM_MINOR_CHANGE = "minorChange";
/**
* The node service
*/
private NodeService nodeService;
/**
* The coci service
*/
private CheckOutCheckInService cociService;
/**
* Set node service
*
* @param nodeService the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Set the checkIn checkOut service
*
* @param cociService the checkIn checkOut Service
*/
public void setCociService(CheckOutCheckInService cociService)
{
this.cociService = cociService;
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.repo.ref.NodeRef, org.alfresco.repo.ref.NodeRef)
*/
public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef)
{
// First ensure that the actionedUponNodeRef is a workingCopy
if (this.nodeService.exists(actionedUponNodeRef) == true &&
this.nodeService.hasAspect(actionedUponNodeRef, ContentModel.ASPECT_WORKING_COPY) == true)
{
// Get the version description
String description = (String)ruleAction.getParameterValue(PARAM_DESCRIPTION);
Map<String, Serializable> versionProperties = new HashMap<String, Serializable>(1);
versionProperties.put(Version.PROP_DESCRIPTION, description);
// determine whether the change is minor or major
Boolean minorChange = (Boolean)ruleAction.getParameterValue(PARAM_MINOR_CHANGE);
if (minorChange != null && minorChange.booleanValue() == false)
{
versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MAJOR);
}
else
{
versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MINOR);
}
// TODO determine whether the document should be kept checked out
// Check the node in
this.cociService.checkin(actionedUponNodeRef, versionProperties);
}
}
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_DESCRIPTION, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_DESCRIPTION)));
}
}

View File

@@ -0,0 +1,113 @@
/*
* 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.action.executer;
import java.util.List;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
/**
* Check out action executor
*
* @author Roy Wetherall
*/
public class CheckOutActionExecuter extends ActionExecuterAbstractBase
{
public static final String NAME = "check-out";
public static final String PARAM_DESTINATION_FOLDER = "destination-folder";
public static final String PARAM_ASSOC_TYPE_QNAME = "assoc-type";
public static final String PARAM_ASSOC_QNAME = "assoc-name";
/**
* The version operations service
*/
private CheckOutCheckInService cociService;
/**
* The node service
*/
private NodeService nodeService;
/**
* Set the node service
*
* @param nodeService the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Set the coci service
*
* @param cociService the coci service
*/
public void setCociService(CheckOutCheckInService cociService)
{
this.cociService = cociService;
}
/**
* Add the parameter defintions
*/
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_DESTINATION_FOLDER, DataTypeDefinition.NODE_REF, false, getParamDisplayLabel(PARAM_DESTINATION_FOLDER)));
paramList.add(new ParameterDefinitionImpl(PARAM_ASSOC_TYPE_QNAME, DataTypeDefinition.QNAME, false, getParamDisplayLabel(PARAM_ASSOC_TYPE_QNAME)));
paramList.add(new ParameterDefinitionImpl(PARAM_ASSOC_QNAME, DataTypeDefinition.QNAME, false, getParamDisplayLabel(PARAM_ASSOC_QNAME)));
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.repo.ref.NodeRef, org.alfresco.repo.ref.NodeRef)
*/
public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef)
{
if (this.nodeService.exists(actionedUponNodeRef) == true &&
this.nodeService.hasAspect(actionedUponNodeRef, ContentModel.ASPECT_WORKING_COPY) == false)
{
// Get the destination details
NodeRef destinationParent = (NodeRef)ruleAction.getParameterValue(PARAM_DESTINATION_FOLDER);
QName destinationAssocTypeQName = (QName)ruleAction.getParameterValue(PARAM_ASSOC_TYPE_QNAME);
QName destinationAssocQName = (QName)ruleAction.getParameterValue(PARAM_ASSOC_QNAME);
if (destinationParent == null || destinationAssocTypeQName == null || destinationAssocQName == null)
{
// Check the node out to the current location
this.cociService.checkout(actionedUponNodeRef);
}
else
{
// Check the node out to the specified location
this.cociService.checkout(
actionedUponNodeRef,
destinationParent,
destinationAssocTypeQName,
destinationAssocQName);
}
}
}
}

View File

@@ -0,0 +1,78 @@
/*
* 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.action.executer;
import java.util.List;
import org.alfresco.repo.action.RuntimeActionService;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.CompositeAction;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Add features action executor implementation.
*
* @author Roy Wetherall
*/
public class CompositeActionExecuter extends ActionExecuterAbstractBase
{
/**
* Action constants
*/
public static final String NAME = "composite-action";
/**
* The action service
*/
private RuntimeActionService actionService;
/**
* Set the action service
*
* @param actionService the action service
*/
public void setActionService(RuntimeActionService actionService)
{
this.actionService = actionService;
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.service.cmr.repository.NodeRef, NodeRef)
*/
public void executeImpl(Action action, NodeRef actionedUponNodeRef)
{
if (action instanceof CompositeAction)
{
for (Action subAction : ((CompositeAction)action).getActions())
{
// We don't check the conditions of sub-actions and they don't have an execution history
this.actionService.directActionExecution(subAction, actionedUponNodeRef);
}
}
}
/**
* Add parameter definitions
*/
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
// No parameters
}
}

View File

@@ -0,0 +1,170 @@
/*
* Copyright (C) 2005 Jesper Steen M<>ller
*
* 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.action.executer;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.metadata.MetadataExtracter;
import org.alfresco.repo.content.metadata.MetadataExtracterRegistry;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.repository.ContentReader;
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.namespace.QName;
/**
* Extract metadata from any added content.
* <p>
* The metadata is extracted from the content and compared to the current
* property values. Missing or zero-length properties are replaced,
* otherwise they are left as is.<br/>
* <i>This may change if the action gets parameterized in future</i>.
*
* @author Jesper Steen M<>ller
*/
public class ContentMetadataExtracter extends ActionExecuterAbstractBase
{
/**
* Action constants
*/
public static final String NAME = "extract-metadata";
/*
* TODO: Action parameters.
*
* Currently none exist, but it may be nice to add a 'policy' parameter for
* overwriting the extracted properties, with the following possible values:
* 1) Never: Never overwrite node properties that
* exist (i.e. preserve values, nulls, and blanks)
* 2) Pragmatic: Write
* extracted properties if they didn't exist before, are null, or evaluate
* to an empty string.
* 3) Always: Always store the extracted properes.
*
* Policies 1 and 2 will preserve previously set properties in case nodes
* are moved/copied, making this action run on the same content several
* times. However, if a property is deliberately cleared (e.g. by putting
* the empty string into the "decription" field), the pragmatic policy would
* indeed overwrite it. The current implementation matches the 'pragmatic'
* policy.
*/
/**
* The node service
*/
private NodeService nodeService;
/**
* Set the node service
*
* @param nodeService the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Our content service
*/
private ContentService contentService;
/**
* @param contentService The contentService to set.
*/
public void setContentService(ContentService contentService)
{
this.contentService = contentService;
}
/**
* Our Extracter
*/
private MetadataExtracterRegistry metadataExtracterRegistry;
/**
* @param metadataExtracterRegistry The metadataExtracterRegistry to set.
*/
public void setMetadataExtracterRegistry(MetadataExtracterRegistry metadataExtracterRegistry)
{
this.metadataExtracterRegistry = metadataExtracterRegistry;
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.service.cmr.repository.NodeRef,
* NodeRef)
*/
public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef)
{
if (this.nodeService.exists(actionedUponNodeRef) == true)
{
ContentReader cr = contentService.getReader(actionedUponNodeRef, ContentModel.PROP_CONTENT);
// 'cr' may be null, e.g. for folders and the like
if (cr != null && cr.getMimetype() != null)
{
MetadataExtracter me = metadataExtracterRegistry.getExtracter(cr.getMimetype());
if (me != null)
{
Map<QName, Serializable> newProps = new HashMap<QName, Serializable>(7, 0.5f);
me.extract(cr, newProps);
Map<QName, Serializable> allProps = nodeService.getProperties(actionedUponNodeRef);
/*
* The code below implements a modestly conservative
* 'preserve' policy which shouldn't override values
* accidentally.
*/
boolean changed = false;
for (QName key : newProps.keySet())
{
Serializable value = newProps.get(key);
if (value == null)
continue; // Content extracters shouldn't do this
// Look up the old value, and check for nulls
Serializable oldValue = allProps.get(key);
if (oldValue == null || oldValue.toString().length() == 0)
{
allProps.put(key, value);
changed = true;
}
}
// TODO: Should we be adding the associated aspects or is
// that done by the type system
// (or are ad-hoc properties allowed?)
if (changed)
nodeService.setProperties(actionedUponNodeRef, allProps);
}
}
}
}
@Override
protected void addParameterDefintions(List<ParameterDefinition> arg0)
{
// None!
}
}

View File

@@ -0,0 +1,148 @@
/*
* Copyright (C) 2005 Jesper Steen M<>ller
*
* 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.action.executer;
import java.io.Serializable;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ActionImpl;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.content.metadata.MetadataExtracterRegistry;
import org.alfresco.repo.content.transform.AbstractContentTransformerTest;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.GUID;
/**
* Test of the ActionExecuter for extracting metadata. Note: This test makes
* assumptions about the PDF test data for PdfBoxExtracter.
*
* @author Jesper Steen M<>ller
*/
public class ContentMetadataExtracterTest extends BaseSpringTest
{
protected static final String QUICK_TITLE = "The quick brown fox jumps over the lazy dog";
protected static final String QUICK_DESCRIPTION = "Gym class featuring a brown fox and lazy dog";
protected static final String QUICK_CREATOR = "Nevin Nollop";
private NodeService nodeService;
private ContentService contentService;
private MetadataExtracterRegistry metadataExtracterRegistry;
private StoreRef testStoreRef;
private NodeRef rootNodeRef;
private NodeRef nodeRef;
private ContentMetadataExtracter executer;
private final static String ID = GUID.generate();
@Override
protected void onSetUpInTransaction() throws Exception
{
this.nodeService = (NodeService) this.applicationContext.getBean("nodeService");
this.contentService = (ContentService) this.applicationContext.getBean("contentService");
this.metadataExtracterRegistry = (MetadataExtracterRegistry) this.applicationContext
.getBean("metadataExtracterRegistry");
// Create the store and get the root node
this.testStoreRef = this.nodeService.createStore(
StoreRef.PROTOCOL_WORKSPACE,
"Test_" + System.currentTimeMillis());
this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef);
// Create the node used for tests
this.nodeRef = this.nodeService.createNode(
this.rootNodeRef, ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}testnode"),
ContentModel.TYPE_CONTENT).getChildRef();
// Setup the content from the PDF test data
ContentWriter cw = this.contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
cw.setMimetype(MimetypeMap.MIMETYPE_PDF);
cw.putContent(AbstractContentTransformerTest.loadQuickTestFile("pdf"));
// Get the executer instance
this.executer = (ContentMetadataExtracter) this.applicationContext.getBean(ContentMetadataExtracter.NAME);
}
/**
* Test execution of the extraction itself
*/
public void testFromBlanks()
{
// Test that the action writes properties when they don't exist or are
// unset
// Get the old props
Map<QName, Serializable> props = this.nodeService.getProperties(this.nodeRef);
props.remove(ContentModel.PROP_CREATOR);
props.put(ContentModel.PROP_TITLE, "");
props.put(ContentModel.PROP_DESCRIPTION, null); // Wonder how this will
// be handled
this.nodeService.setProperties(this.nodeRef, props);
// Execute the action
ActionImpl action = new ActionImpl(ID, SetPropertyValueActionExecuter.NAME, null);
this.executer.execute(action, this.nodeRef);
// Check that the properties have been set
assertEquals(QUICK_TITLE, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_TITLE));
assertEquals(QUICK_DESCRIPTION, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_DESCRIPTION));
assertEquals(QUICK_CREATOR, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_CREATOR));
}
/**
* Test execution of the pragmatic approach
*/
public void testFromPartial()
{
// Test that the action does not overwrite properties that are already
// set
String myCreator = "Null-op";
String myTitle = "The hot dog is eaten by the city fox";
// Get the old props
Map<QName, Serializable> props = this.nodeService.getProperties(this.nodeRef);
props.put(ContentModel.PROP_CREATOR, myCreator);
props.put(ContentModel.PROP_TITLE, myTitle);
props.remove(ContentModel.PROP_DESCRIPTION); // Allow this baby
this.nodeService.setProperties(this.nodeRef, props);
// Execute the action
ActionImpl action = new ActionImpl(ID, SetPropertyValueActionExecuter.NAME, null);
this.executer.execute(action, this.nodeRef);
// Check that the properties have been preserved
assertEquals(myTitle, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_TITLE));
assertEquals(myCreator, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_CREATOR));
// But this one should have been set
assertEquals(QUICK_DESCRIPTION, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_DESCRIPTION));
}
// If we implement other policies than "pragmatic", they should be tested as
// well...
}

View File

@@ -0,0 +1,100 @@
/*
* 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.action.executer;
import java.util.List;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.CopyService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
/**
* Copy action executor.
* <p>
* Copies the actioned upon node to a specified location.
*
* @author Roy Wetherall
*/
public class CopyActionExecuter extends ActionExecuterAbstractBase
{
public static final String NAME = "copy";
public static final String PARAM_DESTINATION_FOLDER = "destination-folder";
public static final String PARAM_ASSOC_TYPE_QNAME = "assoc-type";
public static final String PARAM_ASSOC_QNAME = "assoc-name";
public static final String PARAM_DEEP_COPY = "deep-copy";
/**
* Node operations service
*/
private CopyService copyService;
/**
* The node service
*/
private NodeService nodeService;
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void setCopyService(CopyService copyService)
{
this.copyService = copyService;
}
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_DESTINATION_FOLDER, DataTypeDefinition.NODE_REF, true, getParamDisplayLabel(PARAM_DESTINATION_FOLDER)));
paramList.add(new ParameterDefinitionImpl(PARAM_ASSOC_TYPE_QNAME, DataTypeDefinition.QNAME, true, getParamDisplayLabel(PARAM_ASSOC_TYPE_QNAME)));
paramList.add(new ParameterDefinitionImpl(PARAM_ASSOC_QNAME, DataTypeDefinition.QNAME, true, getParamDisplayLabel(PARAM_ASSOC_QNAME)));
paramList.add(new ParameterDefinitionImpl(PARAM_DEEP_COPY, DataTypeDefinition.BOOLEAN, false, getParamDisplayLabel(PARAM_DEEP_COPY)));
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.repo.ref.NodeRef, org.alfresco.repo.ref.NodeRef)
*/
public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef)
{
if (this.nodeService.exists(actionedUponNodeRef) == true)
{
NodeRef destinationParent = (NodeRef)ruleAction.getParameterValue(PARAM_DESTINATION_FOLDER);
QName destinationAssocTypeQName = (QName)ruleAction.getParameterValue(PARAM_ASSOC_TYPE_QNAME);
QName destinationAssocQName = (QName)ruleAction.getParameterValue(PARAM_ASSOC_QNAME);
// TODO get this from a parameter value
boolean deepCopy = false;
this.copyService.copy(
actionedUponNodeRef,
destinationParent,
destinationAssocTypeQName,
destinationAssocQName,
deepCopy);
}
}
}

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.action.executer;
import java.util.List;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.version.VersionService;
/**
* Add features action executor implementation.
*
* @author Roy Wetherall
*/
public class CreateVersionActionExecuter extends ActionExecuterAbstractBase
{
/**
* Action constants
*/
public static final String NAME = "create-version";
public NodeService nodeService;
public VersionService versionService;
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void setVersionService(VersionService versionService)
{
this.versionService = versionService;
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.service.cmr.repository.NodeRef, NodeRef)
*/
public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef)
{
if (this.nodeService.exists(actionedUponNodeRef) == true &&
this.nodeService.hasAspect(actionedUponNodeRef, ContentModel.ASPECT_VERSIONABLE) == true)
{
// TODO would be nice to be able to set the version details
this.versionService.createVersion(actionedUponNodeRef, null);
}
}
/**
* @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefintions(java.util.List)
*/
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
}
}

View File

@@ -0,0 +1,249 @@
/*
* 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.action.executer;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.exporter.ACPExportPackageHandler;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ActionServiceException;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.view.ExporterCrawlerParameters;
import org.alfresco.service.cmr.view.ExporterService;
import org.alfresco.service.cmr.view.Location;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.TempFileProvider;
/**
* Exporter action executor
*
* @author gavinc
*/
public class ExporterActionExecuter extends ActionExecuterAbstractBase
{
public static final String NAME = "export";
public static final String PARAM_STORE = "store";
public static final String PARAM_PACKAGE_NAME = "package-name";
public static final String PARAM_DESTINATION_FOLDER = "destination";
public static final String PARAM_INCLUDE_CHILDREN = "include-children";
public static final String PARAM_INCLUDE_SELF = "include-self";
public static final String PARAM_ENCODING = "encoding";
private static final String TEMP_FILE_PREFIX = "alf";
/**
* The exporter service
*/
private ExporterService exporterService;
/**
* The node service
*/
private NodeService nodeService;
/**
* The content service
*/
private ContentService contentService;
/**
* Sets the ExporterService to use
*
* @param exporterService The ExporterService
*/
public void setExporterService(ExporterService exporterService)
{
this.exporterService = exporterService;
}
/**
* Sets the NodeService to use
*
* @param nodeService The NodeService
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Sets the ContentService to use
*
* @param contentService The ContentService
*/
public void setContentService(ContentService contentService)
{
this.contentService = contentService;
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.repo.ref.NodeRef, org.alfresco.repo.ref.NodeRef)
*/
public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef)
{
File zipFile = null;
try
{
String packageName = (String)ruleAction.getParameterValue(PARAM_PACKAGE_NAME);
File dataFile = new File(packageName);
File contentDir = new File(packageName);
// create a temporary file to hold the zip
zipFile = TempFileProvider.createTempFile(TEMP_FILE_PREFIX, ACPExportPackageHandler.ACP_EXTENSION);
ACPExportPackageHandler zipHandler = new ACPExportPackageHandler(new FileOutputStream(zipFile),
dataFile, contentDir);
ExporterCrawlerParameters params = new ExporterCrawlerParameters();
boolean includeChildren = true;
Boolean withKids = (Boolean)ruleAction.getParameterValue(PARAM_INCLUDE_CHILDREN);
if (withKids != null)
{
includeChildren = withKids.booleanValue();
}
params.setCrawlChildNodes(includeChildren);
boolean includeSelf = false;
Boolean andMe = (Boolean)ruleAction.getParameterValue(PARAM_INCLUDE_SELF);
if (andMe != null)
{
includeSelf = andMe.booleanValue();
}
params.setCrawlSelf(includeSelf);
params.setExportFrom(new Location(actionedUponNodeRef));
// perform the actual export
this.exporterService.exportView(zipHandler, params, null);
// now the export is done we need to create a node in the repository
// to hold the exported package
NodeRef zip = createExportZip(ruleAction, actionedUponNodeRef);
ContentWriter writer = this.contentService.getWriter(zip, ContentModel.PROP_CONTENT, true);
writer.setEncoding((String)ruleAction.getParameterValue(PARAM_ENCODING));
writer.setMimetype(MimetypeMap.MIMETYPE_ACP);
writer.putContent(zipFile);
}
catch (FileNotFoundException fnfe)
{
throw new ActionServiceException("export.package.error", fnfe);
}
finally
{
// try and delete the temporary file
if (zipFile != null)
{
zipFile.delete();
}
}
}
/**
* @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefintions(java.util.List)
*/
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_PACKAGE_NAME, DataTypeDefinition.TEXT, true,
getParamDisplayLabel(PARAM_PACKAGE_NAME)));
paramList.add(new ParameterDefinitionImpl(PARAM_ENCODING, DataTypeDefinition.TEXT, true,
getParamDisplayLabel(PARAM_ENCODING)));
paramList.add(new ParameterDefinitionImpl(PARAM_STORE, DataTypeDefinition.TEXT, true,
getParamDisplayLabel(PARAM_STORE)));
paramList.add(new ParameterDefinitionImpl(PARAM_DESTINATION_FOLDER, DataTypeDefinition.NODE_REF, true,
getParamDisplayLabel(PARAM_DESTINATION_FOLDER)));
paramList.add(new ParameterDefinitionImpl(PARAM_INCLUDE_CHILDREN, DataTypeDefinition.BOOLEAN, false,
getParamDisplayLabel(PARAM_INCLUDE_CHILDREN)));
paramList.add(new ParameterDefinitionImpl(PARAM_INCLUDE_SELF, DataTypeDefinition.BOOLEAN, false,
getParamDisplayLabel(PARAM_INCLUDE_SELF)));
}
/**
* Creates the ZIP file node in the repository for the export
*
* @param ruleAction The rule being executed
* @return The NodeRef of the newly created ZIP file
*/
private NodeRef createExportZip(Action ruleAction, NodeRef actionedUponNodeRef)
{
// create a node in the repository to represent the export package
NodeRef exportDest = (NodeRef)ruleAction.getParameterValue(PARAM_DESTINATION_FOLDER);
String packageName = (String)ruleAction.getParameterValue(PARAM_PACKAGE_NAME);
// add the default Alfresco content package extension if an extension hasn't been given
if (packageName.indexOf(".") == -1)
{
packageName = packageName + "." + ACPExportPackageHandler.ACP_EXTENSION;
}
// set the name for the new node
Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>(1);
contentProps.put(ContentModel.PROP_NAME, packageName);
// create the node to represent the zip file
String assocName = QName.createValidLocalName(packageName);
ChildAssociationRef assocRef = this.nodeService.createNode(
exportDest, ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, assocName),
ContentModel.TYPE_CONTENT, contentProps);
NodeRef zipNodeRef = assocRef.getChildRef();
// build a description string to be set on the node representing the content package
String desc = "";
String storeRef = (String)ruleAction.getParameterValue(PARAM_STORE);
NodeRef rootNode = this.nodeService.getRootNode(new StoreRef(storeRef));
if (rootNode.equals(actionedUponNodeRef))
{
desc = I18NUtil.getMessage("export.root.package.description");
}
else
{
String spaceName = (String)this.nodeService.getProperty(actionedUponNodeRef, ContentModel.PROP_NAME);
String pattern = I18NUtil.getMessage("export.package.description");
if (pattern != null && spaceName != null)
{
desc = MessageFormat.format(pattern, spaceName);
}
}
// apply the titled aspect to behave in the web client
Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>(3, 1.0f);
titledProps.put(ContentModel.PROP_TITLE, packageName);
titledProps.put(ContentModel.PROP_DESCRIPTION, desc);
this.nodeService.addAspect(zipNodeRef, ContentModel.ASPECT_TITLED, titledProps);
return zipNodeRef;
}
}

View File

@@ -0,0 +1,85 @@
/*
* 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.action.executer;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.content.transform.magick.ImageMagickContentTransformer;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NoTransformerException;
/**
* Transfor action executer
*
* @author Roy Wetherall
*/
public class ImageTransformActionExecuter extends TransformActionExecuter
{
/**
* Action constants
*/
public static final String NAME = "transform-image";
public static final String PARAM_CONVERT_COMMAND = "convert-command";
private ImageMagickContentTransformer imageMagickContentTransformer;
/**
* Set the image magick content transformer
*
* @param imageMagickContentTransformer the conten transformer
*/
public void setImageMagickContentTransformer(ImageMagickContentTransformer imageMagickContentTransformer)
{
this.imageMagickContentTransformer = imageMagickContentTransformer;
}
/**
* Add parameter definitions
*/
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
super.addParameterDefintions(paramList);
paramList.add(new ParameterDefinitionImpl(PARAM_CONVERT_COMMAND, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_CONVERT_COMMAND)));
}
/**
* @see org.alfresco.repo.action.executer.TransformActionExecuter#doTransform(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.ContentReader, org.alfresco.service.cmr.repository.ContentWriter)
*/
protected void doTransform(Action ruleAction, ContentReader contentReader, ContentWriter contentWriter)
{
// check if the transformer is going to work, i.e. is available
if (!this.imageMagickContentTransformer.isAvailable())
{
throw new NoTransformerException(contentReader.getMimetype(), contentWriter.getMimetype());
}
// Try and transform the content
String convertCommand = (String)ruleAction.getParameterValue(PARAM_CONVERT_COMMAND);
// create some options for the transform
Map<String, Object> options = new HashMap<String, Object>(5);
options.put(ImageMagickContentTransformer.KEY_OPTIONS, convertCommand);
this.imageMagickContentTransformer.transform(contentReader, contentWriter, options);
}
}

View File

@@ -0,0 +1,147 @@
/*
* 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.action.executer;
import java.io.File;
import java.util.List;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.importer.ACPImportPackageHandler;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.ContentReader;
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.view.ImporterService;
import org.alfresco.service.cmr.view.Location;
import org.alfresco.util.TempFileProvider;
/**
* Importer action executor
*
* @author gavinc
*/
public class ImporterActionExecuter extends ActionExecuterAbstractBase
{
public static final String NAME = "import";
public static final String PARAM_ENCODING = "encoding";
public static final String PARAM_DESTINATION_FOLDER = "destination";
private static final String TEMP_FILE_PREFIX = "alf";
private static final String TEMP_FILE_SUFFIX = ".acp";
/**
* The importer service
*/
private ImporterService importerService;
/**
* The node service
*/
private NodeService nodeService;
/**
* The content service
*/
private ContentService contentService;
/**
* Sets the ImporterService to use
*
* @param importerService The ImporterService
*/
public void setImporterService(ImporterService importerService)
{
this.importerService = importerService;
}
/**
* Sets the NodeService to use
*
* @param nodeService The NodeService
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Sets the ContentService to use
*
* @param contentService The ContentService
*/
public void setContentService(ContentService contentService)
{
this.contentService = contentService;
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.repo.ref.NodeRef, org.alfresco.repo.ref.NodeRef)
*/
public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef)
{
if (this.nodeService.exists(actionedUponNodeRef) == true)
{
// The node being passed in should be an Alfresco content package
ContentReader reader = this.contentService.getReader(actionedUponNodeRef, ContentModel.PROP_CONTENT);
if (reader != null)
{
if (MimetypeMap.MIMETYPE_ACP.equals(reader.getMimetype()))
{
File zipFile = null;
try
{
// unfortunately a ZIP file can not be read directly from an input stream so we have to create
// a temporary file first
zipFile = TempFileProvider.createTempFile(TEMP_FILE_PREFIX, TEMP_FILE_SUFFIX);
reader.getContent(zipFile);
ACPImportPackageHandler importHandler = new ACPImportPackageHandler(zipFile,
(String)ruleAction.getParameterValue(PARAM_ENCODING));
NodeRef importDest = (NodeRef)ruleAction.getParameterValue(PARAM_DESTINATION_FOLDER);
this.importerService.importView(importHandler, new Location(importDest), null, null);
}
finally
{
// now the import is done, delete the temporary file
if (zipFile != null)
{
zipFile.delete();
}
}
}
}
}
}
/**
* @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefintions(java.util.List)
*/
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_DESTINATION_FOLDER, DataTypeDefinition.NODE_REF,
true, getParamDisplayLabel(PARAM_DESTINATION_FOLDER)));
paramList.add(new ParameterDefinitionImpl(PARAM_ENCODING, DataTypeDefinition.TEXT,
true, getParamDisplayLabel(PARAM_ENCODING)));
}
}

View File

@@ -0,0 +1,128 @@
/*
* 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.action.executer;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
/**
* Link category action executor
*
* @author Roy Wetherall
*/
public class LinkCategoryActionExecuter extends ActionExecuterAbstractBase
{
/**
* Rule constants
*/
public static final String NAME = "link-category";
public static final String PARAM_CATEGORY_ASPECT = "category-aspect";
public static final String PARAM_CATEGORY_VALUE = "category-value";
/**
* The node service
*/
private NodeService nodeService;
/**
* The dictionary service
*/
private DictionaryService dictionaryService;
/**
* Sets the node service
*
* @param nodeService the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Sets the dictionary service
*
* @param dictionaryService the dictionary service
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* Add the parameter definitions
*/
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_CATEGORY_ASPECT, DataTypeDefinition.QNAME, true, getParamDisplayLabel(PARAM_CATEGORY_ASPECT)));
paramList.add(new ParameterDefinitionImpl(PARAM_CATEGORY_VALUE, DataTypeDefinition.NODE_REF, true, getParamDisplayLabel(PARAM_CATEGORY_VALUE)));
}
/**
* Execute action implementation
*/
@Override
protected void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef)
{
// Double check that the node still exists
if (this.nodeService.exists(actionedUponNodeRef) == true)
{
// Get the rule parameter values
QName categoryAspect = (QName)ruleAction.getParameterValue(PARAM_CATEGORY_ASPECT);
NodeRef categoryValue = (NodeRef)ruleAction.getParameterValue(PARAM_CATEGORY_VALUE);
// Check that the apect is classifiable and is currently applied to the node
if (this.dictionaryService.isSubClass(categoryAspect, ContentModel.ASPECT_CLASSIFIABLE) == true)
{
// Get the category property qname
QName categoryProperty = null;
Map<QName, PropertyDefinition> propertyDefs = this.dictionaryService.getAspect(categoryAspect).getProperties();
for (Map.Entry<QName, PropertyDefinition> entry : propertyDefs.entrySet())
{
if (DataTypeDefinition.CATEGORY.equals(entry.getValue().getDataType().getName()) == true)
{
// Found the category property
categoryProperty = entry.getKey();
break;
}
}
if (categoryAspect != null)
{
// Add the aspect setting the category property to the approptiate values
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
properties.put(categoryProperty, categoryValue);
this.nodeService.addAspect(actionedUponNodeRef, categoryAspect, properties);
}
}
}
}
}

View File

@@ -0,0 +1,106 @@
/*
* 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.action.executer;
import java.util.List;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
/**
* Mail action executor implementation.
*
* @author Roy Wetherall
*/
public class MailActionExecuter extends ActionExecuterAbstractBase
{
private static Log logger = LogFactory.getLog(MailActionExecuter.class);
/**
* Action executor constants
*/
public static final String NAME = "mail";
public static final String PARAM_TO = "to";
public static final String PARAM_SUBJECT = "subject";
public static final String PARAM_TEXT = "text";
/**
* From address
*/
public static final String FROM_ADDRESS = "alfresco_repository@alfresco.org";
/**
* The java mail sender
*/
private JavaMailSender javaMailSender;
/**
* Set the java mail sender
*
* @param javaMailSender the java mail sender
*/
public void setMailService(JavaMailSender javaMailSender)
{
this.javaMailSender = javaMailSender;
}
/**
* Execute the rule action
*/
@Override
protected void executeImpl(
Action ruleAction,
NodeRef actionedUponNodeRef)
{
// Create the simple mail message
SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
simpleMailMessage.setTo((String)ruleAction.getParameterValue(PARAM_TO));
simpleMailMessage.setSubject((String)ruleAction.getParameterValue(PARAM_SUBJECT));
simpleMailMessage.setText((String)ruleAction.getParameterValue(PARAM_TEXT));
simpleMailMessage.setFrom(FROM_ADDRESS);
try
{
// Send the message
javaMailSender.send(simpleMailMessage);
}
catch (Throwable e)
{
// don't stop the action but let admins know email is not getting sent
logger.error("Failed to send email to " + (String)ruleAction.getParameterValue(PARAM_TO), e);
}
}
/**
* Add the parameter definitions
*/
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_TO, DataTypeDefinition.TEXT, true, getParamDisplayLabel(PARAM_TO)));
paramList.add(new ParameterDefinitionImpl(PARAM_SUBJECT, DataTypeDefinition.TEXT, true, getParamDisplayLabel(PARAM_SUBJECT)));
paramList.add(new ParameterDefinitionImpl(PARAM_TEXT, DataTypeDefinition.TEXT, true, getParamDisplayLabel(PARAM_TEXT)));
}
}

View File

@@ -0,0 +1,80 @@
/*
* 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.action.executer;
import java.util.List;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
/**
* Copy action executor.
* <p>
* Copies the actioned upon node to a specified location.
*
* @author Roy Wetherall
*/
public class MoveActionExecuter extends ActionExecuterAbstractBase
{
public static final String NAME = "move";
public static final String PARAM_DESTINATION_FOLDER = "destination-folder";
public static final String PARAM_ASSOC_TYPE_QNAME = "assoc-type";
public static final String PARAM_ASSOC_QNAME = "assoc-name";
/**
* Node service
*/
private NodeService nodeService;
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_DESTINATION_FOLDER, DataTypeDefinition.NODE_REF, true, getParamDisplayLabel(PARAM_DESTINATION_FOLDER)));
paramList.add(new ParameterDefinitionImpl(PARAM_ASSOC_TYPE_QNAME, DataTypeDefinition.QNAME, true, getParamDisplayLabel(PARAM_ASSOC_TYPE_QNAME)));
paramList.add(new ParameterDefinitionImpl(PARAM_ASSOC_QNAME, DataTypeDefinition.QNAME, true, getParamDisplayLabel(PARAM_ASSOC_QNAME)));
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.repo.ref.NodeRef, org.alfresco.repo.ref.NodeRef)
*/
public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef)
{
if (this.nodeService.exists(actionedUponNodeRef) == true)
{
NodeRef destinationParent = (NodeRef)ruleAction.getParameterValue(PARAM_DESTINATION_FOLDER);
QName destinationAssocTypeQName = (QName)ruleAction.getParameterValue(PARAM_ASSOC_TYPE_QNAME);
QName destinationAssocQName = (QName)ruleAction.getParameterValue(PARAM_ASSOC_QNAME);
this.nodeService.moveNode(
actionedUponNodeRef,
destinationParent,
destinationAssocTypeQName,
destinationAssocQName);
}
}
}

View File

@@ -0,0 +1,83 @@
/*
* 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.action.executer;
import java.util.List;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
/**
* Add features action executor implementation.
*
* @author Roy Wetherall
*/
public class SetPropertyValueActionExecuter extends ActionExecuterAbstractBase
{
/**
* Action constants
*/
public static final String NAME = "set-property-value";
public static final String PARAM_PROPERTY = "property";
public static final String PARAM_VALUE = "value";
/**
* The node service
*/
private NodeService nodeService;
/**
* Set the node service
*
* @param nodeService the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.service.cmr.repository.NodeRef, NodeRef)
*/
public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef)
{
if (this.nodeService.exists(actionedUponNodeRef) == true)
{
// Set the value of the property
this.nodeService.setProperty(
actionedUponNodeRef,
(QName)ruleAction.getParameterValue(PARAM_PROPERTY),
ruleAction.getParameterValue(PARAM_VALUE));
}
}
/**
* Add parameter definitions
*/
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_PROPERTY, DataTypeDefinition.QNAME, true, getParamDisplayLabel(PARAM_PROPERTY)));
paramList.add(new ParameterDefinitionImpl(PARAM_VALUE, DataTypeDefinition.ANY, true, getParamDisplayLabel(PARAM_VALUE)));
}
}

View File

@@ -0,0 +1,97 @@
/*
* 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.action.executer;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ActionImpl;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.GUID;
/**
* Is sub class evaluator test
*
* @author Roy Wetherall
*/
public class SetPropertyValueActionExecuterTest extends BaseSpringTest
{
private NodeService nodeService;
private StoreRef testStoreRef;
private NodeRef rootNodeRef;
private NodeRef nodeRef;
private SetPropertyValueActionExecuter executer;
private final static String ID = GUID.generate();
private final static String TEST_VALUE = "TestValue";
@Override
protected void onSetUpInTransaction() throws Exception
{
this.nodeService = (NodeService)this.applicationContext.getBean("nodeService");
// Create the store and get the root node
this.testStoreRef = this.nodeService.createStore(
StoreRef.PROTOCOL_WORKSPACE, "Test_"
+ System.currentTimeMillis());
this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef);
// Create the node used for tests
this.nodeRef = this.nodeService.createNode(
this.rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}testnode"),
ContentModel.TYPE_CONTENT).getChildRef();
// Get the executer instance
this.executer = (SetPropertyValueActionExecuter)this.applicationContext.getBean(SetPropertyValueActionExecuter.NAME);
}
/**
* Test execution
*/
public void testExecution()
{
// Check that the property is empty
assertNull(this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_NAME));
// Execute the action
ActionImpl action = new ActionImpl(ID, SetPropertyValueActionExecuter.NAME, null);
action.setParameterValue(SetPropertyValueActionExecuter.PARAM_PROPERTY, ContentModel.PROP_NAME);
action.setParameterValue(SetPropertyValueActionExecuter.PARAM_VALUE, TEST_VALUE);
this.executer.execute(action, this.nodeRef);
// Check that the property value has been set
assertEquals(TEST_VALUE, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_NAME));
// Check what happens when a bad property name is set
action.setParameterValue(SetPropertyValueActionExecuter.PARAM_PROPERTY, QName.createQName("{test}badProperty"));
try
{
this.executer.execute(action, this.nodeRef);
fail("We would expect and exception to be thrown since the property name is invalid.");
}
catch (Throwable exception)
{
// Good .. we where expecting this
}
}
}

View File

@@ -0,0 +1,103 @@
/*
* 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.action.executer;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
/**
* Simple workflow action executor
*
* @author Roy Wetherall
*/
public class SimpleWorkflowActionExecuter extends ActionExecuterAbstractBase
{
public static final String NAME = "simple-workflow";
public static final String PARAM_APPROVE_STEP = "approve-step";
public static final String PARAM_APPROVE_FOLDER = "approve-folder";
public static final String PARAM_APPROVE_MOVE = "approve-move";
public static final String PARAM_REJECT_STEP = "reject-step";
public static final String PARAM_REJECT_FOLDER = "reject-folder";
public static final String PARAM_REJECT_MOVE = "reject-move";
private NodeService nodeService;
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_APPROVE_STEP, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_APPROVE_STEP)));
paramList.add(new ParameterDefinitionImpl(PARAM_APPROVE_FOLDER, DataTypeDefinition.NODE_REF, false, getParamDisplayLabel(PARAM_APPROVE_FOLDER)));
paramList.add(new ParameterDefinitionImpl(PARAM_APPROVE_MOVE, DataTypeDefinition.BOOLEAN, false, getParamDisplayLabel(PARAM_APPROVE_MOVE)));
paramList.add(new ParameterDefinitionImpl(PARAM_REJECT_STEP, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_REJECT_STEP)));
paramList.add(new ParameterDefinitionImpl(PARAM_REJECT_FOLDER, DataTypeDefinition.NODE_REF, false, getParamDisplayLabel(PARAM_REJECT_FOLDER)));
paramList.add(new ParameterDefinitionImpl(PARAM_REJECT_MOVE, DataTypeDefinition.BOOLEAN, false, getParamDisplayLabel(PARAM_REJECT_MOVE)));
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
protected void executeImpl(
Action ruleAction,
NodeRef actionedUponNodeRef)
{
if (this.nodeService.exists(actionedUponNodeRef) == true)
{
// Get the parameter values
String approveStep = (String)ruleAction.getParameterValue(PARAM_APPROVE_STEP);
NodeRef approveFolder = (NodeRef)ruleAction.getParameterValue(PARAM_APPROVE_FOLDER);
Boolean approveMove = (Boolean)ruleAction.getParameterValue(PARAM_APPROVE_MOVE);
String rejectStep = (String)ruleAction.getParameterValue(PARAM_REJECT_STEP);
NodeRef rejectFolder = (NodeRef)ruleAction.getParameterValue(PARAM_REJECT_FOLDER);
Boolean rejectMove = (Boolean)ruleAction.getParameterValue(PARAM_REJECT_MOVE);
// Set the property values
Map<QName, Serializable> propertyValues = new HashMap<QName, Serializable>();
propertyValues.put(ContentModel.PROP_APPROVE_STEP, approveStep);
propertyValues.put(ContentModel.PROP_APPROVE_FOLDER, approveFolder);
if (approveMove != null)
{
propertyValues.put(ContentModel.PROP_APPROVE_MOVE, approveMove.booleanValue());
}
propertyValues.put(ContentModel.PROP_REJECT_STEP, rejectStep);
propertyValues.put(ContentModel.PROP_REJECT_FOLDER, rejectFolder);
if (rejectMove != null)
{
propertyValues.put(ContentModel.PROP_REJECT_MOVE, rejectMove.booleanValue());
}
// Apply the simple workflow aspect to the node
this.nodeService.addAspect(actionedUponNodeRef, ContentModel.ASPECT_SIMPLE_WORKFLOW, propertyValues);
}
}
}

View File

@@ -0,0 +1,103 @@
/*
* 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.action.executer;
import java.util.List;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
/**
* Add features action executor implementation.
*
* @author Roy Wetherall
*/
public class SpecialiseTypeActionExecuter extends ActionExecuterAbstractBase
{
/**
* Action constants
*/
public static final String NAME = "specialise-type";
public static final String PARAM_TYPE_NAME = "type-name";
/**
* The node service
*/
private NodeService nodeService;
/**
* The dictionary service
*/
private DictionaryService dictionaryService;
/**
* Set the node service
*
* @param nodeService the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Set the dictionary service
*
* @param dictionaryService the dictionary service
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.service.cmr.repository.NodeRef, NodeRef)
*/
public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef)
{
if (this.nodeService.exists(actionedUponNodeRef) == true)
{
// Get the type of the node
QName currentType = this.nodeService.getType(actionedUponNodeRef);
QName destinationType = (QName)ruleAction.getParameterValue(PARAM_TYPE_NAME);
// Ensure that we are performing a specialise
if (currentType.equals(destinationType) == false &&
this.dictionaryService.isSubClass(destinationType, currentType) == true)
{
// Specialise the type of the node
this.nodeService.setType(actionedUponNodeRef, destinationType);
}
}
}
/**
* @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefintions(java.util.List)
*/
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_TYPE_NAME, DataTypeDefinition.QNAME, true, getParamDisplayLabel(PARAM_TYPE_NAME)));
}
}

View File

@@ -0,0 +1,90 @@
/*
* 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.action.executer;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ActionImpl;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.BaseAlfrescoSpringTest;
import org.alfresco.util.GUID;
/**
* Specialise type action execution test
*
* @author Roy Wetherall
*/
public class SpecialiseTypeActionExecuterTest extends BaseAlfrescoSpringTest
{
/**
* The test node reference
*/
private NodeRef nodeRef;
/**
* The specialise action executer
*/
private SpecialiseTypeActionExecuter executer;
/**
* Id used to identify the test action created
*/
private final static String ID = GUID.generate();
/**
* Called at the begining of all tests
*/
@Override
protected void onSetUpInTransaction() throws Exception
{
super.onSetUpInTransaction();
// Create the node used for tests
this.nodeRef = this.nodeService.createNode(
this.rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}testnode"),
ContentModel.TYPE_CONTENT).getChildRef();
// Get the executer instance
this.executer = (SpecialiseTypeActionExecuter)this.applicationContext.getBean(SpecialiseTypeActionExecuter.NAME);
}
/**
* Test execution
*/
public void testExecution()
{
// Check the type of the node
assertEquals(ContentModel.TYPE_CONTENT, this.nodeService.getType(this.nodeRef));
// Execute the action
ActionImpl action = new ActionImpl(ID, SpecialiseTypeActionExecuter.NAME, null);
action.setParameterValue(SpecialiseTypeActionExecuter.PARAM_TYPE_NAME, ContentModel.TYPE_FOLDER);
this.executer.execute(action, this.nodeRef);
// Check that the node's type has not been changed since it would not be a specialisation
assertEquals(ContentModel.TYPE_CONTENT, this.nodeService.getType(this.nodeRef));
// Execute the action agian
action.setParameterValue(SpecialiseTypeActionExecuter.PARAM_TYPE_NAME, ContentModel.TYPE_DICTIONARY_MODEL);
this.executer.execute(action, this.nodeRef);
// Check that the node's type has now been changed
assertEquals(ContentModel.TYPE_DICTIONARY_MODEL, this.nodeService.getType(this.nodeRef));
}
}

View File

@@ -0,0 +1,247 @@
/*
* 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.action.executer;
import java.util.List;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.CopyService;
import org.alfresco.service.cmr.repository.MimetypeService;
import org.alfresco.service.cmr.repository.NoTransformerException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Transfor action executer
*
* @author Roy Wetherall
*/
public class TransformActionExecuter extends ActionExecuterAbstractBase
{
/**
* The logger
*/
private static Log logger = LogFactory.getLog(TransformActionExecuter.class);
/**
* Action constants
*/
public static final String NAME = "transform";
public static final String PARAM_MIME_TYPE = "mime-type";
public static final String PARAM_DESTINATION_FOLDER = "destination-folder";
public static final String PARAM_ASSOC_TYPE_QNAME = "assoc-type";
public static final String PARAM_ASSOC_QNAME = "assoc-name";
private DictionaryService dictionaryService;
private NodeService nodeService;
private ContentService contentService;
private CopyService copyService;
private MimetypeService mimetypeService;
/**
* Set the mime type service
*
* @param mimetypeService the mime type service
*/
public void setMimetypeService(MimetypeService mimetypeService)
{
this.mimetypeService = mimetypeService;
}
/**
* Set the node service
*
* @param nodeService set the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Set the dictionary service
*
* @param dictionaryService the dictionary service
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* Set the content service
*
* @param contentService the content service
*/
public void setContentService(ContentService contentService)
{
this.contentService = contentService;
}
/**
* Set the copy service
*
* @param copyService the copy service
*/
public void setCopyService(CopyService copyService)
{
this.copyService = copyService;
}
/**
* Add parameter definitions
*/
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_MIME_TYPE, DataTypeDefinition.TEXT, true, getParamDisplayLabel(PARAM_MIME_TYPE)));
paramList.add(new ParameterDefinitionImpl(PARAM_DESTINATION_FOLDER, DataTypeDefinition.NODE_REF, true, getParamDisplayLabel(PARAM_DESTINATION_FOLDER)));
paramList.add(new ParameterDefinitionImpl(PARAM_ASSOC_TYPE_QNAME, DataTypeDefinition.QNAME, true, getParamDisplayLabel(PARAM_ASSOC_TYPE_QNAME)));
paramList.add(new ParameterDefinitionImpl(PARAM_ASSOC_QNAME, DataTypeDefinition.QNAME, true, getParamDisplayLabel(PARAM_ASSOC_QNAME)));
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
protected void executeImpl(
Action ruleAction,
NodeRef actionedUponNodeRef)
{
if (this.nodeService.exists(actionedUponNodeRef) == false)
{
// node doesn't exist - can't do anything
return;
}
// First check that the node is a sub-type of content
QName typeQName = this.nodeService.getType(actionedUponNodeRef);
if (this.dictionaryService.isSubClass(typeQName, ContentModel.TYPE_CONTENT) == false)
{
// it is not content, so can't transform
return;
}
// Get the mime type
String mimeType = (String)ruleAction.getParameterValue(PARAM_MIME_TYPE);
// Get the details of the copy destination
NodeRef destinationParent = (NodeRef)ruleAction.getParameterValue(PARAM_DESTINATION_FOLDER);
QName destinationAssocTypeQName = (QName)ruleAction.getParameterValue(PARAM_ASSOC_TYPE_QNAME);
QName destinationAssocQName = (QName)ruleAction.getParameterValue(PARAM_ASSOC_QNAME);
// Copy the content node
NodeRef copyNodeRef = this.copyService.copy(
actionedUponNodeRef,
destinationParent,
destinationAssocTypeQName,
destinationAssocQName,
false);
// Get the content reader
ContentReader contentReader = this.contentService.getReader(actionedUponNodeRef, ContentModel.PROP_CONTENT);
if (contentReader == null)
{
// for some reason, this action is premature
throw new AlfrescoRuntimeException(
"Attempting to execute content transformation rule " +
"but content has not finished writing, i.e. no URL is available.");
}
String originalMimetype = contentReader.getMimetype();
// get the writer and set it up
ContentWriter contentWriter = this.contentService.getWriter(copyNodeRef, ContentModel.PROP_CONTENT, true);
contentWriter.setMimetype(mimeType); // new mimetype
contentWriter.setEncoding(contentReader.getEncoding()); // original encoding
// Adjust the name of the copy
String originalName = (String)nodeService.getProperty(actionedUponNodeRef, ContentModel.PROP_NAME);
String newName = transformName(originalName, originalMimetype, mimeType);
nodeService.setProperty(copyNodeRef, ContentModel.PROP_NAME, newName);
String originalTitle = (String)nodeService.getProperty(actionedUponNodeRef, ContentModel.PROP_TITLE);
if (originalTitle != null && originalTitle.length() > 0)
{
String newTitle = transformName(originalTitle, originalMimetype, mimeType);
nodeService.setProperty(copyNodeRef, ContentModel.PROP_TITLE, newTitle);
}
// Try and transform the content
try
{
doTransform(ruleAction, contentReader, contentWriter);
}
catch(NoTransformerException e)
{
if (logger.isDebugEnabled())
{
logger.debug("No transformer found to execute rule: \n" +
" reader: " + contentReader + "\n" +
" writer: " + contentWriter + "\n" +
" action: " + this);
}
// TODO: Revisit this for alternative solutions
nodeService.deleteNode(copyNodeRef);
}
}
protected void doTransform(Action ruleAction, ContentReader contentReader, ContentWriter contentWriter)
{
this.contentService.transform(contentReader, contentWriter);
}
/**
* Transform name from original extension to new extension
*
* @param original
* @param originalMimetype
* @param newMimetype
* @return
*/
private String transformName(String original, String originalMimetype, String newMimetype)
{
// get the current extension
int dotIndex = original.lastIndexOf('.');
StringBuilder sb = new StringBuilder(original.length());
if (dotIndex > -1)
{
// we found it
sb.append(original.substring(0, dotIndex));
}
else
{
// no extension
sb.append(original);
}
// add the new extension
String newExtension = mimetypeService.getExtension(newMimetype);
sb.append('.').append(newExtension);
// done
return sb.toString();
}
}