Version Differences for Miscellaneous Scripts

(AHPSCRIPTS-20)
(AHPSCRIPTS-103)
Line 2061:
  }     }  
  }</pre>    }</pre> 
       
    + = Publish Output of Step Command in File in Report =  
       
    + ==== AHPSCRIPTS-111 ====  
    + <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 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();  
    + }  
       
       
    + String REPORT_NAME = "DB Log";  
    + String REPORT_FILE = "Database_Log.txt";  
    + String STEP_NAME = "Execute Database Patches"; // change to the name of the step  
       
    + JobTrace jobTrace = JobTraceLookup.getCurrent();  
       
    + StepTrace[] stepTraces = jobTrace.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);  
    +  
    + // create a report  
    + String reportPath = PublishPathHelper.getInstance().getPublishPath(JobTraceLookup.getCurrent(), REPORT_NAME);  
    + VarService vs = VarService.getInstance();  
    + reportPath = vs.resolve(reportPath);  
    +  
    + File reportDir = new File(reportPath);  
    + reportDir.mkdirs();  
    +  
    + File reportFile = new File(reportDir, REPORT_FILE);  
    + FileWriter writer = new FileWriter(reportFile);  
    + writer.write(output);  
    + writer.close();  
    +  
    + break;  
    + }  
    + }</pre>