Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Code Block
languagejava
linenumberstrue
import com.atlassian.jira.bc.issue.search.SearchService;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.config.util.JiraHome;
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.search.SearchException;
import com.atlassian.jira.issue.search.SearchResults;
import com.atlassian.jira.security.JiraAuthenticationContext;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.web.bean.PagerFilter;
import com.atlassian.query.Query;

     
ApplicationUser loginUser =  ComponentAccessor.getComponent(JiraAuthenticationContext.class).getLoggedInUser();
SearchService searchService = ComponentAccessor.getComponentOfType(SearchService.class);

IssueManager issueManager = ComponentAccessor.getIssueManager();
SearchService.ParseResult parseResult = searchService.parseQuery(loginUser, " jql ");

try {
    SearchResults<Issue> searchResults = searchService.search(loginUser, parseResult.getQuery(), PagerFilter.getUnlimitedFilter());
    List<Issue> issueList = searchResults.getResults();

    for (Issue issue : issueList) {
        issueManager.archiveIssue(loginUser,issue, EventDispatchOption.DOISSUE_NOT_DISPATCHARCHIVED,false);
    }
    for (Issue issue : issueList) {
        issueManager.restoreIssue(loginUser,issue, EventDispatchOption.DOISSUE_NOT_DISPATCHRESTORED,false);
    }
} catch (Exception e) {
    e.printStackTrace();
}