Hi Experts,
I have rest service to create issue in my jira plugin which is calling by third party api but the while creating issue i am getting below exception.
Exception:
[INFO] [talledLocalContainer] 2. Error while creating issue: {issuetype=The issue type selected is invalid., pid=Anonymous users do not have permission to create issues in this project. Please try logging in first.}
Note:
how to provide user in create method of issueService interface ( issueService.create(user, createValidationResult) because no buddy logged in while creating issue it is just background service which is calling by third party api to create issue in particular project. Please suggsest some idea to solve this problem.
Code:
IssueService issueService = ComponentAccessor.getComponent(IssueService.class);
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
String projectKey="IHD";
issueInputParameters.setSummary("123"+ ":"+"Create Jira Id");
issueInputParameters.setIssueTypeId("10000");
issueInputParameters.setAssigneeId("admin");
issueInputParameters.setReporterId("admin");
issueInputParameters.setPriorityId("1");
issueInputParameters.setDescription("Create Jira Id");
ProjectService projectService = ComponentAccessor.getComponent(ProjectService.class);
Project project = projectService.getProjectByKey(ComponentAccessor.getUserManager().getUserByKey("dipesh"), projectKey).getProject();
issueInputParameters.setProjectId(project.getId());
CreateValidationResult createValidationResult = issueService.validateCreate(ComponentAccessor.getUserManager().getUserByKey("dipesh"), issueInputParameters);
if (_**createValidationResult.getErrorCollection().hasAnyErrors())**_ {
// If the validation fails, render the list of issues with the error in a flash message
System.out.println("Error while creating issue: "+createValidationResult.getErrorCollection().getErrors());
}
if (createValidationResult.isValid()) {
**IssueResult createResult = issueService.create(ComponentAccessor.getUserManager().getUserByKey("dipesh"), createValidationResult);**
System.out.println("Issue Created. issueId: "+createResult.getIssue().getId());
}