Java API
From 1.7.7.1 for JIRA up to 9.16
From 1.7.9 for JIRA 9.17+
Please find an example ScriptRunner code below which showcase usage of 3 managers LinkTypeManager, PriorityManager and ResolutionManager
with the common following methods:
public Collection<Project> getProjects(Integer issueTypeSchemeId);
public Boolean addSchemeToProject(Integer issueTypeSchemeId, Long projectId);
public void removeSchemesFromProject(Long projectId);
public IdName getScheme(Long projectId);
This is important that getScheme
method returns an empty IdName object without id and name set if there is no Issue Type Scheme attached to a project.
Aslo a dedicated methods for each manager:
LinkTypeManager
public Collection<IdName> getLinks(Long projectId, Long issueTypeId);
PriorityManager
public Collection<IdName> getPriorities(Long projectId, Long issueTypeId);
ResolutionManager
public Collection<IdName> getResolutions(Long projectId, Long issueTypeId);
where IdName
is defined as follows:
public class IdName {
public String id;
public String name;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Java Example
import java.lang.StringBuilder
import com.develocenter.jira.extschemes.manager.export.ResolutionManager
import com.develocenter.jira.extschemes.manager.export.PriorityManager
import com.develocenter.jira.extschemes.manager.export.LinkTypeManager
import com.develocenter.jira.extschemes.manager.export.IdName
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.jira.project.Project
@WithPlugin("com.develocenter.jira.links-scheme")
@PluginModule LinkTypeManager linkTypeManager
@PluginModule PriorityManager priorityManager
@PluginModule ResolutionManager resolutionManager
/* Find on /secure/admin/ViewIssueTypeLinkSchemes.jspa - hoover on(go to) name link and check schemeId in a link*/
Integer issueTypeLinkTypeSchemeId = new Integer(3);
/* Find on /secure/admin/ViewIssueTypeExtendedPrioritySchemes.jspa - hoover on(go to) name link and check schemeId in a link*/
Integer issueTypePrioritySchemeId = new Integer(3);
/* Find on /secure/admin/ViewIssueTypeResolutionSchemes.jspa - hoover on(go to) name link and check schemeId in a link*/
Integer issueTypeResolutionSchemeId = new Integer(3);
Long projectId = new Long(10200);
Long issueTypeId = new Long(10002);
StringBuilder stringBuilder = new StringBuilder();
/* Links Exampe*/
Collection<Project> projects = linkTypeManager.getProjects(issueTypeLinkTypeSchemeId);
stringBuilder.append("<b>Links Example</b><br><br>List of Projects assigned to schme:<br>"+projects.toString()+"<br><br>");
linkTypeManager.addSchemeToProject(issueTypeLinkTypeSchemeId,projectId);
projects = linkTypeManager.getProjects(issueTypeLinkTypeSchemeId);
stringBuilder.append("Assigning new project to a scheme and showing updated list:<br>"+projects.toString()+"<br><br>");
Collection<IdName> allowedLinkTypes = linkTypeManager.getLinks(projectId, issueTypeId);
stringBuilder.append("Link Types available for already assigned project and choosen issue type (linkType.getId() is null):<br>");
allowedLinkTypes.stream().forEach(linkType -> {
stringBuilder.append(linkType.getName()+" ("+linkType.getId()+")<br>")}
);
stringBuilder.append("<br>");
IdName itLinkTypeScheme = linkTypeManager.getScheme(projectId);
stringBuilder.append("Getting a scheme from project:<br>"+itLinkTypeScheme.getName()+" ("+itLinkTypeScheme.getId()+")"+"<br><br>");
linkTypeManager.removeSchemesFromProject(projectId);
projects = linkTypeManager.getProjects(issueTypeLinkTypeSchemeId);
stringBuilder.append("Removing newly assigned scheme from a project and showing updated list:<br>"+projects.toString()+"<br><br>");
/* Priority Example*/
projects = priorityManager.getProjects(issueTypePrioritySchemeId);
stringBuilder.append("<b>Priority Example</b><br><br>List of Projects assigned to schme:<br>"+projects.toString()+"<br><br>");
priorityManager.addSchemeToProject(issueTypePrioritySchemeId,projectId);
projects = priorityManager.getProjects(issueTypePrioritySchemeId);
stringBuilder.append("Assigning new project to a scheme and showing updated list:<br>"+projects.toString()+"<br><br>");
Collection<IdName> allowedPrioritires = priorityManager.getPriorities(projectId, issueTypeId);
stringBuilder.append("Priorities available for already assigned project and choosen issue type:<br>");
allowedPrioritires.stream().forEach(priority -> {
stringBuilder.append(priority.getName()+" ("+priority.getId()+")<br>")}
);
stringBuilder.append("<br>");
IdName itPriorityScheme = priorityManager.getScheme(projectId);
stringBuilder.append("Getting a scheme from project:<br>"+itPriorityScheme.getName()+" ("+itPriorityScheme.getId()+")"+"<br><br>");
priorityManager.removeSchemesFromProject(projectId);
projects = priorityManager.getProjects(issueTypePrioritySchemeId);
stringBuilder.append("Removing newly assigned scheme from a project and showing updated list:<br>"+projects.toString()+"<br><br>");
/* Resolution Example*/
projects = resolutionManager.getProjects(issueTypeResolutionSchemeId);
stringBuilder.append("<b>Resolution Example</b><br>List of Projects assigned to schme:<br>"+projects.toString()+"<br><br>");
resolutionManager.addSchemeToProject(issueTypeResolutionSchemeId,projectId);
projects = resolutionManager.getProjects(issueTypeResolutionSchemeId);
stringBuilder.append("Assigning new project to a scheme and showing updated list:<br>"+projects.toString()+"<br><br>");
Collection<IdName> allowedResolutions = resolutionManager.getResolutions(projectId, issueTypeId);
stringBuilder.append("Resolution available for already assigned project and choosen issue type:<br>");
allowedResolutions.stream().forEach(resolution -> {
stringBuilder.append(resolution.getName()+" ("+resolution.getId()+")<br>")}
);
stringBuilder.append("<br>");
IdName itResolutionScheme = resolutionManager.getScheme(projectId);
stringBuilder.append("Getting a scheme from project:<br>"+itResolutionScheme.getName()+" ("+itResolutionScheme.getId()+")"+"<br><br>");
resolutionManager.removeSchemesFromProject(projectId);
projects = resolutionManager.getProjects(issueTypeResolutionSchemeId);
stringBuilder.append("Removing newly assigned scheme from a project and showing updated list:<br>"+projects.toString()+"<br><br>");
Example Result
Links Example
List of Projects assigned to schme:
[Project: DOIT, Project: TESTS]
Assigning new project to a scheme and showing updated list:
[Project: DOIT, Project: TESTS, Project: SDESK]
Link Types available for already assigned project and choosen issue type (linkType.getId() is null):
clones (null)
is blocked by (null)
is cloned by (null)
Getting a scheme from project:
Defect Issue Type Link Scheme (3)
Removing newly assigned scheme from a project and showing updated list:
[Project: DOIT, Project: TESTS]
Priority Example
List of Projects assigned to schme:
[Project: SCRUM, Project: TESTS]
Assigning new project to a scheme and showing updated list:
[Project: SCRUM, Project: TESTS, Project: SDESK]
Priorities available for already assigned project and choosen issue type:
Blocker (10001)
Minor (10002)
Getting a scheme from project:
Solid Issue Type Priority Scheme (3)
Removing newly assigned scheme from a project and showing updated list:
[Project: SCRUM, Project: TESTS]
Resolution Example
List of Projects assigned to schme:
[Project: KAN]
Assigning new project to a scheme and showing updated list:
[Project: KAN, Project: SDESK]
Resolution available for already assigned project and choosen issue type:
Done (10004)
Won't Fix (10100)
Rejected (10102)
Getting a scheme from project:
Change Issue Type Resolution Scheme (3)
Removing newly assigned scheme from a project and showing updated list:
[Project: KAN]