KickJava   Java API By Example, From Geeks To Geeks.

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


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.ArrayList JavaDoc;
50 import java.util.Iterator JavaDoc;
51 import java.util.List JavaDoc;
52 import java.util.Date JavaDoc;
53
54 import org.apache.turbine.RunData;
55 import org.apache.turbine.TemplateContext;
56 import org.apache.torque.TorqueException;
57 import org.apache.torque.om.NumberKey;
58 import org.apache.turbine.tool.IntakeTool;
59 import org.apache.fulcrum.intake.model.Group;
60 import org.apache.fulcrum.intake.model.Field;
61
62 import org.tigris.scarab.actions.base.RequireLoginFirstAction;
63 import org.tigris.scarab.om.Attribute;
64 import org.tigris.scarab.om.AttributeGroup;
65 import org.tigris.scarab.om.AttributeManager;
66 import org.tigris.scarab.om.AttributeType;
67 import org.tigris.scarab.om.AttributeTypeManager;
68 import org.tigris.scarab.om.ROptionOption;
69 import org.tigris.scarab.om.ParentChildAttributeOption;
70 import org.tigris.scarab.om.ScarabUser;
71 import org.tigris.scarab.om.AttributeOption;
72 import org.tigris.scarab.om.AttributeOptionPeer;
73 import org.tigris.scarab.om.IssueType;
74 import org.tigris.scarab.om.Module;
75 import org.tigris.scarab.om.Transition;
76 import org.tigris.scarab.om.TransitionPeer;
77 import org.tigris.scarab.util.ScarabConstants;
78 import org.tigris.scarab.util.Log;
79 import org.tigris.scarab.tools.ScarabRequestTool;
80 import org.tigris.scarab.tools.ScarabLocalizationTool;
81 import org.tigris.scarab.services.cache.ScarabCache;
82
83 /**
84  * This class deals with modifying Global Attributes.
85  *
86  * @author <a HREF="mailto:jon@collab.net">Jon S. Stevens</a>
87  * @version $Id: GlobalAttributeEdit.java 9724 2005-06-06 16:50:17Z jorgeuriarte $
88  */

