1. Atlassian
  2. Project: Atlassian
  3. jiraconnect-android

Commits

Robert Massaioli  committed e96f56d Merge

Merged andorid-22 with master branch.

This solves:

- ANDROID-18
- ANDROID-22

  • Participants
  • Parent commits c3f6533, ed58401
  • Branches default

Comments (0)

Files changed (5)

File jiraconnect-android-main/src/com/atlassian/jconnect/droid/acra/JiraReportSender.java

View file
         Issue issue = null;
         final AndroidHttpClient client = AndroidHttpClient.newInstance("JIRA Connect Android Client");
         try {
-            HttpPost post = new HttpPost(RestURLGenerator.getIssueCreateURI(issueParams));
+            final HttpPost post = RestURLGenerator.getIssueCreateURI(issueParams);
             post.setEntity(multipartEntity);
             final HttpResponse resp = client.execute(post);
             final StatusLine status = resp.getStatusLine();

File jiraconnect-android-main/src/com/atlassian/jconnect/droid/jira/Issue.java

View file
 
 import android.os.Parcel;
 import android.os.Parcelable;
+import android.util.Log;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Ordering;
     private final boolean hasUpdates;
 
     public static final class Builder {
+        private static final String TAG = Builder.class.getName();
+
         private final String key;
         private String status;
         private String title;
         }
 
         public Issue build() {
+            if (dateUpdated == null) {
+                Log.w(TAG, "You tried to build an issue but provided no 'dateUpdated'. Defaulting the updated date to right now.");
+                dateUpdated = new Date();
+            }
             return new Issue(this);
         }
 

File jiraconnect-android-main/src/com/atlassian/jconnect/droid/net/RestURLGenerator.java

View file
 package com.atlassian.jconnect.droid.net;
 
-import static com.atlassian.jconnect.droid.net.Utf8UrlEncoder.urlEncode;
-import static java.lang.String.format;
+import java.io.UnsupportedEncodingException;
 
-import java.io.UnsupportedEncodingException;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpParams;
 
 import com.atlassian.jconnect.droid.task.CreateIssueParams;
 
 public class RestURLGenerator {
-    public static String getIssueCreateURI(CreateIssueParams params) throws UnsupportedEncodingException {
-        final String base = format("%s/rest/jconnect/latest/issue/create?project=%s", params.url, urlEncode(params.project));
-        return params.apiKey != null ? base + "&apikey=" + urlEncode(params.apiKey) : base;
+    private final RequestType reqestType;
+    private final String baseUrl;
+    private final String restUrl;
+    private final HttpParams params;
+
+    public static enum RequestType {
+        GET,
+        POST;
     }
 
+    RestURLGenerator(RequestType reqestType, String baseUrl, String restUrl, HttpParams params) {
+        super();
+        this.reqestType = reqestType;
+        this.baseUrl = baseUrl;
+        this.restUrl = restUrl;
+        this.params = params;
+    }
+
+    public static class Builder {
+        private final RequestType requestType;
+        private final String baseUrl;
+        private final String restUrl;
+        private final HttpParams params;
+
+        public Builder(RequestType requestType, String baseUrl, String restUrl) {
+            super();
+            this.requestType = requestType;
+            this.baseUrl = baseUrl;
+            this.restUrl = restUrl;
+            this.params = new BasicHttpParams();
+        }
+
+        public Builder addBooleanParameter(String name, boolean value) {
+            params.setBooleanParameter(name, value);
+            return this;
+        }
+
+        public Builder addDoubleParameter(String name, double value) {
+            params.setDoubleParameter(name, value);
+            return this;
+        }
+
+        public Builder addIntParameter(String name, int value) {
+            params.setIntParameter(name, value);
+            return this;
+        }
+
+        public Builder addLongParameter(String name, long value) {
+            params.setLongParameter(name, value);
+            return this;
+        }
+
+        public Builder addParameter(String name, Object value) {
+            params.setParameter(name, value);
+            return this;
+        }
+
+        public Builder addStringParameterIfNotBlank(String name, String value) {
+            if (value != null && !value.trim().equals("")) {
+                params.setParameter(name, value);
+            }
+            return this;
+        }
+
+        public RestURLGenerator build() {
+            return new RestURLGenerator(requestType, baseUrl, restUrl, params);
+        }
+    }
+
+    public HttpGet asGet() {
+        final HttpGet request = new HttpGet(new StringBuilder().append(baseUrl).append(restUrl).toString());
+        request.setParams(params);
+        return request;
+    }
+
+    public HttpPost asPost() {
+        final HttpPost request = new HttpPost(new StringBuilder().append(baseUrl).append(restUrl).toString());
+        request.setParams(params);
+        return request;
+    }
+
+    public static HttpPost getIssueCreateURI(CreateIssueParams params) throws UnsupportedEncodingException {
+        return new RestURLGenerator.Builder(RequestType.POST, params.url, "/rest/jconnect/latest/issue/create").addParameter("project", params.project)
+                .addStringParameterIfNotBlank("apikey", params.apiKey)
+                .build()
+                .asPost();
+    }
 }

File jiraconnect-android-main/src/com/atlassian/jconnect/droid/persistence/IssuePersister.java

View file
 import com.atlassian.jconnect.droid.Api;
 import com.atlassian.jconnect.droid.jira.Comment;
 import com.atlassian.jconnect.droid.jira.Issue;
+import com.atlassian.jconnect.droid.jira.Issue.Builder;
 import com.atlassian.jconnect.droid.jira.IssueParser;
 import com.atlassian.jconnect.droid.jira.IssuesWithComments;
+import com.google.common.base.Function;
+import com.google.common.collect.Lists;
 
 /**
  * Responsible for local storage of all data related to issues. This class uses
 
         if (db != null) db.close();
 
-        List<Issue> solidIssues = new ArrayList<Issue>();
-        for (Issue.Builder tempIssue : issues) {
-            solidIssues.add(tempIssue.build());
-        }
-        return new IssuesWithComments(solidIssues, System.currentTimeMillis());
+        return new IssuesWithComments(Lists.transform(issues, new Function<Issue.Builder, Issue>() {
+            @Override
+            public Issue apply(Builder issueBuilder) {
+                return issueBuilder.build();
+            }
+        }), System.currentTimeMillis());
     }
 
     private static final String OLD_ISSUES_CACHE_FILE = "issueswithcomments.json";

File jiraconnect-android-main/src/com/atlassian/jconnect/droid/task/CreateFeedbackTask.java

View file
 import org.apache.http.entity.mime.MultipartEntity;
 import org.apache.http.util.EntityUtils;
 import org.json.JSONException;
+import org.json.JSONObject;
 
 import android.net.http.AndroidHttpClient;
 import android.os.AsyncTask;
             throw new IllegalArgumentException("Should have exactly 1 params object");
         }
 
-        CreateIssueParams params = paramsArray[0];
-        MultipartEntity entity = params.toMultipartEntity();
+        final CreateIssueParams params = paramsArray[0];
+        final MultipartEntity entity = params.toMultipartEntity();
         if (entity == null) return null;
 
-        String issueKey = null;
+        Issue issue = null;
         final AndroidHttpClient client = AndroidHttpClient.newInstance("JIRA Connect Android Client");
         try {
-            HttpPost post = new HttpPost(RestURLGenerator.getIssueCreateURI(params));
+            final HttpPost post = RestURLGenerator.getIssueCreateURI(params);
             post.setEntity(entity);
             final HttpResponse resp = client.execute(post);
             final StatusLine status = resp.getStatusLine();
+            final String responseAsString = EntityUtils.toString(resp.getEntity());
             if (status.getStatusCode() == 200) {
-                issueKey = IssueParser.parseIssueKey(resp.getEntity());
+                issue = (new IssueParser(LOG_TAG)).parse(new JSONObject(responseAsString));
             } else {
-                Log.e(LOG_TAG, format("Received %s: %s: %s", status.getStatusCode(), status.getReasonPhrase(), EntityUtils.toString(resp.getEntity())));
+                Log.e(LOG_TAG, format("Queried %s and Received %s: %s: %s", post.getURI(), status.getStatusCode(), status.getReasonPhrase(), responseAsString));
             }
         } catch (IOException e) {
             Log.e(LOG_TAG, "Failed to create JIRA issue", e);
             client.close();
             cleanUpAttachments(params);
         }
-        return new Issue.Builder(issueKey).title(params.summary).build();
+
+        return issue;
     }
 
     /**
 
     @Override
     protected void onPostExecute(Issue issue) {
-        RemoteFeedbackService owner = contextRef.get();
+        final RemoteFeedbackService owner = contextRef.get();
         if (owner != null) {
             if (issue != null) {
                 owner.onFeedbackCreated(issue);