IssueService: fix version is null. Why

Heinz Wittig August 3, 2016

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?

 

12 answers

0 votes
adammarkham
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.
October 20, 2016

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)
0 votes
Heinz Wittig August 7, 2016

tank you Steven smile

0 votes
Steven F Behnke
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.
August 5, 2016

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.

0 votes
Heinz Wittig August 5, 2016

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?

 

 

 

0 votes
Heinz Wittig August 5, 2016

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

 

0 votes
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 4, 2016

HI @Heinz Wittig , were you able to solve the issue? can you share your java code in a gist file over github?

0 votes
Heinz Wittig August 4, 2016

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?

 

 

0 votes
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 4, 2016

no need to authenticationContext, Component accessor can be imported easily

0 votes
Heinz Wittig August 4, 2016

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?

0 votes
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 3, 2016

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

https://answers.atlassian.com/questions/277703

0 votes
Heinz Wittig August 3, 2016

Yes correctly I don't have NPE, and some values are in issueResult.getIssue().

I'm sorry: of witch Script Console did you speak?

0 votes
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 3, 2016

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?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events