Source Code Cross Referenced for ModifyIssue.java in  » Issue-Tracking » scarab-0.21 » org » tigris » scarab » actions » 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 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        package org.tigris.scarab.actions;
0002:
0003:        /* ================================================================
0004:         * Copyright (c) 2000-2003 CollabNet.  All rights reserved.
0005:         * 
0006:         * Redistribution and use in source and binary forms, with or without
0007:         * modification, are permitted provided that the following conditions are
0008:         * met:
0009:         * 
0010:         * 1. Redistributions of source code must retain the above copyright
0011:         * notice, this list of conditions and the following disclaimer.
0012:         * 
0013:         * 2. Redistributions in binary form must reproduce the above copyright
0014:         * notice, this list of conditions and the following disclaimer in the
0015:         * documentation and/or other materials provided with the distribution.
0016:         * 
0017:         * 3. The end-user documentation included with the redistribution, if
0018:         * any, must include the following acknowlegement: "This product includes
0019:         * software developed by Collab.Net <http://www.Collab.Net/>."
0020:         * Alternately, this acknowlegement may appear in the software itself, if
0021:         * and wherever such third-party acknowlegements normally appear.
0022:         * 
0023:         * 4. The hosted project names must not be used to endorse or promote
0024:         * products derived from this software without prior written
0025:         * permission. For written permission, please contact info@collab.net.
0026:         * 
0027:         * 5. Products derived from this software may not use the "Tigris" or 
0028:         * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without 
0029:         * prior written permission of Collab.Net.
0030:         * 
0031:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
0032:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
0033:         * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0034:         * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
0035:         * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
0036:         * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
0037:         * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0038:         * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
0039:         * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
0040:         * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
0041:         * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0042:         *
0043:         * ====================================================================
0044:         * 
0045:         * This software consists of voluntary contributions made by many
0046:         * individuals on behalf of Collab.Net.
0047:         */
0048:
0049:        import java.util.ArrayList;
0050:        import java.util.HashMap;
0051:        import java.util.HashSet;
0052:        import java.util.Iterator;
0053:        import java.util.List;
0054:        import java.util.Map;
0055:        import java.util.Set;
0056:
0057:        import org.apache.commons.collections.map.LinkedMap;
0058:        import org.apache.commons.fileupload.FileItem;
0059:        import org.apache.fulcrum.intake.model.Field;
0060:        import org.apache.fulcrum.intake.model.Group;
0061:        import org.apache.fulcrum.parser.ParameterParser;
0062:        import org.apache.torque.om.NumberKey;
0063:        import org.apache.turbine.RunData;
0064:        import org.apache.turbine.TemplateContext;
0065:        import org.apache.turbine.Turbine;
0066:        import org.apache.turbine.tool.IntakeTool;
0067:        import org.tigris.scarab.actions.base.BaseModifyIssue;
0068:        import org.tigris.scarab.attribute.DateAttribute;
0069:        import org.tigris.scarab.attribute.OptionAttribute;
0070:        import org.tigris.scarab.attribute.UserAttribute;
0071:        import org.tigris.scarab.notification.NotificationManagerFactory;
0072:        import org.tigris.scarab.om.Activity;
0073:        import org.tigris.scarab.om.ActivitySet;
0074:        import org.tigris.scarab.notification.ActivityType;
0075:        import org.tigris.scarab.om.Attachment;
0076:        import org.tigris.scarab.om.AttachmentManager;
0077:        import org.tigris.scarab.om.Attribute;
0078:        import org.tigris.scarab.om.AttributeOption;
0079:        import org.tigris.scarab.om.AttributeOptionManager;
0080:        import org.tigris.scarab.om.AttributeValue;
0081:        import org.tigris.scarab.om.Condition;
0082:        import org.tigris.scarab.om.Depend;
0083:        import org.tigris.scarab.om.DependManager;
0084:        import org.tigris.scarab.om.DependType;
0085:        import org.tigris.scarab.om.DependTypeManager;
0086:        import org.tigris.scarab.om.Issue;
0087:        import org.tigris.scarab.om.IssueManager;
0088:        import org.tigris.scarab.om.IssueType;
0089:        import org.tigris.scarab.om.Module;
0090:        import org.tigris.scarab.om.ScarabUser;
0091:        import org.tigris.scarab.services.security.ScarabSecurity;
0092:        import org.tigris.scarab.tools.ScarabGlobalTool;
0093:        import org.tigris.scarab.tools.ScarabLocalizationTool;
0094:        import org.tigris.scarab.tools.ScarabRequestTool;
0095:        import org.tigris.scarab.tools.localization.L10NKeySet;
0096:        import org.tigris.scarab.tools.localization.L10NMessage;
0097:        import org.tigris.scarab.util.ComponentLocator;
0098:        import org.tigris.scarab.util.Log;
0099:        import org.tigris.scarab.util.MutableBoolean;
0100:        import org.tigris.scarab.util.ScarabConstants;
0101:        import org.tigris.scarab.util.ScarabException;
0102:        import org.tigris.scarab.util.ScarabUtil;
0103:
0104:        /**
0105:         * This class is responsible for edit issue forms.
0106:         * ScarabIssueAttributeValue
0107:         * @author <a href="mailto:elicia@collab.net">Elicia David</a>
0108:         * @version $Id: ModifyIssue.java 10231 2006-07-31 22:19:06Z dabbous $
0109:         */
0110:        public class ModifyIssue extends BaseModifyIssue {
0111:
0112:            public void doSubmitattributes(RunData data, TemplateContext context)
0113:                    throws Exception {
0114:                if (isCollision(data, context)) {
0115:                    return;
0116:                }
0117:
0118:                final ScarabRequestTool scarabR = getScarabRequestTool(context);
0119:                final ScarabLocalizationTool l10n = getLocalizationTool(context);
0120:                final Issue issue = scarabR.getIssue();
0121:                final Module module = scarabR.getCurrentModule();
0122:
0123:                if (issue == null) {
0124:                    // no need to set the message here as
0125:                    // it is done in scarabR.getIssue()
0126:                    return;
0127:                }
0128:                final ScarabUser user = (ScarabUser) data.getUser();
0129:                if (!user.hasPermission(ScarabSecurity.ISSUE__EDIT, issue
0130:                        .getModule())) {
0131:                    scarabR.setAlertMessage(NO_PERMISSION_MESSAGE);
0132:                    return;
0133:                }
0134:
0135:                final IntakeTool intake = getIntakeTool(context);
0136:
0137:                final boolean isReasonRequired = module.isIssueReasonRequired();
0138:
0139:                // Reason field is required to modify attributes
0140:                final Group reasonGroup = intake.get("Attachment",
0141:                        "attCommentKey" + issue.getQueryKey(), false);
0142:                final Field reasonField = reasonGroup.get("Data");
0143:
0144:                if (isReasonRequired) {
0145:                    reasonField.setRequired(true);
0146:                }
0147:
0148:                // make sure to trim the whitespace
0149:                String reasonFieldString = reasonField.toString();
0150:                if (reasonFieldString != null) {
0151:                    reasonFieldString = reasonFieldString.trim();
0152:                }
0153:                String saveAsFieldString = data.getParameters().get(
0154:                        "saveReasonAs");
0155:                if (saveAsFieldString != null) {
0156:                    saveAsFieldString = saveAsFieldString.trim();
0157:                }
0158:                final boolean saveAsComment = "Comment"
0159:                        .equalsIgnoreCase(saveAsFieldString);
0160:
0161:                if (reasonGroup == null || !reasonField.isValid()
0162:                        || reasonFieldString.length() == 0) {
0163:                    if (isReasonRequired) {
0164:                        reasonField
0165:                                .setMessage("ExplanatoryReasonRequiredToModifyAttributes");
0166:                    }
0167:                }
0168:
0169:                // Set any other required flags
0170:                final Map selectedOptions = new HashMap();
0171:                final Map conditionallyRequiredFields = new HashMap();
0172:                final IssueType issueType = issue.getIssueType();
0173:                final List requiredAttributes = issueType
0174:                        .getRequiredAttributes(issue.getModule());
0175:                final LinkedMap modMap = issue.getModuleAttributeValuesMap();
0176:                for (Iterator iter = modMap.mapIterator(); iter.hasNext();) {
0177:                    final AttributeValue aval = (AttributeValue) modMap
0178:                            .get(iter.next());
0179:                    final Group group = intake.get("AttributeValue", aval
0180:                            .getQueryKey(), false);
0181:                    Field field = null;
0182:                    if (group != null) {
0183:                        if (aval instanceof  OptionAttribute) {
0184:                            // use optionId instead
0185:                            field = group.get("OptionId");
0186:                            // Will store the selected optionId, for later query against conditions.
0187:                            final Object fieldValue = field.getValue();
0188:                            if (null != fieldValue) {
0189:                                selectedOptions.put(fieldValue, field);
0190:                            }
0191:
0192:                        } else {
0193:                            field = group.get("Value");
0194:                        }
0195:                        // check required attributes
0196:                        for (int j = requiredAttributes.size() - 1; j >= 0; j--) {
0197:                            if (aval.getAttribute().getPrimaryKey().equals(
0198:                                    ((Attribute) requiredAttributes.get(j))
0199:                                            .getPrimaryKey())) {
0200:                                field.setRequired(true);
0201:                                break;
0202:                            }
0203:                        }
0204:                    }
0205:                    /**
0206:                     * If the field has any conditional constraint, will be added to the collection for later query.
0207:                     */
0208:                    final List conditions = aval instanceof  UserAttribute ? aval
0209:                            .getAttribute().getConditions()
0210:                            : aval.getRModuleAttribute().getConditions();
0211:                    if (conditions.size() > 0) {
0212:                        for (Iterator it = conditions.iterator(); it.hasNext();) {
0213:                            final Condition cond = (Condition) it.next();
0214:                            final Integer id = cond.getOptionId();
0215:                            List fields = (List) conditionallyRequiredFields
0216:                                    .get(id);
0217:                            if (fields == null) {
0218:                                fields = new ArrayList();
0219:                            }
0220:                            fields.add(field != null ? (Object) field
0221:                                    : (Object) aval); // !breaks any generics on this list!
0222:                            conditionallyRequiredFields.put(id, fields);
0223:                        }
0224:                    }
0225:
0226:                }
0227:
0228:                final boolean attributeValuesValid = submitattributesCheckRequiredAttributes(
0229:                        issue, conditionallyRequiredFields, selectedOptions);
0230:
0231:                if (intake.isAllValid() && attributeValuesValid) {
0232:                    submitattributesPerform(context, user, saveAsComment);
0233:                } else {
0234:                    scarabR.setAlertMessage(ERROR_MESSAGE);
0235:                }
0236:            }
0237:
0238:            /**
0239:             * Now that we have all the info, we will force the 'required' status of any field
0240:             * whose requiredOptionId has been set in the issue.
0241:             * @return false when required attributres are not meet, 
0242:             *  although intake.isValid() is also used sometimes to represent this condition.
0243:             */
0244:            private boolean submitattributesCheckRequiredAttributes(
0245:                    final Issue issue, final Map conditionallyRequiredFields,
0246:                    final Map selectedOptions) throws Exception {
0247:                boolean attributeValuesValid = true;
0248:                for (Iterator requiredIds = conditionallyRequiredFields
0249:                        .keySet().iterator(); requiredIds.hasNext();) {
0250:                    final Integer attributeId = (Integer) requiredIds.next();
0251:                    if (selectedOptions.keySet().contains(attributeId)) {
0252:                        final List fields = (List) conditionallyRequiredFields
0253:                                .get(attributeId);
0254:                        for (Iterator iter = fields.iterator(); iter.hasNext();) {
0255:                            final Object next = iter.next();
0256:                            if (next instanceof  Field) {
0257:                                final Field field = (Field) next;
0258:                                if (field.getValue().toString().length() == 0) {
0259:                                    field.setRequired(true);
0260:                                    field
0261:                                            .setMessage("ConditionallyRequiredAttribute");
0262:                                }
0263:                            } else if (next instanceof  UserAttribute) {
0264:                                // An attribute that doesn't exist in intake needs to be 
0265:                                //  added to this issue. 
0266:                                // Currently only UserAttributes exists in this category.
0267:                                final UserAttribute originalAv = (UserAttribute) next;
0268:                                // get attribute value from issue to avoid cached value from intake
0269:                                final UserAttribute freshAv = (UserAttribute) issue
0270:                                        .getAttributeValue(originalAv
0271:                                                .getAttribute());
0272:
0273:                                if (freshAv == null
0274:                                        || freshAv.getValue() == null) {
0275:
0276:                                    final AttributeOption option = AttributeOptionManager
0277:                                            .getInstance(attributeId);
0278:                                    // Will append the error message to the attribute the user 
0279:                                    //  is trying to change instead, since the user attributes
0280:                                    // are on a different part/tab on the screen.
0281:                                    final Field f = (Field) selectedOptions
0282:                                            .get(attributeId);
0283:                                    final L10NMessage msg = new L10NMessage(
0284:                                            L10NKeySet.ConditionallyRequiredUserAttribute,
0285:                                            new Object[] {
0286:                                                    // use original attribute value and it won't be null
0287:                                                    originalAv.getAttribute()
0288:                                                            .getName(),
0289:                                                    option.getName() });
0290:                                    f.setMessage(msg.getMessage());
0291:                                    attributeValuesValid = false;
0292:                                }
0293:                            }
0294:                        }
0295:                    }
0296:                }
0297:                return attributeValuesValid;
0298:            }
0299:
0300:            /** Performs the actual changes to the issue for a doSubmitattributes
0301:             * once all pre-conditions have been checked.
0302:             **/
0303:            private void submitattributesPerform(final TemplateContext context,
0304:                    final ScarabUser user, final boolean saveAsComment)
0305:                    throws Exception {
0306:
0307:                // get required tools
0308:                final ScarabRequestTool scarabR = getScarabRequestTool(context);
0309:                final ScarabLocalizationTool l10n = getLocalizationTool(context);
0310:                final Issue issue = scarabR.getIssue();
0311:                final LinkedMap modMap = issue.getModuleAttributeValuesMap();
0312:                final IntakeTool intake = getIntakeTool(context);
0313:                final Group reasonGroup = intake.get("Attachment",
0314:                        "attCommentKey" + issue.getQueryKey(), false);
0315:
0316:                // start building attribute maps holding the changes
0317:                final HashMap newAttVals = new HashMap();
0318:                // Set the attribute values entered 
0319:                final Iterator iter2 = modMap.mapIterator();
0320:                boolean modifiedAttribute = false;
0321:                while (iter2.hasNext()) {
0322:                    final AttributeValue aval = (AttributeValue) modMap
0323:                            .get(iter2.next());
0324:                    final AttributeValue aval2 = AttributeValue.getNewInstance(
0325:                            aval.getAttributeId(), aval.getIssue());
0326:                    aval2.setProperties(aval);
0327:
0328:                    final Group group = intake.get("AttributeValue", aval
0329:                            .getQueryKey(), false);
0330:                    String oldValue = "";
0331:                    String newValue = "";
0332:
0333:                    if (group != null) {
0334:                        if (aval instanceof  OptionAttribute) {
0335:                            newValue = group.get("OptionId").toString();
0336:                            oldValue = aval.getOptionIdAsString();
0337:                        } else {
0338:                            newValue = group.get("Value").toString();
0339:                            oldValue = aval.getValue();
0340:                        }
0341:                        // A value has been entered for the attribute.
0342:                        // The old value is different from the new, or is unset:
0343:                        // Set new value.
0344:                        if (newValue.length() > 0
0345:                                && ((oldValue == null) || (oldValue != null && !oldValue
0346:                                        .trim().equals(newValue.trim())))) {
0347:                            group.setProperties(aval2);
0348:                            newAttVals.put(aval.getAttributeId(), aval2);
0349:                            modifiedAttribute = true;
0350:                        }
0351:                        // The attribute is being undefined. 
0352:                        else if (oldValue != null && newValue.length() == 0
0353:                                && oldValue.length() != 0) {
0354:                            aval2.setValue(null);
0355:                            newAttVals.put(aval.getAttributeId(), aval2);
0356:                            modifiedAttribute = true;
0357:                        }
0358:                    }
0359:                }
0360:                if (!modifiedAttribute && !saveAsComment) {
0361:                    scarabR.setAlertMessage(L10NKeySet.MustModifyAttribute);
0362:                    return;
0363:                }
0364:                final Attachment attachment = AttachmentManager.getInstance();
0365:                reasonGroup.setProperties(attachment);
0366:
0367:                try {
0368:                    DateAttribute.convertDateAttributes(newAttVals.values(),
0369:                            l10n.get(L10NKeySet.ShortDatePattern));
0370:                    final ActivitySet activitySet = issue.setAttributeValues(
0371:                            null, newAttVals, attachment, user);
0372:                    // save reason as a comment as well?
0373:                    if (saveAsComment) {
0374:                        issue.addComment(activitySet, attachment, user);
0375:                    } else {
0376:                        NotificationManagerFactory.getInstance()
0377:                                .addActivityNotification(
0378:                                        ActivityType.ATTRIBUTE_CHANGED,
0379:                                        activitySet, issue, user);
0380:                    }
0381:                    intake.removeAll();
0382:                    scarabR.setConfirmMessage(L10NKeySet.ChangesSaved);
0383:                } catch (Exception se) {
0384:                    scarabR.setAlertMessage(l10n.getMessage(se));
0385:                }
0386:            }
0387:
0388:            /**
0389:             *  Modifies attachments of type "url".
0390:             */
0391:            public void doSaveurl(RunData data, TemplateContext context)
0392:                    throws Exception {
0393:                if (isCollision(data, context)) {
0394:                    return;
0395:                }
0396:
0397:                ScarabRequestTool scarabR = getScarabRequestTool(context);
0398:                Issue issue = scarabR.getIssue();
0399:                if (issue == null) {
0400:                    // no need to set the message here as
0401:                    // it is done in scarabR.getIssue()
0402:                    return;
0403:                }
0404:
0405:                IntakeTool intake = getIntakeTool(context);
0406:                ScarabUser user = (ScarabUser) data.getUser();
0407:
0408:                List urls = issue.getUrls();
0409:                ActivitySet activitySet = null;
0410:                for (int i = 0; i < urls.size(); i++) {
0411:                    Attachment attachment = (Attachment) urls.get(i);
0412:                    if (attachment.getTypeId().equals(Attachment.URL__PK)
0413:                            && !attachment.getDeleted()) {
0414:                        Group group = intake.get("Attachment", attachment
0415:                                .getQueryKey(), false);
0416:
0417:                        Field nameField = group.get("Name");
0418:                        Field dataField = group.get("Data");
0419:                        if (dataField.isValid()) {
0420:                            dataField.setRequired(true);
0421:                        }
0422:
0423:                        if (intake.isAllValid()) {
0424:                            // store the new and old data
0425:                            String oldDescription = attachment.getName();
0426:                            String oldURL = new String(attachment.getData());
0427:                            String newDescription = nameField.toString();
0428:                            String newURL = dataField.toString();
0429:
0430:                            if (!oldDescription.equals(newDescription)) {
0431:                                group.setProperties(attachment);
0432:                                attachment.save();
0433:                                activitySet = issue.doChangeUrlDescription(
0434:                                        activitySet, user, attachment,
0435:                                        oldDescription);
0436:                                scarabR.setConfirmMessage(L10NKeySet.UrlSaved);
0437:                            }
0438:                            if (!oldURL.equals(newURL)) {
0439:                                group.setProperties(attachment);
0440:                                attachment.save();
0441:                                activitySet = issue.doChangeUrlUrl(activitySet,
0442:                                        user, attachment, oldURL);
0443:                                scarabR.setConfirmMessage(L10NKeySet.UrlSaved);
0444:                            }
0445:                        } else {
0446:                            scarabR.setAlertMessage(ERROR_MESSAGE);
0447:                        }
0448:                    }
0449:                }
0450:
0451:                // if there is a new URL, add it
0452:                Group newGroup = intake.get("Attachment", "urlKey", false);
0453:                if (newGroup != null) {
0454:                    Field dataField = newGroup.get("Data");
0455:                    String dataFieldString = dataField.toString();
0456:                    if (dataFieldString != null
0457:                            && dataFieldString.trim().length() > 0) {
0458:                        if (intake.isAllValid()) {
0459:                            // create the new attachment
0460:                            Attachment attachment = AttachmentManager
0461:                                    .getInstance();
0462:                            // set the form data to the attachment object
0463:                            newGroup.setProperties(attachment);
0464:                            activitySet = issue.addUrl(attachment, user);
0465:
0466:                            // remove the group
0467:                            intake.remove(newGroup);
0468:                            scarabR.setConfirmMessage(L10NKeySet.UrlSaved);
0469:                            NotificationManagerFactory.getInstance()
0470:                                    .addActivityNotification(
0471:                                            ActivityType.URL_ADDED,
0472:                                            activitySet, issue, user);
0473:                        } else {
0474:                            scarabR.setAlertMessage(ERROR_MESSAGE);
0475:                        }
0476:                    }
0477:                }
0478:            }
0479:
0480:            /**
0481:             * Enable edition mode for the comment page.
0482:             */
0483:            public void doEditcommentpage(RunData data, TemplateContext context)
0484:                    throws Exception {
0485:                if (isCollision(data, context)) {
0486:                    return;
0487:                }
0488:                ScarabUser user = (ScarabUser) data.getUser();
0489:                ScarabRequestTool scarabR = getScarabRequestTool(context);
0490:                Issue issue = scarabR.getIssue();
0491:                if (issue == null) {
0492:                    // no need to set the message here as
0493:                    // it is done in scarabR.getIssue()
0494:                    return;
0495:                }
0496:                if (!user.hasPermission(ScarabSecurity.ISSUE__COMMENT, issue
0497:                        .getModule())) {
0498:                    scarabR.setAlertMessage(NO_PERMISSION_MESSAGE);
0499:                    return;
0500:                }
0501:                data.getParameters().add("edit_comments", "true");
0502:                data.getParameters().add("fullcomments",
0503:                        data.getParameters().get("fullcomments"));
0504:                return;
0505:            }
0506:
0507:            /**
0508:             *  Adds an attachment of type "comment".
0509:             */
0510:            public void doSubmitcomment(RunData data, TemplateContext context)
0511:                    throws Exception {
0512:                ScarabRequestTool scarabR = getScarabRequestTool(context);
0513:                ScarabLocalizationTool l10n = getLocalizationTool(context);
0514:                Issue issue = scarabR.getIssue();
0515:                if (issue == null) {
0516:                    // no need to set the message here as
0517:                    // it is done in scarabR.getIssue()
0518:                    return;
0519:                }
0520:                ScarabUser user = (ScarabUser) data.getUser();
0521:                if (!user.hasPermission(ScarabSecurity.ISSUE__COMMENT, issue
0522:                        .getModule())) {
0523:                    scarabR.setAlertMessage(NO_PERMISSION_MESSAGE);
0524:                    return;
0525:                }
0526:
0527:                IntakeTool intake = getIntakeTool(context);
0528:                Group group = intake.get("Attachment", "commentKey", false);
0529:                if (group != null) {
0530:                    Attachment attachment = AttachmentManager.getInstance();
0531:                    try {
0532:                        group.setProperties(attachment);
0533:                    } catch (Exception e) {
0534:                        scarabR.setAlertMessage(ERROR_MESSAGE);
0535:                        return;
0536:                    }
0537:
0538:                    try {
0539:                        issue.addComment(attachment, (ScarabUser) data
0540:                                .getUser());
0541:                    } catch (Exception e) {
0542:                        String l10nMessage = l10n.getMessage(e);
0543:                        scarabR.setAlertMessage(l10nMessage);
0544:                        return;
0545:                    }
0546:                    scarabR.setConfirmMessage(L10NKeySet.CommentSaved);
0547:                    intake.remove(group);
0548:                } else {
0549:                    scarabR.setAlertMessage(ERROR_MESSAGE);
0550:                }
0551:            }
0552:
0553:            /**
0554:             * Add an attachment of type "file"
0555:             */
0556:            public void doSubmitfile(RunData data, TemplateContext context)
0557:                    throws Exception {
0558:                ScarabRequestTool scarabR = getScarabRequestTool(context);
0559:                Issue issue = scarabR.getIssue();
0560:                if (issue == null) {
0561:                    // no need to set the message here as
0562:                    // it is done in scarabR.getIssue()
0563:                    return;
0564:                }
0565:                ScarabUser user = (ScarabUser) data.getUser();
0566:                if (!user.hasPermission(ScarabSecurity.ISSUE__ATTACH, issue
0567:                        .getModule())) {
0568:                    scarabR.setAlertMessage(NO_PERMISSION_MESSAGE);
0569:                    return;
0570:                }
0571:
0572:                IntakeTool intake = getIntakeTool(context);
0573:                Group group = intake.get("Attachment", "fileKey"
0574:                        + issue.getQueryKey(), false);
0575:                Field nameField = group.get("Name");
0576:                // set some required fields
0577:                if (nameField.isValid()) {
0578:                    nameField.setRequired(true);
0579:                }
0580:                // validate intake
0581:                if (intake.isAllValid() && group != null) {
0582:                    // adding a file is a special process
0583:                    addFileAttachment(issue, group, (Attachment) null, scarabR,
0584:                            data, intake);
0585:                    ActivitySet activitySet = issue.doSaveFileAttachments(user);
0586:                    if (activitySet != null) {
0587:                        scarabR.setConfirmMessage(L10NKeySet.FileSaved);
0588:                        NotificationManagerFactory.getInstance()
0589:                                .addActivityNotification(
0590:                                        ActivityType.ATTACHMENT_CREATED,
0591:                                        activitySet, issue, user);
0592:
0593:                    } else {
0594:                        scarabR.setAlertMessage(ERROR_MESSAGE);
0595:                    }
0596:                } else {
0597:                    scarabR.setAlertMessage(ERROR_MESSAGE);
0598:                }
0599:            }
0600:
0601:            /**
0602:             * Adds a file attachment to an issue.
0603:             *
0604:             * @param issue The issue to add an attachment to.
0605:             * @param group Intake group.
0606:             * @param attachment The attachment to add, or <code>null</code>
0607:             * to use a new blank one.
0608:             * @param scarabR Request tool.
0609:             * @param data Contextual data.
0610:             * @param intake Intake tool.
0611:             */
0612:            static void addFileAttachment(Issue issue, Group group,
0613:                    Attachment attachment, ScarabRequestTool scarabR,
0614:                    RunData data, IntakeTool intake) throws Exception {
0615:                if (group != null) {
0616:                    Field nameField = group.get("Name");
0617:                    Field fileField = group.get("File");
0618:                    nameField.setRequired(true);
0619:                    fileField.setRequired(true);
0620:                    Field mimeAField = group.get("MimeTypeA");
0621:                    Field mimeBField = group.get("MimeTypeB");
0622:                    String mimeA = mimeAField.toString();
0623:                    String mimeB = mimeBField.toString();
0624:                    String mimeType = null;
0625:                    if (mimeB != null && mimeB.trim().length() > 0) {
0626:                        mimeType = mimeB;
0627:                    } else if ("autodetect".equals(mimeA)
0628:                            && fileField.isValid()) {
0629:                        try {
0630:                            String filename = ((FileItem) fileField.getValue())
0631:                                    .getName();
0632:                            String contentType = ComponentLocator
0633:                                    .getMimeTypeService().getContentType(
0634:                                            filename, null);
0635:                            if (contentType == null) {
0636:                                // could not match extension.
0637:                                mimeAField
0638:                                        .setMessage("intake_CouldNotDetermineMimeType");
0639:                            } else {
0640:                                mimeType = contentType;
0641:                            }
0642:                        } catch (Exception e) {
0643:                            // we do not want any exception thrown here to affect
0644:                            // the user experience, it is just considered a 
0645:                            // non-detectable file type.  But still the exception is
0646:                            // not expected, so log it.
0647:                            mimeAField
0648:                                    .setMessage("intake_CouldNotDetermineMimeType");
0649:                            Log
0650:                                    .get()
0651:                                    .info(
0652:                                            "Could not determine mimetype of uploaded file.",
0653:                                            e);
0654:                        }
0655:                    } else {
0656:                        mimeAField.setRequired(true);
0657:                        mimeType = mimeA;
0658:                    }
0659:                    if (group.isAllValid()) {
0660:                        if (attachment == null) {
0661:                            attachment = AttachmentManager.getInstance();
0662:                        }
0663:                        group.setProperties(attachment);
0664:                        attachment.setMimeType(mimeType);
0665:                        issue.addFile(attachment, (ScarabUser) data.getUser());
0666:                        // remove the group so that the form data doesn't show up again
0667:                        intake.remove(group);
0668:                    } else {
0669:                        scarabR.setAlertMessage(ERROR_MESSAGE);
0670:                    }
0671:                } else {
0672:                    scarabR
0673:                            .setAlertMessage(L10NKeySet.CouldNotLocateAttachmentGroup);
0674:                }
0675:            }
0676:
0677:            /**
0678:             *  Edits a comment.
0679:             */
0680:            public void doEditcomment(RunData data, TemplateContext context)
0681:                    throws Exception {
0682:                if (isCollision(data, context)) {
0683:                    return;
0684:                }
0685:
0686:                ScarabUser user = (ScarabUser) data.getUser();
0687:                ScarabRequestTool scarabR = getScarabRequestTool(context);
0688:                ScarabLocalizationTool l10n = getLocalizationTool(context);
0689:                Issue issue = scarabR.getIssue();
0690:                if (issue == null) {
0691:                    // no need to set the message here as
0692:                    // it is done in scarabR.getIssue()
0693:                    return;
0694:                }
0695:
0696:                if (!user.hasPermission(ScarabSecurity.ISSUE__COMMENT, issue
0697:                        .getModule())) {
0698:                    scarabR.setAlertMessage(NO_PERMISSION_MESSAGE);
0699:                    return;
0700:                }
0701:
0702:                ParameterParser params = data.getParameters();
0703:                Object[] keys = params.getKeys();
0704:                ActivitySet activitySet = null;
0705:                for (int i = 0; i < keys.length; i++) {
0706:                    String key = (String) keys[i];
0707:                    if (key.startsWith("edit_comment_")) {
0708:                        String attachmentId = key.substring(13);
0709:                        String newComment = params.getString(key, "");
0710:                        Attachment attachment = AttachmentManager.getInstance(
0711:                                new NumberKey(attachmentId), false);
0712:                        try {
0713:                            activitySet = issue.doEditComment(activitySet,
0714:                                    newComment, attachment, user);
0715:                        } catch (ScarabException se) {
0716:                            scarabR.setAlertMessage(l10n.getMessage(se));
0717:                        }
0718:                    }
0719:                }
0720:                if (activitySet != null) {
0721:                    scarabR.setConfirmMessage(DEFAULT_MSG);
0722:                } else {
0723:                    scarabR.setInfoMessage(L10NKeySet.NoCommentsChanged);
0724:                }
0725:            }
0726:
0727:            /**
0728:             *  Deletes a url.
0729:             */
0730:            public void doDeleteurl(RunData data, TemplateContext context)
0731:                    throws Exception {
0732:                if (isCollision(data, context)) {
0733:                    return;
0734:                }
0735:
0736:                ScarabRequestTool scarabR = getScarabRequestTool(context);
0737:                Issue issue = scarabR.getIssue();
0738:                if (issue == null) {
0739:                    // no need to set the message here as
0740:                    // it is done in scarabR.getIssue()
0741:                    return;
0742:                }
0743:
0744:                ScarabUser user = (ScarabUser) data.getUser();
0745:                if (!user.hasPermission(ScarabSecurity.ISSUE__EDIT, issue
0746:                        .getModule())) {
0747:                    scarabR.setAlertMessage(NO_PERMISSION_MESSAGE);
0748:                    return;
0749:                }
0750:
0751:                ParameterParser params = data.getParameters();
0752:                Object[] keys = params.getKeys();
0753:                ActivitySet activitySet = null;
0754:                for (int i = 0; i < keys.length; i++) {
0755:                    String key = (String) keys[i];
0756:                    if (key.startsWith("url_delete_")) {
0757:                        String attachmentId = key.substring(11);
0758:                        Attachment attachment = AttachmentManager.getInstance(
0759:                                new NumberKey(attachmentId), false);
0760:                        activitySet = issue.doDeleteUrl(activitySet,
0761:                                attachment, user);
0762:                    }
0763:                }
0764:                if (activitySet != null) {
0765:                    scarabR.setConfirmMessage(DEFAULT_MSG);
0766:                    NotificationManagerFactory.getInstance()
0767:                            .addActivityNotification(ActivityType.URL_DELETED,
0768:                                    activitySet, issue, user);
0769:                } else {
0770:                    scarabR.setInfoMessage(L10NKeySet.NoUrlsChanged);
0771:                }
0772:            }
0773:
0774:            /**
0775:             *  Deletes a file.
0776:             */
0777:            public void doDeletefile(RunData data, TemplateContext context)
0778:                    throws Exception {
0779:                if (isCollision(data, context)) {
0780:                    return;
0781:                }
0782:
0783:                ScarabRequestTool scarabR = getScarabRequestTool(context);
0784:                Issue issue = scarabR.getIssue();
0785:                if (issue == null) {
0786:                    // no need to set the message here as
0787:                    // it is done in scarabR.getIssue()
0788:                    return;
0789:                }
0790:
0791:                ScarabUser user = (ScarabUser) data.getUser();
0792:                if (!user.hasPermission(ScarabSecurity.ISSUE__EDIT, issue
0793:                        .getModule())) {
0794:                    scarabR.setAlertMessage(NO_PERMISSION_MESSAGE);
0795:                    return;
0796:                }
0797:
0798:                ParameterParser params = data.getParameters();
0799:                Object[] keys = params.getKeys();
0800:                ActivitySet activitySet = null;
0801:
0802:                boolean allFilesDeleted = true;
0803:
0804:                boolean deletePhysically = Turbine
0805:                        .getConfiguration()
0806:                        .getBoolean("scarab.attachment.remove.permanent", false);
0807:
0808:                for (int i = 0; i < keys.length; i++) {
0809:                    String key = (String) keys[i];
0810:                    if (key.startsWith("file_delete_")) {
0811:                        String attachmentId = key.substring(12);
0812:                        Attachment attachment = AttachmentManager.getInstance(
0813:                                new NumberKey(attachmentId), false);
0814:                        MutableBoolean physicallyDeleted = new MutableBoolean(
0815:                                false);
0816:                        activitySet = issue.doRemoveAttachment(activitySet,
0817:                                physicallyDeleted, attachment, user);
0818:                        //set deleted to false if at least for one of the
0819:                        //deleted attachmnents the file was not removed from
0820:                        //disk. 
0821:                        if (deletePhysically
0822:                                && !physicallyDeleted.booleanValue()) {
0823:                            allFilesDeleted = false;
0824:                        }
0825:                    }
0826:                }
0827:
0828:                if (activitySet != null) {
0829:                    if (allFilesDeleted) {
0830:                        scarabR.setConfirmMessage(DEFAULT_MSG);
0831:                    } else {
0832:                        scarabR
0833:                                .setAlertMessage(L10NKeySet.FilesPartiallyDeleted);
0834:                    }
0835:                    NotificationManagerFactory.getInstance()
0836:                            .addActivityNotification(
0837:                                    ActivityType.ATTACHMENT_REMOVED,
0838:                                    activitySet, issue, user);
0839:                } else {
0840:                    scarabR.setInfoMessage(L10NKeySet.NoFilesChanged);
0841:                }
0842:            }
0843:
0844:            /**
0845:             *  Modifies the dependency type between the current issue
0846:             *  And its parent or child issue.
0847:             */
0848:            /*public void doDeletedependencies(RunData data, TemplateContext context)
0849:                throws Exception
0850:            {
0851:                saveDependencyDeletions(data, context);
0852:            }
0853:             */
0854:
0855:            /**
0856:             *  Modifies the dependency type between the current issue
0857:             *  And its parent or child issue.
0858:             */
0859:            public void doSavedependencychanges(RunData data,
0860:                    TemplateContext context) throws Exception {
0861:                saveDependencyChanges(data, context, false);
0862:            }
0863:
0864:            /**
0865:             *  Modifies the dependency type between the current issue
0866:             *  And its parent or child issue.
0867:             */
0868:            public void doSavenewdependencies(RunData data,
0869:                    TemplateContext context) throws Exception {
0870:                saveNewDependencies(data, context, false);
0871:            }
0872:
0873:            /**
0874:             *  Modifies the dependency type between the current issue
0875:             *  And its parent or child issue.
0876:             */
0877:            private void saveDependencyChanges(RunData data,
0878:                    TemplateContext context, boolean doDelete) throws Exception {
0879:                if (isCollision(data, context)) {
0880:                    return;
0881:                }
0882:
0883:                ScarabRequestTool scarabR = getScarabRequestTool(context);
0884:                ScarabLocalizationTool l10n = getLocalizationTool(context);
0885:                Issue issue = scarabR.getIssue();
0886:                if (issue == null) {
0887:                    // no need to set the message here as
0888:                    // it is done in scarabR.getIssue()
0889:                    return;
0890:                }
0891:
0892:                ScarabUser user = (ScarabUser) data.getUser();
0893:                if (!user.hasPermission(ScarabSecurity.ISSUE__EDIT, issue
0894:                        .getModule())) {
0895:                    scarabR.setAlertMessage(NO_PERMISSION_MESSAGE);
0896:                    return;
0897:                }
0898:
0899:                IntakeTool intake = getIntakeTool(context);
0900:                String modifyDepTo = data.getParameters().get("modifyDepTo");
0901:                boolean changesMade = false;
0902:
0903:                DependType newDependType = null;
0904:                if (modifyDepTo == null || modifyDepTo.equals("")) {
0905:                    // no dependType set -> error
0906:                } else if (modifyDepTo.equals("remove")) {
0907:                    changesMade = doRemoveSelectedDependencies(issue, intake,
0908:                            scarabR, context, l10n, user);
0909:                } else {
0910:                    /* If modifyDepTo equals "-1" we want the current issue to become
0911:                     * a prerequisite for the other issue.
0912:                     */
0913:                    boolean setAsPrerequisite = false;
0914:                    if (modifyDepTo.equals("-1")) {
0915:                        modifyDepTo = modifyDepTo.substring(1);
0916:                        setAsPrerequisite = true;
0917:                    }
0918:
0919:                    newDependType = DependTypeManager
0920:                            .getInstanceById(modifyDepTo);
0921:                    changesMade = doUpdatedependencies(issue, intake, scarabR,
0922:                            context, user, newDependType, setAsPrerequisite);
0923:                }
0924:
0925:                if (!changesMade) {
0926:                    scarabR.setInfoMessage(NO_CHANGES_MADE);
0927:                }
0928:            }
0929:
0930:            /**
0931:             *  Modifies the dependency type between the current issue
0932:             *  And its parent or child issue.
0933:             */
0934:            private void saveNewDependencies(RunData data,
0935:                    TemplateContext context, boolean doDelete) throws Exception {
0936:                if (isCollision(data, context)) {
0937:                    return;
0938:                }
0939:
0940:                ScarabRequestTool scarabR = getScarabRequestTool(context);
0941:                ScarabLocalizationTool l10n = getLocalizationTool(context);
0942:                Issue issue = scarabR.getIssue();
0943:                if (issue == null) {
0944:                    // no need to set the message here as
0945:                    // it is done in scarabR.getIssue()
0946:                    return;
0947:                }
0948:
0949:                ScarabUser user = (ScarabUser) data.getUser();
0950:                if (!user.hasPermission(ScarabSecurity.ISSUE__EDIT, issue
0951:                        .getModule())) {
0952:                    scarabR.setAlertMessage(NO_PERMISSION_MESSAGE);
0953:                    return;
0954:                }
0955:
0956:                IntakeTool intake = getIntakeTool(context);
0957:                Group group = intake.get("Depend", "newDep"
0958:                        + issue.getQueryKey(), false);
0959:
0960:                boolean depAdded = doAdddependency(issue, intake, group,
0961:                        scarabR, context, l10n, user);
0962:                if (!depAdded) {
0963:                    scarabR.setAlertMessage(ERROR_MESSAGE);
0964:                    scarabR.setInfoMessage(NO_CHANGES_MADE);
0965:                } else {
0966:                    intake.remove(group);
0967:                }
0968:            }
0969:
0970:            /**
0971:             *  Modifies the dependency type between the current issue
0972:             *  And its parent or child issue.
0973:             */
0974:            /*
0975:            private void saveDependencyDeletions(RunData data, TemplateContext context)
0976:                throws Exception
0977:            {
0978:                if (isCollision(data, context)) 
0979:                {
0980:                    return;
0981:                }
0982:
0983:                ScarabRequestTool scarabR = getScarabRequestTool(context);
0984:                ScarabLocalizationTool l10n = getLocalizationTool(context);
0985:                Issue issue = scarabR.getIssue();
0986:                if (issue == null)
0987:                {
0988:                    // no need to set the message here as
0989:                    // it is done in scarabR.getIssue()
0990:                    return;
0991:                }
0992:
0993:                ScarabUser user = (ScarabUser)data.getUser();
0994:                if (!user.hasPermission(ScarabSecurity.ISSUE__EDIT, 
0995:                                       issue.getModule()))
0996:                {
0997:                    scarabR.setAlertMessage(NO_PERMISSION_MESSAGE);
0998:                    return;
0999:                }
1000:
1001:                IntakeTool intake = getIntakeTool(context);
1002:                
1003:                //"newDep"+issue.getQueryKey()         depnewDep2dti
1004:                //                                     dep100del
1005:                String intakeKey        = "newDep" + issue.getQueryKey();
1006:
1007:                Group group = intake.get("Depend", intakeKey, false);
1008:                if(group != null)
1009:                {
1010:                String reasonForChange = group.get("Description").toString();
1011:
1012:                boolean done = doUpdatedependencies(issue, intake, scarabR, 
1013:                                                           context, l10n, user, 
1014:                                                           reasonForChange, true);
1015:                if (!done)
1016:                {
1017:                    scarabR.setInfoMessage(NO_CHANGES_MADE);
1018:                }
1019:                else
1020:                {
1021:                    intake.remove(group);
1022:                }
1023:                }
1024:            }
1025:             */
1026:
1027:            /**
1028:             *  Modifies the dependency type between the current issue
1029:             *  And its parent or child issue.
1030:             */
1031:            private boolean doAdddependency(Issue issue, IntakeTool intake,
1032:                    Group group, ScarabRequestTool scarabR,
1033:                    TemplateContext context, ScarabLocalizationTool l10n,
1034:                    ScarabUser user) throws Exception {
1035:                // Check that dependency type entered is valid
1036:                Field type = group.get("TypeId");
1037:                Integer typeAsInteger = null;
1038:                try {
1039:                    typeAsInteger = (Integer) type.getValue();
1040:                } catch (Exception e) {
1041:                    type.setMessage(l10n.get(L10NKeySet.SelectRelation));
1042:                    return false;
1043:                }
1044:                boolean needRoleSwitch = false;
1045:                if (typeAsInteger.intValue() < 1) {
1046:                    typeAsInteger = new Integer(-1 * typeAsInteger.intValue());
1047:                    needRoleSwitch = true;
1048:                }
1049:
1050:                type.setRequired(true);
1051:                // Check that child ID entered is valid
1052:                Field childId = group.get("ObserverUniqueId");
1053:                childId.setRequired(true);
1054:                if (!type.isValid() && childId.isValid()) {
1055:                    type.setMessage(l10n
1056:                            .get(L10NKeySet.EnterValidDependencyType));
1057:                    return false;
1058:                } else if (type.isValid() && !childId.isValid()) {
1059:                    childId.setMessage(l10n.get(L10NKeySet.EnterValidIssueId));
1060:                    return false;
1061:                }
1062:                String childIdStr = childId.toString();
1063:                // we need to struggle here because if there is no
1064:                // issue id, we just want to return because the person
1065:                // on the page could just be updating existing deps
1066:                // and in this case, the issue id might be empty.
1067:                if (childIdStr != null) {
1068:                    childIdStr.trim();
1069:                }
1070:                if (childIdStr == null || childIdStr.length() == 0) {
1071:                    return true;
1072:                }
1073:                // Check that child ID entered corresponds to a valid issue
1074:                // The id might not have the prefix appended so use the current
1075:                // module prefix as the thing to try.
1076:                Issue childIssue = null;
1077:                Module currentModule = scarabR.getCurrentModule();
1078:                try {
1079:                    childIssue = IssueManager.getIssueById(childIdStr,
1080:                            currentModule.getCode());
1081:                } catch (Exception e) {
1082:                    // Ignore this
1083:                }
1084:                if (childIssue == null || childIssue.getDeleted()) {
1085:                    childId.setMessage(l10n.get(L10NKeySet.EnterValidIssueId));
1086:                    return false;
1087:                }
1088:
1089:                // Make sure issue is not being marked as dependant on itself.
1090:                else if (childIssue.equals(issue)) {
1091:                    childId.setMessage(l10n
1092:                            .get(L10NKeySet.CannotAddSelfDependency));
1093:                    return false;
1094:                }
1095:                if (intake.isAllValid()) {
1096:                    Depend depend = DependManager.getInstance();
1097:                    depend.setDefaultModule(currentModule);
1098:                    group.setProperties(depend);
1099:                    depend.setTypeId(typeAsInteger);
1100:                    ActivitySet activitySet = null;
1101:                    try {
1102:                        Issue workingIssue = issue;
1103:                        if (needRoleSwitch) {
1104:                            depend.exchangeRoles();
1105:                            workingIssue = childIssue;
1106:                        }
1107:                        activitySet = issue.doAddDependency(activitySet,
1108:                                depend, workingIssue, user);
1109:                    } catch (ScarabException se) {
1110:                        childId
1111:                                .setMessage(se.getL10nMessage()
1112:                                        .getMessage(l10n));
1113:                        return false;
1114:                    } catch (Exception e) {
1115:                        log().debug("Delete error: ", e);
1116:                        return false;
1117:                    }
1118:
1119:                    scarabR.setConfirmMessage(DEFAULT_MSG);
1120:                    if (activitySet != null) {
1121:                        // FIXME: I think that we are sending too many emails here
1122:                        NotificationManagerFactory.getInstance()
1123:                                .addActivityNotification(
1124:                                        ActivityType.DEPENDENCY_CREATED,
1125:                                        activitySet, childIssue, user);
1126:                        NotificationManagerFactory.getInstance()
1127:                                .addActivityNotification(
1128:                                        ActivityType.DEPENDENCY_CREATED,
1129:                                        activitySet, issue, user);
1130:                    }
1131:                    return true;
1132:                } else {
1133:                    return false;
1134:                }
1135:            }
1136:
1137:            /**
1138:             *  Modifies the dependency type between the current issue
1139:             *  And its parent or child issue.
1140:             */
1141:            private boolean doUpdatedependencies(Issue issue,
1142:                    IntakeTool intake, ScarabRequestTool scarabR,
1143:                    TemplateContext context, ScarabUser user,
1144:                    DependType newDependType, boolean setAsPrerequisite)
1145:                    throws Exception {
1146:
1147:                ActivitySet activitySet = null;
1148:                List dependencies = issue.getAllDependencies();
1149:
1150:                for (int i = 0; i < dependencies.size(); i++) {
1151:                    Issue workingIssue = issue;
1152:                    Depend oldDepend = (Depend) dependencies.get(i);
1153:                    DependType oldDependType = oldDepend.getDependType();
1154:                    String intakeKey = oldDepend.getObserverId().toString();
1155:                    boolean this IsPrerequisite = true;
1156:                    Group group = intake.get("Depend", intakeKey, false);
1157:                    if (group == null) {
1158:                        this IsPrerequisite = false;
1159:                        intakeKey = oldDepend.getObservedId().toString();
1160:                        group = intake.get("Depend", intakeKey, false);
1161:                        if (group == null) {
1162:                            // there is nothing to do here.
1163:                            continue;
1164:                        }
1165:                        workingIssue = IssueManager.getInstance(oldDepend
1166:                                .getObservedId(), false);
1167:                    }
1168:
1169:                    Depend newDepend = DependManager.getInstance();
1170:                    // copy oldDepend properties to newDepend
1171:                    newDepend.setProperties(oldDepend);
1172:
1173:                    // set properties on the object
1174:                    group.setProperties(newDepend);
1175:
1176:                    boolean isSelected = newDepend.getSelected();
1177:                    boolean dependTypeModified = !oldDependType
1178:                            .equals(newDependType);
1179:                    boolean needRoleSwitch = newDependType.getName().equals(
1180:                            "blocking")
1181:                            && setAsPrerequisite != this IsPrerequisite;
1182:                    if (isSelected && (dependTypeModified || needRoleSwitch)) {
1183:                        // need to do this because newDepend could have the deleted
1184:                        // flag set to true if someone selected it as well as 
1185:                        // clicked the save changes button. this is why we have the 
1186:                        // doDeleted flag as well...issue.doChange will only do the
1187:                        // change if the deleted flag is false...so force it...
1188:                        newDepend.setDeleted(false);
1189:                        newDepend.setDependType(newDependType);
1190:
1191:                        if (needRoleSwitch) {
1192:                            newDepend.exchangeRoles();
1193:                        }
1194:
1195:                        // make the changes
1196:                        activitySet = workingIssue.doChangeDependencyType(
1197:                                activitySet, oldDepend, newDepend, user);
1198:                    }
1199:                    intake.remove(group);
1200:                }
1201:
1202:                // something changed...
1203:                if (activitySet != null) {
1204:                    scarabR.setConfirmMessage(DEFAULT_MSG);
1205:                    NotificationManagerFactory.getInstance()
1206:                            .addActivityNotification(
1207:                                    ActivityType.DEPENDENCY_CHANGED,
1208:                                    activitySet, issue, user);
1209:                    return true;
1210:                } else // nothing changed
1211:                {
1212:                    return false;
1213:                }
1214:            }
1215:
1216:            /**
1217:             *  Modifies the dependency type between the current issue
1218:             *  And its parent or child issue.
1219:             */
1220:            private boolean doRemoveSelectedDependencies(Issue issue,
1221:                    IntakeTool intake, ScarabRequestTool scarabR,
1222:                    TemplateContext context, ScarabLocalizationTool l10n,
1223:                    ScarabUser user) throws Exception {
1224:
1225:                ActivitySet activitySet = null;
1226:                List dependencies = issue.getAllDependencies();
1227:
1228:                for (int i = 0; i < dependencies.size(); i++) {
1229:                    Depend oldDepend = (Depend) dependencies.get(i);
1230:
1231:                    // Assume, issue takes the role "observer"
1232:                    String intakeKey = oldDepend.getObserverId().toString();
1233:                    Group group = intake.get("Depend", intakeKey, false);
1234:                    Issue workingIssue = issue;
1235:
1236:                    if (group == null) {
1237:                        // Maybe issue takes the role "observed"
1238:                        intakeKey = oldDepend.getObservedId().toString();
1239:                        group = intake.get("Depend", intakeKey, false);
1240:                        if (group == null) {
1241:                            // there is nothing to do here.
1242:                            continue;
1243:                        }
1244:                        workingIssue = oldDepend.getIssueRelatedByObservedId();
1245:                    }
1246:
1247:                    group.setProperties(oldDepend);
1248:                    if (oldDepend.getSelected()) {
1249:                        try {
1250:                            activitySet = workingIssue.doDeleteDependency(
1251:                                    activitySet, oldDepend, user);
1252:                        } catch (ScarabException se) {
1253:                            // it will error out if they attempt to delete
1254:                            // a dep via a child dep.
1255:                            String l10nKey = se.getMessage();
1256:                            scarabR.setAlertMessage(l10n.get(l10nKey));
1257:                        } catch (Exception e) {
1258:                            scarabR.setAlertMessage(ERROR_MESSAGE);
1259:                            log().debug("Delete error: ", e);
1260:                        }
1261:                    }
1262:                    intake.remove(group);
1263:                }
1264:
1265:                // something changed...
1266:                if (activitySet != null) {
1267:                    scarabR.setConfirmMessage(DEFAULT_MSG);
1268:                    NotificationManagerFactory.getInstance()
1269:                            .addActivityNotification(
1270:                                    ActivityType.DEPENDENCY_CHANGED,
1271:                                    activitySet, issue, user);
1272:
1273:                    return true;
1274:                } else // nothing changed
1275:                {
1276:                    return false;
1277:                }
1278:            }
1279:
1280:            /**
1281:             * Redirects to AssignIssue page.
1282:             */
1283:            public void doEditassignees(RunData data, TemplateContext context)
1284:                    throws Exception {
1285:                IntakeTool intake = getIntakeTool(context);
1286:                intake.removeAll();
1287:                ScarabRequestTool scarabR = getScarabRequestTool(context);
1288:                Issue issue = scarabR.getIssue();
1289:                if (issue == null) {
1290:                    // no need to set the message here as
1291:                    // it is done in scarabR.getIssue()
1292:                    return;
1293:                }
1294:                ScarabUser user = (ScarabUser) data.getUser();
1295:                if (user.hasPermission(ScarabSecurity.ISSUE__ASSIGN, issue
1296:                        .getModule())) {
1297:                    data.getParameters().add("id", issue.getUniqueId());
1298:                    data.getParameters().add("issue_ids", issue.getUniqueId());
1299:                    scarabR.resetAssociatedUsers();
1300:                    setTarget(data, "AssignIssue.vm");
1301:                } else {
1302:                    scarabR.setAlertMessage(NO_PERMISSION_MESSAGE);
1303:                }
1304:            }
1305:
1306:            /**
1307:             * Redirects to MoveIssue page with move action selected.
1308:             */
1309:            public void doMove(RunData data, TemplateContext context)
1310:                    throws Exception {
1311:                boolean collisionOccurred = isCollision(data, context);
1312:                context.put("collisionDetectedOnMoveAttempt",
1313:                        collisionOccurred ? Boolean.TRUE : Boolean.FALSE);
1314:                if (collisionOccurred) {
1315:                    // Report the collision to the user.
1316:                    return;
1317:                }
1318:                ScarabRequestTool scarabR = getScarabRequestTool(context);
1319:                Module module = scarabR.getCurrentModule();
1320:                List moveToModules = ((ScarabUser) data.getUser())
1321:                        .getCopyToModules(module, "move");
1322:                if (moveToModules.size() > 0) {
1323:                    ParameterParser pp = data.getParameters();
1324:                    pp.setString("mv_0rb", "move");
1325:                    ((IntakeTool) context.get("intake")).get("MoveIssue")
1326:                            .getDefault().get("Action").init(pp);
1327:                    String[] issueIds = pp.getStrings("issue_ids");
1328:                    String currentIssueId = getScarabRequestTool(context)
1329:                            .getIssue().getUniqueId();
1330:                    if (!ScarabUtil.contains(issueIds, currentIssueId)) {
1331:                        pp.add("issue_ids", currentIssueId);
1332:                    }
1333:                    setTarget(data, "MoveIssue.vm");
1334:                } else {
1335:                    scarabR.setAlertMessage(NO_PERMISSION_MESSAGE);
1336:                    setTarget(data, "ViewIssue.vm");
1337:                }
1338:            }
1339:
1340:            /**
1341:             * Redirects to MoveIssue page with copy action selected.
1342:             */
1343:            public void doCopy(RunData data, TemplateContext context)
1344:                    throws Exception {
1345:                boolean collisionOccurred = isCollision(data, context);
1346:                context.put("collisionDetectedOnMoveAttempt",
1347:                        collisionOccurred ? Boolean.TRUE : Boolean.FALSE);
1348:                if (collisionOccurred) {
1349:                    // Report the collision to the user.
1350:                    return;
1351:                }
1352:                ParameterParser pp = data.getParameters();
1353:                pp.setString("mv_0rb", "copy");
1354:                ((IntakeTool) context.get("intake")).get("MoveIssue")
1355:                        .getDefault().get("Action").init(pp);
1356:                String[] issueIds = pp.getStrings("issue_ids");
1357:                String currentIssueId = getScarabRequestTool(context)
1358:                        .getIssue().getUniqueId();
1359:                if (!ScarabUtil.contains(issueIds, currentIssueId)) {
1360:                    pp.add("issue_ids", currentIssueId);
1361:                }
1362:                setTarget(data, "MoveIssue.vm");
1363:            }
1364:
1365:            /**
1366:             * does not actually modify an issue, but sets the preferred view
1367:             * of an issue for the current session
1368:             */
1369:            public void doSetissueview(RunData data, TemplateContext context)
1370:                    throws Exception {
1371:                String tab = data.getParameters().getString("tab",
1372:                        ScarabConstants.ISSUE_VIEW_ALL);
1373:                data.getUser().setTemp(ScarabConstants.TAB_KEY, tab);
1374:            }
1375:
1376:            /**
1377:             * This action method delegates on the doAddmyself method from AssignIssue
1378:             * action, assigning the current user to the issue in the specified userattribute.
1379:             * 
1380:             * @see AssignIssue#doAddmyself(RunData, TemplateContext)
1381:             * @param data
1382:             * @param context
1383:             * @throws Exception
1384:             */
1385:            public void doAddmyself(RunData data, TemplateContext context)
1386:                    throws Exception {
1387:                ScarabRequestTool scarabR = this .getScarabRequestTool(context);
1388:
1389:                ScarabUser user = (ScarabUser) data.getUser();
1390:                Issue issue = scarabR.getIssue();
1391:                if (user.hasPermission(ScarabSecurity.ISSUE__ASSIGN, issue
1392:                        .getModule())) {
1393:                    // We'll set the info required by AssignIssue.doAddmyself (the)
1394:                    // same that in doEditassignees in this same class.
1395:                    data.getParameters().add("id", issue.getUniqueId());
1396:                    data.getParameters().add("issue_ids", issue.getUniqueId());
1397:
1398:                    scarabR.resetAssociatedUsers();
1399:
1400:                    // Lets cross-call the AssignIssue Turbine action!
1401:                    AssignIssue assignAction = new AssignIssue();
1402:                    assignAction.doAddmyself(data, context);
1403:                    assignAction.doDone(data, context);
1404:                } else {
1405:                    scarabR.setAlertMessage(NO_PERMISSION_MESSAGE);
1406:                }
1407:            }
1408:
1409:            public void doDeleteissue(RunData data, TemplateContext context)
1410:                    throws Exception {
1411:                ScarabRequestTool scarabR = this .getScarabRequestTool(context);
1412:                ScarabUser user = (ScarabUser) data.getUser();
1413:                Issue issue = scarabR.getIssue();
1414:                if (user != null && issue != null) {
1415:                    issue.deleteIssue(user);
1416:                }
1417:                L10NMessage msg = new L10NMessage(L10NKeySet.IssueDeleted,
1418:                        issue.getUniqueId());
1419:                scarabR.setInfoMessage(msg);
1420:            }
1421:
1422:            public void doRemovemyself(RunData data, TemplateContext context)
1423:                    throws Exception {
1424:                ScarabRequestTool scarabR = this .getScarabRequestTool(context);
1425:
1426:                ScarabUser user = (ScarabUser) data.getUser();
1427:                Issue issue = scarabR.getIssue();
1428:                if (user.hasPermission(ScarabSecurity.ISSUE__ASSIGN, issue
1429:                        .getModule())) {
1430:                    // We'll set the info required by AssignIssue.doRemovemyself (the)
1431:                    // same that in doEditassignees in this same class.
1432:                    data.getParameters().add("id", issue.getUniqueId());
1433:                    data.getParameters().add("issue_ids", issue.getUniqueId());
1434:
1435:                    scarabR.resetAssociatedUsers();
1436:
1437:                    // Lets cross-call the AssignIssue Turbine action!
1438:                    AssignIssue assignAction = new AssignIssue();
1439:                    assignAction.doRemovemyself(data, context);
1440:                    assignAction.doDone(data, context);
1441:                } else {
1442:                    scarabR.setAlertMessage(NO_PERMISSION_MESSAGE);
1443:                }
1444:            }
1445:
1446:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.