KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > action > executer > SimpleWorkflowActionExecuter


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.action.executer;
18
19 import java.io.Serializable JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.List JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import org.alfresco.model.ContentModel;
25 import org.alfresco.repo.action.ParameterDefinitionImpl;
26 import org.alfresco.service.cmr.action.Action;
27 import org.alfresco.service.cmr.action.ParameterDefinition;
28 import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
29 import org.alfresco.service.cmr.repository.NodeRef;
30 import org.alfresco.service.cmr.repository.NodeService;
31 import org.alfresco.service.namespace.QName;
32
33 /**
34  * Simple workflow action executor
35  *
36  * @author Roy Wetherall
37  */

38 public class SimpleWorkflowActionExecuter extends ActionExecuterAbstractBase
39 {
40     public static final String JavaDoc NAME = "simple-workflow";
41     public static final String JavaDoc PARAM_APPROVE_STEP = "approve-step";
42     public static final String JavaDoc PARAM_APPROVE_FOLDER = "approve-folder";
43     public static final String JavaDoc PARAM_APPROVE_MOVE = "approve-move";
44     public static final String JavaDoc PARAM_REJECT_STEP = "reject-step";
45     public static final String JavaDoc PARAM_REJECT_FOLDER = "reject-folder";
46     public static final String JavaDoc PARAM_REJECT_MOVE = "reject-move";
47     
48     private NodeService nodeService;
49
50     public void setNodeService(NodeService nodeService)
51     {
52         this.nodeService = nodeService;
53     }
54
55     @Override JavaDoc
56     protected void addParameterDefintions(List JavaDoc<ParameterDefinition> paramList)
57     {
58         paramList.add(new ParameterDefinitionImpl(PARAM_APPROVE_STEP, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_APPROVE_STEP)));
59         paramList.add(new ParameterDefinitionImpl(PARAM_APPROVE_FOLDER, DataTypeDefinition.NODE_REF, false, getParamDisplayLabel(PARAM_APPROVE_FOLDER)));
60         paramList.add(new ParameterDefinitionImpl(PARAM_APPROVE_MOVE, DataTypeDefinition.BOOLEAN, false, getParamDisplayLabel(PARAM_APPROVE_MOVE)));
61         paramList.add(new ParameterDefinitionImpl(PARAM_REJECT_STEP, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_REJECT_STEP)));
62         paramList.add(new ParameterDefinitionImpl(PARAM_REJECT_FOLDER, DataTypeDefinition.NODE_REF, false, getParamDisplayLabel(PARAM_REJECT_FOLDER)));
63         paramList.add(new ParameterDefinitionImpl(PARAM_REJECT_MOVE, DataTypeDefinition.BOOLEAN, false, getParamDisplayLabel(PARAM_REJECT_MOVE)));
64     }
65
66     /**
67      * @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
68      */

69     @Override JavaDoc
70     protected void executeImpl(
71             Action ruleAction,
72             NodeRef actionedUponNodeRef)
73     {
74         if (this.nodeService.exists(actionedUponNodeRef) == true)
75         {
76             // Get the parameter values
77
String JavaDoc approveStep = (String JavaDoc)ruleAction.getParameterValue(PARAM_APPROVE_STEP);
78             NodeRef approveFolder = (NodeRef)ruleAction.getParameterValue(PARAM_APPROVE_FOLDER);
79             Boolean JavaDoc approveMove = (Boolean JavaDoc)ruleAction.getParameterValue(PARAM_APPROVE_MOVE);
80             String JavaDoc rejectStep = (String JavaDoc)ruleAction.getParameterValue(PARAM_REJECT_STEP);
81             NodeRef rejectFolder = (NodeRef)ruleAction.getParameterValue(PARAM_REJECT_FOLDER);
82             Boolean JavaDoc rejectMove = (Boolean JavaDoc)ruleAction.getParameterValue(PARAM_REJECT_MOVE);
83             
84             // Set the property values
85
Map JavaDoc<QName, Serializable JavaDoc> propertyValues = new HashMap JavaDoc<QName, Serializable JavaDoc>();
86             propertyValues.put(ContentModel.PROP_APPROVE_STEP, approveStep);
87             propertyValues.put(ContentModel.PROP_APPROVE_FOLDER, approveFolder);
88             if (approveMove != null)
89             {
90                 propertyValues.put(ContentModel.PROP_APPROVE_MOVE, approveMove.booleanValue());
91             }
92             propertyValues.put(ContentModel.PROP_REJECT_STEP, rejectStep);
93             propertyValues.put(ContentModel.PROP_REJECT_FOLDER, rejectFolder);
94             if (rejectMove != null)
95             {
96                 propertyValues.put(ContentModel.PROP_REJECT_MOVE, rejectMove.booleanValue());
97             }
98             
99             // Apply the simple workflow aspect to the node
100
this.nodeService.addAspect(actionedUponNodeRef, ContentModel.ASPECT_SIMPLE_WORKFLOW, propertyValues);
101         }
102     }
103 }
104
Popular Tags