From: Jim Procter Date: Fri, 20 Jul 2018 15:12:51 +0000 (+0100) Subject: JAL-3070 pull up hostURL and postURL to UIinfo and getter for action ext X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=97264690f394f98cf13cd1d834a53e8956fb1b0e;p=jalview.git JAL-3070 pull up hostURL and postURL to UIinfo and getter for action ext --- diff --git a/src/jalview/gui/WsJobParameters.java b/src/jalview/gui/WsJobParameters.java index 10798f6..e65e799 100644 --- a/src/jalview/gui/WsJobParameters.java +++ b/src/jalview/gui/WsJobParameters.java @@ -69,14 +69,13 @@ import javax.swing.border.TitledBorder; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; -import net.miginfocom.swing.MigLayout; - import compbio.metadata.Argument; import compbio.metadata.Option; import compbio.metadata.Parameter; import compbio.metadata.Preset; import compbio.metadata.PresetManager; import compbio.metadata.RunnerConfig; +import net.miginfocom.swing.MigLayout; /** * job parameter editing/browsing dialog box. User can browse existing settings @@ -967,7 +966,7 @@ public class WsJobParameters extends JPanel implements ItemListener, int p = 0; if (args.length > 0) { - Vector services = new Vector(); + Vector services = new Vector<>(); services.addElement(args[p++]); Jws2Discoverer.getDiscoverer().setServiceUrls(services); } @@ -984,7 +983,7 @@ public class WsJobParameters extends JPanel implements ItemListener, for (Jws2Instance service : disc.getServices()) { lastserv = service; - if (p >= args.length || service.serviceType.equalsIgnoreCase(args[p])) + if (p >= args.length || service.getName().equalsIgnoreCase(args[p])) { if (lastserv != null) { diff --git a/src/jalview/ws/api/UIinfo.java b/src/jalview/ws/api/UIinfo.java index 81c4ff3..cf44266 100644 --- a/src/jalview/ws/api/UIinfo.java +++ b/src/jalview/ws/api/UIinfo.java @@ -9,12 +9,13 @@ public class UIinfo private String ServiceType; public UIinfo(String serviceType, String action, String name, - String description) + String description, String hosturl) { this.setServiceType(serviceType == null ? "" : serviceType); this.Action = action == null ? "" : action; this.description = description == null ? "" : description; this.Name = name == null ? "" : name; + this.hostURL = hosturl; } /** @@ -85,6 +86,9 @@ public class UIinfo return (ServiceType == null && other.getServiceType() == null || ServiceType != null && other.getServiceType() != null && ServiceType.equals(other.getServiceType())) + && (hostURL == null && other.getHostURL() == null + || hostURL != null && other.getHostURL() != null + && hostURL.equals(other.getHostURL())) && (Name == null && other.getName() == null || Name != null && other.getName() != null && Name.equals(other.getName())) @@ -96,9 +100,24 @@ public class UIinfo && description.equals(other.getDescription())); } + /** + * @return short description of what the service will do + */ + public String getActionText() + { + return getAction() + " with " + getName(); + } + String Action; String Name; String description; + + String hostURL; + + public String getHostURL() + { + return hostURL; + } } \ No newline at end of file diff --git a/src/jalview/ws/jws2/Jws2Client.java b/src/jalview/ws/jws2/Jws2Client.java index 4e135d1..d9b7e77 100644 --- a/src/jalview/ws/jws2/Jws2Client.java +++ b/src/jalview/ws/jws2/Jws2Client.java @@ -28,6 +28,7 @@ import jalview.gui.JvSwingUtils; import jalview.gui.WebserviceInfo; import jalview.gui.WsJobParameters; import jalview.util.MessageManager; +import jalview.ws.api.UIinfo; import jalview.ws.jws2.dm.AAConSettings; import jalview.ws.jws2.dm.JabaWsParamSet; import jalview.ws.jws2.jabaws2.Jws2Instance; @@ -142,16 +143,17 @@ public abstract class Jws2Client extends jalview.ws.WSClient // anonymous constructor - used for headless method calls only } - protected WebserviceInfo setWebService(Jws2Instance serv, boolean b) + protected WebserviceInfo setWebService(UIinfo serv, boolean b) { + // TODO pullup WebServiceName = serv.getName(); WebServiceJobTitle = serv.getActionText(); - WsURL = serv.hosturl; + WsURL = serv.getHostURL(); if (!b) { return new WebserviceInfo(WebServiceJobTitle, WebServiceJobTitle + " using service hosted at " - + serv.hosturl + "\n" + + WsURL + "\n" + (serv.getDescription() != null ? serv.getDescription() : ""), @@ -181,7 +183,7 @@ public abstract class Jws2Client extends jalview.ws.WSClient abstract void attachWSMenuEntry(JMenu wsmenu, final Jws2Instance service, final AlignFrame alignFrame); - protected boolean registerAAConWSInstance(final JMenu wsmenu, + static boolean registerAAConWSInstance(final JMenu wsmenu, final Jws2Instance service, final AlignFrame alignFrame) { final AlignAnalysisUIText aaui = service.getAlignAnalysisUI(); // null ; // @@ -214,7 +216,7 @@ public abstract class Jws2Client extends jalview.ws.WSClient { AbstractJabaCalcWorker worker = (AbstractJabaCalcWorker) aaconClient .get(0); - if (!worker.service.hosturl.equals(service.hosturl)) + if (!worker.service.getHostURL().equals(service.getHostURL())) { // javax.swing.SwingUtilities.invokeLater(new Runnable() { @@ -365,10 +367,11 @@ public abstract class Jws2Client extends jalview.ws.WSClient else { if (service != null - && !fave.getService().hosturl.equals(service.hosturl)) + && !fave.getService().getHostURL() + .equals(service.getHostURL())) { - Cache.log.debug("Changing AACon service to " + service.hosturl - + " from " + fave.getService().hosturl); + Cache.log.debug("Changing AACon service to " + service.getHostURL() + + " from " + fave.getService().getHostURL()); fave.setService(service); } } diff --git a/src/jalview/ws/jws2/Jws2Discoverer.java b/src/jalview/ws/jws2/Jws2Discoverer.java index b6c5473..e4ff459 100644 --- a/src/jalview/ws/jws2/Jws2Discoverer.java +++ b/src/jalview/ws/jws2/Jws2Discoverer.java @@ -281,7 +281,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI for (Jws2Instance svc : services) { svcs[ipos] = svc; - spos[ipos++] = 1000 * svcUrls.indexOf(svc.getHost()) + 1 + spos[ipos++] = 1000 * svcUrls.indexOf(svc.getHostURL()) + 1 + svctypes.indexOf(svc.getName()); } jalview.util.QuickSort.sort(spos, svcs); @@ -418,7 +418,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI // previous service of this type already present atpoint.addSeparator(); } - atpoint.add(hitm = new JMenuItem(service.getHost())); + atpoint.add(hitm = new JMenuItem(service.getHostURL())); hitm.setForeground(Color.blue); hitm.addActionListener(new ActionListener() { @@ -426,7 +426,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI @Override public void actionPerformed(ActionEvent e) { - Desktop.showUrl(service.getHost()); + Desktop.showUrl(service.getHostURL()); } }); hitm.setToolTipText(JvSwingUtils.wrapTooltip(false, @@ -442,7 +442,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI for (final Jws2Instance sv : alternates.get(service.getName())) { JMenuItem itm; - hitm.add(itm = new JMenuItem(sv.getHost())); + hitm.add(itm = new JMenuItem(sv.getHostURL())); itm.setForeground(Color.blue); itm.addActionListener(new ActionListener() { @@ -491,12 +491,13 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI ArrayList hostlist = new ArrayList<>(); for (Jws2Instance service : enumerableServices) { - ArrayList hostservices = hosts.get(service.getHost()); + ArrayList hostservices = hosts + .get(service.getHostURL()); if (hostservices == null) { - hosts.put(service.getHost(), + hosts.put(service.getHostURL(), hostservices = new ArrayList<>()); - hostlist.add(service.getHost()); + hostlist.add(service.getHostURL()); } hostservices.add(service); } @@ -563,7 +564,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI @Override public void actionPerformed(ActionEvent e) { - Desktop.showUrl(service.getHost()); + Desktop.showUrl(service.getHostURL()); } }); hitm.setToolTipText( @@ -606,7 +607,8 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI for (Jws2Instance instance : getDiscoverer().services) { System.out.println("Service " + i++ + " " - + instance.getClass() + "@" + instance.getHost() + + instance.getClass() + "@" + + instance.getHostURL() + ": " + instance.getActionText()); } @@ -1016,7 +1018,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI { if (svc.getName().equals(serviceName)) { - if (serviceurl == null || serviceurl.equals(svc.getHost())) + if (serviceurl == null || serviceurl.equals(svc.getHostURL())) { response = svc; break; @@ -1041,8 +1043,8 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI prefmap = new HashMap<>(); preferredServiceMap.put(afid, prefmap); } - prefmap.put(serviceName, selectedServer.getHost()); - prefmap.put(serviceAction, selectedServer.getHost()); + prefmap.put(serviceName, selectedServer.getHostURL()); + prefmap.put(serviceAction, selectedServer.getHostURL()); } public void setPreferredServiceFor(String serviceType, diff --git a/src/jalview/ws/jws2/jabaws2/Jws2Instance.java b/src/jalview/ws/jws2/jabaws2/Jws2Instance.java index 69f9072..85ac238 100644 --- a/src/jalview/ws/jws2/jabaws2/Jws2Instance.java +++ b/src/jalview/ws/jws2/jabaws2/Jws2Instance.java @@ -41,7 +41,6 @@ import compbio.metadata.RunnerConfig; public class Jws2Instance extends UIinfo { - public String hosturl; public JABAService service; @@ -64,8 +63,7 @@ public class Jws2Instance extends UIinfo public Jws2Instance(String hosturl, String serviceType, String action, String description, JABAService service) { - super(action, action, serviceType, description); - this.hosturl = hosturl; + super(action, action, serviceType, description, hosturl); this.service = service; int p = description.indexOf("MORE INFORMATION:"); if (p > -1) @@ -107,32 +105,12 @@ public class Jws2Instance extends UIinfo } catch (Exception ex) { System.err.println("Exception when retrieving presets for service " - + getServiceType() + " at " + hosturl); + + getServiceType() + " at " + getHostURL()); } } return presets; } - public String getHost() - { - return hosturl; - /* - * try { URL serviceurl = new URL(hosturl); if (serviceurl.getPort()!=80) { - * return serviceurl.getHost()+":"+serviceurl.getPort(); } return - * serviceurl.getHost(); } catch (Exception e) { - * System.err.println("Failed to parse service URL '" + hosturl + - * "' as a valid URL!"); } return null; - */ - } - - /** - * @return short description of what the service will do - */ - public String getActionText() - { - return getAction() + " with " + getServiceType(); - } - /** * non-thread safe - blocks whilst accessing service to get complete set of * available options and parameters @@ -192,11 +170,14 @@ public class Jws2Instance extends UIinfo public String getUri() { + // TODO verify that service parameter sets in projects are consistent with + // Jalview 2.10.4 // this is only valid for Jaba 1.0 - this formula might have to change! - return hosturl - + (hosturl.lastIndexOf("/") == (hosturl.length() - 1) ? "" + return getHostURL() + + (getHostURL().lastIndexOf("/") == (getHostURL().length() - 1) + ? "" : "/") - + getServiceType(); + + getName(); } private boolean hasParams = false, lookedForParams = false; diff --git a/src/jalview/ws/rest/RestServiceDescription.java b/src/jalview/ws/rest/RestServiceDescription.java index a83c005..9268975 100644 --- a/src/jalview/ws/rest/RestServiceDescription.java +++ b/src/jalview/ws/rest/RestServiceDescription.java @@ -67,7 +67,7 @@ public class RestServiceDescription boolean vseparable, char gapCharacter) { super(); - this.details = new UIinfo(action, action, name, description); + this.details = new UIinfo(action, action, name, description, postUrl); this.postUrl = postUrl == null ? "" : postUrl; this.urlSuffix = urlSuffix == null ? "" : urlSuffix; if (inputParams != null) @@ -521,7 +521,8 @@ public class RestServiceDescription { p++; } - details = new UIinfo(list[p + 1], list[p + 1], list[p], list[p + 2]); + details = new UIinfo(list[p + 1], list[p + 1], list[p], list[p + 2], + postUrl); invalid |= !configureFromServiceInputProperties(list[p + 3], warnings); if (list.length - p > 5 && list[p + 5] != null && list[p + 5].trim().length() > 5) diff --git a/test/jalview/ws/jws2/ParameterUtilsTest.java b/test/jalview/ws/jws2/ParameterUtilsTest.java index c0aa2ee..7876522 100644 --- a/test/jalview/ws/jws2/ParameterUtilsTest.java +++ b/test/jalview/ws/jws2/ParameterUtilsTest.java @@ -26,6 +26,7 @@ import static org.testng.AssertJUnit.assertTrue; import jalview.bin.Cache; import jalview.gui.JvOptionPane; +import jalview.ws.api.UIinfo; import jalview.ws.jabaws.JalviewJabawsTestUtils; import jalview.ws.jws2.jabaws2.Jws2Instance; @@ -128,7 +129,7 @@ public class ParameterUtilsTest * @param service * @return */ - public boolean isForTesting(Jws2Instance service) + public boolean isForTesting(UIinfo service) { return serviceTests.size() == 0 || serviceTests.contains(service.serviceType.toLowerCase());