Author: paperwing
Date: 2012-08-02 13:02:28 -0700 (Thu, 02 Aug 2012)
New Revision: 30076

Modified:
   
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/SimpleAppOld.java
   
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/WebQuerier.java
   
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/server/AppGetResponder.java
   
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/InstallFromStorePanel.java
Log:
Switched download site combo box location with search text box, the "all apps" 
icon now changes to open folder when clicked. WebQuerier now has methods to 
change its current download site.

Modified: 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/SimpleAppOld.java
===================================================================
--- 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/SimpleAppOld.java
        2012-08-02 18:36:06 UTC (rev 30075)
+++ 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/manager/SimpleAppOld.java
        2012-08-02 20:02:28 UTC (rev 30076)
@@ -44,7 +44,7 @@
         * A regular expression representing valid app versions, which are in 
the format major.minor[.patch][-tag],
         * eg. 3.0.0-SNAPSHOT, or 3.0.
         */
-       public static final Pattern APP_VERSION_TAG_REGEX = 
Pattern.compile("(0|([1-9]+\\d*))\\.(\\d)+(\\.(\\d)+)?(-.*)?");
+       public static final Pattern APP_VERSION_TAG_REGEX = 
Pattern.compile("(0|([1-9]+\\d*))\\.(\\d)+(\\.(\\d)+)?(.*)?");
 
        @Override
        public Object createAppInstance(CySwingAppAdapter appAdapter) throws 
