From b819430315217868e39609f16a805143e569165b Mon Sep 17 00:00:00 2001
From: Elena.Budnik <ebudnik@irap.omp.eu>
Date: Fri, 23 Mar 2018 16:34:27 +0100
Subject: [PATCH] getPlot final

---
 php/classes/WebServer.php      | 90 ++++++++++++++++++++++++++++++++++++------------------------------------------------------
 php/rest/getDataset.php        |  2 +-
 php/rest/getTimeTablesList.php |  2 --
 public/wsdl/Methods_AMDA.wsdl  | 63 +++++++++++++++++----------------------------------------------
 4 files changed, 54 insertions(+), 103 deletions(-)

diff --git a/php/classes/WebServer.php b/php/classes/WebServer.php
index d9fd6dd..8be2454 100644
--- a/php/classes/WebServer.php
+++ b/php/classes/WebServer.php
@@ -71,6 +71,11 @@ class WebServer
 			return array("error" => $msg);
 	}
 	
+	private function isGetPlotRequest($name){
+
+		return (substr($name,0,7) == 'getplot');
+	}
+	
 	private function xsl2vot($inputName, $outputName) 
 	{   
 		// Load Time table
@@ -148,20 +153,6 @@ class WebServer
 
 		return WSConfigClass::getUrl().$ttListResult;
 	}
