Revision: 3393
Author: silva.josemanuel1
Date: Wed Mar 24 07:30:37 2010
Log: Made code more general and reusable (mainly for testing)
http://code.google.com/p/power-architect/source/detail?r=3393

Modified:
 /trunk/src/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java
 /trunk/src/ca/sqlpower/architect/enterprise/JSONResponseHandler.java
 /trunk/src/ca/sqlpower/architect/swingui/enterprise/RevisionsTable.java

=======================================
--- /trunk/src/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java Mon Mar 22 09:39:58 2010 +++ /trunk/src/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java Wed Mar 24 07:30:37 2010
@@ -59,6 +59,7 @@
 import ca.sqlpower.diff.DiffInfo;
 import ca.sqlpower.diff.SimpleDiffChunkJSONConverter;
 import ca.sqlpower.enterprise.TransactionInformation;
+import ca.sqlpower.enterprise.client.ClientSideSession;
 import ca.sqlpower.enterprise.client.SPServerInfo;
 import ca.sqlpower.sql.DataSourceCollection;
 import ca.sqlpower.sql.DatabaseListChangeEvent;
@@ -76,7 +77,7 @@
 import ca.sqlpower.util.UserPrompter.UserPromptOptions;
 import ca.sqlpower.util.UserPrompter.UserPromptResponse;

-public class ArchitectClientSideSession extends ArchitectSessionImpl {
+public class ArchitectClientSideSession extends ArchitectSessionImpl implements ClientSideSession {

private static Logger logger = Logger.getLogger(ArchitectClientSideSession.class);
        private static CookieStore cookieStore = new BasicCookieStore();
@@ -323,21 +324,11 @@
        }
     }

-       /**
-     * Requests the server for the transaction list.
-     *
- * @return A list of TransactionInformation containing all the information about revisions of this project.
-     * @throws IOException
-     * @throws URISyntaxException
-     * @throws JSONException
-     * @throws ParseException
-     */
public List<TransactionInformation> getTransactionList(long fromVersion, long toVersion)
     throws IOException, URISyntaxException, JSONException, ParseException {

         SPServerInfo serviceInfo = projectLocation.getServiceInfo();
         HttpClient httpClient = createHttpClient(serviceInfo);
- List<TransactionInformation> transactions = new ArrayList<TransactionInformation>();

         try {

@@ -346,22 +337,8 @@
"/project/" + projectLocation.getUUID() + "/revision_list",
                     "versions=" + fromVersion + ":" + toVersion,
                     new JSONResponseHandler());
-            JSONArray jsonArray = new JSONArray(message.getBody());
-
-            for (int i = 0; i < jsonArray.length(); i++) {
-
-                JSONObject json = jsonArray.getJSONObject(i);
- TransactionInformation transaction = new TransactionInformation(
-                        json.getLong("number"),
- TransactionInformation.DATE_FORMAT.parse(json.getString("time")),
-                        json.getString("author"),
-                        json.getString("description"),
-                        json.getString("simpleDescription"));
-                transactions.add(transaction);
-
-            }
-
-            return transactions;
+
+            return decodeJSONRevisionList(message.getBody());

         } finally {
             httpClient.getConnectionManager().shutdown();
@@ -485,6 +462,27 @@
         }

        }
+
+ public static List<TransactionInformation> decodeJSONRevisionList(String json)
+       throws JSONException, ParseException {
+        JSONArray jsonArray = new JSONArray(json);
+ List<TransactionInformation> transactions = new ArrayList<TransactionInformation>();
+
+        for (int i = 0; i < jsonArray.length(); i++) {
+
+            JSONObject jsonItem = jsonArray.getJSONObject(i);
+ TransactionInformation transaction = new TransactionInformation(
+                    jsonItem.getLong("number"),
+ TransactionInformation.DATE_FORMAT.parse(jsonItem.getString("time")),
+                    jsonItem.getString("author"),
+                    jsonItem.getString("description"),
+                    jsonItem.getString("simpleDescription"));
+            transactions.add(transaction);
+
+        }
+
+        return transactions;
+       }

public static void deleteServerWorkspace(ProjectLocation projectLocation) throws URISyntaxException, ClientProtocolException, IOException {
        SPServerInfo serviceInfo = projectLocation.getServiceInfo();
=======================================
--- /trunk/src/ca/sqlpower/architect/enterprise/JSONResponseHandler.java Fri Mar 12 13:32:07 2010 +++ /trunk/src/ca/sqlpower/architect/enterprise/JSONResponseHandler.java Wed Mar 24 07:30:37 2010
@@ -45,7 +45,15 @@
             while ((line = reader.readLine()) != null) {
                 buffer.append(line).append("\n");
             }
-            JSONObject message = new JSONObject(buffer.toString());
+            return handleResponse(buffer.toString());
+        } catch (Exception ex) {
+            throw new RuntimeException(ex);
+        }
+    }
+
+    public JSONMessage handleResponse(String json) {
+        try {
+            JSONObject message = new JSONObject(json);

// Does the response contain data? If so, return it. Communication
             // with the resource has been successful.
@@ -59,15 +67,15 @@
// Does the response contain an exception? If so, reconstruct, and then // re-throw it. There has been an exception on the server. if (message.getString("responseKind").equals("exceptionStackTrace")) {
-
+
JSONArray stackTraceStrings = new JSONArray(message.getString("data")); StringBuffer stackTraceMessage = new StringBuffer(); for (int i = 0; i < stackTraceStrings.length(); i++) { stackTraceMessage.append("\n").append(stackTraceStrings.get(i));
                         }
-
+
                         throw new Exception(stackTraceMessage.toString());
-
+
                     } else {
// This exception represents a(n epic) client-server miscommunication
                         throw new Exception("Unable to parse response ");
=======================================
--- /trunk/src/ca/sqlpower/architect/swingui/enterprise/RevisionsTable.java Thu Feb 25 09:33:27 2010 +++ /trunk/src/ca/sqlpower/architect/swingui/enterprise/RevisionsTable.java Wed Mar 24 07:30:37 2010
@@ -45,8 +45,8 @@
 import javax.swing.table.DefaultTableCellRenderer;
 import javax.swing.table.DefaultTableModel;

-import ca.sqlpower.architect.enterprise.ArchitectClientSideSession;
 import ca.sqlpower.enterprise.TransactionInformation;
+import ca.sqlpower.enterprise.client.ClientSideSession;
 import ca.sqlpower.swingui.SPSUtils;

 /**
@@ -56,7 +56,7 @@

private static final String[] HEADERS = {"Version", "Time Created", "Author", "Description"};

-    private ArchitectClientSideSession session;
+    private ClientSideSession session;

private List<TransactionInformation> transactions = new ArrayList<TransactionInformation>();

@@ -123,7 +123,7 @@
         }
      }

- public RevisionsTable(ArchitectClientSideSession session, long fromRevision, long toRevision) { + public RevisionsTable(ClientSideSession session, long fromRevision, long toRevision) {
         super();

         this.session = session;

To unsubscribe from this group, send email to 
architect-commits+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.

Reply via email to