Monday, April 2, 2012

Calling bip runReport from job manager

Here is a quick experiment with Oracle job scheduler manager. As Venkat blogged about long time ago, Oracle Job Manager can be used to call custom Java code. One customer of ours asked about using Job manager to run/schedule BI-Publisher reports? Why would you do that I asked? The final solution we ended up chosing used ADF pages and taskflows.
Privately, I decided to take the challenge and see how to go about implementing the requested functionality. I am taking the WS route and luckily bip comes with several awesome web services, one of them is runReport.
Create a new Jdeveloper generic application:
Application Name: jobManager
Package prefix: bip
Click Next and name your project
Project Name: bip


Next, we’ll add a proxy web service for the BIP server
Add a java class: callBIP


We need to add the 3 jars to the project in order to be able to run custom Java jobs.
    - schedulerrpccalls.jar
    - xdocore.jar
- versioninfor.jar
The code below will call the bip web services, pass in the report xdo absolute path to be run and save the output to the local drive .


package bip;
import com.oracle.xmlns.oxp.service.v2.AccessDeniedException_Exception;
import com.oracle.xmlns.oxp.service.v2.InvalidParametersException_Exception;
import com.oracle.xmlns.oxp.service.v2.OperationFailedException_Exception;
import com.oracle.xmlns.oxp.service.v2.ReportRequest;
import com.oracle.xmlns.oxp.service.v2.ReportResponse;
import com.oracle.xmlns.oxp.service.v2.ReportService;
import com.oracle.xmlns.oxp.service.v2.ReportService_Service;
import com.siebel.analytics.scheduler.javahostrpccalls.SchedulerJavaExtension;
import com.siebel.analytics.scheduler.javahostrpccalls.SchedulerJobException;
import com.siebel.analytics.scheduler.javahostrpccalls.SchedulerJobInfo;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class callBIP implements SchedulerJavaExtension {
public static String userID = "weblogic";
public static String password = "welcome1";
private static ReportService_Service reportService_Service;
        public void cancel() {
        }
    public void run(SchedulerJobInfo jobInfo) throws SchedulerJobException {
        reportService_Service = new ReportService_Service();
        ReportService reportService = reportService_Service.getV2ReportService();
        try {
//Take the first paramater as the report xdo file and call the bip web service
            ReportResponse reportOutput =
                callBIP.runBipReport(reportService, jobInfo.parameter(0));
//Save output to local drive
       String strFilePath = "C://temp//report.pdf";
       FileOutputStream out = new FileOutputStream(strFilePath);
            out.write(reportOutput.getReportBytes());
            out.close();           
        } catch (IOException e) {
            jobInfo.setMessage(e.getMessage());
            jobInfo.setStatus(2);
        } catch (InvalidParametersException_Exception e) {
           jobInfo.setMessage(e.getMessage());
            jobInfo.setStatus(2);
        } catch (AccessDeniedException_Exception e) {
           jobInfo.setMessage(e.getMessage());
            jobInfo.setStatus(2);
        } catch (OperationFailedException_Exception e) {
           jobInfo.setMessage(e.getMessage());
            jobInfo.setStatus(2);
        }
    }
    public static ReportResponse runBipReport(ReportService reportService,
                                           String reportName) throws InvalidParametersException_Exception,
                                                                            AccessDeniedException_Exception,
                                                                            OperationFailedException_Exception,
                                                                            FileNotFoundException,
                                                                            IOException {
        ReportRequest req = new ReportRequest();
        req.setAttributeLocale("en-US");
        req.setAttributeFormat("pdf");
        req.setReportAbsolutePath(reportName);
        ReportResponse reportOutput = reportService.runReport(req, userID, password);
        return reportOutput;
    }

    }
}

Compile the code and deploy the JAR file to the javahost lib directory.
Change the javahost config.xml flag to enable custom java code processing by javahost.

Start Job Manager and enter the class name bip.callBIP, the class Path jar file: bipFile.jar. The report full xdo path is passed as a parameter in the parameters section



Execute the job et voila
Of course reports can be scheduled as well using this approach.

a+
Fiston