I have developed a post-function that will try to transit all the linked issues in a status to another and copy the last comment.
The problem is that they transition normally but they don't re-index, even while setting in the code the command for that.
@Override public void execute(Map transientVars, Map args, PropertySet propertySet) throws WorkflowException { MutableIssue issue = getIssue(transientVars); String executer = String.valueOf(args.get(EXECUTING_USER)); String linkTypeId = String.valueOf(args.get(LINK_TYPE_ID)); String linkTypeName = IssueLinkServices.getIssueLinkTypeById(linkTypeId).getName(); String transitionId = String.valueOf(args.get(EXECUTABLE_TRANSITION)); String selectedStatusId = String.valueOf(args.get(STATUS_ID)); String statusName = WorkflowServices.getStatusById(selectedStatusId).getName(); List<Issue> linkedIssues = IssueLinkServices.getLinkedIssuesOfLinkType(issue, linkTypeId); for (Issue linkedIssue : linkedIssues) { if (isIssueInAllowedStatus(linkedIssue, selectedStatusId)) { WorkflowServices.transitionIssue(linkedIssue, issue, transitionId, UserServices.getUserByUsername(executer), CommentServices.CommentOption.WITH_LAST_COMMENT); } } linkedIssues.add(issue); IssueServices.reIndex(linkedIssues); } private boolean isIssueInAllowedStatus(Issue issue, String allowedTransitionStatus) { return issue.getStatusObject().getId().equalsIgnoreCase(allowedTransitionStatus); }
public static void transitionIssue(Issue issueToTransit, Issue issueSourceForComment, String transitionId, ApplicationUser applicationUser, CommentOption commentOption) { log.debug("Starting transition of issue '{}', using the transition with ID '{}' and the executor is '" + applicationUser.getName() + "'", issueToTransit.getKey(), transitionId); IssueService issueService = ComponentAccessor.getIssueService(); IssueInputParameters issueInputParameters = issueService.newIssueInputParameters(); Comment lastComment = CommentServices.getLastCommentfromIssue(issueSourceForComment); if (commentOption.equals(CommentOption.WITH_LAST_COMMENT)) { log.debug("During the transition will copy the last comment from the issue {}", issueSourceForComment.getKey()); issueInputParameters = issueInputParameters.setComment(String.valueOf(lastComment.getBody())); } log.debug("Validating transition"); IssueService.TransitionValidationResult transitionValidationResult = issueService.validateTransition(applicationUser, issueToTransit.getId(), Integer.parseInt(transitionId), issueInputParameters); if (!transitionValidationResult.isValid()) { log.error("Transition validation failed. {}", ErrorServices.convertErrorCollectionToString(transitionValidationResult.getErrorCollection())); return; } log.debug("Transitioning issue {}", issueToTransit.getKey()); IssueService.IssueResult result = issueService.transition(applicationUser, transitionValidationResult); if (!result.isValid()) { log.error("Executing the transition failed. {}", ErrorServices.convertErrorCollectionToString(result.getErrorCollection())); return; } log.debug("Validating if last comment was created or create it"); if (isLastCommentNotCreated(issueSourceForComment, issueToTransit) && commentOption.equals(CommentOption.WITH_LAST_COMMENT)) { log.debug("Last comment was not created. Creating it ..."); CommentServices.addCommentToIssue(lastComment.getBody(), issueToTransit, lastComment.getAuthorApplicationUser(), CommentNotification.AVOID_NOTIFICATION); } }
public static void reIndex(MutableIssue issue) { try{ ComponentAccessor.getIssueIndexManager().reIndex(issue); } catch (IndexException ex) { log.error("Error indexing issue " + issue.getKey(), ex); } } public static void reIndex(Collection<Issue> issues) { try{ ComponentAccessor.getIssueIndexManager().reIndexIssueObjects(issues); } catch (IndexException ex) { log.error("Error indexing issues", ex); } }
The linked issues are JIRA Service Desk issues, but I don't think that should a problem.
As I mentioned this is a post-function, executed in another project workflow (which is not JSD). This code is for JIRA 6.4.7 in Amazon Linux.
The major problem is that I don't see anything in atlassian-jira.log; not one single line about Index problems, it just shows the "debug" logs used in the code.
Community moderators have prevented the ability to post new answers.
Just for reference to solve this you would need to create another thread, the only condition is that the variable objects must be final; in my case would be
final IssueService issueService = ComponentAccessor.getIssueService();
final IssueService.TransitionValidationResult transitionValidationResult = ...;
Example:
private static final ScheduledExecutorService worker = Executors.newSingleThreadScheduledExecutor(); public void transition() { ...CODE_TO_GET_TRANSITION_VALIDATION RESULT... Runnable runnable = new Runnable() { @Override public void run() { IssueService.IssueResult result = issueService.transition(applicationUser, transitionValidationResult); log.debug("Transition is valid: " + result.isValid()); if (!result.isValid()) { log.error("Executing the transition failed. {}", ErrorServices.convertErrorCollectionToString(result.getErrorCollection())); return; } } }; worker.schedule(runnable, 2, TimeUnit.SECONDS); ...REST_OF_CODE.... }
Hi Eduardo,
From a quick review of your code it appears that you are collecting a list of issues for reindexing
List<Issue> linkedIssues = IssueLinkServices.getLinkedIssuesOfLinkType(issue, linkTypeId);
IssueServices.reIndex(linkedIssues);
public
static
void
reIndex(MutableIssue issue) {
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yeah, there are two functions in IssueServices.reIndex (which are just another layer to make it easier to recall the methods): # one is for single issue. # one for a collection of issues (which List already implements this). I actually don't know if the second method works, according to their documentation it does (https://docs.atlassian.com/jira/6.4.7/com/atlassian/jira/issue/index/IssueIndexManager.html#reIndexIssueObjects%28java.util.Collection%29)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.