@Override public ActionPlan create(NewActionPlan newActionPlan) { HttpRequest request = requestFactory.post(NewActionPlan.BASE_URL, newActionPlan.urlParams()); if (!request.ok()) { throw new IllegalStateException( "Fail to create action plan. Bad HTTP response status: " + request.code()); } return createActionPlanResult(request); }
private HttpRequest executeSimpleAction(String actionPlanKey, String action) { HttpRequest request = requestFactory.post( "/api/action_plans/" + action, EncodingUtils.toMap("key", actionPlanKey)); if (!request.ok()) { throw new IllegalStateException( "Fail to " + action + " action plan. Bad HTTP response status: " + request.code()); } return request; }
@Override public List<ActionPlan> find(String projectKey) { HttpRequest request = requestFactory.get(ActionPlanQuery.BASE_URL, EncodingUtils.toMap("project", projectKey)); if (!request.ok()) { throw new IllegalStateException( "Fail to search for action plans. Bad HTTP response status: " + request.code()); } List<ActionPlan> result = new ArrayList<ActionPlan>(); String json = request.body("UTF-8"); Map jsonRoot = (Map) JSONValue.parse(json); List<Map> jsonActionPlans = (List) jsonRoot.get("actionPlans"); if (jsonActionPlans != null) { for (Map jsonActionPlan : jsonActionPlans) { result.add(new ActionPlan(jsonActionPlan)); } } return result; }