I am trying to create a JIRA plugin that does the following:
List
object) of the voters on that issue. My problem is that the javadoc has little to no information. Following a tutorial, I currently have:
public class VotersCount extends AbstractJiraContextProvider {
@Override
public Map<String, Integer> getContextMap(User user, JiraHelper jiraHelper) {
Map<String, Integer> contextMap = new HashMap<>();
Issue currentIssue = (Issue) jiraHelper.getContextParams().get("issue");
// Issue[] linkedIssues = currentIssue.getLinkedIssuesBy(...); //Step 1 mock code
// Voter[] voters = linkedissues[3].getVoters(); //Step 2 mock code
int count = voters.length; //Pretend there is some calculation here
contextMap.put("votersCount", count);
return contextMap;
}
}
(and I use votersCount
in the .vm file.)
However, I see no explanation in the javadocs for AbstractJiraContextProvider
and getContextMap
so I'm not even sure if it's the right approach.
In my own research I found the class ViewVoters
which has the method Collection<UserBean> getVoters()
, which is something I can work with, but I don't know how to obtain or construct such an object in a way which will interact with a given issue.
I am looking for a working code to replace my 2 lines of mock code.
1) Use one of the methods from IssueLinkService. Maybe getIssueLinks
2) issueVoterAccessor.getVoterUserkeys
Instances of IssueLinkService and IssueVoterAccessor should be injected as parameters to constructor of your VotersCount.
I solved it by using the following:
To get issues linked to Issue issue
by specified link types:
LinkCollection linkCollection = ComponentAccessor.getIssueLinkManager().getLinkCollectionOverrideSecurity(issue); Set<IssueLinkType> linkTypes = linkCollection.getLinkTypes(); // Perform operations on the set to get the issues you want. for (IssueLinkType linkType : linkTypes) { List<Issue> l1 = linkCollection.getOutwardIssues(linkType.getName()); List<Issue> l2 = linkCollection.getInwardIssues(linkType.getName()); }
To get all the voters on Issue issue
:
ComponentAccessor.getVoteManager().getVoterUserkeys(issue);
I was later shown that one can extend CalculatedCFType
and override getValueFromIssue
which hands you the current issue as a parameter instead of the using
Issue currentIssue = (Issue) jiraHelper.getContextParams().get("issue");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.