Merge branch 'mikhail.golubev/configurable-issues-states'
[idea/community.git] / plugins / tasks / tasks-core / jira / src / com / intellij / tasks / jira / rest / api20alpha1 / JiraRestApi20Alpha1.java
index 77c42205f3f968f4e0b3706882cc9c8de04db545..bc70d239ce733b6c8daa5de19678336e89ccbb10 100644 (file)
@@ -2,7 +2,10 @@ package com.intellij.tasks.jira.rest.api20alpha1;
 
 import com.google.gson.reflect.TypeToken;
 import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.tasks.*;
+import com.intellij.tasks.CustomTaskState;
+import com.intellij.tasks.LocalTask;
+import com.intellij.tasks.Task;
+import com.intellij.tasks.TaskBundle;
 import com.intellij.tasks.jira.JiraRepository;
 import com.intellij.tasks.jira.rest.JiraRestApi;
 import com.intellij.tasks.jira.rest.JiraRestTask;
@@ -25,8 +28,7 @@ import java.util.Set;
  */
 public class JiraRestApi20Alpha1 extends JiraRestApi {
   private static final Logger LOG = Logger.getInstance(JiraRestApi20Alpha1.class);
-  private static final Type ISSUES_WRAPPER_TYPE = new TypeToken<JiraResponseWrapper.Issues<JiraIssueApi20Alpha1>>() { /* empty */
-  }.getType();
+  private static final Type ISSUES_WRAPPER_TYPE = new TypeToken<JiraResponseWrapper.Issues<JiraIssueApi20Alpha1>>() {/* empty */}.getType();
 
   public JiraRestApi20Alpha1(JiraRepository repository) {
     super(repository);
@@ -35,10 +37,12 @@ public class JiraRestApi20Alpha1 extends JiraRestApi {
   @NotNull
   @Override
   public Set<CustomTaskState> getAvailableTaskStates(@NotNull Task task) throws Exception {
+    // REST API of JIRA 4.x for retrieving possible transitions is very limited: we can't fetch possible resolutions and
+    // names of transition destinations. So we have no other options than to hardcode them.
     final HashSet<CustomTaskState> result = new HashSet<CustomTaskState>();
-    result.add(CustomTaskState.fromPredefined(TaskState.IN_PROGRESS));
-    result.add(CustomTaskState.fromPredefined(TaskState.RESOLVED));
-    result.add(CustomTaskState.fromPredefined(TaskState.REOPENED));
+    result.add(new CustomTaskState("4", "In Progress"));
+    result.add(new CustomTaskState("5", "Resolved (Fixed)"));
+    result.add(new CustomTaskState("3", "Reopened"));
     return result;
   }
 
@@ -70,25 +74,23 @@ public class JiraRestApi20Alpha1 extends JiraRestApi {
   @Nullable
   @Override
   protected String getRequestForStateTransition(@NotNull CustomTaskState state) {
-    // REST API of JIRA 4.x for retrieving possible transitions is very limited: we can't fetch possible resolutions and
-    // names of transition destinations. So we have no other options than to hardcode them.
-    final TaskState taskState = state.asPredefined();
-    if (taskState != null) {
-      switch (taskState) {
-        case IN_PROGRESS:
-          return  "{\"transition\": \"4\"}";
-        case RESOLVED:
-          // 5 for "Resolved", 2 for "Closed"
-          return  "{\"transition\": \"5\", \"resolution\": \"Fixed\"}";
-        case REOPENED:
-          return  "{\"transition\": \"3\"}";
-        default:
-          return null;
+    try {
+      switch (Integer.parseInt(state.getId())) {
+        case 4: // In Progress
+          return "{\"transition\": \"4\"}";
+        case 5: // Resolved (2 for "Closed")
+          return "{\"transition\": \"5\", \"resolution\": \"Fixed\"}";
+        case 3: // Reopened
+          return "{\"transition\": \"3\"}";
       }
     }
+    catch (NumberFormatException ignored) {
+    }
+    LOG.error("Unknown ID of predefined issue state: " + state.getId());
     return null;
   }
 
+
   @Override
   public void updateTimeSpend(@NotNull LocalTask task, @NotNull String timeSpent, String comment) throws Exception {
     throw new Exception(TaskBundle.message("jira.failure.no.time.spent"));