Wednesday, July 4, 2012

How to Use Java package in side Lombardi (IBM BPM) ??

We all know that we can deploy custom jar files to Lombardi and use those classes with connectors.
But do we know that it is also possible to access those classes directly from the server script in the service where write the code using js. Here is an example of how to use that.
First add your jar files inside the teamworks libary which is available in location <installation                     directory>\applications\teamworks.ear\teamworks.war if your are using Lombardi Teamworks 6.2.
Alternatively if you are using Lombardi 7.x , add the jar as server file in the files available in on the Left side palette in the Authoring environment.

Below example is tested in Lombardi 6.2 and 7.1.  The custom jar that is used is itext.jar with slight modifcations.
In the below example we ave tried to create pdf file and save it at the location "applications\teamworks.ear\teamworks.war\html\custom".

var fileRoot = "applications\\teamworks.ear\\teamworks.war\\html\\custom"; 
var iText = Packages.com.lombardisoftware.consulting.utils.itext.IText.createITextDocument(fileRoot + "\\" + tw.local.currentDateString+'-'+tw.system.user_id + ".pdf", "Simple"); 
var norm = Packages.com.lombardisoftware.consulting.utils.itext.IText.getNormalFont(); 
var bold = Packages.com.lombardisoftware.consulting.utils.itext.IText.getBoldFont(); 
var subHeader = Packages.com.lowagie.text.FontFactory.getFont("ComicSansMS-Bold", 16); 
function ITextCreateTable() {
 return new Packages.com.lowagie.text.pdf.PdfPTable(2);
 }
 function ITextAddTableHeader(table, title) {
 var para = new Packages.com.lowagie.text.Paragraph(title, subHeader); 
var cell = new Packages.com.lowagie.text.pdf.PdfPCell(para);
 cell.setColspan(2); 
table.addCell(cell); 
}
 function ITextAddTableBoldCell(table, text) { 
var phr = new Packages.com.lowagie.text.Phrase(new java.lang.String(text), bold);
table.addCell(phr); 

function ITextAddTableCell(table, text) {
 var phr = new Packages.com.lowagie.text.Phrase(new java.lang.String(text), norm);
 table.addCell(phr); }
 // Header
 try {
 var doc = iText.doc; Packages.com.lombardisoftware.consulting.utils.itext.IText.addTitle(iText, "Onboarding Request for " + tw.local.user.firstName + "\n"); Packages.com.lombardisoftware.consulting.utils.itext.IText.addTitle(iText, " ");
 // Empty Para for space.. 
// Content
 if (true) {
 var table = ITextCreateTable(); 
ITextAddTableHeader(table, "Account Request");
 ITextAddTableBoldCell(table, "User Name:"); 
ITextAddTableCell(table, tw.local.user.firstName+" "+tw.local.user.lastName );
 doc.add(table);
 Packages.com.lombardisoftware.consulting.utils.itext.IText.addTitle(iText, " "); // Empty Para for space.. 
}
 if (true) { 
var table = ITextCreateTable(); 
ITextAddTableHeader(table, "Email Request");
 ITextAddTableBoldCell(table, "Email Address:");
 ITextAddTableCell(table, tw.local.user.email); 
doc.add(table);
 Packages.com.lombardisoftware.consulting.utils.itext.IText.addTitle(iText, " "); // Empty Para for space.. 
}
 if (true) {
 var table = ITextCreateTable();
 ITextAddTableHeader(table, "Profession Request"); 
ITextAddTableBoldCell(table, "Profession:");
 ITextAddTableCell(table, tw.local.user.profession);
 doc.add(table); 
Packages.com.lombardisoftware.consulting.utils.itext.IText.addTitle(iText, " "); // Empty Para for space.. 
}
 if (true) { 
var table = ITextCreateTable();
 ITextAddTableHeader(table, "Employment Request");
 ITextAddTableBoldCell(table, "Employed:");
 ITextAddTableCell(table, tw.local.user.employed);
 doc.add(table);
 Packages.com.lombardisoftware.consulting.utils.itext.IText.addTitle(iText, " "); // Empty Para for space..
 }
 if (true) { var table = ITextCreateTable();
 ITextAddTableHeader(table, "Social Security Request");
 ITextAddTableBoldCell(table, "SSN:"); 
ITextAddTableCell(table, tw.local.user.ssn);
 doc.add(table);
 Packages.com.lombardisoftware.consulting.utils.itext.IText.addTitle(iText, " "); // Empty Para for space..
 } // Adding a signature field in AcroForm format... 
var acroForm = iText.writer.getAcroForm(); 
acroForm.addSignature("approve", 50, 20, 400, 50); } 
finally { iText.doc.close(); 
}

Similar script can be written for using any jar. 
Some one can try it and let me know if it is not working.




No comments:

Post a Comment