import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.bc.JiraServiceContextImpl
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.issue.search.*
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.index.IndexException
import com.atlassian.jira.ManagerFactory
import com.atlassian.jira.user.ApplicationUser
import org.apache.log4j.Category
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.util.ImportUtils
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.user.ApplicationUsers
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.ManagerFactory
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.ComponentManager

import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;

WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );

//This function works with a filter shared
String jqlSearch = " filter=XXXXX ";
SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class)
ComponentManager componentManager = ComponentManager.getInstance()
CommentManager commentManager = ComponentAccessor.getCommentManager()
IssueManager issueManager = ComponentAccessor.getIssueManager();
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
UserUtil userUtil = ComponentAccessor.getUserUtil()
def searchProvider = ComponentAccessor.getComponent(SearchProvider.class)
def user2 = userUtil.getUserByKey("user_admin")
Category log = Category.getInstance("com.onresolve.jira.groovy")
log.setLevel(org.apache.log4j.Level.DEBUG)
log.debug "START Service"

SearchService.ParseResult parseResult = searchService.parseQuery(user2.getDirectoryUser(), jqlSearch)

if (parseResult.isValid()) {
def searchResult = searchService.search(user2.getDirectoryUser(), parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
issues = searchResult.issues.collect {issueManager.getIssueObject(it.id)}
log.debug "Size:" + issues.size();



for ( issue in issues ){

log.debug "Issue: " +issue.getKey();
issueobtained = issueManager.getIssueObject(issue.getKey());
ManagerFactory.getIndexManager().reIndex(issueobtained.getGenericValue());
}
log.debug "FINISH Service"

} else {
log.debug("Invalid JQL: " + jqlSearch);
}

Posted by:.

2 replies on “Service to reindex issues of a filter with Groovy in JIRA

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s