KickJava   Java API By Example, From Geeks To Geeks.

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


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.RIssueTypeAttribute;
62 import org.tigris.scarab.om.RIssueTypeOption;
63 import org.tigris.scarab.om.ScarabUser;
64 import org.tigris.scarab.services.cache.ScarabCache;
65 import org.tigris.scarab.tools.ScarabLocalizationTool;
66 import org.tigris.scarab.tools.ScarabRequestTool;
67 import org.tigris.scarab.util.ScarabConstants;
68
69 /**
70  * @author <a HREF="mailto:elicia@collab.net">Elicia David</a>
71  * @version $Id: IssueTypeAttributeEdit.java 9255 2004-11-14 21:07:04Z dep4b $
72  */

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

78     public synchronized void doSave(RunData data, TemplateContext context)
79         throws Exception JavaDoc
80     {
81         IntakeTool intake = getIntakeTool(context);
82         ScarabRequestTool scarabR = getScarabRequestTool(context);
83         ScarabLocalizationTool l10n = getLocalizationTool(context);
84         Attribute attribute = scarabR.getAttribute();
85         IssueType issueType = scarabR.getIssueType();
86         if (issueType.isSystemDefined())
87         {
88             scarabR.setAlertMessage(getLocalizationTool(context)
89                                        .get("SystemSpecifiedIssueType"));
90             return;
91         }
92         if (intake.isAllValid())
93         {
94             List JavaDoc rios = issueType.getRIssueTypeOptions(attribute, false);
95             // Check for duplicate sequence numbers
96
if (areThereDupeSequences(rios, intake,
97                     "RIssueTypeOption","Order", 0))
98             {
99                 scarabR.setAlertMessage(l10n.format("DuplicateSequenceNumbersFound",
100                          l10n.get("AttributeOptions").toLowerCase()));
101                 return;
102             }
103
104             if (rios != null)
105             {
106                 for (int i=rios.size()-1; i>=0; i--)
107                 {
108                     RIssueTypeOption rio = (RIssueTypeOption)rios.get(i);
109                     Group rioGroup = intake.get("RIssueTypeOption",
110                                      rio.getQueryKey(), false);
111                     rioGroup.setProperties(rio);
112                     rio.save();
113                     ScarabCache.clear();
114                     scarabR.setConfirmMessage(l10n.get(DEFAULT_MSG));
115                 }
116             }
117         }
118         if (attribute.isOptionAttribute())
119         {
120             List JavaDoc options = issueType.getRIssueTypeOptions(attribute, true);
121             if (options == null || options.isEmpty())
122             {
123                 RIssueTypeAttribute ria = issueType.getRIssueTypeAttribute(attribute);
124                 if (ria.getRequired())
125                 {
126                     ria.setRequired(false);
127                     ria.save();
128                     scarabR.setAlertMessage(l10n.get("DeletedOptionsFromRequiredAttribute"));
129                 }
130             }
131         }
132     }
133
134     /**
135      * Unmaps attribute options to issueTypes.
136      */

137     public void doDeleteissuetypeoptions(RunData data,
138                                           TemplateContext context)
139         throws Exception JavaDoc
140     {
141         ScarabRequestTool scarabR = getScarabRequestTool(context);
142         ScarabLocalizationTool l10n = getLocalizationTool(context);
143         ScarabUser user = (ScarabUser)data.getUser();
144         IssueType issueType = scarabR.getIssueType();
145         Attribute attribute = scarabR.getAttribute();
146
147         if (issueType.isSystemDefined())
148         {
149             scarabR.setAlertMessage(l10n.get("SystemSpecifiedIssueType"));
150             return;
151         }
152         ParameterParser params = data.getParameters();
153         Object JavaDoc[] keys = params.getKeys();
154         String JavaDoc key;
155         String JavaDoc optionId;
156
157         for (int i =0; i<keys.length; i++)
158         {
159             key = keys[i].toString();
160             if (key.startsWith("delete_"))
161             {
162                optionId = key.substring(7);
163                AttributeOption option = AttributeOptionManager
164                   .getInstance(new Integer JavaDoc(optionId));
165
166                RIssueTypeOption rio = issueType.getRIssueTypeOption(option);
167                List JavaDoc rios = issueType.getRIssueTypeOptions(attribute,
168                                                           false);
169                try
170                {
171                    rio.delete(user, scarabR.getCurrentModule());
172                    rios.remove(rio);
173                }
174                catch (Exception JavaDoc e)
175                {
176                    scarabR.setAlertMessage(ScarabConstants.NO_PERMISSION_MESSAGE);
177                }
178                scarabR.setConfirmMessage(l10n.get(DEFAULT_MSG));
179             }
180         }
181         if (attribute.isOptionAttribute())
182         {
183             List JavaDoc options = issueType.getRIssueTypeOptions(attribute, true);
184             if (options == null || options.isEmpty())
185             {
186                 RIssueTypeAttribute ria = issueType.getRIssueTypeAttribute(attribute);
187                 if (ria.getRequired())
188                 {
189                     ria.setRequired(false);
190                     ria.save();
191                     scarabR.setAlertMessage(l10n.get("DeletedOptionsFromRequiredAttribute"));
192                 }
193             }
194         }
195     }
196
197
198     /**
199      * Selects option to add to attribute.
200      */

201     public void doSelectissuetypeoption(RunData data,
202                                          TemplateContext context)
203         throws Exception JavaDoc
204     {
205         ScarabRequestTool scarabR = getScarabRequestTool(context);
206         ScarabLocalizationTool l10n = getLocalizationTool(context);
207         IssueType issueType = scarabR.getIssueType();
208         if (issueType.isSystemDefined())
209         {
210             scarabR.setAlertMessage(l10n.get("SystemSpecifiedIssueType"));
211             return;
212         }
213         String JavaDoc[] optionIds = data.getParameters().getStrings("option_ids");
214  
215         if (optionIds == null || optionIds.length <= 0)
216         {
217             scarabR.setAlertMessage(l10n.get("SelectOption"));
218             return;
219         }
220         else
221         {
222             for (int i=0; i < optionIds.length; i++)
223             {
224                 AttributeOption option = null;
225                 try
226                 {
227                     option = scarabR.getAttributeOption(new Integer JavaDoc(optionIds[i]));
228                     issueType.addRIssueTypeOption(option);
229                 }
230                 catch(Exception JavaDoc e)
231                 {
232                     e.printStackTrace();
233                 }
234             }
235             doCancel(data, context);
236             scarabR.setConfirmMessage(l10n.get(DEFAULT_MSG));
237         }
238     }
239     /**
240      * Overridden method to check for system defined issue types
241      * and prevent new attributes from being added to them.
242      */

243
244     public void doGotoothertemplate(RunData data,
245                                      TemplateContext context)
246         throws Exception JavaDoc
247     {
248         ScarabRequestTool scarabR = getScarabRequestTool(context);
249         IssueType issueType = scarabR.getIssueType();
250         ScarabLocalizationTool l10n = getLocalizationTool(context);
251         if (issueType.isSystemDefined())
252         {
253             scarabR.setAlertMessage(l10n.get("SystemSpecifiedIssueType"));
254             return;
255         }
256         super.doGotoothertemplate(data,context);
257     }
258
259     /**
260      * Manages clicking of the Done button
261      */

262     public void doDone( RunData data, TemplateContext context )
263         throws Exception JavaDoc
264     {
265         doSave(data, context);
266         if (getScarabRequestTool(context).getAlertMessage() == null)
267         {
268             doCancel( data, context);
269         }
270     }
271
272 }
273
Popular Tags