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 java.util.List;
050:
051: import org.apache.fulcrum.intake.model.Group;
052: import org.apache.fulcrum.parser.ParameterParser;
053: import org.apache.turbine.RunData;
054: import org.apache.turbine.TemplateContext;
055: import org.apache.turbine.tool.IntakeTool;
056: import org.tigris.scarab.actions.base.RequireLoginFirstAction;
057: import org.tigris.scarab.om.Attribute;
058: import org.tigris.scarab.om.AttributeOption;
059: import org.tigris.scarab.om.AttributeOptionManager;
060: import org.tigris.scarab.om.IssueType;
061: import org.tigris.scarab.om.Module;
062: import org.tigris.scarab.om.RIssueTypeAttribute;
063: import org.tigris.scarab.om.RModuleAttribute;
064: import org.tigris.scarab.om.RModuleOption;
065: import org.tigris.scarab.services.cache.ScarabCache;
066: import org.tigris.scarab.tools.ScarabLocalizationTool;
067: import org.tigris.scarab.tools.ScarabRequestTool;
068: import org.tigris.scarab.workflow.WorkflowFactory;
069:
070: /**
071: * @author <a href="mailto:elicia@collab.net">Elicia David</a>
072: * @version $Id: ModuleAttributeEdit.java 9366 2005-01-04 17:24:36Z jorgeuriarte $
073: */
074: public class ModuleAttributeEdit extends RequireLoginFirstAction {
075: /**
076: * Changes the properties of existing AttributeOptions.
077: */
078: public synchronized void doSave(RunData data,
079: TemplateContext context) throws Exception {
080: ScarabRequestTool scarabR = getScarabRequestTool(context);
081: ScarabLocalizationTool l10n = getLocalizationTool(context);
082: Module module = scarabR.getCurrentModule();
083: IssueType issueType = scarabR.getIssueType();
084:
085: if (issueType.getLocked()) {
086: scarabR.setAlertMessage(l10n.get("LockedIssueType"));
087: return;
088: }
089: Attribute attribute = scarabR.getAttribute();
090: RIssueTypeAttribute ria = issueType
091: .getRIssueTypeAttribute(attribute);
092: if (ria != null && ria.getLocked()) {
093: scarabR.setAlertMessage(l10n.format("LockedAttribute",
094: attribute.getName()));
095: return;
096: }
097:
098: IntakeTool intake = getIntakeTool(context);
099: if (intake.isAllValid()) {
100: List rmos = module.getRModuleOptions(attribute, issueType,
101: false);
102: // Check for duplicate sequence numbers
103: if (areThereDupeSequences(rmos, intake, "RModuleOption",
104: "Order", 0))
105:
106: {
107: scarabR.setAlertMessage(l10n.format(
108: "DuplicateSequenceNumbersFound", l10n.get(
109: "AttributeOptions").toLowerCase()));
110: return;
111: }
112: if (rmos != null) {
113: for (int i = rmos.size() - 1; i >= 0; i--) {
114: RModuleOption rmo = (RModuleOption) rmos.get(i);
115: Group rmoGroup = intake.get("RModuleOption", rmo
116: .getQueryKey(), false);
117: // if option gets set to inactive, delete dependencies
118: if (rmoGroup != null) {
119: String newActive = rmoGroup.get("Active")
120: .toString();
121: String oldActive = String.valueOf(rmo
122: .getActive());
123: if (newActive.equals("false")
124: && oldActive.equals("true")) {
125: WorkflowFactory.getInstance()
126: .deleteWorkflowsForOption(
127: rmo.getAttributeOption(),
128: module, issueType);
129: }
130: rmoGroup.setProperties(rmo);
131: rmo.save();
132: }
133: ScarabCache.clear();
134: scarabR.setConfirmMessage(l10n.get(DEFAULT_MSG));
135: }
136: }
137: }
138: if (attribute.isOptionAttribute()) {
139: List options = module.getRModuleOptions(attribute,
140: issueType, true);
141: if (options == null || options.isEmpty()) {
142: RModuleAttribute rma = module.getRModuleAttribute(
143: attribute, issueType);
144: if (rma.getRequired()) {
145: rma.setRequired(false);
146: rma.save();
147: scarabR
148: .setAlertMessage(l10n
149: .get("DeletedOptionsFromRequiredAttribute"));
150: }
151: }
152: }
153: }
154:
155: /**
156: * Unmaps attribute options to modules.
157: */
158: public void doDeleteattributeoptions(RunData data,
159: TemplateContext context) throws Exception {
160: ScarabRequestTool scarabR = getScarabRequestTool(context);
161: ScarabLocalizationTool l10n = getLocalizationTool(context);
162: IssueType issueType = scarabR.getIssueType();
163: if (issueType.getLocked()) {
164: scarabR.setAlertMessage(l10n.get("LockedIssueType"));
165: return;
166: }
167: Attribute attribute = scarabR.getAttribute();
168: RIssueTypeAttribute ria = issueType
169: .getRIssueTypeAttribute(attribute);
170: if (ria != null && ria.getLocked()) {
171: scarabR.setAlertMessage(l10n.format("LockedAttribute",
172: attribute.getName()));
173: return;
174: }
175:
176: Module module = scarabR.getCurrentModule();
177: ParameterParser params = data.getParameters();
178: Object[] keys = params.getKeys();
179: String key;
180: String optionId;
181:
182: for (int i = 0; i < keys.length; i++) {
183: key = keys[i].toString();
184: if (key.startsWith("delete_")) {
185: optionId = key.substring(7);
186: AttributeOption option = AttributeOptionManager
187: .getInstance(new Integer(optionId));
188:
189: RModuleOption rmo = module.getRModuleOption(option,
190: issueType);
191: rmo.delete();
192:
193: // Remove option - module mapping from template type
194: RModuleOption rmo2 = module.getRModuleOption(option,
195: scarabR.getIssueType(issueType.getTemplateId()
196: .toString()));
197: rmo2.delete();
198: scarabR.setConfirmMessage(l10n.get(DEFAULT_MSG));
199: ScarabCache.clear();
200: getIntakeTool(context).removeAll();
201: data.getParameters().add(
202: "att_0id",
203: option.getAttribute().getAttributeId()
204: .toString());
205: }
206: }
207: if (attribute.isOptionAttribute()) {
208: List options = module.getRModuleOptions(attribute,
209: issueType, true);
210: if (options == null || options.isEmpty()) {
211: RModuleAttribute rma = module.getRModuleAttribute(
212: attribute, issueType);
213: if (rma.getRequired()) {
214: rma.setRequired(false);
215: rma.save();
216: scarabR
217: .setAlertMessage(l10n
218: .get("DeletedOptionsFromRequiredAttribute"));
219: }
220: }
221: }
222: }
223:
224: /**
225: * Selects option to add to attribute.
226: */
227: public void doSelectattributeoption(RunData data,
228: TemplateContext context) throws Exception {
229: ScarabRequestTool scarabR = getScarabRequestTool(context);
230: ScarabLocalizationTool l10n = getLocalizationTool(context);
231: IssueType issueType = scarabR.getIssueType();
232: if (issueType.getLocked()) {
233: scarabR.setAlertMessage(l10n.get("LockedIssueType"));
234: return;
235: }
236: Attribute attribute = scarabR.getAttribute();
237: RIssueTypeAttribute ria = issueType
238: .getRIssueTypeAttribute(attribute);
239: if (ria != null && ria.getLocked()) {
240: scarabR.setAlertMessage(l10n.format("LockedAttribute",
241: attribute.getName()));
242: return;
243: }
244: Module module = scarabR.getCurrentModule();
245:
246: String[] optionIds = data.getParameters().getStrings(
247: "option_ids");
248:
249: if (optionIds == null || optionIds.length <= 0) {
250: scarabR.setAlertMessage(l10n.get("SelectOption"));
251: return;
252: } else {
253: for (int i = 0; i < optionIds.length; i++) {
254: AttributeOption option = null;
255: try {
256: option = scarabR.getAttributeOption(new Integer(
257: optionIds[i]));
258: module.addAttributeOption(issueType, option);
259: } catch (Exception e) {
260: e.printStackTrace();
261: }
262: }
263: ScarabCache.clear();
264: scarabR.setConfirmMessage(l10n.get(DEFAULT_MSG));
265: doCancel(data, context);
266: }
267: }
268:
269: /**
270: * Manages clicking of the Done button
271: */
272: public void doDone(RunData data, TemplateContext context)
273: throws Exception {
274: doSave(data, context);
275: if (getScarabRequestTool(context).getAlertMessage() == null) {
276: doCancel(data, context);
277: }
278: }
279: }
|