Author: paperwing
Date: 2012-06-01 13:41:55 -0700 (Fri, 01 Jun 2012)
New Revision: 29421
Modified:
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/CyActivator.java
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/WebApp.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:
refs #1050 Install from store button now working with current app store API,
but as of yet we don't have many releases to download from the app store
Modified:
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/CyActivator.java
===================================================================
---
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/CyActivator.java
2012-06-01 20:35:06 UTC (rev 29420)
+++
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/CyActivator.java
2012-06-01 20:41:55 UTC (rev 29421)
@@ -353,7 +353,7 @@
registerService(bc, appManager, AppManager.class, new
Properties());
// AbstractCyAction implementation for updated app manager
- AppManagerAction appManagerAction2 = new
AppManagerAction(appManager, cySwingApplicationRef, fileUtilServiceRef,
taskManagerRef);
+ AppManagerAction appManagerAction2 = new
AppManagerAction(appManager, cySwingApplicationRef, fileUtilServiceRef,
dialogTaskManagerRef);
registerService(bc, appManagerAction2, CyAction.class, new
Properties());
Thread serverThread = new Thread() {
Modified:
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/WebApp.java
===================================================================
---
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/WebApp.java
2012-06-01 20:35:06 UTC (rev 29420)
+++
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/WebApp.java
2012-06-01 20:41:55 UTC (rev 29421)
@@ -1,6 +1,8 @@
package org.cytoscape.app.internal.net;
import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Set;
import javax.swing.ImageIcon;
@@ -47,8 +49,66 @@
private ImageIcon imageIcon;
+ private List<Release> releases;
+
+ public static class Release implements Comparable<Release> {
+ private String relativeUrl;
+ private String releaseDate;
+ private String releaseVersion;
+ private String compatibleCytoscapeVersions;
+
+ @Override
+ public int compareTo(Release other) {
+ return
releaseDate.compareToIgnoreCase(other.releaseDate);
+ }
+
+ public String getRelativeUrl() {
+ return relativeUrl;
+ }
+
+ public String getReleaseDate() {
+ return releaseDate;
+ }
+
+ public String getReleaseVersion() {
+ return releaseVersion;
+ }
+
+ public String getCompatibleCytoscapeVersions() {
+ return compatibleCytoscapeVersions;
+ }
+
+
+ public void setRelativeUrl(String relativeUrl) {
+ this.relativeUrl = relativeUrl;
+ }
+
+ public void setReleaseDate(String releaseDate) {
+ this.releaseDate = releaseDate;
+ }
+
+ public void setReleaseVersion(String releaseVersion) {
+ this.releaseVersion = releaseVersion;
+ }
+
+ public void setCompatibleCytoscapeVersions(String
compatibleCytoscapeVersions) {
+ this.compatibleCytoscapeVersions =
compatibleCytoscapeVersions;
+ }
+
+
+
+
+ /*
+ "release_download_url":"/apps/metanetter/download/0.1",
+ "created_iso":"2012-05-11T10:32:58",
+ "version":"0.1",
+ "works_with":"3.0";
+ */
+ }
+
public WebApp() {
appTags = new HashSet<AppTag>();
+ releases = new LinkedList<Release>();
}
/**
@@ -144,6 +204,10 @@
return compatibleCytoscapeVersion;
}
+ public List<Release> getReleases() {
+ return releases;
+ }
+
public void setFullName(String fullName) {
this.fullName = fullName;
}
@@ -192,8 +256,14 @@
this.imageIcon = imageIcon;
}
+ public void setReleases(List<Release> releases) {
+ this.releases = releases;
+ }
+
@Override
public String toString() {
return fullName;
}
+
+
}
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-06-01 20:35:06 UTC (rev 29420)
+++
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/WebQuerier.java
2012-06-01 20:41:55 UTC (rev 29421)
@@ -9,8 +9,11 @@
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -35,6 +38,11 @@
private static final String REQUEST_JSON_HEADER_KEY =
"X-Requested-With";
private static final String REQUEST_JSON_HEADER_VALUE =
"XMLHttpRequest";
+ /**
+ * A regular expression for version lists that are compatible with the
current version of Cytoscape.
+ */
+ private static final String COMPATIBLE_RELEASE_REGEX =
"(^\\s*|.*,)\\s*3(\\..*)?\\s*(\\s*$|,.*)";
+
private StreamUtil streamUtil;
/** A reference to the result obtained by the last successful query for
all available apps. */
@@ -196,6 +204,43 @@
} catch (NumberFormatException e) {
}
+ try {
+ List<WebApp.Release> releases = new
LinkedList<WebApp.Release>();
+
+ if (jsonObject.has("releases")) {
+ JSONArray jsonReleases =
jsonObject.getJSONArray("releases");
+ JSONObject jsonRelease;
+
+ for (int releaseIndex = 0;
releaseIndex < jsonReleases.length(); releaseIndex++) {
+ jsonRelease =
jsonReleases.getJSONObject(releaseIndex);
+
+ WebApp.Release release
= new WebApp.Release();
+
+
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());
+
+ releases.add(release);
+ }
+
+ // Sort releases by release date
+ Collections.sort(releases);
+
+ /*
+
"release_download_url":"/apps/metanetter/download/0.1",
+ "created_iso":"2012-05-11T10:32:58",
+ "version":"0.1",
+ "works_with":"3.0";
+ */
+ }
+
+ webApp.setReleases(releases);
+ } catch (JSONException e) {
+ DebugHelper.print("Error obtaining
releases for app: " + webApp.getFullName() + ", "
+ + e.getMessage());
+ }
+
// DebugHelper.print("Obtaining ImageIcon: " +
iconUrlPrefix + webApp.getIconUrl());
// webApp.setImageIcon(new ImageIcon(new
URL(iconUrlPrefix + webApp.getIconUrl())));
@@ -295,31 +340,55 @@
* @param version The desired version, or <code>null</code> to obtain
the latest release
* @param directory The directory used to store the downloaded file
*/
- public File downloadApp(String appName, String version, File directory)
throws AppDownloadException {
- Set<WebApp> apps = getAllApps();
+ public File downloadApp(WebApp webApp, String version, File directory)
throws AppDownloadException {
+
+ List<WebApp.Release> compatibleReleases = new
LinkedList<WebApp.Release>();
- // Check that the app was found in the app store's current list
of apps
- boolean appFound = false;
- for (WebApp webApp : apps) {
- if (webApp.getName().equalsIgnoreCase(appName)) {
- appFound = true;
- break;
+ for (WebApp.Release release : webApp.getReleases()) {
+
+ // Get releases that are compatible with the current
version of Cytoscape
+ if
(release.getReleaseVersion().matches(COMPATIBLE_RELEASE_REGEX)) {
+ compatibleReleases.add(release);
}
}
- if (appFound) {
+
+ if (compatibleReleases.size() > 0) {
+ WebApp.Release releaseToDownload = null;
+
+ if (version != null) {
+ for (WebApp.Release compatibleRelease :
compatibleReleases) {
+ if
(compatibleRelease.getReleaseVersion().matches(
+ "(^\\s*|.*,)\\s*" +
version + "\\s*(\\s*$|,.*)")) {
+ releaseToDownload =
compatibleRelease;
+ }
+ }
+
+ if (releaseToDownload == null) {
+ throw new AppDownloadException("No
release with the requested version " + version
+ + " was found for the
requested app " + webApp.getFullName());
+ }
+ } else {
+ releaseToDownload =
compatibleReleases.get(compatibleReleases.size() - 1);
+ }
+
+ URL downloadUrl = null;
try {
-
- // Find the download url
- String releaseUrl = getReleaseUrl(appName,
version);
+ downloadUrl = new URL(APP_STORE_URL +
releaseToDownload.getRelativeUrl());
+ } catch (MalformedURLException e) {
+ throw new AppDownloadException("Unable to
obtain URL for version " + version
+ + " of the release for " +
webApp.getFullName());
+ }
+
+ if (downloadUrl != null) {
+ try {
- if (releaseUrl != null) {
- URL downloadUrl = new URL(releaseUrl);
-
// Prepare to download
ReadableByteChannel readableByteChannel
= Channels.newChannel(downloadUrl.openStream());
- File outputFile = new
File(directory.getCanonicalPath() + File.separator + appName + ".jar");
+ // Output file has same name as app,
but spaces are replaced with hyphens
+ File outputFile = new
File(directory.getCanonicalPath() + File.separator
+ +
webApp.getName().replaceAll("\\s", "-") + ".jar");
if (outputFile.exists()) {
outputFile.delete();
@@ -331,15 +400,14 @@
fileOutputStream.getChannel().transferFrom(readableByteChannel, 0, 1 << 24);
return outputFile;
+ } catch (IOException e) {
+ throw new AppDownloadException("Error
while downloading app " + webApp.getFullName()
+ + ": " +
e.getMessage());
}
-
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
}
-
} else {
- DebugHelper.print("No app with name " + appName + "
found.");
+ throw new AppDownloadException("No available releases
were found for the app "
+ + webApp.getFullName() + ".");
}
return null;
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-06-01 20:35:06 UTC (rev 29420)
+++
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/net/server/AppGetResponder.java
2012-06-01 20:41:55 UTC (rev 29421)
@@ -82,6 +82,7 @@
String installStatus = "app-not-found";
boolean appFoundInStore = false;
+ WebApp appToDownload = null;
// Check if the app is available on the app
store
// TODO: Use a web query to do this?
@@ -89,6 +90,7 @@
for (WebApp webApp :
appManager.getWebQuerier().getAllApps()) {
if (webApp.getName().equals(appName)) {
appFoundInStore = true;
+ appToDownload = webApp;
break;
}
}
@@ -97,7 +99,7 @@
if (appFoundInStore) {
- File appFile =
appManager.getWebQuerier().downloadApp(appName, version, new
File(appManager.getDownloadedAppsPath()));
+ File appFile =
appManager.getWebQuerier().downloadApp(appToDownload, version, new
File(appManager.getDownloadedAppsPath()));
if (appFile == null) {
installStatus =
"version-not-found";
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-06-01 20:35:06 UTC (rev 29420)
+++
core3/impl/trunk/app-impl/src/main/java/org/cytoscape/app/internal/ui/InstallFromStorePanel.java
2012-06-01 20:41:55 UTC (rev 29421)
@@ -219,11 +219,19 @@
tagsSplitPane.setDividerLocation(160);
+ javax.swing.tree.DefaultMutableTreeNode treeNode1 = new
javax.swing.tree.DefaultMutableTreeNode("root");
+ javax.swing.tree.DefaultMutableTreeNode treeNode2 = new
javax.swing.tree.DefaultMutableTreeNode("all apps (0)");
+ treeNode1.add(treeNode2);
+ tagsTree.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
+ tagsTree.setFocusable(false);
tagsTree.setRootVisible(false);
tagsScrollPane.setViewportView(tagsTree);
tagsSplitPane.setLeftComponent(tagsScrollPane);
+ treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("root");
+ resultsTree.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
+ resultsTree.setFocusable(false);
resultsTree.setRootVisible(false);
resultsScrollPane.setViewportView(resultsTree);
@@ -239,6 +247,7 @@
descriptionScrollPane.setViewportView(descriptionTextPane);
installButton.setText("Install");
+ installButton.setEnabled(false);
installButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
installButtonActionPerformed(evt);
@@ -246,6 +255,7 @@
});
viewOnAppStoreButton.setText("View on App Store");
+ viewOnAppStoreButton.setEnabled(false);
viewOnAppStoreButton.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
viewOnAppStoreButtonActionPerformed(evt);
@@ -256,14 +266,14 @@
descriptionPanel.setLayout(descriptionPanelLayout);
descriptionPanelLayout.setHorizontalGroup(
descriptionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(descriptionScrollPane,
javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
+ .addComponent(descriptionScrollPane,
javax.swing.GroupLayout.DEFAULT_SIZE, 259, Short.MAX_VALUE)
.addComponent(installButton, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(viewOnAppStoreButton,
javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE)
+ .addComponent(viewOnAppStoreButton,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
);
descriptionPanelLayout.setVerticalGroup(
descriptionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(descriptionPanelLayout.createSequentialGroup()
- .addComponent(descriptionScrollPane,
javax.swing.GroupLayout.DEFAULT_SIZE, 289, Short.MAX_VALUE)
+ .addComponent(descriptionScrollPane,
javax.swing.GroupLayout.DEFAULT_SIZE, 365, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(viewOnAppStoreButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
@@ -280,7 +290,7 @@
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
- .addComponent(descriptionSplitPane,
javax.swing.GroupLayout.DEFAULT_SIZE, 533, Short.MAX_VALUE)
+ .addComponent(descriptionSplitPane,
javax.swing.GroupLayout.DEFAULT_SIZE, 635, Short.MAX_VALUE)
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addComponent(installFromFileButton)
@@ -299,7 +309,7 @@
.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)
- .addComponent(descriptionSplitPane,
javax.swing.GroupLayout.DEFAULT_SIZE, 354, Short.MAX_VALUE)
+ .addComponent(descriptionSplitPane)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(installFromFileButton))
);
@@ -324,11 +334,12 @@
fileChooserFilters.add(fileChooserFilter);
// Show the dialog
- File[] files = fileUtil.getFiles(parent,
+ final File[] files = fileUtil.getFiles(parent,
"Choose file(s)", FileUtil.LOAD,
FileUtil.LAST_DIRECTORY, "Install", true, fileChooserFilters);
if (files != null) {
+ /*
for (int index = 0; index < files.length; index++) {
AppParser appParser = appManager.getAppParser();
@@ -358,6 +369,35 @@
}
}
}
+ */
+
+ taskManager.execute(new TaskIterator(new Task() {
+
+ @Override
+ public void run(TaskMonitor taskMonitor) throws
Exception {
+ taskMonitor.setTitle("Installing app");
+
+ double progress = 0;
+
+ taskMonitor.setStatusMessage("Installing app");
+
+ for (int index = 0; index < files.length;
index++) {
+ AppParser appParser = appManager.getAppParser();
+
+ App app = null;
+
+ app = appParser.parseApp(files[index]);
+ appManager.installApp(app);
+ }
+
+ taskMonitor.setProgress(1.0);
+ }
+
+ @Override
+ public void cancel() {
+ }
+
+ }));
}
}
@@ -415,7 +455,6 @@
private void installButtonActionPerformed(java.awt.event.ActionEvent evt) {
- /*
final WebQuerier webQuerier = appManager.getWebQuerier();
final WebApp appToDownload = selectedApp;
@@ -430,7 +469,7 @@
taskMonitor.setStatusMessage("Installing app: "
+ appToDownload.getFullName());
// Download app
- File appFile =
webQuerier.downloadApp(appToDownload.getName(), null, new
File(appManager.getDownloadedAppsPath()));
+ File appFile = webQuerier.downloadApp(appToDownload,
null, new File(appManager.getDownloadedAppsPath()));
if (appFile != null) {
// Parse app
@@ -451,7 +490,6 @@
}
}));
- */
}
private void buildTagsTree() {
@@ -552,11 +590,17 @@
descriptionTextPane.setText(text);
this.selectedApp = selectedApp;
+
+ installButton.setEnabled(true);
+ viewOnAppStoreButton.setEnabled(true);
} else {
descriptionTextPane.setText("App description is displayed
here.");
this.selectedApp = null;
+
+ installButton.setEnabled(false);
+ viewOnAppStoreButton.setEnabled(false);
}
}
--
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.