This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
validators [2018/01/16 13:54] pawel |
validators [2019/02/13 09:10] (current) root added cascading drop down |
||
|---|---|---|---|
| Line 42: | Line 42: | ||
| </ | </ | ||
| - | === Verify if custom field value is not greater than 3 characters long === | + | === Verify if custom field value is 5 characters long === |
| <code java> | <code java> | ||
| import com.atlassian.jira.component.ComponentAccessor; | import com.atlassian.jira.component.ComponentAccessor; | ||
| - | //import com.atlassian.jira.ComponentManager; | ||
| import com.atlassian.jira.issue.CustomFieldManager; | import com.atlassian.jira.issue.CustomFieldManager; | ||
| - | //import com.atlassian.jira.issue.fields.CustomField; | ||
| import com.atlassian.jira.issue.IssueManager; | import com.atlassian.jira.issue.IssueManager; | ||
| - | //import com.atlassian.jira.issue.Issue; | ||
| - | //import com.atlassian.jira.issue.ModifiedValue; | ||
| - | //import com.atlassian.jira.issue.util.DefaultIssueChangeHolder; | ||
| def customfield_ID = " | def customfield_ID = " | ||
| Line 60: | Line 55: | ||
| - | if (cFieldValue.size() | + | if (cFieldValue.size() |
| return false | return false | ||
| } | } | ||
| Line 68: | Line 63: | ||
| </ | </ | ||
| + | === Verify if any other tickets have the same dates as requested === | ||
| + | |||
| + | <code java> | ||
| + | import com.atlassian.jira.component.ComponentAccessor | ||
| + | import com.atlassian.jira.issue.search.SearchProvider | ||
| + | import com.atlassian.jira.jql.parser.JqlQueryParser | ||
| + | import com.atlassian.jira.web.bean.PagerFilter | ||
| + | import com.atlassian.jira.datetime.DateTimeFormatUtils | ||
| + | import org.apache.commons.lang.time.DateUtils | ||
| + | import java.text.SimpleDateFormat | ||
| + | import java.util.Date.* | ||
| + | import java.lang.String.* | ||
| + | //logging | ||
| + | import org.apache.log4j.Logger | ||
| + | import org.apache.log4j.Level | ||
| + | def log = Logger.getLogger(" | ||
| + | log.setLevel(Level.DEBUG) | ||
| + | // this function returns list of issues for JQL | ||
| + | |||
| + | def findIssues(String jqlQuery) { | ||
| + | def issueManager = ComponentAccessor.issueManager | ||
| + | def user = ComponentAccessor.jiraAuthenticationContext.user | ||
| + | def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class) | ||
| + | def searchProvider = ComponentAccessor.getComponent(SearchProvider.class) | ||
| + | def query = jqlQueryParser.parseQuery(jqlQuery) | ||
| + | def results = searchProvider.search(query, | ||
| + | |||
| + | results.issues.collect { issue -> issueManager.getIssueObject(issue.id) } | ||
| + | |||
| + | } | ||
| + | def customFieldManager = ComponentAccessor.getCustomFieldManager() | ||
| + | def isd = cfValues[' | ||
| + | def ied = cfValues[' | ||
| + | def ie = cfValues[' | ||
| + | def inputStartDate | ||
| + | def inputEndDate | ||
| + | def inputEnvironment = ie.toString() | ||
| + | def issues | ||
| + | if (! isd || ! ied){ | ||
| + | log.debug(" | ||
| + | }else{ | ||
| + | inputStartDate = isd.format(" | ||
| + | inputEndDate = ied.format(" | ||
| + | issues = findIssues(' | ||
| + | } | ||
| + | log.debug(" | ||
| + | log.debug(" | ||
| + | log.debug(" | ||
| + | log.debug(" | ||
| + | |||
| + | if ( ! issues){ | ||
| + | return true | ||
| + | log.debug(" | ||
| + | }else{ | ||
| + | return false | ||
| + | log.debug(" | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | === Validate user changed the OD Environment field if it was " | ||
| + | <code java> | ||
| + | import com.atlassian.jira.component.ComponentAccessor | ||
| + | import com.atlassian.jira.issue.Issue | ||
| + | import org.apache.log4j.Logger | ||
| + | import org.apache.log4j.Level | ||
| + | def log = Logger.getLogger(" | ||
| + | log.setLevel(Level.DEBUG) | ||
| + | |||
| + | Issue issue = issue | ||
| + | |||
| + | def customFieldManager = ComponentAccessor.getCustomFieldManager() | ||
| + | def issueManager = ComponentAccessor.getIssueManager() | ||
| + | def customField = customFieldManager.getCustomFieldObjectByName(" | ||
| + | def originalIssue = issueManager.getIssueObject(issue.id) | ||
| + | |||
| + | def originalValue = originalIssue.getCustomFieldValue(customField).toString() | ||
| + | def newValue = issue.getCustomFieldValue(customField).toString() | ||
| + | |||
| + | log.debug(" | ||
| + | log.debug(" | ||
| + | |||
| + | if (originalValue.equals(" | ||
| + | if ( newValue != originalValue ) { | ||
| + | log.debug(" | ||
| + | return true | ||
| + | }else{ | ||
| + | log.debug(" | ||
| + | return false | ||
| + | } | ||
| + | }else{ | ||
| + | |||
| + | log.debug(" | ||
| + | return true | ||
| + | |||
| + | } | ||
| + | </ | ||
| + | |||
| + | === Validate if user is allowed to change the OD Environment field === | ||
| + | |||
| + | <code java> | ||
| + | import com.atlassian.jira.component.ComponentAccessor | ||
| + | import com.atlassian.jira.issue.Issue | ||
| + | import org.apache.log4j.Logger | ||
| + | import org.apache.log4j.Level | ||
| + | def log = Logger.getLogger(" | ||
| + | log.setLevel(Level.DEBUG) | ||
| + | |||
| + | Issue issue = issue | ||
| + | |||
| + | def customFieldManager = ComponentAccessor.getCustomFieldManager() | ||
| + | def issueManager = ComponentAccessor.getIssueManager() | ||
| + | def customField = customFieldManager.getCustomFieldObjectByName(" | ||
| + | def originalIssue = issueManager.getIssueObject(issue.id) | ||
| + | |||
| + | def originalValue = originalIssue.getCustomFieldValue(customField).toString() | ||
| + | def newValue = issue.getCustomFieldValue(customField).toString() | ||
| + | |||
| + | log.debug(" | ||
| + | log.debug(" | ||
| + | |||
| + | if ( newValue != originalValue ) { | ||
| + | if (! originalValue.equals(" | ||
| + | log.debug(" | ||
| + | return false | ||
| + | |||
| + | }else{ | ||
| + | log.debug(" | ||
| + | return true | ||
| + | } | ||
| + | }else{ | ||
| + | log.debug(" | ||
| + | return true | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | === Allow only specific users in project ABC or users in a group " | ||
| + | |||
| + | <code java> | ||
| + | import com.atlassian.jira.component.ComponentAccessor | ||
| + | import com.atlassian.jira.issue.Issue | ||
| + | def groupManager = ComponentAccessor.getGroupManager() | ||
| + | |||
| + | (issue.projectObject.key == ' | ||
| + | |||
| + | |||
| + | </ | ||
| + | |||
| + | === Only allow users in group " | ||
| + | |||
| + | <code java> | ||
| + | import com.atlassian.jira.component.ComponentAccessor | ||
| + | import com.atlassian.jira.issue.Issue | ||
| + | def groupManager = ComponentAccessor.getGroupManager() | ||
| + | |||
| + | groupManager.isUserInGroup(currentUser, | ||
| + | </ | ||
| + | |||
| + | === Check if user is in group " | ||
| + | |||
| + | <code java> | ||
| + | import com.atlassian.jira.component.ComponentAccessor | ||
| + | import com.atlassian.jira.issue.Issue | ||
| + | import com.atlassian.jira.security.roles.ProjectRoleManager | ||
| + | |||
| + | def projectManager = ComponentAccessor.projectManager | ||
| + | def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager) | ||
| + | def role = projectRoleManager.getProjectRole(" | ||
| + | |||
| + | def groupManager = ComponentAccessor.getGroupManager() | ||
| + | |||
| + | if (groupManager.isUserInGroup(currentUser, | ||
| + | return true | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | === Check if cascading child drop down is set to " | ||
| + | The following script was found on Atlassian community here: [[https:// | ||
| + | Use the **Custom Validator** for this script-runner script. | ||
| + | <code java> | ||
| + | import com.atlassian.jira.component.ComponentAccessor | ||
| + | import com.atlassian.jira.issue.MutableIssue | ||
| + | import com.opensymphony.workflow.InvalidInputException | ||
| + | |||
| + | def issue = issue as MutableIssue | ||
| + | def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName(" | ||
| + | def cfValue = issue.getCustomFieldValue(cf) as HashMap | ||
| + | |||
| + | def parentOption = cfValue.values().getAt(0)? | ||
| + | def childOption = cfValue.values().getAt(1)? | ||
| + | |||
| + | if (!childOption) { | ||
| + | throw new InvalidInputException(" | ||
| + | } | ||
| + | </ | ||