I am implementing a fragment with a REST endpoint and I would like to display an error if the issue does not have any components. The button is called "MounaGenerate" and here is my implementation of the fragment below:
Here is my implementation of the REST endpoint:
import groovy.transform.BaseScript
import com.atlassian.jira.issue.Issue;
import javax.ws.rs.core.Response
import org.apache.log4j.Logger
import groovy.transform.BaseScript
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import javax.ws.rs.core.MultivaluedMap
import com.atlassian.jira.component.ComponentAccessor
import javax.ws.rs.core.Response
import com.opensymphony.workflow.WorkflowException
@BaseScript CustomEndpointDelegate delegate
mounaGenerate(httpMethod: "GET", groups: ["jira-users"]) {
def log = Logger.getLogger("atlassian-jira.log")
def components = issue.components
log.warn("MOUNA COMPONENTS "+components)
if(components.empty) {
log.warn("MOUNA EMPTY")
throw new WorkflowException("Issue does not have components")
}
}
I am getting the following error on my log:
2023-09-05 14:30:09,456+0200 https-openssl-nio-443-exec-6 ERROR mouh 870x1330103x2 1ic193i 10.250.160.111 /rest/scriptrunner/latest/custom/mounaGenerate [c.o.s.r.rest.common.UserCustomScriptEndpoint] Script endpoint failed on method: GET mounaGenerate
2023-09-05 14:30:09,456+0200 https-openssl-nio-443-exec-6 ERROR mouh 870x1330103x2 1ic193i 10.250.160.111 /rest/scriptrunner/latest/custom/mounaGenerate [c.o.s.r.rest.common.UserCustomScriptEndpoint]
Ideally, I would like a new page to be shown like the following that says that there is an error because the issue does not have any components:
How can I do this?
The issue object needs to be accessed in a different way:
package SuperFeature
import groovy.transform.BaseScript
import com.atlassian.jira.issue.Issue;
import javax.ws.rs.core.Response
import org.apache.log4j.Logger
import groovy.transform.BaseScript
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import javax.ws.rs.core.MultivaluedMap
import com.atlassian.jira.component.ComponentAccessor
import javax.ws.rs.core.Response
import com.opensymphony.workflow.WorkflowException
@BaseScript CustomEndpointDelegate delegate
mounaGenerate(httpMethod: "GET", groups: ["jira-users"])
{
MultivaluedMap queryParams, String body ->
def log1 = Logger.getLogger("atlassian-jira.log")
def issueId = queryParams.getFirst("issueId") as Long
Issue myissue = ComponentAccessor.getIssueManager().getIssueObject(issueId)
def issueKey = myissue.getKey()
def componentNames = myissue.getComponents()*.name
log1.warn("MOUNA componentNames "+componentNames)
if(componentNames.empty) {
log.warn("MOUNA EMPTY")
throw new WorkflowException("Issue does not have components")
}else{
log1.warn("MOUNA componentNames NOT EMPTY")
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.