Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to Assign Issues using Java

pavanbachuDexcom October 9, 2018
  • I have set up a JIRA server on a local machine and have created A software project and have uploaded issues using excel.
  • The motive is to modify few fields using Java like: STATUS, getIssueID based on issue title and upload docs and also to modify assignee and Labels.
  • Struck at modifying assignee and Labels.
  • Please find the gist of pom.xml

2 answers

1 vote
Rambabu Patina _Appfire_
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 10, 2018

Hi @pavanbachuDexcom, Please have a look at the similar question at https://community.developer.atlassian.com/t/componentaccessor-not-initialised/1143.

Hope this helps you. Thanks. 

pavanbachuDexcom October 10, 2018

@Rambabu Patina _Appfire_  I  have tried that solution but it's throwing null pointer when setting assignee?

IssueManager mockIssueManager = mock(IssueManager.class);
final MockComponentWorker componentAccessorWorker = new MockComponentWorker();
componentAccessorWorker.addMock(IssueManager.class,mockIssueManager);
ComponentAccessor.initialiseWorker(componentAccessorWorker);
MutableIssue io = ComponentAccessor.getIssueManager().getIssueObject(issueID);
io.setAssignee(" ");

 

 

 

Rambabu Patina _Appfire_
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 10, 2018

@pavanbachuDexcom Here what's the user id you are providing in the method

setAssignee(<Provide valid user id>) 
pavanbachuDexcom October 10, 2018

I am passing a regular string, is there a better way to get the user id?

Rambabu Patina _Appfire_
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 11, 2018

Try this way:

setAssignee(ApplicationUser assignee) // For this method you have to pass the type ApplicationUser

setAssigneeId(String assigneeId) // For this method you can provide user id.

pavanbachuDexcom October 11, 2018

How do we get the Application User instance ?

Rambabu Patina _Appfire_
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 11, 2018

@pavanbachuDexcom

You already have the ComponentAccessor reference, so

If you want to get the current logged in user try

ApplicationUser currentUser  = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

To get other users try:

ApplicationUser currentUser  = ComponentAccessor.getUserManager().getUserByKey(String userKey);

or 

ApplicationUser currentUser  = ComponentAccessor.getUserManager().getUserByName(String userName);

Hope this helps you.

0 votes
pavanbachuDexcom October 9, 2018
Tried Code 
IssueManager issueManager = ComponentAccessor.getIssueManager();
MutableIssue io = issueManager.getIssueObject(issueID);
io.setAssigneeId("XXXX");

 

Got exception 

This is not expected to occur on a production system.
Developers that encounter this message within a unit test
should use n MockitoMocksInContainer rule to initialize mockito and ComponentAccessor.
For more detailed explanation read the documentation
for MockComponentWorker in the jira-tests artifact for more information
about what causes this error and how to address it.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events