Hi I use the IssueService to get a MutableIssue. On the GUI the FixVersion is setted. But when I dubug the value is null. What I'm doing wrong?
IssueService issueService = ComponentAccessor.getIssueService(); final IssueService.IssueResult issueResult = issueService.getIssue(authenticationContext.getUser(), issueKey); Collection<Version> fixVersions =issueResult.getIssue().getFixVersions();
And here the fixVersions Collection is empty.
What I'm doing wrong?
Is there a permission problem?
This doesn't seem like a ScriptRunner issue but you can use the IssueManager to get the issue:
import com.atlassian.jira.component.ComponentAccessor def issueManager = ComponentAccessor.getIssueManager() def issue = issueManager.getIssueObject(issueKey)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I labeled your question so that Adaptavist can find it. You need to label your question with the add-on in question otherwise the proper people cannot find it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The code is:
Controller to take the action:
import ..... @Path("issue") @Produces({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON }) public class PlanningIssueRestResource { private final Logger log = LoggerFactory.getLogger(PlanningIssueRestResource.class); private PlanningIssueService planningIssueService; private JiraAuthenticationContext authenticationContext; private ObjectMapper objectMapper; public PlanningIssueRestResource(PlanningIssueService planningIssueService, JiraAuthenticationContext authenticationContext) { this.authenticationContext = authenticationContext; this.planningIssueService = planningIssueService; } @POST @Path("{issueKey}/createSubTask") public Response createSubTasks(@PathParam("issueKey") String issueKey, String subtaskString) throws JsonParseException, JsonMappingException, IOException, CreateException, IndexException{ objectMapper = new ObjectMapper(); objectMapper.configure(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER, true); List<CpSubtaskPhase> subTaskList = objectMapper.readValue(subtaskString, objectMapper.getTypeFactory() .constructCollectionType(List.class, CpSubtaskPhase.class)); HashMap<String, List<String>> results = planningIssueService.createSubTaskFrom(subTaskList, authenticationContext); return Response.ok().entity(results).build(); } }
And the PlanningIssueService:
import ...... public class PlanningIssueServiceImpl implements PlanningIssueService { @Override public HashMap<String, List<String>> createSubTaskFrom(List<CpSubtaskPhase> subtaskList, JiraAuthenticationContext authenticationContext) throws CreateException, IndexException { IssueService issueService = ComponentAccessor.getIssueService(); HashMap<String, List<String>> results = new HashMap<String, List<String>>(); ArrayList<String> created = new ArrayList<String>(); ArrayList<String> errors = new ArrayList<String>(); results.put("CREATED", created); results.put("ERROR", errors); Issue issue = null; try { issue = getIssueObject(issueService, authenticationContext, subtaskList.get(0).getIssueKey()); } catch (Exception e) { errors.add("ERROR - not found on the System: " + subtaskList.get(0).getIssueKey() + e.getStackTrace().toString()); } for (CpSubtaskPhase subtask : subtaskList) { if (subtask.isChecked()) { try { created.add(createSubTask(issue, issueService, subtask, authenticationContext)); } catch (Exception e) { errors.add(e.getMessage()); } catch (Exception e) { errors.add("ERROR on create issue: " + subtask.getSummary() + e.getStackTrace().toString()); } } } return results; } private String createSubTask(Issue issue, IssueService issueService, CpSubtaskPhase subTask, JiraAuthenticationContext authenticationContext) throws Exception { ApplicationUser applicationUser = authenticationContext.getUser(); UserManager userManager = ComponentAccessor.getUserManager(); VersionManager versionManager = ComponentAccessor.getVersionManager(); SubTaskManager subTaskManager = ComponentAccessor.getSubTaskManager(); IssueIndexManager issueIndexManager = ComponentAccessor.getIssueIndexManager(); ProjectComponentManager projComponentManager = ComponentAccessor.getProjectComponentManager(); LabelManager labelManager = ComponentAccessor.getComponent(LabelManager.class); //Here some actions to set the values on the subtask MutableIssue assignedSubtaskIssue = assignedTask.getIssue(); subTaskManager.createSubTaskIssueLink(issue, assignedSubtaskIssue, applicationUser.getDirectoryUser()); ImportUtils.setIndexIssues(true); issueIndexManager.reIndex(assignedSubtaskIssue); ImportUtils.setIndexIssues(false); IssueInputParameters issueInputValues = issueService.newIssueInputParameters(); issueInputValues.setComponentIds(component.getId()); UpdateValidationResult validateUpdate = issueService.validateUpdate(applicationUser, assignedSubtaskIssue.getId(), issueInputValues); if (!validateUpdate.isValid()) { throw new Exception(validateUpdate); } IssueResult update = issueService.update(applicationUser, validateUpdate); if (!update.isValid()) { throw new Exception(update); } MutableIssue componentUpdateSubTask = update.getIssue(); return "Created issue: " + componentUpdateSubTask.getSummary(); } public Issue getIssueObject(IssueService issueService, JiraAuthenticationContext authenticationContext, String issueKey) throws Exception { final IssueService.IssueResult issueResult = issueService.getIssue(authenticationContext.getUser(), issueKey); //Already here I have an empty fixVersion collection (by debugging) if (!issueResult.isValid()) { throw new Exception(issueResult); } return issueResult.getIssue(); } }
Any suggestions?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No I'm sorry I was not able to solve this issue. Gist is out of the policy right of my conpany. I can't access it (unfortunatelly). I can past the code here
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI @Heinz Wittig , were you able to solve the issue? can you share your java code in a gist file over github?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok I runn it:
import com.atlassian.jira.component.ComponentAccessor def issueService = ComponentAccessor.getIssueService(); def user = ComponentAccessor.jiraAuthenticationContext.user; def issueResult = issueService.getIssue(user, "CON-2660"); def issue = issueResult.getIssue(); def fixVersions = issue.getFixVersions(); fixVersions.each {fixVersion -> log.info("FixVersion: ${fixVersion.name}")}
this give me a list of the Fixversion. OK. But now I have to search the error in my java code.
What say this to me? That I go to take the Issue in a wrong way?
It's possible to install the Script runner in development mode?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
no need to authenticationContext, Component accessor can be imported easily
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok I found it and installed it. I try now to debug a little bit. But How does this help me to find the error on Java code? And how can I Inject (in the script) ComponentAccessor and authenticationContext?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
it's part of admin section of the script runner plugin, i guess you have script runner installed, using the console it becomes easier to troubleshoot issues in groovy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes correctly I don't have NPE, and some values are in issueResult.getIssue().
I'm sorry: of witch Script Console did you speak?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If it was a permission problem then getIssue() would have been null resulting in null pointer exception, from the docs -
" the issue will be null if the issue does not exist or the user does not have permission. "
But you don't get NPE instead you are able to call getFixVersions() method on the mutableIssue, did you try executing this script in the Script Console, and printing the results?
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.