KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.List JavaDoc;
50
51 import org.apache.fulcrum.intake.model.Group;
52 import org.apache.fulcrum.parser.ParameterParser;
53 import org.apache.turbine.RunData;
54 import org.apache.turbine.TemplateContext;
55 import org.apache.turbine.tool.IntakeTool;
56 import org.tigris.scarab.actions.base.RequireLoginFirstAction;
57 import org.tigris.scarab.om.Attribute;
58 import org.tigris.scarab.om.AttributeOption;
59 import org.tigris.scarab.om.AttributeOptionManager;
60 import org.tigris.scarab.om.IssueType;
61 import org.tigris.scarab.om.Module;
62 import org.tigris.scarab.om.RIssueTypeAttribute;
63 import org.tigris.scarab.om.RModuleAttribute;
64 import org.tigris.scarab.om.RModuleOption;
65 import org.tigris.scarab.services.cache.ScarabCache;
66 import org.tigris.scarab.tools.ScarabLocalizationTool;
67 import org.tigris.scarab.tools.ScarabRequestTool;
68 import org.tigris.scarab.workflow.WorkflowFactory;
69
70 /**
71  * @author <a HREF="mailto:elicia@collab.net">Elicia David</a>
72  * @version $Id: ModuleAttributeEdit.java 9366 2005-01-04 17:24:36Z jorgeuriarte $
73  */

