KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > actions > admin > ConditionEdit


1 package org.tigris.scarab.actions.admin;
2
3 /* ================================================================
4  * Copyright (c) 2000-2002 CollabNet. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * 3. The end-user documentation included with the redistribution, if
18  * any, must include the following acknowlegement: "This product includes
19  * software developed by Collab.Net <http://www.Collab.Net/>."
20  * Alternately, this acknowlegement may appear in the software itself, if
21  * and wherever such third-party acknowlegements normally appear.
22  *
23  * 4. The hosted project names must not be used to endorse or promote
24  * products derived from this software without prior written
25  * permission. For written permission, please contact info@collab.net.
26  *
27  * 5. Products derived from this software may not use the "Tigris" or
28  * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
29  * prior written permission of Collab.Net.
30  *
31  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
32  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34  * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
35  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
37  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
39  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  *
43  * ====================================================================
44  *
45  * This software consists of voluntary contributions made by many
46  * individuals on behalf of Collab.Net.
47  */

48
49 import org.apache.fulcrum.intake.model.Group;
50 import org.apache.torque.TorqueException;
51 import org.apache.torque.util.Criteria;
52 import org.apache.turbine.RunData;
53 import org.apache.turbine.TemplateContext;
54 import org.apache.turbine.tool.IntakeTool;
55 import org.tigris.scarab.actions.base.RequireLoginFirstAction;
56 import org.tigris.scarab.om.Attribute;
57 import org.tigris.scarab.om.AttributeManager;
58 import org.tigris.scarab.om.ConditionManager;
59 import org.tigris.scarab.om.ConditionPeer;
60 import org.tigris.scarab.om.Module;
61 import org.tigris.scarab.om.RModuleAttribute;
62 import org.tigris.scarab.om.RModuleAttributeManager;
63 import org.tigris.scarab.om.RModuleAttributePeer;
64 import org.tigris.scarab.om.RModuleIssueType;
65 import org.tigris.scarab.om.RModuleIssueTypeManager;
66 import org.tigris.scarab.om.RModuleIssueTypePeer;
67 import org.tigris.scarab.om.Transition;
68 import org.tigris.scarab.om.TransitionManager;
69 import org.tigris.scarab.tools.ScarabRequestTool;
70 import org.tigris.scarab.util.ScarabConstants;
71
72 public class ConditionEdit extends RequireLoginFirstAction
73 {
74     private int transitionId;
75     private int moduleId;
76     private int attributeId;
77     private int issueTypeId;
78
79     public void doDelete(RunData data, TemplateContext context) throws TorqueException, Exception JavaDoc
80     {
81         IntakeTool intake = getIntakeTool(context);
82         Group attrGroup = intake.get("ConditionEdit", IntakeTool.DEFAULT_KEY);
83         data.getParameters().remove(attrGroup.get("ConditionsArray").getKey());
84         updateObject(data, context, null);
85     }
86
87     private void delete(RunData data) throws TorqueException, Exception JavaDoc
88     {
89         int nObjectType = data.getParameters().getInt("obj_type");
90         Criteria crit = new Criteria();
91         switch (nObjectType)
92         {
93             case ScarabConstants.TRANSITION_OBJECT:
94                 crit.add(ConditionPeer.TRANSITION_ID, data.getParameters().getInt("transition_id"));
95                 break;
96             case ScarabConstants.GLOBAL_ATTRIBUTE_OBJECT:
97                 crit.add(ConditionPeer.ATTRIBUTE_ID, data.getParameters().getInt("attId"));
98                 crit.add(ConditionPeer.MODULE_ID, 0);
99                 crit.add(ConditionPeer.ISSUE_TYPE_ID, 0);
100                 break;
101             case ScarabConstants.MODULE_ATTRIBUTE_OBJECT:
102                 crit.add(ConditionPeer.ATTRIBUTE_ID, data.getParameters().getInt("attId"));
103                 crit.add(ConditionPeer.MODULE_ID, data.getParameters().getInt("module_id"));
104                 crit.add(ConditionPeer.ISSUE_TYPE_ID, data.getParameters().getInt("issueTypeId"));
105                 break;
106         }
107         ConditionPeer.doDelete(crit);
108         ConditionManager.clear();
109         TransitionManager.clear();
110     }
111     
112     private void updateObject(RunData data, TemplateContext context, Integer JavaDoc aConditions[]) throws Exception JavaDoc
113     {
114         ScarabRequestTool scarabR = getScarabRequestTool(context);
115         switch (data.getParameters().getInt("obj_type"))
116         {
117             case ScarabConstants.TRANSITION_OBJECT:
118                 Transition transition = scarabR.getTransition(data.getParameters().getInteger("transition_id"));
119                 transition.setConditionsArray(aConditions);
120                 transition.save();
121                 break;
122             case ScarabConstants.GLOBAL_ATTRIBUTE_OBJECT:
123                 Attribute attribute = scarabR.getAttribute(data.getParameters().getInteger("attId"));
124                 attribute.setConditionsArray(aConditions);
125                 attribute.save();
126                 break;
127             case ScarabConstants.MODULE_ATTRIBUTE_OBJECT:
128                 Module module = scarabR.getCurrentModule();
129                 RModuleAttribute rma = RModuleAttributePeer.retrieveByPK(data.getParameters().getInteger("moduleId"), data.getParameters().getInteger("attId"), data.getParameters().getInteger("issueTypeId"));
130                 rma.setConditionsArray(aConditions);
131                 RModuleAttributeManager.clear();
132                 ConditionManager.clear();
133                 rma.save(); /** TODO: Esto sobra! **/
134                 break;
135             case ScarabConstants.BLOCKED_MODULE_ISSUE_TYPE_OBJECT:
136                 RModuleIssueType rmit = RModuleIssueTypePeer.retrieveByPK(scarabR.getCurrentModule().getModuleId(), data.getParameters().getInteger("issuetypeid"));
137                 rmit.setConditionsArray(aConditions);
138                 rmit.save();
139                 RModuleIssueTypeManager.clear();
140                 ConditionManager.clear();
141                 break;
142         }
143         AttributeManager.clear();
144     }
145     
146     public void doSave(RunData data, TemplateContext context) throws Exception JavaDoc
147     {
148         this.delete(data);
149         IntakeTool intake = getIntakeTool(context);
150         Group attrGroup = intake.get("ConditionEdit", IntakeTool.DEFAULT_KEY);
151         Integer JavaDoc aConditions[] = ((Integer JavaDoc[])attrGroup.get("ConditionsArray").getValue());
152         updateObject(data, context, aConditions);
153             
154     }
155     
156     public void doCancel(RunData data, TemplateContext context) throws Exception JavaDoc
157     {
158         String JavaDoc lastTemplate = getCancelTemplate(data);
159         if (lastTemplate != null)
160         {
161             setTarget(data, lastTemplate);
162         }
163         else
164         {
165             super.doCancel(data, context);
166         }
167     }
168 }
169
170
Popular Tags