Source Code Cross Referenced for GlobalAttributeEdit.java in  » Issue-Tracking » scarab-0.21 » org » tigris » scarab » actions » admin » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Issue Tracking » scarab 0.21 » org.tigris.scarab.actions.admin 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.tigris.scarab.actions.admin;
002:
003:        /* ================================================================
004:         * Copyright (c) 2000-2002 CollabNet.  All rights reserved.
005:         * 
006:         * Redistribution and use in source and binary forms, with or without
007:         * modification, are permitted provided that the following conditions are
008:         * met:
009:         * 
010:         * 1. Redistributions of source code must retain the above copyright
011:         * notice, this list of conditions and the following disclaimer.
012:         * 
013:         * 2. Redistributions in binary form must reproduce the above copyright
014:         * notice, this list of conditions and the following disclaimer in the
015:         * documentation and/or other materials provided with the distribution.
016:         * 
017:         * 3. The end-user documentation included with the redistribution, if
018:         * any, must include the following acknowlegement: "This product includes
019:         * software developed by Collab.Net <http://www.Collab.Net/>."
020:         * Alternately, this acknowlegement may appear in the software itself, if
021:         * and wherever such third-party acknowlegements normally appear.
022:         * 
023:         * 4. The hosted project names must not be used to endorse or promote
024:         * products derived from this software without prior written
025:         * permission. For written permission, please contact info@collab.net.
026:         * 
027:         * 5. Products derived from this software may not use the "Tigris" or 
028:         * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without 
029:         * prior written permission of Collab.Net.
030:         * 
031:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
032:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
033:         * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
034:         * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
035:         * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
036:         * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
037:         * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
038:         * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
039:         * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
040:         * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
041:         * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
042:         *
043:         * ====================================================================
044:         * 
045:         * This software consists of voluntary contributions made by many
046:         * individuals on behalf of Collab.Net.
047:         */
048:
049:        import java.util.ArrayList;
050:        import java.util.Iterator;
051:        import java.util.List;
052:        import java.util.Date;
053:
054:        import org.apache.turbine.RunData;
055:        import org.apache.turbine.TemplateContext;
056:        import org.apache.torque.TorqueException;
057:        import org.apache.torque.om.NumberKey;
058:        import org.apache.turbine.tool.IntakeTool;
059:        import org.apache.fulcrum.intake.model.Group;
060:        import org.apache.fulcrum.intake.model.Field;
061:
062:        import org.tigris.scarab.actions.base.RequireLoginFirstAction;
063:        import org.tigris.scarab.om.Attribute;
064:        import org.tigris.scarab.om.AttributeGroup;
065:        import org.tigris.scarab.om.AttributeManager;
066:        import org.tigris.scarab.om.AttributeType;
067:        import org.tigris.scarab.om.AttributeTypeManager;
068:        import org.tigris.scarab.om.ROptionOption;
069:        import org.tigris.scarab.om.ParentChildAttributeOption;
070:        import org.tigris.scarab.om.ScarabUser;
071:        import org.tigris.scarab.om.AttributeOption;
072:        import org.tigris.scarab.om.AttributeOptionPeer;
073:        import org.tigris.scarab.om.IssueType;
074:        import org.tigris.scarab.om.Module;
075:        import org.tigris.scarab.om.Transition;
076:        import org.tigris.scarab.om.TransitionManager;
077:        import org.tigris.scarab.om.TransitionPeer;
078:        import org.tigris.scarab.util.ScarabConstants;
079:        import org.tigris.scarab.util.Log;
080:        import org.tigris.scarab.tools.ScarabRequestTool;
081:        import org.tigris.scarab.tools.ScarabLocalizationTool;
082:        import org.tigris.scarab.services.cache.ScarabCache;
083:
084:        /**
085:         * This class deals with modifying Global Attributes.
086:         *
087:         * @author <a href="mailto:jon@collab.net">Jon S. Stevens</a>
088:         * @version $Id: GlobalAttributeEdit.java 10042 2006-04-11 11:28:39Z jorgeuriarte $
089:         */
090:        public class GlobalAttributeEdit extends RequireLoginFirstAction {
091:            /**
092:             * Used on GlobalAttributeEdit.vm to modify Attribute Name/Description/Type
093:             * Use doSaveoptions to modify the options.
094:             */
095:            public boolean doSaveattributedata(RunData data,
096:                    TemplateContext context) throws Exception {
097:                IntakeTool intake = getIntakeTool(context);
098:                ScarabRequestTool scarabR = getScarabRequestTool(context);
099:                ScarabLocalizationTool l10n = getLocalizationTool(context);
100:                boolean success = true;
101:                boolean confirmDelete = false;
102:
103:                if (intake.isAllValid()) {
104:                    Attribute attr = scarabR.getAttribute();
105:
106:                    Group attrGroup = null;
107:                    boolean isDupe = false;
108:                    Field attributeName = null;
109:                    Field description = null;
110:                    if (attr.getAttributeId() == null) {
111:                        // new attribute
112:                        attrGroup = intake.get("Attribute",
113:                                IntakeTool.DEFAULT_KEY);
114:                        attr.setCreatedBy(((ScarabUser) data.getUser())
115:                                .getUserId());
116:                        attr.setCreatedDate(new Date());
117:                    } else {
118:                        attrGroup = intake.get("Attribute", attr.getQueryKey());
119:                    }
120:                    attributeName = attrGroup.get("Name");
121:                    description = attrGroup.get("Description");
122:                    isDupe = Attribute.checkForDuplicate(attributeName
123:                            .toString().trim(), attr);
124:
125:                    // Check for blank attribute names.
126:                    if (attributeName.toString().trim().length() == 0) {
127:                        attributeName
128:                                .setMessage("intake_AttributeNameNotAllowedEmpty");
129:                        scarabR.setAlertMessage(l10n.get(ERROR_MESSAGE));
130:                        success = false;
131:                    }
132:                    if (description.toString().trim().length() == 0) {
133:                        description
134:                                .setMessage("intake_AttributeDescriptionNotAllowedEmpty");
135:                        scarabR.setAlertMessage(l10n.get(ERROR_MESSAGE));
136:                        success = false;
137:                    }
138:                    // Check for duplicate attribute names.
139:                    else if (isDupe) {
140:                        scarabR.setAlertMessage(l10n
141:                                .get("CannotCreateDuplicateAttribute"));
142:                        success = false;
143:                    } else {
144:                        // if deleting attribute, and attribute is associated
145:                        // With modules or issue types, give confirmation.
146:                        if (!attr.getDeleted()
147:                                && attrGroup.get("Deleted").toString().equals(
148:                                        "true")
149:                                && (attr.hasModuleMappings() || attr
150:                                        .hasGlobalIssueTypeMappings())) {
151:                            context.put("deleting", "deleting");
152:                            confirmDelete = true;
153:                            success = false;
154:                        }
155:                        for (int i = 0; i < attrGroup.getFieldNames().length; i++) {
156:                            String fieldName = attrGroup.getFieldNames()[i];
157:                            if (!fieldName.equals("Deleted") || !confirmDelete) {
158:                                attrGroup.get(fieldName).setProperty(attr);
159:                            }
160:                        }
161:                        attr.save();
162:                        mapAttribute(data, context);
163:                        if (success) {
164:                            scarabR.setConfirmMessage(l10n.get(DEFAULT_MSG));
165:                            AttributeManager.clear();
166:                        }
167:                    }
168:                } else {
169:                    success = false;
170:                    scarabR.setAlertMessage(l10n.get(ERROR_MESSAGE));
171:                }
172:                return success;
173:            }
174:
175:            /**
176:             * Deletes attribute and its mappings after confirmation.
177:             */
178:            public void doDeleteattribute(RunData data, TemplateContext context)
179:                    throws Exception {
180:                ScarabRequestTool scarabR = getScarabRequestTool(context);
181:                Attribute attr = scarabR.getAttribute();
182:                if (attr.isSystemDefined()) {
183:                    scarabR.setAlertMessage(getLocalizationTool(context).get(
184:                            "CannotDeleteSystemSpecifiedAttribute"));
185:                    return;
186:                }
187:                if (attr.getAttributeId() != null) {
188:                    attr.deleteModuleMappings();
189:                    attr.deleteIssueTypeMappings();
190:                    attr.setDeleted(true);
191:                    attr.save();
192:                    scarabR.setConfirmMessage(getLocalizationTool(context).get(
193:                            DEFAULT_MSG));
194:                    setTarget(data, getCancelTemplate(data));
195:                }
196:            }
197:
198:            /**
199:             * Used on AttributeEdit.vm to change the name of an existing
200:             * AttributeOption or add a new one if the name doesn't already exist.
201:             */
202:            public synchronized boolean doSaveoptions(RunData data,
203:                    TemplateContext context) throws Exception {
204:                IntakeTool intake = (IntakeTool) context
205:                        .get(ScarabConstants.INTAKE_TOOL);
206:                ScarabRequestTool scarabR = (ScarabRequestTool) context
207:                        .get(ScarabConstants.SCARAB_REQUEST_TOOL);
208:                ScarabLocalizationTool l10n = getLocalizationTool(context);
209:
210:                if (intake.isAllValid()) {
211:                    // get the Attribute that we are working on
212:                    Attribute attribute = scarabR.getAttribute();
213:                    if (log().isDebugEnabled()) {
214:                        log().debug(
215:                                "doSaveoptions for attribute id="
216:                                        + attribute.getAttributeId());
217:                    }
218:                    Group attGroup = intake.get("Attribute", attribute
219:                            .getQueryKey());
220:                    String attributeTypeId = attGroup.get("TypeId").toString();
221:                    AttributeType attributeType = AttributeTypeManager
222:                            .getInstance(new NumberKey(attributeTypeId), false);
223:
224:                    if (attributeType.getAttributeClass().getName().equals(
225:                            "select-one")) {
226:                        if (log().isDebugEnabled()) {
227:                            log().debug(
228:                                    "attribute id="
229:                                            + attribute.getAttributeId()
230:                                            + " is an option attribute");
231:                        }
232:                        boolean somethingSaved = false;
233:                        // get the list of ParentChildAttributeOptions's 
234:                        // used to display the page
235:                        List pcaoList = attribute
236:                                .getParentChildAttributeOptions();
237:                        // Check for duplicate sequence numbers
238:                        if (areThereDupeSequences(pcaoList, intake,
239:                                "ParentChildAttributeOption", "PreferredOrder",
240:                                0)) {
241:                            scarabR.setAlertMessage(l10n.format(
242:                                    "DuplicateSequenceNumbersFound", l10n.get(
243:                                            "AttributeOptions").toLowerCase()));
244:                            return false;
245:                        }
246:                        for (int i = pcaoList.size() - 1; i >= 0; i--) {
247:                            ParentChildAttributeOption pcao = (ParentChildAttributeOption) pcaoList
248:                                    .get(i);
249:
250:                            if (pcao.getChildOption().isSystemDefined()) {
251:                                if (Log.get().isDebugEnabled()) {
252:                                    Log
253:                                            .get()
254:                                            .debug(
255:                                                    "PCAO("
256:                                                            + pcao
257:                                                            + ") is used by a system defined issue type");
258:                                }
259:                            } else {
260:                                Group pcaoGroup = intake.get(
261:                                        "ParentChildAttributeOption", pcao
262:                                                .getQueryKey());
263:
264:                                // there could be errors here so catch and re-display
265:                                // the same screen again.
266:                                Integer currentParentId = null;
267:                                try {
268:                                    // store the currentParentId
269:                                    currentParentId = pcao.getParentId();
270:                                    // map the form data onto the objects
271:                                    pcaoGroup.setProperties(pcao);
272:
273:                                    // If deleting, delete mappings with module 
274:                                    if (pcao.getDeleted()) {
275:                                        AttributeOption option = AttributeOptionPeer
276:                                                .retrieveByPK(pcao
277:                                                        .getOptionId());
278:                                        if (log().isDebugEnabled()) {
279:                                            log()
280:                                                    .debug(
281:                                                            "deleting mappings for option id="
282:                                                                    + option
283:                                                                            .getOptionId());
284:                                        }
285:                                        option.deleteModuleMappings();
286:                                        option.deleteIssueTypeMappings();
287:                                    }
288:
289:                                    List ancestors = null;
290:                                    try {
291:                                        ancestors = pcao.getAncestors();
292:                                    } catch (Exception e) {
293:                                        scarabR
294:                                                .setAlertMessage(l10n
295:                                                        .get("RecursiveParentChildRelationship"));
296:                                        intake.remove(pcaoGroup);
297:                                        return false;
298:                                    }
299:                                    if (ancestors.contains(pcao.getOptionId())) {
300:                                        scarabR
301:                                                .setAlertMessage(l10n
302:                                                        .get("RecursiveParentChildRelationship"));
303:                                        intake.remove(pcaoGroup);
304:                                        return false;
305:                                    }
306:
307:                                    // save the PCAO now..
308:                                    pcao.save();
309:
310:                                    // if we are changing the parent id's, then we want
311:                                    // to remove the old one after the new one is created
312:                                    if (!pcao.getParentId().equals(
313:                                            currentParentId)) {
314:                                        if (log().isDebugEnabled()) {
315:                                            log()
316:                                                    .debug(
317:                                                            "removing parent relationship for option id="
318:                                                                    + pcao
319:                                                                            .getOptionId()
320:                                                                    + ", old parent id="
321:                                                                    + currentParentId);
322:                                        }
323:                                        ROptionOption.doRemove(currentParentId,
324:                                                pcao.getOptionId());
325:                                    }
326:
327:                                    // also remove the group because we are re-displaying
328:                                    // the form data and we want it fresh
329:                                    intake.remove(pcaoGroup);
330:                                    if (log().isDebugEnabled()) {
331:                                        log().debug(
332:                                                "Saved pcao for attribute id="
333:                                                        + pcao.getAttributeId()
334:                                                        + " and option id="
335:                                                        + pcao.getOptionId());
336:                                    }
337:                                    somethingSaved = true;
338:                                } catch (Exception se) {
339:                                    // on error, reset to previous values
340:                                    intake.remove(pcaoGroup);
341:                                    scarabR
342:                                            .setAlertMessage(l10n
343:                                                    .getMessage(se));
344:                                    log().error("", se);
345:                                    return false;
346:                                }
347:                            }
348:                        }
349:                        if (somethingSaved) {
350:                            scarabR.setConfirmMessage(l10n.get(DEFAULT_MSG));
351:                            AttributeManager.clear();
352:                        }
353:
354:                        // handle adding the new line.
355:                        ParentChildAttributeOption newPCAO = ParentChildAttributeOption
356:                                .getInstance();
357:                        Group newPCAOGroup = intake.get(
358:                                "ParentChildAttributeOption", newPCAO
359:                                        .getQueryKey());
360:                        if (newPCAOGroup != null) {
361:                            log().debug("checking for a new pcao");
362:                            try {
363:                                // assign the form data to the object
364:                                newPCAOGroup.setProperties(newPCAO);
365:                                // only add a new entry if there is a name defined
366:                                if (newPCAO.getName() != null
367:                                        && newPCAO.getName().length() > 0) {
368:                                    // save the new PCAO
369:                                    newPCAO.setAttributeId(attribute
370:                                            .getAttributeId());
371:                                    try {
372:                                        newPCAO.save();
373:                                        if (log().isDebugEnabled()) {
374:                                            log()
375:                                                    .debug(
376:                                                            "Saved NEW pcao for attribute id="
377:                                                                    + newPCAO
378:                                                                            .getAttributeId()
379:                                                                    + " and option id="
380:                                                                    + newPCAO
381:                                                                            .getOptionId());
382:                                        }
383:                                        pcaoList.add(newPCAO);
384:                                        IssueType issueType = null;
385:                                        AttributeOption option = null;
386:
387:                                        // If user came from editing a module,
388:                                        // Add new option to module.
389:                                        String cancelTemplate = getCancelTemplate(data);
390:                                        if (cancelTemplate != null
391:                                                && (cancelTemplate
392:                                                        .equals("admin,AttributeOptionSelect.vm") || cancelTemplate
393:                                                        .equals("admin,GlobalAttributeOptionSelect.vm"))) {
394:                                            issueType = scarabR.getIssueType();
395:                                            option = scarabR
396:                                                    .getAttributeOption(newPCAO
397:                                                            .getOptionId());
398:                                            if (log().isDebugEnabled()) {
399:                                                log()
400:                                                        .debug(
401:                                                                "cancelTemplate="
402:                                                                        + cancelTemplate
403:                                                                        + " issuetype id="
404:                                                                        + issueType
405:                                                                                .getIssueTypeId()
406:                                                                        + " and option id="
407:                                                                        + option
408:                                                                                .getOptionId());
409:                                            }
410:                                        }
411:                                        // add new option to current module
412:                                        if (cancelTemplate
413:                                                .equals("admin,AttributeOptionSelect.vm")) {
414:                                            scarabR.getCurrentModule()
415:                                                    .addAttributeOption(
416:                                                            issueType, option);
417:                                            data
418:                                                    .getParameters()
419:                                                    .setString(
420:                                                            ScarabConstants.CANCEL_TEMPLATE,
421:                                                            "admin,ModuleAttributeEdit.vm");
422:                                            if (log().isDebugEnabled()) {
423:                                                log()
424:                                                        .debug(
425:                                                                "Adding mapping to module id"
426:                                                                        + scarabR
427:                                                                                .getCurrentModule()
428:                                                                                .getModuleId());
429:                                            }
430:                                        }
431:                                        // add new option to current issue type
432:                                        else if (cancelTemplate
433:                                                .equals("admin,GlobalAttributeOptionSelect.vm")) {
434:                                            issueType
435:                                                    .addRIssueTypeOption(option);
436:                                            data
437:                                                    .getParameters()
438:                                                    .setString(
439:                                                            ScarabConstants.CANCEL_TEMPLATE,
440:                                                            "admin,IssueTypeAttributeEdit.vm");
441:                                            log()
442:                                                    .debug(
443:                                                            "Adding mapping to issuetype");
444:                                        }
445:                                        scarabR.setConfirmMessage(l10n
446:                                                .get("AttributeOptionAdded")
447:                                                + l10n.get(DEFAULT_MSG));
448:                                    } catch (Exception e) {
449:                                        log()
450:                                                .error(
451:                                                        "Error adding attribute option:",
452:                                                        e);
453:                                        scarabR
454:                                                .setAlertMessage("Error adding attribute option:"
455:                                                        + l10n.getMessage(e));
456:                                    }
457:                                }
458:                            } catch (Exception se) {
459:                                intake.remove(newPCAOGroup);
460:                                scarabR.setAlertMessage(se.getMessage());
461:                                log().error("", se);
462:                                return false;
463:                            }
464:
465:                            // now remove the group to set the page stuff to null
466:                            intake.remove(newPCAOGroup);
467:                            attribute.buildOptionsMap();
468:                            ScarabCache.clear();
469:                        }
470:                    }
471:                }
472:                return true;
473:            }
474:
475:            /*
476:             * Manages clicking of the AllDone button
477:             */
478:            public void doDone(RunData data, TemplateContext context)
479:                    throws Exception {
480:                log().debug("called doDone");
481:                boolean success = doSaveattributedata(data, context);
482:                if (getScarabRequestTool(context).getAttribute()
483:                        .isOptionAttribute()) {
484:                    success = doSaveoptions(data, context);
485:                    updatetransitiondata(data, context);
486:                }
487:                if (success) {
488:                    //if "deleting" is set, do not call 'doCancel' since the control
489:                    //should go to 'confirm delete' page.
490:                    if (!"deleting".equals(context.get("deleting"))) {
491:                        log().debug("calling doCancel");
492:                        doCancel(data, context);
493:                    }
494:                }
495:                //Reset confirm message in case some of the changes got saved
496:                else {
497:                    getScarabRequestTool(context).setConfirmMessage(null);
498:                }
499:            }
500:
501:            /**
502:             * manages attribute to module/issue type mapping.
503:             */
504:
505:            private void mapAttribute(RunData data, TemplateContext context)
506:                    throws Exception {
507:                ScarabRequestTool scarabR = getScarabRequestTool(context);
508:                ScarabLocalizationTool l10n = getLocalizationTool(context);
509:                String lastTemplate = getCancelTemplate(data);
510:                Attribute attribute = scarabR.getAttribute();
511:
512:                if (log().isDebugEnabled()) {
513:                    log().debug(
514:                            "called mapAttribute; lastTemplate=" + lastTemplate
515:                                    + " and attribute id="
516:                                    + attribute.getAttributeId());
517:                }
518:                if (lastTemplate != null && attribute.getAttributeId() != null) {
519:                    // Add attribute to group
520:                    if (lastTemplate.equals("admin,AttributeGroupEdit.vm")
521:                            || lastTemplate
522:                                    .equals("admin,GlobalAttributeGroupEdit.vm")) {
523:                        // Add attribute to group
524:                        String groupId = data.getParameters().getString(
525:                                "groupId");
526:                        if (groupId != null) {
527:                            if (log().isDebugEnabled()) {
528:                                log().debug(
529:                                        "Adding attribute to group id="
530:                                                + groupId);
531:                            }
532:                            AttributeGroup attributeGroup = scarabR
533:                                    .getAttributeGroup(groupId);
534:                            if (!attributeGroup.hasAttribute(attribute)) {
535:                                scarabR.getAttributeGroup(groupId)
536:                                        .addAttribute(attribute);
537:                                scarabR.setConfirmMessage(l10n
538:                                        .get("AttributeAdded"));
539:                            }
540:                        }
541:                    } else if (lastTemplate.equals("admin,ArtifactTypeEdit.vm")) {
542:                        Module currentModule = scarabR.getCurrentModule();
543:                        IssueType issueType = scarabR.getIssueType();
544:                        if (log().isDebugEnabled()) {
545:                            log().debug(
546:                                    "Adding attribute to module id="
547:                                            + currentModule.getModuleId());
548:                        }
549:                        // Add user attribute to module
550:                        if (!attribute.hasMapping(currentModule, issueType)) {
551:                            currentModule.addRModuleAttribute(issueType,
552:                                    attribute);
553:                            scarabR.setConfirmMessage(l10n
554:                                    .get("AttributeAdded"));
555:                        }
556:
557:                    } else if (lastTemplate
558:                            .equals("admin,GlobalArtifactTypeEdit.vm")) {
559:                        IssueType issueType = scarabR.getIssueType();
560:                        if (log().isDebugEnabled()) {
561:                            log().debug(
562:                                    "Assuming user attribute and adding to "
563:                                            + "issuetype id "
564:                                            + issueType.getIssueTypeId());
565:                        }
566:                        // Add user attribute to issue type
567:                        if (!attribute.hasGlobalMapping(issueType)) {
568:                            issueType.addRIssueTypeAttribute(attribute);
569:                            scarabR.setConfirmMessage(l10n
570:                                    .get("AttributeAdded"));
571:                        }
572:                    }
573:                    ScarabCache.clear();
574:                }
575:
576:            }
577:
578:            /**
579:             * Manages clicking of the cancel button.
580:             * FIXME! document that the doCancel method alters the database
581:             * Why does it do this?!!
582:             */
583:            public void doCancel(RunData data, TemplateContext context)
584:                    throws Exception {
585:                String lastTemplate = getCancelTemplate(data);
586:                if (lastTemplate != null) {
587:                    setTarget(data, lastTemplate);
588:                } else {
589:                    super .doCancel(data, context);
590:                }
591:            }
592:
593:            /**
594:             * Saves (creates or updates) transition data.
595:             * 
596:             * @param data
597:             * @param context
598:             * @return true if the operation gets done successfuly, false otherwise
599:             * @throws Exception
600:             */
601:            public boolean doSavetransitiondata(RunData data,
602:                    TemplateContext context) throws Exception {
603:                boolean bRdo = false;
604:                ScarabRequestTool scarabR = getScarabRequestTool(context);
605:                Attribute attr = scarabR.getAttribute();
606:                Integer attributeId = attr.getAttributeId();
607:                if (!data.getParameters().getString("trans_new_RoleId").equals(
608:                        "choose")
609:                        && !data.getParameters().getString("trans_new_FromId")
610:                                .equals("choose")
611:                        && !data.getParameters().getString("trans_new_ToId")
612:                                .equals("choose")) {
613:                    Integer roleId = data.getParameters().getInteger(
614:                            "trans_new_RoleId");
615:                    Integer fromId = data.getParameters().getInteger(
616:                            "trans_new_FromId");
617:                    Integer toId = data.getParameters().getInteger(
618:                            "trans_new_ToId");
619:
620:                    if (roleId.intValue() == -1)
621:                        roleId = null;
622:                    if (fromId.intValue() == -1)
623:                        fromId = null;
624:                    if (toId.intValue() == -1)
625:                        toId = null;
626:                    try {
627:                        Transition transition = new Transition();
628:                        transition.setRoleId(roleId);
629:                        transition.setFromOptionId(fromId);
630:                        transition.setToOptionId(toId);
631:                        transition.setAttributeId(attributeId);
632:                        attr.addTransition(transition);
633:                        attr.save();
634:                        transition.save();
635:                        TransitionManager.getMethodResult().remove(attr,
636:                                TransitionManager.GET_ALL_TRANSITIONS);
637:                        bRdo = true;
638:                    } catch (TorqueException te) {
639:                        this .log().error("doSavetransitiondata(): " + te);
640:                    }
641:                }
642:                updatetransitiondata(data, context);
643:
644:                return bRdo;
645:            }
646:
647:            /**
648:             * Deletes the transitions selected in the form.
649:             * 
650:             * @param data
651:             * @param context
652:             * @return true if the operation gets done successfuly, false otherwise
653:             * @throws Exception
654:             */
655:            public boolean doDeletetransitiondata(RunData data,
656:                    TemplateContext context) throws Exception {
657:                boolean bRdo = false;
658:                boolean bChanges = false;
659:                ScarabRequestTool scarabR = getScarabRequestTool(context);
660:                ScarabLocalizationTool l10n = getLocalizationTool(context);
661:                Attribute attr = scarabR.getAttribute();
662:                List transitions = attr.getTransitions();
663:                Iterator iter = transitions.iterator();
664:
665:                // Will store the transitions to delete in order to avoid the
666:                // ConcurrentModificationException??
667:                List toDelete = new ArrayList();
668:                try {
669:                    while (iter.hasNext()) {
670:                        Transition trans = (Transition) iter.next();
671:                        boolean bDelete = data.getParameters().getBoolean(
672:                                "trans_delete_" + trans.getTransitionId());
673:                        if (bDelete) {
674:                            bChanges = true;
675:                            toDelete.add(trans);
676:                            AttributeManager.clear();
677:                        }
678:                    }
679:                    iter = toDelete.iterator();
680:                    while (iter.hasNext()) {
681:                        Transition trans = (Transition) iter.next();
682:                        transitions.remove(trans);
683:                        TransitionPeer.doDelete(trans);
684:                    }
685:                    if (toDelete.size() > 0) {
686:                        TransitionManager.getMethodResult().remove(attr,
687:                                TransitionManager.GET_ALL_TRANSITIONS);
688:                    }
689:                    bRdo = true;
690:                } catch (TorqueException te) {
691:                    this .log().error("doDeleteTransition(): " + te);
692:                }
693:                scarabR.setConfirmMessage(l10n.get(DEFAULT_MSG));
694:                return bRdo;
695:            }
696:
697:            /**
698:             * 
699:             * @param data
700:             * @param context
701:             * @return
702:             */
703:            private void updatetransitiondata(RunData data,
704:                    TemplateContext context) throws Exception {
705:                ScarabRequestTool scarabR = getScarabRequestTool(context);
706:                ScarabLocalizationTool l10n = getLocalizationTool(context);
707:                Attribute attr = scarabR.getAttribute();
708:                List transitions = attr.getTransitions();
709:                boolean bChanges = false;
710:                for (Iterator iter = transitions.iterator(); iter.hasNext();) {
711:                    // Update the "disabled if blocked" value
712:                    Transition trans = (Transition) iter.next();
713:                    boolean value = data.getParameters().getBoolean(
714:                            "trans_disabled_value_" + trans.getTransitionId());
715:                    boolean newValue = data.getParameters().getBoolean(
716:                            "trans_disabled_new_" + trans.getTransitionId());
717:                    if (value != newValue) {
718:                        trans.setDisabledIfBlocked(newValue);
719:                        trans.save();
720:                        bChanges = true;
721:                    }
722:                }
723:                if (bChanges) {
724:                    TransitionManager.getMethodResult().remove(attr,
725:                            TransitionManager.GET_ALL_TRANSITIONS);
726:                }
727:            }
728:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.