Map startEventParams = new HashMap();
startEventParams.put(EVENT_TYPE, DOCUMENT_EXECUTION_START);
startEventParams.put(BIOBJECT_ID, _parameters.get(EngineConstants.ENV_DOCUMENT_ID));
Integer startEventId = null;
EventServiceProxy eventServiceProxy = (EventServiceProxy)_parameters.get( EngineConstants.ENV_EVENT_SERVICE_PROXY);
try {
String startEventParamsStr = getParamsStr(startEventParams);
eventServiceProxy.fireEvent(startExecutionEventDescription + parametersList, startEventParamsStr,
TALEND_ROLES_HANDLER_CLASS_NAME, TALEND_PRESENTAION_HANDLER_CLASS_NAME);
logger.debug("Start Fire Event");
} catch (Exception e) {
logger.error("problems while registering the start process event", e);
}
if (_command == null) {
logger.error("No command to be executed");
return;
}
Map endEventParams = new HashMap();
endEventParams.put(EVENT_TYPE, DOCUMENT_EXECUTION_END);
// endEventParams.put("biobj-path", params.get(TEMPLATE_PATH));
endEventParams.put(BIOBJECT_ID, _parameters.get("document"));
if (startEventId != null) {
endEventParams.put(START_EVENT_ID, startEventId.toString());
}
String endExecutionEventDescription = null;
BufferedReader input = null;
try {
logger.debug("Java Command:"+_command);
logger.debug("Executable Job Dir:"+_executableJobDir);
Process p = Runtime.getRuntime().exec(_command, _envr, _executableJobDir);
// any error message?
StreamGobbler errorGobbler = new
StreamGobbler(p.getErrorStream(), "ERROR");
// any output?
StreamGobbler outputGobbler = new
StreamGobbler(p.getInputStream(), "OUTPUT");
// kick them off
errorGobbler.start();
outputGobbler.start();
int exitCode = p.waitFor();
//CODICE DA USARE EVENTUALMENTE IN FUTURO CON ALTRE MODIFICHE:
/*this.talendJobClass = Class.forName(talendJobClassName);
this.runJob = this.talendJobClass.getMethod("runJob", new Class[]{String[].class});
int status = ((Integer)runJob.invoke(null, mainMethodParams)).intValue(); */
endExecutionEventDescription = "${talend.execution.executionOk}<br/>";
endEventParams.put("operation-result", "success");
} catch (Throwable e) {
logger.error("Error while executing command " + _command, e);
endExecutionEventDescription = "${talend.execution.executionKo}<br/>";
endEventParams.put("operation-result", "failure");
} finally {
if (_filesToBeDeletedAfterJobExecution != null && _filesToBeDeletedAfterJobExecution.size() > 0) {
Iterator it = _filesToBeDeletedAfterJobExecution.iterator();
while (it.hasNext()) {
File aFile = (File) it.next();
if (aFile != null && aFile.exists())
FileUtils.deleteDirectory(aFile);
}
}
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
try {
String endEventParamsStr = getParamsStr(endEventParams);
eventServiceProxy.fireEvent(endExecutionEventDescription + parametersList, endEventParamsStr,
TALEND_ROLES_HANDLER_CLASS_NAME, TALEND_PRESENTAION_HANDLER_CLASS_NAME);
logger.debug("End fire event");
} catch (Exception e) {
logger.error("problems while registering the end process event", e);