import groovy.transform.CompileStatic; import com.oracle.e1.common.OrchestrationAttributes; import java.sql.*; import groovy.sql.Sql; import groovy.json.JsonOutput; @CompileStatic HashMap main(OrchestrationAttributes orchAttr, Sql sql, HashMap inputMap) { //get the vineyard from the inputs def vineyard = (String)inputMap.get("Vineyard"); //create the output map HashMap returnMap = new HashMap(); try { //execute the sql for average moisture and high for that vineyard, and return the first row def first = sql.firstRow("SELECT AVG(MOISTURE), AVG(HIGH) FROM VINEYARD_MOISTURE WHERE LOCATION=${vineyard} order by date desc"); //log the resulting values orchAttr.writeWarn("first: " + first); orchAttr.writeWarn("first avg moisture: " + first.getProperty("AVG(MOISTURE)")); orchAttr.writeWarn("first avg high: " + first.getProperty("AVG(HIGH)")); if(first != null) { //if a row was returned add the values to the output returnMap.put("averageMoisture", first.getProperty("AVG(MOISTURE)")); returnMap.put("averageHigh", first.getProperty("AVG(HIGH)")); returnMap.put("averageError", Boolean.toString(false)); } } catch(Exception e) { //log any exceptions and return them in the output orchAttr.writeWarn("try to put rows in json",e); returnMap.put("averageError", e.getMessage()); } //write the return values to the log orchAttr.writeWarn("returnMap " + returnMap); return returnMap; }