I am using a REST endpoint in Jira and I am having three files in script editor that are reponsible for this REST endpoint. First, I have a REST_Create_Multiple_Subtasks.groovy file which is responsible for the REST enmdpoint.
Here is its code:
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import com.atlassian.jira.issue.Issue;
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.atlassian.sal.api.ApplicationProperties
import com.atlassian.sal.api.UrlMode
import org.apache.log4j.Logger
import com.atlassian.jira.project.Project
import com.atlassian.jira.bc.project.component.ProjectComponent
import com.atlassian.jira.project.ProjectManager
@BaseScript CustomEndpointDelegate delegate
callSubTaskCreator(httpMethod: "GET", groups: ["jira-users"]) {
MultivaluedMap queryParams, String body ->
def log = Logger.getLogger("atlassian-jira.log")
def subTaskCreatorHashMap= CreateMultipleSubtasks.Configuration_CreateMultipleSubtasks.getSubTaskCreatorHashMap()
String itracCreatemultiplesubtasksProjectCategoriesURL = subTaskCreatorHashMap["itracCreatemultiplesubtasksProjectCategoriesURL"];
log.warn("I AM HERE MOUNA ");
def user = ComponentAccessor.jiraAuthenticationContext?.loggedInUser
Issue issue = ComponentAccessor.getIssueManager().getIssueObject(queryParams.getFirst("issueId") as Long)
long projectID = issue.getProject().get("id") as long
def projectManager = ComponentAccessor.getProjectManager()
Project project = projectManager.getProjectObj(projectID)
int projectCategoryID = project.getProjectCategory().getId() as int
def baseUrl = ScriptRunnerImpl.getOsgiService(ApplicationProperties).getBaseUrl(UrlMode.ABSOLUTE)
int issueTypeID = issue.getIssueTypeId() as int
def itracCreatemultiplesubtasksProjectCategoriesURL2 = itracCreatemultiplesubtasksProjectCategoriesURL.replaceAll(":1:", issue.getKey())
def itracCreatemultiplesubtasksProjectCategoriesURL3 = itracCreatemultiplesubtasksProjectCategoriesURL2.replaceAll(":2:", user.getUsername())
Response.temporaryRedirect(URI.create(itracCreatemultiplesubtasksProjectCategoriesURL3)).build()
}
I have a Fragment_Condition_CreateSubtasks.groovy which is responsible for specifying the conditions under which the REST endpoint should be executed
Here is the code:
import org.apache.log4j.Logger
import com.atlassian.jira.plugin.webfragment.model.JiraHelper
import CreateMultipleSubtasks.Configuration_CreateMultipleSubtasks
def log = Logger.getLogger("atlassian-jira.log")
Configuration_CreateMultipleSubtasks conf = new Configuration_CreateMultipleSubtasks()
def subTaskCreatorHashMap= conf.getSubTaskCreatorHashMap()
String projectKey = subTaskCreatorHashMap["projectKey"];
String issueTypeName = subTaskCreatorHashMap["issueTypeName"];
log.warn("MOUNA PROJECT KEY "+ projectKey+" issuetypename "+issueTypeName)
def val=jiraHelper.project?.key==projectKey && issue.issueType.name==issueTypeName
return val
Finally, I have the file Configuation_CreareSubtasks.groovy which specifies some constant values for the REST endpoint to be read in the 2 previous files:. Here is the code:
public class Configuration_CreateMultipleSubtasks {
static def getSubTaskCreatorHashMap(){
def map = [itracCreatemultiplesubtasksIssueTypesId:5,
itracCreatemultiplesubtasksProjectCategoriesID: [10011, 10200, 10220, 10230, 10240, 10670, 10170, 11170, 11270, 11870, 11871, 11872, 11873, 11874, 11875, 12470],
itracCreatemultiplesubtasksProjectCategoriesURL: "http://itrac-sustservice.eur.ad.sag:5555/web/subtaskmgr/Login.jsp?iTrac=:1:&reporter=:2:",
projectKey: "PIE",
issueTypeName: "Defect"]
return map
}
}
I receive the error:
If you define the class name as 'public', then the name of the file and the class will HAVE to be the same.
You have this class:
public class Configuration_CreateMultipleSubtasks {}
so you should change the file name from Configuation_CreareSubtasks.groovy to Configuration_CreateMultipleSubtasks.groovy.
I think this is a duplicate of another post: https://community.atlassian.com/t5/Jira-Software-questions/MultipleCompilationErrorsException-startup-failed-Compilation/qaq-p/2184531
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.