(→Embed the content of a report into a notification)
|
(→AHPSCRIPTS-23)
|
Line 57: | |||
context.put("reports", reports); | context.put("reports", reports); | ||
}</pre> | }</pre> | ||
+ | = Retrieves Step Trace on Job Trace and Sends Output Via E-mail = | ||
+ | * The following needs to go into the Context Script of a notification template. Then, reference the log in the template text as $output for unformatted text, or <pre>$output</pre> if you want it formatted. | ||
+ | ==== AHPSCRIPTS-138 ==== | ||
+ | <pre>import com.urbancode.anthill3.domain.jobtrace.*; | ||
+ | import com.urbancode.anthill3.domain.workflow.*; | ||
+ | import com.urbancode.anthill3.runtime.paths.*; | ||
+ | import com.urbancode.anthill3.services.file.*; | ||
+ | import com.urbancode.devilfish.services.file.FileInfo; | ||
+ | import com.urbancode.devilfish.services.var.VarService; | ||
+ | import com.urbancode.anthill3.domain.workflow.WorkflowCase; | ||
+ | import java.io.*; | ||
+ | private String getStreamAsString(InputStream inStream) | ||
+ | throws IOException { | ||
+ | StringBuffer result = new StringBuffer(); | ||
+ | try { | ||
+ | byte[] buffer = new byte[4096]; | ||
+ | int length = 0; | ||
+ | while ((length = inStream.read(buffer)) > 0) { | ||
+ | result.append(new String(buffer, 0, length)); | ||
+ | } | ||
+ | } | ||
+ | finally { | ||
+ | try { | ||
+ | inStream.close(); | ||
+ | } | ||
+ | catch (Exception e) {} | ||
+ | } | ||
+ | return result.toString(); | ||
+ | } | ||
+ | WorkflowCase workflow = (WorkflowCase)context.get("workflow"); | ||
+ | String STEP_NAME = "echoer"; // change to the name of the step | ||
+ | jobTraces = workflow.getJobTraceArray(); | ||
+ | for (int j=0; j<jobTraces.length; j++){ | ||
+ | StepTrace[] stepTraces = jobTraces[j].getStepTraceArray(); | ||
+ | for (int s=0; s<stepTraces.length; s++) { | ||
+ | if (STEP_NAME.equals(stepTraces[s].getName())) { | ||
+ | // found the step | ||
+ | CommandTrace cmdTrace = stepTraces[s].getCommandTraceArray()[0]; | ||
+ | FileInfo outputFile = LogPathHelper.getInstance().getLogFileInfoArray(cmdTrace)[0]; | ||
+ | InputStream inStream = FileInfoService.getInstance().getFileInfoAsStream(outputFile); | ||
+ | String output = getStreamAsString(inStream); | ||
+ | |||
+ | context.put("output", output); | ||
+ | |||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | }</pre> |