001: package org.tigris.scarab.actions.admin;
002:
003: /* ================================================================
004: * Copyright (c) 2000-2002 CollabNet. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions are
008: * met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: *
017: * 3. The end-user documentation included with the redistribution, if
018: * any, must include the following acknowlegement: "This product includes
019: * software developed by Collab.Net <http://www.Collab.Net/>."
020: * Alternately, this acknowlegement may appear in the software itself, if
021: * and wherever such third-party acknowlegements normally appear.
022: *
023: * 4. The hosted project names must not be used to endorse or promote
024: * products derived from this software without prior written
025: * permission. For written permission, please contact info@collab.net.
026: *
027: * 5. Products derived from this software may not use the "Tigris" or
028: * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
029: * prior written permission of Collab.Net.
030: *
031: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
032: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
033: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
034: * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
035: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
036: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
037: * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
038: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
039: * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
040: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
041: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
042: *
043: * ====================================================================
044: *
045: * This software consists of voluntary contributions made by many
046: * individuals on behalf of Collab.Net.
047: */
048:
049: import org.apache.fulcrum.intake.model.Group;
050: import org.apache.torque.TorqueException;
051: import org.apache.torque.util.Criteria;
052: import org.apache.turbine.RunData;
053: import org.apache.turbine.TemplateContext;
054: import org.apache.turbine.tool.IntakeTool;
055: import org.tigris.scarab.actions.base.RequireLoginFirstAction;
056: import org.tigris.scarab.om.Attribute;
057: import org.tigris.scarab.om.AttributeManager;
058: import org.tigris.scarab.om.ConditionManager;
059: import org.tigris.scarab.om.ConditionPeer;
060: import org.tigris.scarab.om.Module;
061: import org.tigris.scarab.om.RModuleAttribute;
062: import org.tigris.scarab.om.RModuleAttributeManager;
063: import org.tigris.scarab.om.RModuleAttributePeer;
064: import org.tigris.scarab.om.RModuleIssueType;
065: import org.tigris.scarab.om.RModuleIssueTypeManager;
066: import org.tigris.scarab.om.RModuleIssueTypePeer;
067: import org.tigris.scarab.om.Transition;
068: import org.tigris.scarab.om.TransitionManager;
069: import org.tigris.scarab.tools.ScarabRequestTool;
070: import org.tigris.scarab.util.ScarabConstants;
071:
072: public class ConditionEdit extends RequireLoginFirstAction {
073:
074: public void doDelete(RunData data, TemplateContext context)
075: throws TorqueException, Exception {
076: IntakeTool intake = getIntakeTool(context);
077: Group attrGroup = intake.get("ConditionEdit",
078: IntakeTool.DEFAULT_KEY);
079: data.getParameters().remove(
080: attrGroup.get("ConditionsArray").getKey());
081: updateObject(data, context, null);
082: }
083:
084: private void delete(RunData data) throws TorqueException, Exception {
085: int nObjectType = data.getParameters().getInt("obj_type");
086: Criteria crit = new Criteria();
087: switch (nObjectType) {
088: case ScarabConstants.TRANSITION_OBJECT:
089: Integer tranId = data.getParameters().getInteger(
090: "transition_id");
091: crit.add(ConditionPeer.TRANSITION_ID, tranId);
092: TransitionManager.getMethodResult().remove(
093: TransitionManager.getInstance(tranId),
094: TransitionManager.GET_CONDITIONS);
095: break;
096: case ScarabConstants.GLOBAL_ATTRIBUTE_OBJECT:
097: crit.add(ConditionPeer.ATTRIBUTE_ID, data.getParameters()
098: .getInt("attId"));
099: crit.add(ConditionPeer.MODULE_ID, 0);
100: crit.add(ConditionPeer.ISSUE_TYPE_ID, 0);
101: break;
102: case ScarabConstants.MODULE_ATTRIBUTE_OBJECT:
103: crit.add(ConditionPeer.ATTRIBUTE_ID, data.getParameters()
104: .getInt("attId"));
105: crit.add(ConditionPeer.MODULE_ID, data.getParameters()
106: .getInt("module_id"));
107: crit.add(ConditionPeer.ISSUE_TYPE_ID, data.getParameters()
108: .getInt("issueTypeId"));
109: break;
110: }
111: ConditionPeer.doDelete(crit);
112: ConditionManager.clear();
113: TransitionManager.clear();
114: }
115:
116: private void updateObject(RunData data, TemplateContext context,
117: Integer aConditions[]) throws Exception {
118: ScarabRequestTool scarabR = getScarabRequestTool(context);
119: switch (data.getParameters().getInt("obj_type")) {
120: case ScarabConstants.TRANSITION_OBJECT:
121: Transition transition = scarabR.getTransition(data
122: .getParameters().getInteger("transition_id"));
123: transition.setConditionsArray(aConditions);
124: transition.save();
125: TransitionManager.getMethodResult().remove(transition,
126: TransitionManager.GET_CONDITIONS);
127: break;
128: case ScarabConstants.GLOBAL_ATTRIBUTE_OBJECT:
129: Attribute attribute = scarabR.getAttribute(data
130: .getParameters().getInteger("attId"));
131: attribute.setConditionsArray(aConditions);
132: attribute.save();
133: break;
134: case ScarabConstants.MODULE_ATTRIBUTE_OBJECT:
135: RModuleAttribute rma = RModuleAttributePeer.retrieveByPK(
136: data.getParameters().getInteger("moduleId"), data
137: .getParameters().getInteger("attId"), data
138: .getParameters().getInteger("issueTypeId"));
139: rma.setConditionsArray(aConditions);
140: RModuleAttributeManager.clear();
141: ConditionManager.clear();
142: rma.save();
143: /** TODO: do we need it? **/
144: break;
145: case ScarabConstants.BLOCKED_MODULE_ISSUE_TYPE_OBJECT:
146: RModuleIssueType rmit = RModuleIssueTypePeer.retrieveByPK(
147: scarabR.getCurrentModule().getModuleId(), data
148: .getParameters().getInteger("issuetypeid"));
149: rmit.setConditionsArray(aConditions);
150: rmit.save();
151: RModuleIssueTypeManager.clear();
152: ConditionManager.clear();
153: break;
154: }
155: AttributeManager.clear();
156: }
157:
158: public void doSave(RunData data, TemplateContext context)
159: throws Exception {
160: this .delete(data);
161: IntakeTool intake = getIntakeTool(context);
162: Group attrGroup = intake.get("ConditionEdit",
163: IntakeTool.DEFAULT_KEY);
164: Integer aConditions[] = ((Integer[]) attrGroup.get(
165: "ConditionsArray").getValue());
166: updateObject(data, context, aConditions);
167:
168: }
169:
170: public void doCancel(RunData data, TemplateContext context)
171: throws Exception {
172: String lastTemplate = getCancelTemplate(data);
173: if (lastTemplate != null) {
174: setTarget(data, lastTemplate);
175: } else {
176: super.doCancel(data, context);
177: }
178: }
179: }
|