On JIRA Datacenter, I use a listener to auto-transition an issue into another state and re-index that issue afterwards. Unfortunately, re-indexing seems not to be done on all JIRA instances as JIRA issue navigator shows the prior issue’s status. How to properly re-index an issue via the JAVA API?
// execute workflow transitions within a separate thread:
Thread executorThread = new Thread(new Runnable() {
public void run() {
try {
log.debug("wait 1 second, so that running workflow transitions are finished ...");
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
TransitionValidationResult initialIssueTransitionValidationResult = issueService.validateTransition(user, issue.getId(), Integer.parseInt(transition), issueInputParameters);
if (initialIssueTransitionValidationResult.isValid()) {
IssueResult initialIssueTransitionResult = issueService.transition(user, initialIssueTransitionValidationResult);
if (initialIssueTransitionResult.isValid()) {
log.debug("executing non-nested workflow transition "+Integer.parseInt(transition) + " from '"+issue.getStatus().getName()+"' to '"+initialIssueTransitionResult.getIssue().getStatus().getName()+"'");
List<ChangeItemBean> changeItemList = new ArrayList<ChangeItemBean>();
ChangeItemBean changeItemBean = new ChangeItemBean(ChangeItemBean.CUSTOM_FIELD, myFieldName, issue.getStatus().getId().toString(), issue.getStatus().getName(), initialIssueTransitionResult.getIssue().getStatus().getId().toString(),
"issue has been "+(myFieldState ? "signed-off" : "declined")+": auto transition → "+initialIssueTransitionResult.getIssue().getStatus().getName());
if (changeItemBean != null) {
changeItemList.add( changeItemBean );
createChangeGroup(delegator, user,issue, changeItemList);
}
try {
ComponentAccessor.getIssueIndexManager().reIndex(initialIssueTransitionResult.getIssue()); // ANYTHING, WHICH SHOULD BE DONE DIFFERENTLY, HERE ???
} catch (IndexException e) {
e.printStackTrace();
}
} else {
String msg = jiraAuthenticationContext.getI18nHelper().getText("transition.error", issue.getKey(), initialIssueTransitionResult.getErrorCollection().getErrorMessages().toString());
log.debug("----------------------------");
log.debug("CONFIGURATION ERROR: please check permission of user '" + user.getDisplayName() + "(" + user.getName() + ")' as she/he should be allowed to execute the workflow tranisition below!");
log.debug("(1) "+msg);
log.debug("----------------------------");
// addComment(user, issue, "@admin: Please verify my permission to execute workflow transition mentioned below!\n\n"+msg);
}
} else {
String msg = jiraAuthenticationContext.getI18nHelper().getText("transition.error", issue.getKey(), initialIssueTransitionValidationResult.getErrorCollection().getErrorMessages().toString());
log.debug("----------------------------");
log.debug("CONFIGURATION ERROR: please check permission of user '" + user.getDisplayName() + "(" + user.getName() + ")' as she/he should be allowed to execute the workflow tranisition below!");
log.debug("(2) "+msg);
log.debug("----------------------------");
// addComment(user, issue, "@admin: Please verify my permission to execute workflow transition mentioned below!\n\n"+msg);
}
// unset technical-user to be taken care within bockingWorkflowCondition
Utils.setPropertyString(myProperties,"technical-user",null);
}
});
executorThread.start();