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