74 public class ModuleAttributeEdit extends RequireLoginFirstAction
75 {
76     /**
77      * Changes the properties of existing AttributeOptions.
78      */

79     public synchronized void doSave (RunData data, TemplateContext context)
80         throws Exception JavaDoc
81     {
82         ScarabRequestTool scarabR = getScarabRequestTool(context);
83         ScarabLocalizationTool l10n = getLocalizationTool(context);
84         Module module = scarabR.getCurrentModule();
85         IssueType issueType = scarabR.getIssueType();
86
87         if (issueType.getLocked())
88         {
89             scarabR.setAlertMessage(l10n.get("LockedIssueType"));
90             return;
91         }
92         Attribute attribute = scarabR.getAttribute();
93         RIssueTypeAttribute ria = issueType.getRIssueTypeAttribute(attribute);
94         if (ria != null && ria.getLocked())
95         {
96             scarabR.setAlertMessage(l10n.format("LockedAttribute", attribute.getName()));
97             return;
98         }
99
100         
101         IntakeTool intake = getIntakeTool(context);
102         if (intake.isAllValid())
103         {
104             List JavaDoc rmos = module.getRModuleOptions(attribute, issueType, false);
105             // Check for duplicate sequence numbers
106
if (areThereDupeSequences(rmos, intake, "RModuleOption", "Order", 0))
107
108             {
109                 scarabR.setAlertMessage(l10n.format("DuplicateSequenceNumbersFound",
110                          l10n.get("AttributeOptions").toLowerCase()));
111                 return;
112             }
113             if (rmos != null)
114             {
115                 for (int i=rmos.size()-1; i>=0; i--)
116                 {
117                     RModuleOption rmo = (RModuleOption)rmos.get(i);
118                     Group rmoGroup = intake.get("RModuleOption",
119                                      rmo.getQueryKey(), false);
120                     // if option gets set to inactive, delete dependencies
121
if (rmoGroup != null)
122                     {
123                         String JavaDoc newActive = rmoGroup.get("Active").toString();
124                         String JavaDoc oldActive = String.valueOf(rmo.getActive());
125                         if (newActive.equals("false") && oldActive.equals("true"))
126                         {
127                             WorkflowFactory.getInstance().deleteWorkflowsForOption(
128                                                           rmo.getAttributeOption(),
129                                                           module, issueType);
130                         }
131                         rmoGroup.setProperties(rmo);
132                         rmo.save();
133                     }
134                     ScarabCache.clear();
135                     scarabR.setConfirmMessage(l10n.get(DEFAULT_MSG));
136                 }
137             }
138         }
139         if (attribute.isOptionAttribute())
140         {
141             List JavaDoc options = module.getRModuleOptions(attribute, issueType, true);
142             if (options == null || options.isEmpty())
143             {
144                 RModuleAttribute rma = module.getRModuleAttribute(attribute, issueType);
145                 if (rma.getRequired())
146                 {
147                     rma.setRequired(false);
148                     rma.save();
149                     scarabR.setAlertMessage(l10n.get("DeletedOptionsFromRequiredAttribute"));
150                 }
151             }
152         }
153     }
154
155     /**
156      * Unmaps attribute options to modules.
157      */

158     public void doDeleteattributeoptions(RunData data,
159                                           TemplateContext context)
160         throws Exception JavaDoc
161     {
162         ScarabRequestTool scarabR = getScarabRequestTool(context);
163         ScarabLocalizationTool l10n = getLocalizationTool(context);
164         IssueType issueType = scarabR.getIssueType();
165         if (issueType.getLocked())
166         {
167             scarabR.setAlertMessage(l10n.get("LockedIssueType"));
168             return;
169         }
170         Attribute attribute = scarabR.getAttribute();
171         RIssueTypeAttribute ria = issueType.getRIssueTypeAttribute(attribute);
172         if (ria != null && ria.getLocked())
173         {
174             scarabR.setAlertMessage(l10n.format("LockedAttribute", attribute.getName()));
175             return;
176         }
177
178         Module module = scarabR.getCurrentModule();
179         ParameterParser params = data.getParameters();
180         Object JavaDoc[] keys = params.getKeys();
181         String JavaDoc key;
182         String JavaDoc optionId;
183
184         for (int i =0; i<keys.length; i++)
185         {
186             key = keys[i].toString();
187             if (key.startsWith("delete_"))
188             {
189                optionId = key.substring(7);
190                AttributeOption option = AttributeOptionManager
191                   .getInstance(new Integer JavaDoc(optionId));
192
193                RModuleOption rmo = module.getRModuleOption(option, issueType);
194                rmo.delete();
195
196                // Remove option - module mapping from template type
197
RModuleOption rmo2 = module.getRModuleOption(option,
198                    scarabR.getIssueType(issueType.getTemplateId().toString()));
199                rmo2.delete();
200                scarabR.setConfirmMessage(l10n.get(DEFAULT_MSG));
201                ScarabCache.clear();
202                getIntakeTool(context).removeAll();
203                data.getParameters().add("att_0id", option.getAttribute().getAttributeId().toString());
204             }
205         }
206         if (attribute.isOptionAttribute())
207         {
208             List JavaDoc options = module.getRModuleOptions(attribute, issueType, true);
209             if (options == null || options.isEmpty())
210             {
211                 RModuleAttribute rma = module.getRModuleAttribute(attribute, issueType);
212                 if (rma.getRequired())
213                 {
214                     rma.setRequired(false);
215                     rma.save();
216                     scarabR.setAlertMessage(l10n.get("DeletedOptionsFromRequiredAttribute"));
217                 }
218             }
219         }
220     }
221
222     /**
223      * Selects option to add to attribute.
224      */

225     public void doSelectattributeoption(RunData data,
226                                          TemplateContext context)
227         throws Exception JavaDoc
228     {
229         ScarabRequestTool scarabR = getScarabRequestTool(context);
230         ScarabLocalizationTool l10n = getLocalizationTool(context);
231         IssueType issueType = scarabR.getIssueType();
232         if (issueType.getLocked())
233         {
234             scarabR.setAlertMessage(l10n.get("LockedIssueType"));
235             return;
236         }
237         Attribute attribute = scarabR.getAttribute();
238         RIssueTypeAttribute ria = issueType.getRIssueTypeAttribute(attribute);
239         if (ria != null && ria.getLocked())
240         {
241             scarabR.setAlertMessage(l10n.format("LockedAttribute", attribute.getName()));
242             return;
243         }
244         Module module = scarabR.getCurrentModule();
245
246         String JavaDoc[] optionIds = data.getParameters().getStrings("option_ids");
247  
248         if (optionIds == null || optionIds.length <= 0)
249         {
250             scarabR.setAlertMessage(l10n.get("SelectOption"));
251             return;
252         }
253         else
254         {
255             for (int i=0; i < optionIds.length; i++)
256             {
257                 AttributeOption option = null;
258                 try
259                 {
260                     option = scarabR.getAttributeOption(new Integer JavaDoc(optionIds[i]));
261                     module.addAttributeOption(issueType, option);
262                 }
263                 catch(Exception JavaDoc e)
264                 {
265                     e.printStackTrace();
266                 }
267             }
268             ScarabCache.clear();
269             scarabR.setConfirmMessage(l10n.get(DEFAULT_MSG));
270             doCancel(data, context);
271         }
272     }
273     /**
274      * Manages clicking of the Done button
275      */

276     public void doDone( RunData data, TemplateContext context )
277         throws Exception JavaDoc
278     {
279         doSave(data, context);
280         if (getScarabRequestTool(context).getAlertMessage() == null)
281         {
282             doCancel( data, context);
283         }
284     }
285 }
286
Popular Tags