89 public class GlobalAttributeEdit extends RequireLoginFirstAction
90 {
91     /**
92      * Used on GlobalAttributeEdit.vm to modify Attribute Name/Description/Type
93      * Use doSaveoptions to modify the options.
94      */

95     public boolean doSaveattributedata(RunData data, TemplateContext context)
96         throws Exception JavaDoc
97     {
98         IntakeTool intake = getIntakeTool(context);
99         ScarabRequestTool scarabR = getScarabRequestTool(context);
100         ScarabLocalizationTool l10n = getLocalizationTool(context);
101         boolean success = true;
102         boolean confirmDelete = false;
103
104         if (intake.isAllValid())
105         {
106             Attribute attr = scarabR.getAttribute();
107
108             Group attrGroup = null;
109             boolean isDupe = false;
110             Field attributeName = null;
111             Field description = null;
112             if (attr.getAttributeId() == null)
113             {
114                 // new attribute
115
attrGroup = intake.get("Attribute", IntakeTool.DEFAULT_KEY);
116                 attr.setCreatedBy(((ScarabUser)data.getUser()).getUserId());
117                 attr.setCreatedDate(new Date JavaDoc());
118             }
119             else
120             {
121                 attrGroup = intake.get("Attribute", attr.getQueryKey());
122             }
123             attributeName = attrGroup.get("Name");
124             description = attrGroup.get("Description");
125             isDupe = Attribute.checkForDuplicate(attributeName.toString().trim(), attr);
126
127             // Check for blank attribute names.
128
if (attributeName.toString().trim().length() == 0)
129             {
130                 attributeName.setMessage("intake_AttributeNameNotAllowedEmpty");
131                 scarabR.setAlertMessage(l10n.get(ERROR_MESSAGE));
132                 success = false;
133             }
134             if (description.toString().trim().length() == 0)
135             {
136                 description.setMessage("intake_AttributeDescriptionNotAllowedEmpty");
137                 scarabR.setAlertMessage(l10n.get(ERROR_MESSAGE));
138                 success = false;
139             }
140             // Check for duplicate attribute names.
141
else if (isDupe)
142             {
143                 scarabR.setAlertMessage(
144                     l10n.get("CannotCreateDuplicateAttribute"));
145                 success = false;
146             }
147             else
148             {
149                 // if deleting attribute, and attribute is associated
150
// With modules or issue types, give confirmation.
151
if (!attr.getDeleted() &&
152                     attrGroup.get("Deleted").toString().equals("true") &&
153                     (attr.hasModuleMappings() ||
154                      attr.hasGlobalIssueTypeMappings()))
155                 {
156                     context.put("deleting", "deleting");
157                     confirmDelete=true;
158                     success = false;
159                 }
160                 for (int i = 0; i < attrGroup.getFieldNames().length; i++)
161                 {
162                     String JavaDoc fieldName = attrGroup.getFieldNames()[i];
163                     if (!fieldName.equals("Deleted") || !confirmDelete)
164                     {
165                         attrGroup.get(fieldName).setProperty(attr);
166                     }
167                 }
168                 attr.save();
169                 mapAttribute(data,context);
170                 if (success)
171                 {
172                     scarabR.setConfirmMessage(l10n.get(DEFAULT_MSG));
173                     AttributeManager.clear();
174                 }
175             }
176         }
177         else
178         {
179           success = false;
180           scarabR.setAlertMessage(l10n.get(ERROR_MESSAGE));
181         }
182         return success;
183     }
184
185     /**
186      * Deletes attribute and its mappings after confirmation.
187      */

188     public void doDeleteattribute(RunData data, TemplateContext context)
189         throws Exception JavaDoc
190     {
191         ScarabRequestTool scarabR = getScarabRequestTool(context);
192         Attribute attr = scarabR.getAttribute();
193         if (attr.isSystemDefined())
194         {
195             scarabR.setAlertMessage(getLocalizationTool(context).get
196                                   ("CannotDeleteSystemSpecifiedAttribute"));
197             return;
198         }
199         if (attr.getAttributeId() != null)
200         {
201             attr.deleteModuleMappings();
202             attr.deleteIssueTypeMappings();
203             attr.setDeleted(true);
204             attr.save();
205             scarabR.setConfirmMessage(getLocalizationTool(context).get(DEFAULT_MSG));
206             setTarget(data, getCancelTemplate(data));
207         }
208     }
209
210     /**
211      * Used on AttributeEdit.vm to change the name of an existing
212      * AttributeOption or add a new one if the name doesn't already exist.
213      */

214     public synchronized boolean
215         doSaveoptions(RunData data, TemplateContext context)
216         throws Exception JavaDoc
217     {
218         IntakeTool intake = (IntakeTool)context
219            .get(ScarabConstants.INTAKE_TOOL);
220         ScarabRequestTool scarabR = (ScarabRequestTool)context
221            .get(ScarabConstants.SCARAB_REQUEST_TOOL);
222         ScarabLocalizationTool l10n = getLocalizationTool(context);
223
224         if (intake.isAllValid())
225         {
226             // get the Attribute that we are working on
227
Attribute attribute = scarabR.getAttribute();
228             if (log().isDebugEnabled())
229             {
230                 log().debug("doSaveoptions for attribute id=" +
231                             attribute.getAttributeId());
232             }
233             Group attGroup = intake.get("Attribute", attribute.getQueryKey());
234             String JavaDoc attributeTypeId = attGroup.get("TypeId").toString();
235             AttributeType attributeType = AttributeTypeManager
236                 .getInstance(new NumberKey(attributeTypeId), false);
237
238             if (attributeType.getAttributeClass().getName()
239                                                  .equals("select-one"))
240             {
241                 if (log().isDebugEnabled())
242                 {
243                     log().debug("attribute id=" + attribute.getAttributeId() +
244                                 " is an option attribute");
245                 }
246                 boolean somethingSaved = false;
247                 // get the list of ParentChildAttributeOptions's
248
// used to display the page
249
List JavaDoc pcaoList = attribute.getParentChildAttributeOptions();
250                 // Check for duplicate sequence numbers
251
if (areThereDupeSequences(pcaoList, intake,
252                         "ParentChildAttributeOption","PreferredOrder", 0))
253                 {
254                     scarabR.setAlertMessage(l10n.format("DuplicateSequenceNumbersFound",
255                          l10n.get("AttributeOptions").toLowerCase()));
256                     return false;
257                 }
258                 for (int i=pcaoList.size()-1; i>=0; i--)
259                 {
260                     ParentChildAttributeOption pcao =
261                         (ParentChildAttributeOption)pcaoList.get(i);
262
263                     if (pcao.getChildOption().isSystemDefined())
264                     {
265                         if (Log.get().isDebugEnabled())
266                         {
267                             Log.get().debug("PCAO(" + pcao +
268                                 ") is used by a system defined issue type");
269                         }
270                     }
271                     else
272                     {
273                     Group pcaoGroup = intake.get("ParentChildAttributeOption",
274                                                   pcao.getQueryKey());
275
276                     // there could be errors here so catch and re-display
277
// the same screen again.
278
Integer JavaDoc currentParentId = null;
279                     try
280                     {
281                         // store the currentParentId
282
currentParentId = pcao.getParentId();
283                         // map the form data onto the objects
284
pcaoGroup.setProperties(pcao);
285  
286                         // If deleting, delete mappings with module
287
if (pcao.getDeleted())
288                         {
289                             AttributeOption option = AttributeOptionPeer
290                                 .retrieveByPK(pcao.getOptionId());
291                             if (log().isDebugEnabled())
292                             {
293                                 log().debug("deleting mappings for option id=" +
294                                             option.getOptionId());
295                             }
296                             option.deleteModuleMappings();
297                             option.deleteIssueTypeMappings();
298                         }
299
300                         List JavaDoc ancestors = null;
301                         try
302                         {
303                             ancestors= pcao.getAncestors();
304                         }
305                         catch (Exception JavaDoc e)
306                         {
307                             scarabR.setAlertMessage(
308                                l10n.get("RecursiveParentChildRelationship"));
309                             intake.remove(pcaoGroup);
310                             return false;
311                         }
312                         if (ancestors.contains(pcao.getOptionId()))
313                         {
314                             scarabR.setAlertMessage(
315                                 l10n.get("RecursiveParentChildRelationship"));
316                             intake.remove(pcaoGroup);
317                             return false;
318                         }
319                     
320                         // save the PCAO now..
321
pcao.save();
322
323                         // if we are changing the parent id's, then we want
324
// to remove the old one after the new one is created
325
if (!pcao.getParentId().equals(currentParentId))
326                         {
327                             if (log().isDebugEnabled())
328                             {
329                                 log().debug("removing parent relationship for option id=" +
330                                             pcao.getOptionId() + ", old parent id="
331                                             + currentParentId);
332                             }
333                             ROptionOption.doRemove(currentParentId,
334                                                    pcao.getOptionId());
335                         }
336
337                        // also remove the group because we are re-displaying
338
// the form data and we want it fresh
339
intake.remove(pcaoGroup);
340                        if (log().isDebugEnabled())
341                        {
342                            log().debug("Saved pcao for attribute id=" +
343                                        pcao.getAttributeId() + " and option id="
344                                        + pcao.getOptionId());
345                        }
346                        somethingSaved = true;
347                     }
348                     catch (Exception JavaDoc se)
349                     {
350                         // on error, reset to previous values
351
intake.remove(pcaoGroup);
352                         scarabR.setAlertMessage(l10n.getMessage(se));
353                         log().error("", se);
354                         return false;
355                     }
356                 }
357                 }
358                 if (somethingSaved)
359                 {
360                     scarabR.setConfirmMessage(l10n.get(DEFAULT_MSG));
361                     AttributeManager.clear();
362                 }
363
364                 // handle adding the new line.
365
ParentChildAttributeOption newPCAO =
366                     ParentChildAttributeOption.getInstance();
367                 Group newPCAOGroup = intake.get("ParentChildAttributeOption",
368                                                 newPCAO.getQueryKey());
369                 if (newPCAOGroup != null)
370                 {
371                     log().debug("checking for a new pcao");
372                     try
373                     {
374                         // assign the form data to the object
375
newPCAOGroup.setProperties(newPCAO);
376                         // only add a new entry if there is a name defined
377
if (newPCAO.getName() != null && newPCAO.getName().length() > 0)
378                         {
379                             // save the new PCAO
380
newPCAO.setAttributeId(attribute.getAttributeId());
381                             try
382                             {
383                                 newPCAO.save();
384                                 if (log().isDebugEnabled())
385                                 {
386                                     log().debug("Saved NEW pcao for attribute id="
387                                                 + newPCAO.getAttributeId() + " and option id="
388                                                 + newPCAO.getOptionId());
389                                 }
390                                 pcaoList.add(newPCAO);
391                                 IssueType issueType = null;
392                                 AttributeOption option = null;
393
394                                 // If user came from editing a module,
395
// Add new option to module.
396
String JavaDoc cancelTemplate = getCancelTemplate(data);
397                                 if (cancelTemplate != null
398                                     && (cancelTemplate.equals("admin,AttributeOptionSelect.vm")
399                                         || cancelTemplate.equals("admin,GlobalAttributeOptionSelect.vm")))
400                                 {
401                                     issueType = scarabR.getIssueType();
402                                     option = scarabR.getAttributeOption(newPCAO.getOptionId());
403                                     if (log().isDebugEnabled())
404                                     {
405                                         log().debug("cancelTemplate=" +
406                                                     cancelTemplate +
407                                                     " issuetype id=" +
408                                                     issueType.getIssueTypeId() +
409                                                     " and option id=" +
410                                                     option.getOptionId());
411                                     }
412                                 }
413                                 // add new option to current module
414
if (cancelTemplate.equals("admin,AttributeOptionSelect.vm"))
415                                 {
416                                     scarabR.getCurrentModule()
417                                        .addAttributeOption(issueType, option);
418                                     data.getParameters().setString(
419                                          ScarabConstants.CANCEL_TEMPLATE,
420                                          "admin,ModuleAttributeEdit.vm");
421                                     if (log().isDebugEnabled())
422                                     {
423                                         log().debug("Adding mapping to module id"
424                                                     + scarabR.getCurrentModule()
425                                                     .getModuleId());
426                                     }
427                                 }
428                                 // add new option to current issue type
429
else if (cancelTemplate.equals("admin,GlobalAttributeOptionSelect.vm"))
430                                 {
431                                     issueType.addRIssueTypeOption(option);
432                                     data.getParameters().setString(
433                                          ScarabConstants.CANCEL_TEMPLATE,
434                                          "admin,IssueTypeAttributeEdit.vm");
435                                     log().debug("Adding mapping to issuetype");
436                                 }
437                                 scarabR.setConfirmMessage(
438                                     l10n.get("AttributeOptionAdded") +
439                                     l10n.get(DEFAULT_MSG));
440                             }
441                             catch (Exception JavaDoc e)
442                             {
443                                 log().error("Error adding attribute option:", e);
444                                 scarabR.setAlertMessage("Error adding attribute option:" + l10n.getMessage(e));
445                             }
446                         }
447                     }
448                     catch (Exception JavaDoc se)
449                     {
450                         intake.remove(newPCAOGroup);
451                         scarabR.setAlertMessage(se.getMessage());
452                         log().error("", se);
453                         return false;
454                     }
455
456                     // now remove the group to set the page stuff to null
457
intake.remove(newPCAOGroup);
458                     attribute.buildOptionsMap();
459                     ScarabCache.clear();
460                 }
461             }
462         }
463         return true;
464     }
465
466     /*
467      * Manages clicking of the AllDone button
468      */

469     public void doDone(RunData data, TemplateContext context)
470         throws Exception JavaDoc
471     {
472         log().debug("called doDone");
473         boolean success = doSaveattributedata(data, context);
474         if (getScarabRequestTool(context).getAttribute().isOptionAttribute())
475         {
476             success = doSaveoptions(data, context);
477             updatetransitiondata(data, context);
478         }
479         if (success)
480         {
481             //if "deleting" is set, do not call 'doCancel' since the control
482
//should go to 'confirm delete' page.
483
if(!"deleting".equals(context.get("deleting")))
484             {
485                 log().debug("calling doCancel");
486                 doCancel(data, context);
487             }
488         }
489         //Reset confirm message in case some of the changes got saved
490
else
491         {
492             getScarabRequestTool(context).setConfirmMessage(null);
493         }
494     }
495     /**
496      * manages attribute to module/issue type mapping.
497      */

498
499     private void mapAttribute(RunData data, TemplateContext context)
500         throws Exception JavaDoc
501     {
502         ScarabRequestTool scarabR = getScarabRequestTool(context);
503         ScarabLocalizationTool l10n = getLocalizationTool(context);
504         String JavaDoc lastTemplate = getCancelTemplate(data);
505         Attribute attribute = scarabR.getAttribute();
506
507         if (log().isDebugEnabled())
508         {
509             log().debug("called mapAttribute; lastTemplate=" + lastTemplate +
510                         " and attribute id=" + attribute.getAttributeId());
511         }
512         if (lastTemplate != null && attribute.getAttributeId() != null)
513         {
514             // Add attribute to group
515
if (lastTemplate.equals("admin,AttributeGroupEdit.vm") ||
516                 lastTemplate.equals("admin,GlobalAttributeGroupEdit.vm"))
517             {
518                 // Add attribute to group
519
String JavaDoc groupId = data.getParameters().getString("groupId");
520                 if (groupId != null)
521                 {
522                     if (log().isDebugEnabled())
523                     {
524                         log().debug("Adding attribute to group id=" + groupId);
525                     }
526                     AttributeGroup attributeGroup = scarabR.getAttributeGroup(groupId);
527                     if(!attributeGroup.hasAttribute(attribute))
528                     {
529                         scarabR.getAttributeGroup(groupId).addAttribute(attribute);
530                         scarabR.setConfirmMessage(l10n.get("AttributeAdded"));
531                     }
532                 }
533             }
534             else if (lastTemplate.equals("admin,ArtifactTypeEdit.vm"))
535             {
536             Module currentModule = scarabR.getCurrentModule();
537                 IssueType issueType = scarabR.getIssueType();
538                 if (log().isDebugEnabled())
539                 {
540                     log().debug("Adding attribute to module id=" +
541                                 currentModule.getModuleId());
542                 }
543                 // Add user attribute to module
544
if (!attribute.hasMapping(currentModule, issueType))
545                 {
546                       currentModule.addRModuleAttribute(issueType,attribute);
547                       scarabR.setConfirmMessage(l10n.get("AttributeAdded"));
548                 }
549
550             }
551             else if (lastTemplate.equals("admin,GlobalArtifactTypeEdit.vm"))
552             {
553                 IssueType issueType = scarabR.getIssueType();
554                 if (log().isDebugEnabled())
555                 {
556                     log().debug("Assuming user attribute and adding to "
557                                 + "issuetype id "
558                                 + issueType.getIssueTypeId());
559                 }
560                 // Add user attribute to issue type
561
if (!attribute.hasGlobalMapping(issueType))
562                 {
563                    issueType.addRIssueTypeAttribute(attribute);
564                    scarabR.setConfirmMessage(l10n.get("AttributeAdded"));
565                 }
566             }
567             ScarabCache.clear();
568         }
569
570     }
571
572     /**
573      * Manages clicking of the cancel button.
574      * FIXME! document that the doCancel method alters the database
575      * Why does it do this?!!
576      */

577     public void doCancel(RunData data, TemplateContext context)
578         throws Exception JavaDoc
579     {
580         String JavaDoc lastTemplate = getCancelTemplate(data);
581         if (lastTemplate != null)
582         {
583             setTarget(data, lastTemplate);
584         }
585         else
586         {
587             super.doCancel(data, context);
588         }
589     }
590
591     /**
592      * Saves (creates or updates) transition data.
593      *
594      * @param data
595      * @param context
596      * @return true if the operation gets done successfuly, false otherwise
597      * @throws Exception
598      */

599     public boolean doSavetransitiondata(RunData data, TemplateContext context)
600             throws Exception JavaDoc
601     {
602         boolean bRdo = false;
603         ScarabRequestTool scarabR = getScarabRequestTool(context);
604         Attribute attr = scarabR.getAttribute();
605         Integer JavaDoc attributeId = attr.getAttributeId();
606         if (!data.getParameters().getString("trans_new_RoleId").equals("choose") &&
607                 !data.getParameters().getString("trans_new_FromId").equals("choose") &&
608                 !data.getParameters().getString("trans_new_ToId").equals("choose"))
609         {
610             Integer JavaDoc roleId = data.getParameters().getInteger("trans_new_RoleId");
611             Integer JavaDoc fromId = data.getParameters().getInteger("trans_new_FromId");
612             Integer JavaDoc toId = data.getParameters().getInteger("trans_new_ToId");
613
614             if (roleId.intValue() == -1)
615                 roleId = null;
616             if (fromId.intValue() == -1)
617                 fromId = null;
618             if (toId.intValue() == -1)
619                 toId = null;
620             try
621             {
622                 Transition transition = new Transition();
623                 transition.setRoleId(roleId);
624                 transition.setFromOptionId(fromId);
625                 transition.setToOptionId(toId);
626                 transition.setAttributeId(attributeId);
627                 attr.addTransition(transition);
628                 attr.save();
629                 transition.save();
630                 bRdo = true;
631             }
632             catch (TorqueException te)
633             {
634                 this.log().error("doSavetransitiondata(): " + te);
635             }
636         }
637         updatetransitiondata(data, context);
638         
639         return bRdo;
640     }
641
642     /**
643      * Deletes the transitions selected in the form.
644      *
645      * @param data
646      * @param context
647      * @return true if the operation gets done successfuly, false otherwise
648      * @throws Exception
649      */

650     public boolean doDeletetransitiondata(RunData data, TemplateContext context)
651             throws Exception JavaDoc
652     {
653         boolean bRdo = false;
654         boolean bChanges = false;
655         ScarabRequestTool scarabR = getScarabRequestTool(context);
656         ScarabLocalizationTool l10n = getLocalizationTool(context);
657         Attribute attr = scarabR.getAttribute();
658         List JavaDoc transitions = attr.getTransitions();
659         Iterator JavaDoc iter = transitions.iterator();
660
661         // Will store the transitions to delete in order to avoid the
662
// ConcurrentModificationException??
663
List JavaDoc toDelete = new ArrayList JavaDoc();
664         try
665         {
666             while (iter.hasNext())
667             {
668                 Transition trans = (Transition) iter.next();
669                 boolean bDelete = data.getParameters().getBoolean(
670                         "trans_delete_" + trans.getTransitionId());
671                 if (bDelete)
672                 {
673                     bChanges = true;
674                     toDelete.add(trans);
675                     AttributeManager.clear();
676                 }
677             }
678             iter = toDelete.iterator();
679             while (iter.hasNext())
680             {
681                 Transition trans = (Transition) iter.next();
682                 transitions.remove(trans);
683                 TransitionPeer.doDelete(trans);
684             }
685             bRdo = true;
686         }
687         catch (TorqueException te)
688         {
689             this.log().error("doDeleteTransition(): " + te);
690         }
691         scarabR.setConfirmMessage(l10n.get(DEFAULT_MSG));
692         return bRdo;
693     }
694     
695     /**
696      *
697      * @param data
698      * @param context
699      * @return
700      */

701     private void updatetransitiondata(RunData data, TemplateContext context) throws Exception JavaDoc
702     {
703         ScarabRequestTool scarabR = getScarabRequestTool(context);
704         ScarabLocalizationTool l10n = getLocalizationTool(context);
705         Attribute attr = scarabR.getAttribute();
706         List JavaDoc transitions = attr.getTransitions();
707         for (Iterator JavaDoc iter = transitions.iterator(); iter.hasNext(); )
708         {
709             // Update the "disabled if blocked" value
710
Transition trans = (Transition)iter.next();
711             boolean value = data.getParameters().getBoolean("trans_disabled_value_" + trans.getTransitionId());
712             boolean newValue = data.getParameters().getBoolean("trans_disabled_new_" + trans.getTransitionId());
713             if (value != newValue)
714             {
715                 trans.setDisabledIfBlocked(newValue);
716                 trans.save();
717             }
718         }
719     }
720 }
721
Popular Tags