AppInstanceException {

Modified: 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/WebQuerier.java
===================================================================
--- 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/WebQuerier.java
      2012-08-02 18:36:06 UTC (rev 30075)
+++ 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/WebQuerier.java
      2012-08-02 20:02:28 UTC (rev 30076)
@@ -21,11 +21,15 @@
 
 import org.apache.commons.io.IOUtils;
 import org.cytoscape.app.internal.exception.AppDownloadException;
+import org.cytoscape.app.internal.manager.AppManager;
+import org.cytoscape.app.internal.net.WebQuerier.AppTag;
 import org.cytoscape.app.internal.util.DebugHelper;
 import org.cytoscape.io.util.StreamUtil;
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * This class is responsible for querying the Cytoscape App Store web service 
to obtain
@@ -33,7 +37,7 @@
  */
 public class WebQuerier {
        
-       private static final String APP_STORE_URL = "http://apps3.nrnb.org/";;
+       private static final String DEFAULT_APP_STORE_URL = 
"http://apps3.nrnb.org/";;
        
        private static final String REQUEST_JSON_HEADER_KEY = 
"X-Requested-With";
        private static final String REQUEST_JSON_HEADER_VALUE = 
"XMLHttpRequest";
@@ -43,18 +47,42 @@
         */
        private static final String COMPATIBLE_RELEASE_REGEX = 
"(^\\s*|.*,)\\s*3(\\..*)?\\s*(\\s*$|,.*)";
        
+       private static final Logger logger = 
LoggerFactory.getLogger(WebQuerier.class);
+       
        private StreamUtil streamUtil;
        
        /** A reference to the result obtained by the last successful query for 
all available apps. */
-       private Set<WebApp> apps;
+       // private Set<WebApp> apps;
        
        /** A reference to a map which keeps track of the known set of apps for 
each known tag */
-       private Map<String, Set<WebApp>> appsByTagName;
+       // private Map<String, Set<WebApp>> appsByTagName;
        
        /** A reference to the result obtained by the last successful query for 
all available app tags. */
-       private Map<String, AppTag> appTags;
+       // private Map<String, AppTag> appTags;
        
        /**
+        * A reference to the result obtained by the last successful query for 
all available apps 
+        * to this app store URL.
+        */
+       private Map<String, Set<WebApp>> appsByUrl;
+       
+       /** 
+        * A reference to a map of maps keeping track, for each app store URL, 
the known set of 
+        * apps for each known tag from that URL.
+        */
+       private Map<String, Map<String, Set<WebApp>>> appsByTagNameByUrl;
+       
+       /**
+        * A reference to the set of all known tags for a given app store URL. 
The tags are stored
+        * in a map that maps the tag's string name to a tag object containing 
more information
+        * about the tag, such as the number of apps associated with it.
+        */
+       private Map<String, Map<String, AppTag>> appTagsByUrl;
+       
+       
+       private String currentAppStoreUrl = DEFAULT_APP_STORE_URL;
+       
+       /**
         * A class that represents a tag used for apps, containing information 
about the tag
         * such as its unique name used on the app store website as well as its 
human-readable name.
         */
@@ -108,10 +136,21 @@
        public WebQuerier(StreamUtil streamUtil) {
                this.streamUtil = streamUtil;
                
+               /*
+               // *** Older initialization for previous implementation 
supporting a single app store page
                apps = null;
                appTags = new HashMap<String, AppTag>();
                appsByTagName = new HashMap<String, Set<WebApp>>();
+               */
                
+               appsByUrl = new HashMap<String, Set<WebApp>>();
+               appTagsByUrl = new HashMap<String, Map<String, AppTag>>();
+               appsByTagNameByUrl = new HashMap<String, 
Map<String,Set<WebApp>>>();
+               
+               appsByUrl.put(currentAppStoreUrl, null);
+               appTagsByUrl.put(currentAppStoreUrl, new HashMap<String, 
AppTag>());
+               appsByTagNameByUrl.put(currentAppStoreUrl, new HashMap<String, 
Set<WebApp>>());
+               
                /*
                Set<WebApp> webApps = getAllApps();
                
@@ -149,11 +188,53 @@
                return result;
        }
        
-       public String getAppStoreUrl() {
-               return APP_STORE_URL;
+       public String getDefaultAppStoreUrl() {
+               return DEFAULT_APP_STORE_URL;
        }
        
+       public String getCurrentAppStoreUrl(String url) {
+               return currentAppStoreUrl;
+       }
+       
        /**
+        * Sets the current base url used for app store queries. If the url is 
malformed,
+        * no change is made.
+        * 
+        * @param url The base url of the app store, e.g. 
http://apps.cytoscape.org/
+        */
+       public void setCurrentAppStoreUrl(String url) {
+               boolean malformed = false;
+               
+               try {
+                       URL checkMalformed = new URL(url);
+               } catch (MalformedURLException e) {
+                       malformed = true;
+                       logger.warn("Malformed URL: " + url + ", " + 
e.getMessage());
+               }
+               
+               if (!malformed) {
+                       if (!url.trim().endsWith("/")) {
+                               currentAppStoreUrl = url + "/";
+                       } else {
+                               currentAppStoreUrl = url;
+                       }
+                       
+                       
+                       if (appsByUrl.get(currentAppStoreUrl) == null) {
+                               appsByUrl.put(currentAppStoreUrl, null);
+                       }
+                       
+                       if (appTagsByUrl.get(currentAppStoreUrl) == null) {
+                               appTagsByUrl.put(currentAppStoreUrl, new 
HashMap<String, AppTag>());
+                       }
+                       
+                       if (appsByTagNameByUrl.get(currentAppStoreUrl) == null) 
{
+                               appsByTagNameByUrl.put(currentAppStoreUrl, new 
HashMap<String, Set<WebApp>>());
+                       }
+               }
+       }
+       
+       /**
         * Return the set of all tag names found on the app store. 
         * @return The set of all available tag names
         */
@@ -162,48 +243,82 @@
                // by the web store and is used to build a set of all available 
tags
                Set<WebApp> apps = getAllApps();
                
-               return new HashSet(appTags.values());
+               return new 
HashSet<AppTag>(appTagsByUrl.get(currentAppStoreUrl).values());
        }
        
        public Set<WebApp> getAllApps() {
                // If we have a cached result from the previous query, use that 
one
-               if (apps != null) {
-                       return apps;
+               if (this.appsByUrl.get(currentAppStoreUrl) != null) {
+                       return this.appsByUrl.get(currentAppStoreUrl);
                }
                
                DebugHelper.print("Obtaining apps from app store..");
-               String iconUrlPrefix = APP_STORE_URL.substring(0, 
APP_STORE_URL.length() - 1);
-               
+
                Set<WebApp> result = new HashSet<WebApp>();
                
                String jsonResult = null;
                try {
                        // Obtain information about the app from the website
-                       jsonResult = query(APP_STORE_URL + "backend/all_apps");
+                       jsonResult = query(DEFAULT_APP_STORE_URL + 
"backend/all_apps");
                        
                        // Parse the JSON result
                        JSONArray jsonArray = new JSONArray(jsonResult);
                        JSONObject jsonObject = null;
+                       String keyName;
                        
                        for (int index = 0; index < jsonArray.length(); 
index++) {
                                jsonObject = jsonArray.getJSONObject(index);
                                
                                WebApp webApp = new WebApp();
-                               
webApp.setName(jsonObject.get("fullname").toString());
-                               
webApp.setFullName(jsonObject.get("fullname").toString());
-                               
webApp.setIconUrl(jsonObject.get("icon_url").toString());
                                
-                               webApp.setPageUrl(APP_STORE_URL.substring(0, 
APP_STORE_URL.length() - 1) 
-                                               + 
jsonObject.get("page_url").toString());
-                               
webApp.setDescription(jsonObject.get("description").toString());
-                               
webApp.setDownloadCount(jsonObject.getInt("downloads"));
+                               keyName = "fullname";
+                               if (jsonObject.has(keyName)) {
+                                       
webApp.setName(jsonObject.get(keyName).toString());
+                                       
webApp.setFullName(jsonObject.get(keyName).toString());
+                               } else {
+                                       continue;
+                               }
                                
-                               try {
-                                       
webApp.setStarsPercentage(Integer.parseInt(jsonObject.get("stars_percentage").toString()));
-                                       
webApp.setVotes(Integer.parseInt(jsonObject.get("votes").toString()));
-                               } catch (NumberFormatException e) {
+                               keyName = "icon_url";
+                               if (jsonObject.has(keyName)) {
+                                       
webApp.setIconUrl(jsonObject.get(keyName).toString());
                                }
                                
+                               keyName = "page_url";
+                               if (jsonObject.has(keyName)) {
+                                       
webApp.setPageUrl(currentAppStoreUrl.substring(0, currentAppStoreUrl.length() - 
1) 
+                                                       + 
jsonObject.get(keyName).toString());
+                               }
+                               
+                               keyName = "description";
+                               if (jsonObject.has(keyName)) {
+                                       
webApp.setDescription(jsonObject.get(keyName).toString());
+                               }
+                               
+                               keyName = "downloads";
+                               if (jsonObject.has(keyName)) {
+                                       try {
+                                               
webApp.setDownloadCount(Integer.parseInt(jsonObject.get(keyName).toString()));
+                                       } catch (NumberFormatException e) {
+                                       }
+                               }
+                               
+                               keyName = "stars_percentage";
+                               if (jsonObject.has(keyName)) {
+                                       try {
+                                               
webApp.setStarsPercentage(Integer.parseInt(jsonObject.get(keyName).toString()));
+                                       } catch (NumberFormatException e) {
+                                       }
+                               }
+                               
+                               keyName = "votes";
+                               if (jsonObject.has(keyName)) {
+                                       try {
+                                               
webApp.setVotes(Integer.parseInt(jsonObject.get(keyName).toString()));
+                                       } catch (NumberFormatException e) {
+                                       }
+                               }
+                               
                                try {
                                        List<WebApp.Release> releases = new 
LinkedList<WebApp.Release>();
                                        
@@ -219,8 +334,12 @@
                                                        
release.setRelativeUrl(jsonRelease.get("release_download_url").toString());
                                                        
release.setReleaseDate(jsonRelease.get("created_iso").toString());
                                                        
release.setReleaseVersion(jsonRelease.get("version").toString());
-                                                       
release.setCompatibleCytoscapeVersions(jsonRelease.get("works_with").toString());
                                                        
+                                                       keyName = "works_with";
+                                                       if 
(jsonRelease.has(keyName)) {
+                                                               
release.setCompatibleCytoscapeVersions(jsonRelease.get(keyName).toString());
+                                                       }
+                                                       
                                                        releases.add(release);
                                                }
                                                
@@ -230,7 +349,7 @@
                                        
                                        webApp.setReleases(releases);
                                } catch (JSONException e) {
-                                       DebugHelper.print("Error obtaining 
releases for app: " + webApp.getFullName() + ", " 
+                                       logger.warn("Error obtaining releases 
for app: " + webApp.getFullName() + ", " 
                                                        + e.getMessage());
                                }
                                
@@ -263,7 +382,7 @@
                DebugHelper.print(result.size() + " apps found from web 
store.");
                
                // Cache the result of this query
-               this.apps = result;
+               this.appsByUrl.put(currentAppStoreUrl, result);
                return result;
        }
        
@@ -271,7 +390,10 @@
                // Obtain tags associated with this app from the JSONObject 
representing the app data in JSON format obtained
                // from the web store
                
-               JSONArray appTagObjects = jsonObject.getJSONArray("tags");
+               JSONArray appTagObjects = jsonObject.optJSONArray("tags");
+               if (appTagObjects == null) {
+                       return;
+               }
                
                for (int index = 0; index < appTagObjects.length(); index++) {
                        /*
@@ -282,7 +404,7 @@
                        
                        String appTagName = appTagObjects.get(index).toString();
                        
-                       AppTag appTag = appTags.get(appTagName);
+                       AppTag appTag = 
appTagsByUrl.get(currentAppStoreUrl).get(appTagName);
                        
                        if (appTag == null) {
                                appTag = new AppTag();
@@ -291,45 +413,22 @@
                                appTag.setFullName(appTagName);
                        
                                appTag.setCount(0);
-                               appTags.put(appTagName, appTag);
+                               
appTagsByUrl.get(currentAppStoreUrl).put(appTagName, appTag);
                        }
                        
                        
                        webApp.getAppTags().add(appTag);
                        
                        // Add the app information for this tag to the map 
which keeps apps categorized by tag
-                       if (appsByTagName.get(appTagName) == null) {
-                               appsByTagName.put(appTagName, new 
HashSet<WebApp>());
+                       if 
(appsByTagNameByUrl.get(currentAppStoreUrl).get(appTagName) == null) {
+                               
appsByTagNameByUrl.get(currentAppStoreUrl).put(appTagName, new 
HashSet<WebApp>());
                        }
                        
-                       appsByTagName.get(appTagName).add(webApp);
+                       
appsByTagNameByUrl.get(currentAppStoreUrl).get(appTagName).add(webApp);
                        appTag.setCount(appTag.getCount() + 1);
                }
        }
        
-       public String getAppDescription(String appName) {
-               // Obtain information about the app from the website
-               String jsonResult = null;
-               JSONObject jsonObject = null;
-               
-               try {
-                       jsonResult = query(APP_STORE_URL + "apps/" + appName);
-                       
-                       // Parse the JSON result
-                       jsonObject = new JSONObject(jsonResult);
-                       return jsonObject.get("description").toString();
-               } catch (IOException e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
-               } catch (JSONException e) {
-                       // TODO Auto-generated catch block
-                       DebugHelper.print("Error parsing JSON: " + 
e.getMessage());
-                       e.printStackTrace();
-               }
-               
-               return "";
-       }
-       
        /**
         * Given the unique app name used by the app store, query the app store 
for the 
         * download URL and download the app to the given directory.
@@ -367,7 +466,7 @@
                        
                        URL downloadUrl = null;
                        try {
-                               downloadUrl = new URL(APP_STORE_URL + 
releaseToDownload.getRelativeUrl());
+                               downloadUrl = new URL(DEFAULT_APP_STORE_URL + 
releaseToDownload.getRelativeUrl());
                        } catch (MalformedURLException e) {
                                throw new AppDownloadException("Unable to 
obtain URL for version " + version 
                                                + " of the release for " + 
webApp.getFullName());
@@ -430,6 +529,6 @@
                // Query for apps (which includes tag information) if not done 
so
                Set<WebApp> webApps = getAllApps();
                
-               return appsByTagName.get(tagName);
+               return appsByTagNameByUrl.get(currentAppStoreUrl).get(tagName);
        }
 }

Modified: 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/server/AppGetResponder.java
===================================================================
--- 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/server/AppGetResponder.java
  2012-08-02 18:36:06 UTC (rev 30075)
+++ 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/server/AppGetResponder.java
  2012-08-02 20:02:28 UTC (rev 30076)
@@ -114,7 +114,7 @@
                                        if (appFile == null) {
                                                installStatus = 
"version-not-found";
                                                installError = "An entry for 
the app " + appName + " with version " + version
-                                                       + " was not found in 
the app store database at: " + appManager.getWebQuerier().getAppStoreUrl();
+                                                       + " was not found in 
the app store database at: " + 
appManager.getWebQuerier().getDefaultAppStoreUrl();
                                        } else {
                                                installStatus = "success";
                                                
@@ -135,7 +135,7 @@
                                } else {
                                        installStatus = "app-not-found";
                                        installError = "The app " + appName + " 
is not found in the app store database at "
-                                               + 
appManager.getWebQuerier().getAppStoreUrl();
+                                               + 
appManager.getWebQuerier().getDefaultAppStoreUrl();
                                }
                                
                                responseData.put("install_status", 
installStatus);

Modified: 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/InstallFromStorePanel.java
===================================================================
--- 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/InstallFromStorePanel.java
    2012-08-02 18:36:06 UTC (rev 30075)
+++ 
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/InstallFromStorePanel.java
    2012-08-02 20:02:28 UTC (rev 30076)
@@ -267,7 +267,7 @@
                             .addGroup(layout.createSequentialGroup()
                                 .addComponent(searchAppsLabel)
                                 
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-                                .addComponent(filterTextField, 
javax.swing.GroupLayout.PREFERRED_SIZE, 241, 
javax.swing.GroupLayout.PREFERRED_SIZE)))
+                                .addComponent(filterTextField, 
javax.swing.GroupLayout.PREFERRED_SIZE, 228, 
javax.swing.GroupLayout.PREFERRED_SIZE)))
                         .addGap(0, 0, Short.MAX_VALUE)))
                 .addContainerGap())
         );
@@ -276,13 +276,13 @@
             .addGroup(layout.createSequentialGroup()
                 .addContainerGap()
                 
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+                    .addComponent(downloadSiteLabel)
+                    .addComponent(downloadSiteComboBox, 
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, 
javax.swing.GroupLayout.PREFERRED_SIZE))
+                
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                     .addComponent(searchAppsLabel)
                     .addComponent(filterTextField, 
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, 
javax.swing.GroupLayout.PREFERRED_SIZE))
                 
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-                
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
-                    .addComponent(downloadSiteLabel)
-                    .addComponent(downloadSiteComboBox, 
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, 
javax.swing.GroupLayout.PREFERRED_SIZE))
-                
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addComponent(descriptionSplitPane, 
javax.swing.GroupLayout.DEFAULT_SIZE, 362, Short.MAX_VALUE)
                 
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
@@ -313,7 +313,7 @@
                                                expanded, leaf, row, hasFocus);
                                
                                // Make leaves use the open folder icon when 
selected
-                               if (selected && leaf && row > 0) {
+                               if (selected && leaf) {
                                        setIcon(getOpenIcon());
                                }
                                
@@ -570,7 +570,7 @@
                
                // App image
                text += "<img border=\"0\" ";
-               text += "src=\"" + appManager.getWebQuerier().getAppStoreUrl() 
+               text += "src=\"" + 
appManager.getWebQuerier().getDefaultAppStoreUrl() 
                        + selectedApp.getIconUrl() + "\" alt=\"" + 
selectedApp.getFullName() + "\"/>";
                
                // App name

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to