import groovy.transform.CompileStatic; import com.oracle.e1.common.OrchestrationAttributes; import java.sql.*; import groovy.sql.Sql; import java.util.Date; @CompileStatic HashMap main(OrchestrationAttributes orchAttr, Sql sqlInst, HashMap inputMap) { //write some debug log entries just for testing, these are written to the AIS server log orchAttr.writeWarn("START Groovy Record Vineyard Conditions Connector"); orchAttr.writeWarn("VineyardID " + (String)inputMap.get("VineyardID ")); orchAttr.writeWarn("Precipitation " + (String)inputMap.get("Precipitation")); orchAttr.writeWarn("Moisture Content " + (String)inputMap.get("Moisture Content")); orchAttr.writeWarn("High Temp " + (String)inputMap.get("High Temp")); orchAttr.writeWarn("Low Temp " + (String)inputMap.get("Low Temp")); //build a map for the set of return values HashMap returnMap = new HashMap(); //get inputs and convert to correct types as needed def today = new Date(); def todayString = today.format("yyyy/MM/dd") String vId = (String)inputMap.get("VineyardID"); BigDecimal precip = new BigDecimal((String)inputMap.get("Precipitation")); BigDecimal moist = new BigDecimal((String)inputMap.get("Moisture Content")); BigDecimal high = new BigDecimal((String)inputMap.get("High Temp")); BigDecimal low = new BigDecimal((String)inputMap.get("Low Temp")); //define the SQL insert statement def sqlstr = "INSERT INTO VINEYARD_MOISTURE VALUES (${todayString}, ${vId}, ${precip}, ${moist}, ${high}, ${low})"; try{ //execute the statement def retVal = sqlInst.execute(sqlstr); //set the return error in the return map (as a string) returnMap.put("insertError", Boolean.toString(retVal)); } catch(Exception e) { //insert failed try { //delete and re-acreate it def delsql = "DELETE FROM VINEYARD_MOISTURE WHERE DATE= ${todayString} AND LOCATION= ${vId}"; sqlInst.execute(delsql); def retVal = sqlInst.execute(sqlstr); //return the status of this insert returnMap.put("insertError", Boolean.toString(retVal)); } catch (Exception ex) { //return the exception in the error returnMap.put("insertError", e.getMessage()); //write any exceptions to the log orchAttr.writeWarn("Insert to Vineyard History Failed ", e); } } //write the return values to the log orchAttr.writeWarn("returnMap " + returnMap); //return the map containing return values return returnMap; }