KickJava   Java API By Example, From Geeks To Geeks.

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


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.Field;
52 import org.apache.fulcrum.intake.model.Group;
53 import org.apache.fulcrum.parser.ParameterParser;
54 import org.apache.turbine.RunData;
55 import org.apache.turbine.TemplateContext;
56 import org.apache.turbine.tool.IntakeTool;
57 import org.tigris.scarab.actions.base.RequireLoginFirstAction;
58 import org.tigris.scarab.om.IssueType;
59 import org.tigris.scarab.om.Module;
60 import org.tigris.scarab.om.RModuleIssueType;
61 import org.tigris.scarab.om.ScarabUser;
62 import org.tigris.scarab.services.cache.ScarabCache;
63 import org.tigris.scarab.tools.ScarabLocalizationTool;
64 import org.tigris.scarab.tools.ScarabRequestTool;
65 import org.tigris.scarab.util.Log;
66
67 /**
68  * This action handles associating issue types to modules. It should probably
69  * have 'Module' in its name, but regardless, the base permission for this
70  * class is Module | Configure, so global artifact type actions do not belong
71  * here.
72  *
73  * @author <a HREF="mailto:elicia@collab.net">Elicia David</a>
74  * @version $Id: ManageArtifactTypes.java 9255 2004-11-14 21:07:04Z dep4b $
75  */

