Oracle BI EE 10.1.3.3/2 – Sending Reports to Non-OBI Users – Delivery Manager API of BI Publisher

Another common question that generally comes from end users is “How do we make OBI EE Delivers to email the reports to users who are not part of a Delivery profile?”. Well, there are a variety of ways to achieve this. Let us first list those down
1.   Create a dummy user and assign as many email ids as possible to this dummy user’s delivery profile. While using Delivers, send the reports out to all these users.
2.   Create SA system subject area in BI Administrator and let the subject area be populated from database using Init Blocks. In this case, all the email ids would come from the database.
3.   Use BI Publisher Delivery Manager API to accept multiple email ids as its parameter and send the report to various users.
Today, we shall be looking at the 3rd approach which is easier to implement. Also, this provides us with much more flexibility in delivering the reports to the end users. In order to use this approach, you need to go through the basics of calling Java Classes from Delivers in my blog entry here. For the Delivery Manager API of BI Publisher to work, we need to have the following jars.
a.   Activation.jar – You can get this jar from {OracleBI}\oc4j_bi\j2ee\home\lib
b.   Mail.jar – You can get this jar from {OracleBI}\oc4j_bi\j2ee\home\lib
c.   xdocore.jar – You can get this jar from {OracleBI}\oc4j_bi\j2ee\home\applications\xmlpserver\xmlpserver\WEB-INF\lib
d.   versioninfo.jar – You can get this jar from {OracleBI}\oc4j_bi\j2ee\home\applications\xmlpserver\xmlpserver\WEB-INF\lib
e.   schedulerrpccalls.jar – You can get this jar from {OracleBI}\web\javahost\lib\scheduler
Now open JDeveloper and include the above jars in your classpath. Also, create a Java Class to enter the below code.
package bieesoap;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import oracle.apps.xdo.delivery.DeliveryException;
import oracle.apps.xdo.delivery.DeliveryManager;
import oracle.apps.xdo.delivery.DeliveryPropertyDefinitions;
import oracle.apps.xdo.delivery.DeliveryRequest;
import com.siebel.analytics.scheduler.javahostrpccalls.SchedulerJavaExtension;
import com.siebel.analytics.scheduler.javahostrpccalls.SchedulerJobException;
import com.siebel.analytics.scheduler.javahostrpccalls.SchedulerJobInfo;
import java.io.File;
import javax.activation.CommandMap;
import javax.activation.MailcapCommandMap;
import oracle.apps.xdo.delivery.local.LocalPropertyDefinitions;
public class burstEmail implements SchedulerJavaExtension{
public burstEmail() {
}
public void run(SchedulerJobInfo jobInfo) throws SchedulerJobException {
try
{
FileInputStream fis = new FileInputStream(jobInfo.getResultSetFile());
DeliveryManager dm = new DeliveryManager();
DeliveryRequest req = dm.createRequest(DeliveryManager.TYPE_LOCAL);
req.addProperty(LocalPropertyDefinitions.LOCAL_DESTINATION, “D:\\Output.pdf”);
req.setDocument(fis);
req.submit();
if (req.getStatus() == DeliveryRequest.STATUS_SUCCESSFUL)
{
MailcapCommandMap mc = (MailcapCommandMap)CommandMap.getDefaultCommandMap();
mc.addMailcap(“text/html;; x-java-content-handler=com.sun.mail.handlers.text_html”);
mc.addMailcap(“text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml”);
mc.addMailcap(“text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain”);
mc.addMailcap(“multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed”);
mc.addMailcap(“message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822″);
CommandMap.setDefaultCommandMap(mc);
req = dm.createRequest(DeliveryManager.TYPE_SMTP_EMAIL);
req.addProperty(DeliveryPropertyDefinitions.SMTP_SUBJECT, “Mail from BI Delivers”);
req.addProperty(DeliveryPropertyDefinitions.SMTP_HOST, jobInfo.parameter(1));
req.addProperty(DeliveryPropertyDefinitions.SMTP_FROM, “BIEEDelivers-Admin@oracle.com”);
req.addProperty(DeliveryPropertyDefinitions.SMTP_TO_RECIPIENTS, jobInfo.parameter(0) );
req.addProperty(DeliveryPropertyDefinitions.SMTP_CONTENT_TYPE,”application/pdf”);
req.addProperty(DeliveryPropertyDefinitions.SMTP_CONTENT_FILENAME,”Output.pdf”);
req.setDocument(“D:\\Output.pdf”);
req.submit();
req.close();
}
}
catch(Exception ex)
{
throw new SchedulerJobException(1, 1, ex.getMessage());
}
}
public void cancel() {
}
}
      
As you see, what the above code basically does is, it first stores the report in a local destination and then sends that report out to all the users. jobInfo.parameter(0) can accept comma seperated email ids as parameter. Compile the above code and bundle it into a jar file (including all the above 4 jars). Now, put this deployed jar file in {OracleBI}\web\javahost\lib. This will make the jar file to be accessible by delivers. Once this is done, create a simple ibot with PDF as the attachment
      
Now, in the advanced tab of this ibot, call the above class as shown below. This will accept 2 parameters
   1. Comma Seperated Email ids to which you want to send the report to
   2. Your SMTP mail Server
      
Now, you should be able to send emails out to multiple users. You can use it or customize the above code to your convenience. Let me know if anyone needs the jar file, i will post it here.