-	
-	public function getResultPlot($data) 
-	{			
-		$res = $this->init($data);
-		$vars = $res['vars'];
-		$ID = $vars["plotDirectoryURL"];
-		$filename = WSRESULT.$ID."/request.list.png";
-		if (file_exists($filename)) {
-			$plotWSresult=WSRESULT.$ID."/request.list.png";
-			return array('success' => true, 'plotFileURL' => 'http://'.str_replace(BASE_PATH,$_SERVER['SERVER_NAME'].APACHE_ALIAS,$plotWSresult));
-		}
-		else
-			return array('success' => false);
-	}
 
 /*
 *  Get corresponding orbit parameter ID
@@ -537,7 +528,9 @@ class WebServer
 					$this->throwError("processError","Cannot retrieve process $id info");
 				}
 				
-				return  array('success' => true, 'status' => 'done',  'dataFileURLs' => WSConfigClass::getUrl().$res['result']);
+				$resultTag = $this->isGetPlotRequest($res['result']) ? 'plotURL' : 'dataFileURLs';
+				
+				return  array('success' => true, 'status' => 'done',  $resultTag => WSConfigClass::getUrl().$res['result']);
 			} 
 			catch (Exception $e) 
 			{
@@ -558,7 +551,10 @@ class WebServer
 		}
 		
 		$this->deleteProcess($res['id']);
-		return  array('success' => true, 'status' => $res['status'],  'dataFileURLs' => WSConfigClass::getUrl().$res['result']);
+		
+		$resultTag = $this->isGetPlotRequest($res['result']) ? 'plotURL' : 'dataFileURLs';
+		
+		return  array('success' => true, 'status' => $res['status'],  $resultTag => WSConfigClass::getUrl().$res['result']);
 	}
 	
 /*
@@ -675,8 +671,11 @@ class WebServer
 		
 		$vars = $res['vars'];
 		$mission = $vars["missionID"];
-
-		$resDirName = WSConfigClass::getWsResultDir();  // Define a temporary  directory for results
+		
+		$resultFilePrefix = strtolower(__FUNCTION__)."_".$mission."_".date("YmdHms",strtotime($vars["startTime"]))."_".date("YmdHms",strtotime($vars["stopTime"]));
+		
+		if ($this->userID != "impex") 
+			$resultFilePrefix .= "_".$this->userID;
 
 		$dom = new DomDocument("1.0");
 		$dom->load(plotsXml);
@@ -691,51 +690,22 @@ class WebServer
 		$requestObject = (Object) array(
 			"nodeType" => "request",
 			"file-format" => "PNG",
-			"file-output" => "WS",
-			"ws-result-file" => $resDirName."/request.list.png",
-			"last-plotted-tab" => 1,
+			"result-file" => $resultFilePrefix,
 			"timesrc" => "Interval",
 			"startDate" => $vars["startTime"],
 			"stopDate" => $vars["stopTime"],
-			"tabs" => array()
+			"parameters" => array()
 		);
     
-		$pageObject = (Object) array(
-			"panels" => array()
-		);
-
 		foreach ($paramsList as $paramToPlot)
 		{
-			$panelObject = (Object) array(
-				"panel-plot-type" => "timePlot",
-				"axes" => array(),
-				"params" => array()
-			);
-			
-			$timeAxisObject = (Object) array(
-			);
-			$panelObject->{"axes"}[] = $timeAxisObject;
-
-			$yAxisObject = (Object) array(
-			);
-			$panelObject->{"axes"}[] = $yAxisObject;
-			
 			$paramObject = (Object) array(
-				"id" => 1,
-				"paramid" => $paramToPlot,
-				"param-drawing-type" => "serie",
-				"param-drawing-object" => (Object) array(
-					"serie-yaxis" => "y-left",
-					"serie-lines-activated" => true
-				)
+				"paramid" => $paramToPlot
 			);
-			$panelObject->{"params"}[] = $paramObject;
 			
-			$pageObject->{"panels"}[] = $panelObject;
+			$requestObject->{"parameters"}[] = $paramObject;
 		}
-		
-		$requestObject->{"tabs"}[] = $pageObject;
-		
+
 		$this->service = strtolower(__FUNCTION__);
 		
 		if (!isset($this->requestManager))
@@ -746,8 +716,20 @@ class WebServer
 		} catch (Exception $e) {
 				$this->throwError("plotError", "Exeption detected : ".$e->getMessage());
 		}
-
-		return array('success' => true, 'plotDirectoryURL' => $ID);
+		
+		if (!$plotResult['success']) {
+			$this->throwError("serverError", $plotResult['message']);
+		}
+		
+		if($plotResult['status'] == 'in_progress') {
+			return ['success' => true, 'status' => 'in progress', 'id' => $plotResult['id']];
+		} elseif ($plotResult['status'] == 'done') 
+		{
+			$this->deleteProcess($plotResult['id']);
+			return array('success' => true, 'status' => 'done', 'plotFileURL' => WSConfigClass::getUrl().$plotResult['result']);
+		} else {
+			return ['success' => false, 'message' => 'Unknown status ' . $plotResult['status']];
+		} 
 	}
 }
 ?>
diff --git a/php/rest/getDataset.php b/php/rest/getDataset.php
index 15b0156..8452487 100644
--- a/php/rest/getDataset.php
+++ b/php/rest/getDataset.php
@@ -24,4 +24,4 @@
 	}
 
 	echo json_encode($result);
-	?>
+?>
diff --git a/php/rest/getTimeTablesList.php b/php/rest/getTimeTablesList.php
index 6711158..c0cf9f9 100644
--- a/php/rest/getTimeTablesList.php
+++ b/php/rest/getTimeTablesList.php
@@ -20,5 +20,3 @@
 		echo $result['message'];  
 	}
 ?>
-
-
diff --git a/public/wsdl/Methods_AMDA.wsdl b/public/wsdl/Methods_AMDA.wsdl
index c675bc7..7f4dd5b 100644
--- a/public/wsdl/Methods_AMDA.wsdl
+++ b/public/wsdl/Methods_AMDA.wsdl
@@ -36,9 +36,6 @@
             <xs:element name="getPlot" type="tns:getPlot"/>
             <xs:element name="getPlotResponse" type="tns:getPlotResponse"/>
 
-            <xs:element name="getResultPlot" type="tns:getResultPlot"/>
-            <xs:element name="getResultPlotResponse" type="tns:getResultPlotResponse"/>
-
             <xs:element name="getOrbites" type="tns:getOrbites"/>
             <xs:element name="getOrbitesResponse" type="tns:getOrbitesResponse"/> 
 
@@ -791,6 +788,12 @@ of a set of typically orthogonal axes.
                                 required parameters</xs:documentation>
                         </xs:annotation>
                     </xs:element>
+						  <xs:element maxOccurs="1" minOccurs="0" name="plotURL" type="xs:anyURI">
+                        <xs:annotation>
+                            <xs:documentation>URLs of results plot files. If no URLs - no data for
+                                required parameters</xs:documentation>
+                        </xs:annotation>
+                    </xs:element>
                     <xs:element maxOccurs="1" minOccurs="0" name="status">
                         <xs:annotation>
                             <xs:documentation></xs:documentation>
@@ -948,32 +951,23 @@ of a set of typically orthogonal axes.
                             <xs:documentation>success or not</xs:documentation>
                         </xs:annotation>
                     </xs:element>
-                    <xs:element name="plotDirectoryURL" type="xs:string" minOccurs="1" maxOccurs="1">
-                        <xs:annotation>
-                            <xs:documentation>URL of directory of png file</xs:documentation>
-                        </xs:annotation>
-                    </xs:element>
-                </xs:sequence>
-            </xs:complexType>           
-
-            <xs:complexType name="getResultPlot">
-                <xs:sequence>
-                    <xs:element name="plotDirectoryURL" type="xs:string" minOccurs="1" maxOccurs="1">
+                  <xs:element maxOccurs="1" minOccurs="0" name="status">
                         <xs:annotation>
-                            <xs:documentation>URL of directory of png file</xs:documentation>
+                            <xs:documentation></xs:documentation>
                         </xs:annotation>
+                        <xs:simpleType>
+                            <xs:restriction base="xs:string">
+                                <xs:enumeration value="in progress"/>
+                                <xs:enumeration value="error"/>
+                            </xs:restriction>
+                        </xs:simpleType>
                     </xs:element>
-                </xs:sequence>
-            </xs:complexType>           
-
-            <xs:complexType name="getResultPlotResponse">
-                <xs:sequence>
-                    <xs:element name="success" minOccurs="1" maxOccurs="1" type="xs:boolean">
+                     <xs:element maxOccurs="1" minOccurs="0" name="id" type="xs:string">
                         <xs:annotation>
-                            <xs:documentation>success=true if plot exists and else false </xs:documentation>
+                            <xs:documentation>process ID</xs:documentation>
                         </xs:annotation>
                     </xs:element>
-                    <xs:element name="plotFileURL" type="xs:anyURI" minOccurs="0" maxOccurs="1">
+                    <xs:element name="plotFileURL" type="xs:string" minOccurs="0" maxOccurs="1">
                         <xs:annotation>
                             <xs:documentation>URL of png file</xs:documentation>
                         </xs:annotation>
@@ -1214,14 +1208,6 @@ of a set of typically orthogonal axes.
         <wsdl:part name="parameters" element="tns:getPlotResponse"> </wsdl:part>
     </wsdl:message>
 
-    <wsdl:message name="getResultPlot">
-        <wsdl:part name="parameters" element="tns:getResultPlot"> </wsdl:part>
-    </wsdl:message>
-
-    <wsdl:message name="getResultPlotResponse">
-        <wsdl:part name="parameters" element="tns:getResultPlotResponse"></wsdl:part>
-    </wsdl:message>
-
     <wsdl:message name="getStatus">
         <wsdl:part name="parameters" element="tns:getStatus"></wsdl:part>
     </wsdl:message>
@@ -1290,11 +1276,6 @@ of a set of typically orthogonal axes.
             <wsdl:output message="tns:getPlotResponse"> </wsdl:output>
         </wsdl:operation>
         
-        <wsdl:operation name="getResultPlot">
-            <wsdl:input message="tns:getResultPlot"> </wsdl:input>
-            <wsdl:output message="tns:getResultPlotResponse"> </wsdl:output>
-        </wsdl:operation>
-        
         <wsdl:operation name="getOrbites">
             <wsdl:input message="tns:getOrbites"> </wsdl:input>
             <wsdl:output message="tns:getOrbitesResponse"> </wsdl:output>
@@ -1392,16 +1373,6 @@ of a set of typically orthogonal axes.
             </wsdl:output>
         </wsdl:operation>
  
-        <wsdl:operation name="getResultPlot">
-            <soap:operation soapAction="" style="document"/>
-            <wsdl:input>
-                <soap:body use="literal"/>
-            </wsdl:input>
-            <wsdl:output>
-                <soap:body use="literal"/>
-            </wsdl:output>
-        </wsdl:operation>
- 
         <wsdl:operation name="getOrbites">
             <soap:operation soapAction="" style="document"/>
             <wsdl:input>
--
libgit2 0.21.2