/webportal/src/main/java/org/ala/spatial/analysis/web/MaxentProgressWCController.java

http://alageospatialportal.googlecode.com/ · Java · 139 lines · 105 code · 21 blank · 13 comment · 11 complexity · 9eeb839f268dfb81577aa921f47e4896 MD5 · raw file

  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package org.ala.spatial.analysis.web;
  6. import au.org.emii.portal.composer.UtilityComposer;
  7. import java.net.SocketTimeoutException;
  8. import org.ala.logger.client.RemoteLogger;
  9. import org.ala.spatial.util.CommonData;
  10. import org.apache.commons.httpclient.HttpClient;
  11. import org.apache.commons.httpclient.methods.GetMethod;
  12. import org.zkoss.zk.ui.event.Event;
  13. import org.zkoss.zk.ui.event.Events;
  14. import org.zkoss.zul.Label;
  15. import org.zkoss.zul.Progressmeter;
  16. import org.zkoss.zul.Textbox;
  17. import org.zkoss.zul.Timer;
  18. import org.zkoss.zul.Window;
  19. /**
  20. *
  21. * @author ajay
  22. */
  23. public class MaxentProgressWCController extends UtilityComposer {
  24. RemoteLogger remoteLogger;
  25. Label jobstatus;
  26. Progressmeter jobprogress;
  27. Timer timer;
  28. Textbox tbPid;
  29. public String pid = null;
  30. //public MaxentWCController parent = null;
  31. public Window parent = null;
  32. @Override
  33. public void afterCompose() {
  34. super.afterCompose();
  35. timer.stop();
  36. }
  37. public void start(String pid_) {
  38. pid = pid_;
  39. tbPid.setValue(pid_);
  40. timer.start();
  41. onTimer$timer(null);
  42. }
  43. public void onTimer$timer(Event e) {
  44. if(parent == null) {
  45. parent = (Window) this.getParent();
  46. }
  47. //get status
  48. String status = get("status");
  49. if (status.length() > 0) {
  50. jobstatus.setValue(status);
  51. }
  52. String s = get("state");
  53. if (s.equals("job does not exist")) {
  54. timer.stop();
  55. getMapComposer().showMessage("Prediction request does not exist", "");//get("error"));
  56. this.detach();
  57. return;
  58. }
  59. System.out.println("**************** STATE: " + s);
  60. remoteLogger.logMapAnalysisUpdateStatus(pid, s);
  61. String p = get("progress");
  62. try {
  63. double d = Double.parseDouble(p);
  64. jobprogress.setValue((int) (d * 100));
  65. } catch (Exception ex) {
  66. }
  67. if (s.equals("SUCCESSFUL")) {
  68. timer.stop();
  69. Events.echoEvent("loadMap", parent, null);
  70. //parent.loadMap(null);
  71. this.detach();
  72. } else if (s.startsWith("FAILED")) {
  73. timer.stop();
  74. //String error_info = (s.contains(";")?"\n"+s.substring(s.indexOf(";")+1):"");
  75. String error_info = get("message");
  76. if (!error_info.equals("job does not exist")) {
  77. error_info = " with the following message: \n\n" + error_info;
  78. } else {
  79. error_info = "";
  80. }
  81. getMapComposer().showMessage("Prediction failed" + error_info);
  82. this.detach();
  83. this.parent.detach();
  84. } else if (s.equals("CANCELLED")) {
  85. timer.stop();
  86. getMapComposer().showMessage("Prediction cancelled by user");
  87. this.detach();
  88. }
  89. }
  90. String get(String type) {
  91. try {
  92. StringBuffer sbProcessUrl = new StringBuffer();
  93. sbProcessUrl.append(CommonData.satServer + "/ws/jobs/").append(type).append("?pid=").append(pid);
  94. HttpClient client = new HttpClient();
  95. GetMethod get = new GetMethod(sbProcessUrl.toString());
  96. get.addRequestHeader("Accept", "text/plain");
  97. client.getHttpConnectionManager().getParams().setSoTimeout(timer.getDelay());
  98. int result = client.executeMethod(get);
  99. String slist = get.getResponseBodyAsString();
  100. return slist;
  101. } catch (SocketTimeoutException e) {
  102. } catch (Exception e) {
  103. e.printStackTrace();
  104. }
  105. return "";
  106. }
  107. public void onClick$btnCancel(Event e) {
  108. get("cancel");
  109. this.detach();
  110. }
  111. public void onClick$btnHide(Event e) {
  112. showReferenceNumber();
  113. this.detach();
  114. }
  115. void showReferenceNumber() {
  116. //getMapComposer().showMessage("Reference number to retrieve results: " + pid);
  117. }
  118. }