76 public class ManageArtifactTypes extends RequireLoginFirstAction
77 {
78     /**
79      * Changes the properties of existing IssueTypes.
80      */

81     public synchronized void doSave (RunData data, TemplateContext context)
82         throws Exception JavaDoc
83     {
84         IntakeTool intake = getIntakeTool(context);
85         ScarabRequestTool scarabR = getScarabRequestTool(context);
86         ScarabLocalizationTool l10n = getLocalizationTool(context);
87
88         Module module = scarabR.getCurrentModule();
89         List JavaDoc rmits = module.getRModuleIssueTypes();
90         int navCount = 0;
91         Group rmitGroup = null;
92
93         if (areThereDupeSequences(rmits, intake, "RModuleIssueType", "Order", 0))
94         {
95             scarabR.setAlertMessage(l10n.format("DuplicateSequenceNumbersFound",
96                                      l10n.get("IssueTypes").toLowerCase()));
97             return;
98         }
99
100         if (intake.isAllValid())
101         {
102             for (int i=0;i < rmits.size(); i++)
103             {
104                 RModuleIssueType rmit = (RModuleIssueType)rmits.get(i);
105                 rmitGroup = intake.get("RModuleIssueType",
106                                  rmit.getQueryKey(), false);
107                 Field display = rmitGroup.get("Display");
108
109                 if (display.toString().equals("true"))
110                 {
111                     navCount++;
112                 }
113                 if (navCount > 5)
114                 {
115                    scarabR.setAlertMessage(l10n.get("NavIssueTypeLimit"));
116                    return;
117                 }
118             }
119             for (int i=0;i < rmits.size(); i++)
120             {
121                 RModuleIssueType rmit = (RModuleIssueType)rmits.get(i);
122                 rmitGroup = intake.get("RModuleIssueType",
123                                  rmit.getQueryKey(), false);
124                 rmitGroup.setProperties(rmit);
125                 rmit.save();
126                 
127                 // TODO: document the reason for this
128
String JavaDoc pageNum = data.getParameters().getString("pageNum","1");
129                 data.getParameters().add("pageNum", pageNum);
130             }
131             ScarabCache.clear();
132         }
133     }
134
135
136     /**
137      * Selects issue type to add to module.
138      */

139     public void doSelectissuetype(RunData data, TemplateContext context)
140         throws Exception JavaDoc
141     {
142         ScarabRequestTool scarabR = getScarabRequestTool(context);
143         ScarabLocalizationTool l10n = getLocalizationTool(context);
144         IssueType issueType = scarabR.getIssueType();
145         Module module = scarabR.getCurrentModule();
146
147         if (issueType.getIssueTypeId() == null)
148         {
149             scarabR.setAlertMessage(l10n.get("SelectIssueType"));
150         }
151         else if (module.getRModuleIssueType(issueType) != null)
152         {
153             scarabR.setAlertMessage(l10n.get("IssueTypeAlreadyAssociated"));
154         }
155         else
156         {
157             module.addIssueType(issueType);
158             ScarabCache.clear();
159             scarabR.setConfirmMessage(l10n.get("IssueTypeAddedToModule"));
160             setTarget(data, "admin,ManageArtifactTypes.vm");
161         }
162     }
163
164
165     /**
166      * This manages clicking the cancel button
167      */

168     public void doCreateartifacttype(RunData data, TemplateContext context)
169         throws Exception JavaDoc
170     {
171         data.getParameters().remove("issueTypeId");
172         setTarget(data, getOtherTemplate(data));
173     }
174
175     /**
176      * Deletes an issue type from a module.
177      */

178     public void doDeletemoduleissuetype (RunData data,
179                                           TemplateContext context)
180         throws Exception JavaDoc
181     {
182         ScarabRequestTool scarabR = getScarabRequestTool(context);
183         ScarabLocalizationTool l10n = getLocalizationTool(context);
184         ScarabUser user = (ScarabUser)data.getUser();
185         ParameterParser params = data.getParameters();
186         Module module = scarabR.getCurrentModule();
187         Object JavaDoc[] keys = params.getKeys();
188         String JavaDoc key;
189         String JavaDoc issueTypeId;
190         List JavaDoc rmits = module.getRModuleIssueTypes();
191
192         boolean foundOne = false;
193         boolean success = false;
194         for (int i =0; i<keys.length; i++)
195         {
196             key = keys[i].toString();
197             if (key.startsWith("delete_"))
198             {
199                 if (rmits.size() < 1)
200                 {
201                     scarabR.setAlertMessage(l10n.get("CannotZeroIssueType"));
202                     break;
203                 }
204                 else
205                 {
206                     issueTypeId = key.substring(7);
207                     IssueType issueType = scarabR.getIssueType(issueTypeId);
208                     RModuleIssueType rmit = module.getRModuleIssueType(issueType);
209                     Group rmitGroup = getIntakeTool(context).get("RModuleIssueType",
210                                  rmit.getQueryKey(), false);
211                     Field field = rmitGroup.get("DisplayName");
212                     if (issueType != null)
213                     {
214                         foundOne = true;
215                         if (issueType.getLocked())
216                         {
217                             //scarabR.setAlertMessage(l10n.get("LockedIssueType"));
218
field.setMessage("LockedIssueType");
219                         }
220                         else if (issueType.hasIssues(module))
221                         {
222                             scarabR.setAlertMessage(l10n.get("CannotDeleteIssueTypesWithIssues"));
223                             field.setMessage("IssueTypeHasIssues");
224                         }
225                         else
226                         {
227                             try
228                             {
229                                 // delete module-issue type mappings
230
rmit.delete(user);
231                                 success = true;
232                                 // FIXME! need proper cache invalidation
233
module.getNavIssueTypes().remove(issueType);
234                             }
235                             catch (Exception JavaDoc e)
236                             {
237                                 scarabR.setAlertMessage(
238                                     l10n.get("CannotDeleteIssueType"));
239                                 Log.get().warn(
240                                     "Could not delete issue type", e);
241                             }
242                         }
243
244                     }
245                 }
246             }
247          
248          }
249          if (success)
250          {
251             String JavaDoc msg = l10n.get("SelectedIssueTypesRemovedFromModule");
252             scarabR.setConfirmMessage(msg);
253          }
254          if (!foundOne)
255          {
256              String JavaDoc msg = l10n.get("SelectIssueTypeToDeleteFromModule");
257              scarabR.setAlertMessage(msg);
258          }
259     }
260 }
261
Popular Tags