@@ -13,6 +13,7 @@ |
import csip.annotations.Polling; |
import csip.annotations.Resource; |
import static csip.annotations.ResourceType.EXECUTABLE; |
+import static csip.annotations.ResourceType.FILE; |
import static csip.annotations.ResourceType.OUTPUT; |
import java.io.BufferedReader; |
import java.io.File; |
@@ -20,7 +21,6 @@ |
import java.io.FileReader; |
import java.io.IOException; |
import java.io.PrintWriter; |
-import java.net.URL; |
import java.sql.Connection; |
import java.sql.ResultSet; |
import java.sql.SQLException; |
@@ -31,7 +31,6 @@ |
import javax.ws.rs.Path; |
import oms3.annotations.Description; |
import oms3.annotations.Name; |
-import org.codehaus.jettison.json.JSONException; |
import rhem.utils.DBResources; |
|
/** |
@@ -47,8 +46,9 @@ |
@Path("m/rhem/runrhem/1.0") |
@Polling(first = 10000, next = 2000) |
@Resource(from = DBResources.class) |
-@Resource(file = "/bin/win-x86/rhem_v2.3.exe", id = "rhem", type = EXECUTABLE) |
+@Resource(file = "/bin/win-x86/rhem_v2.3.exe", wine = true, id = "rhem", type = EXECUTABLE) |
@Resource(file = "*.par *.pre *.sum *.out", type = OUTPUT) |
+@Resource(file = "/bin/win-x86/storm_input_865_5517.pre", type = FILE) |
|
public class V1_0 extends ModelDataService { |
|
@@ -93,34 +93,37 @@ |
|
@Override |
public void doProcess() throws ServiceException, FileNotFoundException, IOException { |
-// try (Connection connection = getResourceJDBC(DBResources.MSSQL_SSURGO);) { |
- this.parameterFileName = aoa.scenarioName + ".par"; |
- this.stormFileName = aoa.scenarioName + ".pre"; |
- this.summaryFileName = aoa.scenarioName + ".sum"; |
+ try { |
+ this.parameterFileName = aoa.scenarioName + ".par"; |
+ this.stormFileName = "storm_input_865_5517.pre"; |
+ this.summaryFileName = aoa.scenarioName + ".sum"; |
|
- String line = null; |
- FileReader fileReader |
- = new FileReader("storm_input_865_5517.pre"); |
+ String line = null; |
+ FileReader fileReader = new FileReader(this.stormFileName); |
+ try (BufferedReader bufferedReader |
+ = new BufferedReader(fileReader)) { |
+ try (PrintWriter writer |
+ = new PrintWriter(new File(getWorkspaceDir(), this.stormFileName))) { |
+ while ((line = bufferedReader.readLine()) != null) { |
+ writer.println(line); |
+// System.out.println(line); |
+ } |
+ } catch (FileNotFoundException ex) { |
+ LOG.log(Level.SEVERE, "RHEM-01: FileNotFoundException.", ex); |
+ throw new ServiceException("Problem in writing .par file", ex); |
+ } |
+ } catch (Exception e) { |
+ LOG.log(Level.SEVERE, "RHEM-01: ", e); |
+ throw new ServiceException("Exception: ", e); |
+ } |
|
- // Always wrap FileReader in BufferedReader. |
- BufferedReader bufferedReader |
- = new BufferedReader(fileReader); |
- |
- while ((line = bufferedReader.readLine()) != null) { |
- System.out.println(line); |
+ this.generateParamFile(); |
+// this.generateSummaryFile(); |
+ System.out.println("run model = " + this.runModel()); |
+ } catch (Exception e) { |
+ LOG.log(Level.SEVERE, "RHEM-01: ", e); |
+ throw new ServiceException("Exception: ", e); |
} |
- |
- // Always close files. |
- bufferedReader.close(); |
- |
- |
- this.generateParamFile(); |
- this.generateSummaryFile(); |
-// this.runModel(); |
-// } catch (ServiceException | SQLException se) { |
-// LOG.log(Level.SEVERE, "RHEM-01: SQLException.", se); |
-// throw new ServiceException("SQL problem.", se); |
-// } |
} |
|
private void generateParamFile() throws ServiceException { |
@@ -411,20 +414,18 @@ |
|
private void generateSummaryFile() { |
|
- |
- |
} |
|
private String runModel() throws ServiceException { |
int run = -1; |
try { |
- Executable rhem = getResourceExe("rhem"); |
-// rhem.setArguments("-b", "scenarion_run_3678.run"); |
- rhem.setArguments(this.parameterFileName, this.stormFileName, |
+ Executable rh = getResourceExe("rhem"); |
+ rh.setArguments(this.parameterFileName, this.stormFileName, |
this.summaryFileName, aoa.scenarioName, 0, 2, "y", "y", "n", "n", "y"); |
- run = rhem.exec(); |
+ run = rh.exec(); |
|
- } catch (ServiceException | IOException se) { |
+// } catch (ServiceException | IOException se) { |
+ } catch (Exception se) { |
LOG.log(Level.SEVERE, "RHEM-01: ", se); |
throw new ServiceException("Problem in running the model.", se); |
} |
@@ -432,15 +433,15 @@ |
} |
|
@Override |
- public void postProcess() { |
- |
-// try { |
-// putResult(new File(getWorkspaceDir(), "abc.par"), "summary"); |
- putReport(new File(getWorkspaceDir(), this.parameterFileName), "Parameter input file"); |
-// } catch (JSONException ex) { |
-// LOG.log(Level.SEVERE, "RHEM-01: Error in processing the reponse JSON.", e); |
-// throw new ServiceException("Error in processing the reponse JSON.", e); |
-// } |
+ public void postProcess() throws Exception { |
+ try { |
+ putReport(new File(getWorkspaceDir(), this.parameterFileName), "Parameter input file"); |
+ putReport(new File(getWorkspaceDir(), this.stormFileName), "Storm input file"); |
+ putReport(new File(getWorkspaceDir(), this.summaryFileName), "Summary file"); |
+ } catch (Exception e) { |
+ LOG.log(Level.SEVERE, "RHEM-01: ", e); |
+ throw new Exception("", e); |
+ } |
} |
|
static class AoA { |