/** * Gets the transition for an issue. The issue's state is used as the from state to look up the * available transitions, and to populate the registry. * * @param loginData the user to lazy load the transition if it does not exist in the registry * @param boardConfig The board config * @param issue the issue to transition. * @param toState the state to transition to. This is the actual projects state, and not the * mapped board state * @return */ Transition getTransition( LoginData loginData, ProjectGroupConfig boardConfig, Issue issue, String toState) throws IOException { BoardTransitions boardTransitions = boards.get(boardConfig.getCode()); if (boardTransitions == null) { synchronized (boards) { boardTransitions = boards.get(boardConfig.getCode()); if (boardTransitions == null) { boardTransitions = new BoardTransitions(); boards.put(boardConfig.getCode(), boardTransitions); } } } return boardTransitions.getTransition(loginData, boardConfig, issue, toState); }
private ToStateTransitions load( LoginData loginData, ProjectGroupConfig boardConfig, Issue issue, String toState) throws IOException { final UriBuilder builder = UriBuilder.fromUri(boardConfig.getJiraUrl()) .path("rest") .path("api") .path("2") .path("issue") .path(issue.getKey()) .path("transitions") .queryParam("issueIdOrKey", issue.getKey()); final WebTarget target = loginData.getClient().target(builder); final Response response = target.request(MediaType.APPLICATION_JSON_TYPE).get(); if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { throw new IOException( "Error looking up the transitions for issue " + issue.getKey() + ": " + response.readEntity(String.class)); } Map<String, Transition> states = new HashMap<>(); ModelNode modelNode = ModelNode.fromJSONString(response.readEntity(String.class)); for (ModelNode transitionNode : modelNode.get("transitions").asList()) { Transition transition = new Transition(transitionNode.get("id").asInt(), transitionNode.get("name").asString()); states.put(transition.toState, transition); } ToStateTransitions toStateTransitions = new ToStateTransitions(issue.getState(), states); return toStateTransitions; }