KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.tigris.scarab.actions.admin;
2
3 /* ================================================================
4  * Copyright (c) 2000-2003 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 CollabNet <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 CollabNet.
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 CollabNet.
47  */

48
49 import java.util.List JavaDoc;
50
51 import org.apache.turbine.RunData;
52 import org.apache.turbine.TemplateContext;
53 import org.apache.turbine.tool.IntakeTool;
54 import org.apache.fulcrum.intake.model.Group;
55 import org.apache.fulcrum.intake.model.Field;
56
57 import org.tigris.scarab.actions.base.RequireLoginFirstAction;
58 import org.tigris.scarab.tools.ScarabRequestTool;
59 import org.tigris.scarab.tools.ScarabLocalizationTool;
60 import org.tigris.scarab.om.IssueType;
61 import org.tigris.scarab.om.IssueTypeManager;
62 import org.tigris.scarab.om.IssueTypePeer;
63 import org.tigris.scarab.services.cache.ScarabCache;
64
65 /**
66  * This class deals with modifying Global Artifact Types.
67  *
68  * @author <a HREF="mailto:elicia@collab.net">Elicia David</a>
69  * @author <a HREF="mailto:jon@collab.net">Jon Scott Stevens</a>
70  * @version $Id: GlobalArtifactTypes.java 8343 2003-07-26 18:26:57Z jmcnally $
71  */

72 public class GlobalArtifactTypes extends RequireLoginFirstAction
73 {
74     /**
75      * Used on GlobalAttributeEdit.vm to modify Attribute Name/Description/Type
76      * Use doAddormodifyattributeoptions to modify the options.
77      */

78     public void doSave(RunData data, TemplateContext context)
79         throws Exception JavaDoc
80     {
81         IntakeTool intake = getIntakeTool(context);
82         ScarabLocalizationTool l10n = getLocalizationTool(context);
83         List JavaDoc issueTypes = IssueTypePeer.getAllIssueTypes(false);
84         boolean dupe = false;
85         boolean saved = false;
86         if (intake.isAllValid())
87         {
88             ScarabRequestTool scarabR = getScarabRequestTool(context);
89             for (int i=0; i<issueTypes.size(); i++)
90             {
91                 IssueType issueType = (IssueType)issueTypes.get(i);
92                 Group group = intake.get("IssueType", issueType.getQueryKey());
93                 // make sure name is unique
94
Field field = group.get("Name");
95                 String JavaDoc name = field.toString();
96                 if (IssueTypePeer.isUnique(name, issueType.getIssueTypeId()))
97                 {
98                     group.setProperties(issueType);
99                     issueType.save();
100                     ScarabCache.clear();
101                     saved = true;
102                 }
103                 else
104                 {
105                     dupe = true;
106                     field.setMessage("Duplicate");
107                 }
108             }
109             if (dupe)
110             {
111                 scarabR.setAlertMessage(
112                     l10n.get("ChangesResultDuplicateNames"));
113             }
114             else if (saved)
115             {
116                 scarabR.setConfirmMessage(
117                     l10n.get(DEFAULT_MSG));
118             }
119             else
120             {
121                 scarabR.setInfoMessage(
122                     l10n.get(NO_CHANGES_MADE));
123             }
124         }
125     }
126                 
127     public void doCopy(RunData data, TemplateContext context)
128         throws Exception JavaDoc
129     {
130         Object JavaDoc[] keys = data.getParameters().getKeys();
131         String JavaDoc key;
132         String JavaDoc id;
133         IssueType issueType;
134         boolean didCopy = false;
135         for (int i =0; i<keys.length; i++)
136         {
137             key = keys[i].toString();
138             if (key.startsWith("action_"))
139             {
140                 id = key.substring(7);
141                 issueType = IssueTypeManager.getInstance(new Integer JavaDoc(id));
142                 if (issueType != null)
143                 {
144                     issueType.copyIssueType();
145                     didCopy = true;
146                 }
147             }
148         }
149         ScarabRequestTool scarabR = getScarabRequestTool(context);
150         ScarabLocalizationTool l10n = getLocalizationTool(context);
151         if (didCopy)
152         {
153             scarabR.setConfirmMessage(l10n.get("GlobalArtifactTypeCopied"));
154         }
155         else
156         {
157             scarabR.setInfoMessage(l10n.get(NO_CHANGES_MADE));
158         }
159     }
160
161     public void doDelete(RunData data, TemplateContext context)
162         throws Exception JavaDoc
163     {
164         String JavaDoc key = null;
165         String JavaDoc id = null;
166         IssueType issueType = null;
167         boolean deleted = false;
168         boolean hasIssues = false;
169         boolean immutable = false;
170         Object JavaDoc[] keys = data.getParameters().getKeys();
171         ScarabLocalizationTool l10n = getLocalizationTool(context);
172         IntakeTool intake = getIntakeTool(context);
173         for (int i =0; i<keys.length; i++)
174         {
175              key = keys[i].toString();
176              if (key.startsWith("action_"))
177              {
178                 id = key.substring(7);
179                 issueType = IssueTypeManager.getInstance(new Integer JavaDoc(id));
180                 if (issueType != null)
181                 {
182                     Group group = intake.get("IssueType", issueType.getQueryKey());
183                     Field field = group.get("Name");
184                     if (issueType.isSystemDefined())
185                     {
186                         field.setMessage("CannotDeleteSystemSpecifiedIssueType");
187                         immutable = true;
188                     }
189                     else if (issueType.hasIssues())
190                     {
191                         field.setMessage("IssueTypeHasIssues");
192                         hasIssues = true;
193                     }
194                     else
195                     {
196                         issueType.setDeleted(true);
197                         issueType.save();
198                         deleted = true;
199                     }
200                 }
201             }
202         }
203         ScarabRequestTool scarabR = getScarabRequestTool(context);
204         if (immutable)
205         {
206             scarabR.setAlertMessage(l10n.get("CannotDeleteSystemSpecifiedIssueType"));
207         }
208         else if (hasIssues)
209         {
210             scarabR.setAlertMessage(l10n.get("CannotDeleteIssueTypesWithIssues"));
211         }
212         else if (deleted)
213         {
214             scarabR.setConfirmMessage(l10n.get("GlobalIssueTypesDeleted"));
215         }
216         else
217         {
218             scarabR.setInfoMessage(l10n.get(NO_CHANGES_MADE));
219         }
220     }
221
222     public void doUndelete(RunData data, TemplateContext context)
223         throws Exception JavaDoc
224     {
225         Object JavaDoc[] keys = data.getParameters().getKeys();
226         String JavaDoc key;
227         String JavaDoc id;
228         IssueType issueType;
229         boolean saved = false;
230         for (int i =0; i<keys.length; i++)
231         {
232             key = keys[i].toString();
233             if (key.startsWith("action_"))
234             {
235                 id = key.substring(7);
236                 issueType = IssueTypeManager.getInstance(new Integer JavaDoc(id));
237                 if (issueType != null)
238                 {
239                     issueType.setDeleted(false);
240                     issueType.save();
241                     saved = true;
242                 }
243             }
244         }
245         if (saved)
246         {
247             getScarabRequestTool(context)
248                 .setConfirmMessage(
249                 getLocalizationTool(context)
250                 .get("GlobalIssueTypesUnDeleted"));
251         }
252     }
253 }
254
Popular Tags