Edit Validation Did Not Worked

Yusuf TAMBAG October 26, 2017

Hi,

 

I've added following code for behaviour plugin. I tried returning nothing, throwing invalid input exception and finally below code returning the error collection. Error occurs but jira completes edit operation successfully instead it should remain at Edit screen and show the error message added in the code. 

JIRA Version: 7.4.3

Script Runner: 5.1.6

 

-thank you very much

-yusuf

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.util.SimpleErrorCollection
import org.slf4j.Logger
import org.slf4j.LoggerFactory

Issue issue=(Issue) issue

final String TESPIT_ISSUE_TYPE_NAME="Tespit"
final String ILGILI_TESPITLER_FIELD_NAME="İlgili Tespitler"
final Logger LOG=LoggerFactory.getLogger("tr.gov.tubitak.bilgem.yte.jira.groovy.validators.epid.EPIDIlgiliTespitlerForEditValidator")
CustomFieldManager cfm=ComponentAccessor.getCustomFieldManager()
Collection<CustomField> customFieldCollection=cfm.getCustomFieldObjectsByName(ILGILI_TESPITLER_FIELD_NAME)
SimpleErrorCollection errorCollection = new SimpleErrorCollection()
if(customFieldCollection==null || customFieldCollection.size()!=1) {
errorCollection.addError(ILGILI_TESPITLER_FIELD_NAME,ILGILI_TESPITLER_FIELD_NAME+" alanı bulunamadı veya hatalı, sistem yöneticisine başvurunuz.")
return errorCollection
}

CustomField ilgiliTespitlerField=customFieldCollection.iterator().next()
Object object=issue.getCustomFieldValue(ilgiliTespitlerField)
if(object!=null) {
List<String> issueKeyList=(List<String>) object
List<String> invalidIssues=new ArrayList<String>()
IssueManager issueManager = ComponentAccessor.getIssueManager()
for(String issueKey:issueKeyList) {
Issue linkedIssue=issueManager.getIssueByCurrentKey(issueKey)
if(!linkedIssue.getIssueType().getName().equals(TESPIT_ISSUE_TYPE_NAME)) {
invalidIssues.add(linkedIssue.getKey()+":"+linkedIssue.getIssueType().getName())
}
}
if(invalidIssues.size()>0) {
LOG.error("Invalid issues exists, size: "+invalidIssues.size())
StringBuffer buffer=new StringBuffer()
buffer.append(ILGILI_TESPITLER_FIELD_NAME+" alanına sadece '"+TESPIT_ISSUE_TYPE_NAME+"' türünde talep seçilebilir:")
boolean first=true
for(String invalid:invalidIssues) {
if(!first)
buffer.append(" ,")
else {
buffer.append(" ")
first = false
}
buffer.append(invalid + "\n")
}
errorCollection.addError(ILGILI_TESPITLER_FIELD_NAME,buffer.toString())
return errorCollection
}
}

 

 

1 answer

0 votes
Thanos Batagiannis _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 1, 2017

Hey Yusuf, 

According to the documentation, to disallow the transition you throw a new InvalidInputException (com.opensymphony.workflow.InvalidInputException).

regards, Thanos

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events