comparison ssdt-jira-plugins-v2/plugins/src/main/java/org/nwoca/ssdt/jira/RequireDocumentIssueValidator.java @ 0:92d945347fc0

V2 of the SSDT JIRA Plugins. Uses new Maven 2 based project. Created for JIRA 3.12.
author smith
date Tue, 20 May 2008 17:11:35 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:92d945347fc0
1 /*
2 * RequireDocumentIssueValidator.java
3 *
4 * Created on May 14, 2007, 1:04 PM
5 *
6 * To change this template, choose Tools | Template Manager
7 * and open the template in the editor.
8 */
9
10 package org.nwoca.ssdt.jira;
11
12 import com.atlassian.jira.ComponentManager;
13 import com.atlassian.jira.ManagerFactory;
14 import com.atlassian.jira.issue.Issue;
15 import com.atlassian.jira.issue.MutableIssue;
16 import com.atlassian.jira.issue.fields.CustomField;
17 import com.atlassian.jira.issue.link.IssueLink;
18 import com.atlassian.jira.issue.link.IssueLinkManager;
19 import com.atlassian.jira.workflow.WorkflowActionsBean;
20 import com.opensymphony.module.propertyset.PropertySet;
21 import com.opensymphony.workflow.InvalidInputException;
22 import com.opensymphony.workflow.Validator;
23 import com.opensymphony.workflow.WorkflowException;
24 import java.util.Collection;
25 import java.util.List;
26 import java.util.Map;
27
28 /**
29 * Validator requires to an issue type of "Document" or a sub-task of type "Document".
30 *
31 * These are custom issue types used by the SSDT.
32 *
33 * @author SMITH
34 */
35 public class RequireDocumentIssueValidator implements Validator {
36
37
38 /**
39 * Creates a new instance of RequireDocumentIssueValidator
40 */
41 public RequireDocumentIssueValidator() {
42 }
43
44 public void validate(Map transientVars, Map args, PropertySet ps)
45 throws InvalidInputException, WorkflowException {
46
47 Issue issue = (Issue) transientVars.get("issue");
48 CustomField docRequiredField = ManagerFactory.getCustomFieldManager()
49 .getCustomFieldObjectByName("Documentation Required");
50
51 if (docRequiredField == null) {
52 return;
53 }
54
55 String docRequired = (String)issue.getCustomFieldValue(docRequiredField);
56
57 if (docRequired == null || docRequired.startsWith("No")) {
58 return;
59 }
60
61 if (docRequired.startsWith("Yes")) {
62
63 Collection subtasks = issue.getSubTaskObjects();
64 for (Object o : subtasks) {
65 MutableIssue subt = (MutableIssue)o;
66 if (subt.getIssueTypeObject().getName().equals("Document Subtask")) {
67 return;
68 }
69 }
70
71 IssueLinkManager lm = ComponentManager.getInstance().getIssueLinkManager();
72 List links = lm.getOutwardLinks(issue.getId());
73 for (Object o : links) {
74 IssueLink link = (IssueLink)o;
75 if (link.getIssueLinkType().getName().equals("Documention") ) {
76 return;
77 }
78 }
79
80 throw new InvalidInputException("Issue requiring documentation must have "
81 + "at least one 'Document' Subtask or a 'Documention' link." );
82
83 }
84
85 return;
86 }
87
88 }