Hi!
I'm sorry in advance if I sound like don't knw what I'm talking about. That's because I don't.
We've got 3 listener scripts set up, that copy issues from Service Desk to Core and sync all the info between the issues, including status, field updates and comments. At some point not long ago the script that synchronizes statuses stopped working.
We first thought that it cold be due to the fact that we've added some new events. We've updated the event list for the listener to include the new events. Apon investigating further we've discovered that there are two errors in the code:
[Static type checking] - Cannot find matching method Transition#<init>(int,java.lang.Strng).
Here's the code
def transitionIssue(Issue issue, String value) {
if (value.equals(issue.getStatusId())) {
return;
}
WorkflowManager workflowManager = ComponentAccessor.getWorkflowManager();
IssueService issueService = ComponentAccessor.getIssueService()
// JiraAuthenticationContext jiraAuthenticationContext = ComponentAccessor.getJiraAuthenticationContext();
// ApplicationUser currentUser = jiraAuthenticationContext.getLoggedInUser();
try {
// jiraAuthenticationContext.setLoggedInUser(user);
String fromStatusId = issue.getStatus().getId();
//log.debug("Transitioning issue from " + issue.getStatus().getName() + "-" + fromStatusId + " to " + value);
JiraWorkflow workflow = workflowManager.getWorkflow(issue);
Map<String, Set<Transition>> transitionMap = new HashMap<>();
for (ActionDescriptor action : workflow.getAllActions()){
String statusToId = workflowManager.getNextStatusIdForAction(issue, action.getId());
//log.error("Action with id " +action.getId() + " leads to status " + statusToId);
if (!fromStatusId.equals(statusToId)) {
Transition transition = new Transition(action.getId(), statusToId);
for (StepDescriptor step: workflow.getStepsForTransition(action)){
transitionMap.compute((String) step.getMetaAttributes().get("jira.status.id"), new BiFunction<String, Set<Transition>, Set<Transition>>() {
@Override
public Set<Transition> apply(String k, Set<Transition> v) {
Set<Transition> transitionSet = v == null ? new HashSet<>() : v;
transitionSet.add(transition);
return transitionSet;
}
})
};
}
else {
log.error("The transition leads to itself");
}
};
and
[Static type checking] - Cannot call Script30#findPath(java.util.Map <java.lang.String, java.util.Set>, java.util.Set < java.lang.String>, java.lang.String, java.lang.String) with arguments [java.util.Map<String, Set>, java.util.Set ,T extends java.lang.Object>, java.lan.String, java.land.String]
Code:
def Optional<List<Integer>> findPath(Map<String, Set<Transition>> transitionMap,
String statusFromId, String statusToId) {
return findPath(transitionMap, Collections.emptySet(), statusFromId, statusToId);
}
def Optional<List<Integer>> findPath(Map<String, Set<Transition>> transitionMap, Set<String> visited,
String statusFromId, String statusToId) {
List<Integer> shortestPath = null;
Set<Transition> transitions = transitionMap.get(statusFromId);
if (transitions == null) {
return Optional.empty();
} else {
Set<String> visitedPrime = new HashSet<>(visited);
visitedPrime.add(statusFromId);
for (Transition transition : transitions) {
if (transition.statusToId.equals(statusToId)) {
return Optional.of(Collections.singletonList(transition.actionId));
} else if (!visited.contains(transition.statusToId)) {
Optional<List<Integer>> path = findPath(transitionMap, visitedPrime, transition.statusToId, statusToId);
if (path.isPresent() && (shortestPath == null || shortestPath.size() - 1 > path.get().size())) {
shortestPath = new ArrayList<>();
shortestPath.add(transition.actionId);
shortestPath.addAll(path.get());
}
}
}
}
return Optional.ofNullable(shortestPath);
}
Thank you in advance for any help!