Wednesday, 26 February 2014

Genarating CSV File from OAF:

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.io.FileWriter;




if("printErrors".equals(pageContext.getParameter(EVENT_PARAM))){
try

{
System.out.println("printErrors1");
String csv = "D:\\output.csv";
FileWriter writer = new FileWriter(csv);
Connection conn = am.getOADBTransaction().getJdbcConnection();

String Query = "select attribute1,attribute2,attribute3 from  XXX_ERROR_TBL";

PreparedStatement stmt = conn.prepareStatement(Query);
writer.append("File Name");
writer.append(',');
writer.append("Row Number");
writer.append(',');
writer.append("Error Message");
writer.append('\n');

for(ResultSet resultset = stmt.executeQuery(); resultset.next();)
{
pageContext.writeDiagnostics(this, "Query Executed", 1);
String result = resultset.getString("attribute1");
String result1 = resultset.getString("attribute2");
String result2 = resultset.getString("attribute3");
System.out.println("results are "+result);
System.out.println("results1 are "+result1);
System.out.println("results2 are "+result2);
writer.append(result);
writer.append(',');
writer.append(result1);
writer.append(',');
writer.append(result2);
writer.append('\n');

}
writer.flush();
writer.close();

}

catch(Exception exception)

{
throw new OAException("Error in Staffing Query"+exception, OAException.ERROR);
}

}//close if printErrors

// End writing CSV




How to Read CSV and insert Errors in Table dynamically:

if (pageContext.getParameter("uploadItm") != null) {
DataObject fileUploadData =
(DataObject)pageContext.getNamedDataObject("uploadFileItm2");
String fileName = null;
String contentType = null;
Long fileSize = null;
Integer fileType = new Integer(6);
BlobDomain uploadedByteStream = null;
BufferedReader in = null;
long count = 0;
long errorCount = 0;
String fileId=am.getOADBTransaction().getSequenceValue("gConItem_fileID_SEQ").toString();
try {
fileName =
(String)fileUploadData.selectValue(null, "UPLOAD_FILE_NAME");
contentType =
(String)fileUploadData.selectValue(null, "UPLOAD_FILE_MIME_TYPE");
uploadedByteStream =
(BlobDomain)fileUploadData.selectValue(null, fileName);
in =
new BufferedReader(new InputStreamReader(uploadedByteStream.getBinaryStream()));


fileSize = new Long(uploadedByteStream.getLength());
System.out.println("fileSize" + fileSize);
} catch (NullPointerException ex) {
throw new OAException("Please Select a File to Upload",
OAException.ERROR);
}


try {


//Open the CSV file for reading
String lineReader = "";
long t = 0;
int z = 1;
String removeRow="N";
String[] linetext;

while (((lineReader = in.readLine()) != null)) {

//Split the deliminated data and
if (lineReader.trim().length() > 0) {

linetext = lineReader.split(",");
t++;
count=t;
if (t > 1) {

//Print the current line being
int a = linetext.length;
// System.out.println("line text length is : "+a);
Row arrow = arvo.createRow();
// need to enable after altering table
// arrow.setAttribute("FileId",fileId);
removeRow="N";
for (int k = 0; k < a; k++)
{
try {
arrow.setAttribute(k,linetext[k].toString());
}
catch (Exception e)
{ //inserting errors in error table dynamically
Row errorrow = errorVO.createRow();
errorrow.setAttribute(0,fileName);
errorrow.setAttribute(1,t);
errorrow.setAttribute(2,e.getMessage().toString());
removeRow="Y";
break; }
//System.out.println("line number"+t+"and cloumn"+k);
// System.out.println(linetext[k]);
// arrow.setAttribute(k, linetext[k]);
}
if (removeRow.equalsIgnoreCase("N"))
{ arvo.insertRow(arrow);
}else{ arrow.remove(); errorCount++;
} z++;
if (z % 10000 == 0) am.getOADBTransaction().commit();
}
// System.out.println("record"+t);
}
// need to save records here
}
System.out.println("end time");
}
catch (IOException e)
{
throw new OAException(e.getMessage(), OAException.ERROR);
}
configId=pageContext.getParameter("configHeaderIdFV").toString();
String convItm=pageContext.getParameter("convertionItemFV").toString();
String ou=pageContext.getParameter("ouIdFv").toString();
String invOrg=null;
if(pageContext.getParameter("invOrgIdFV")!=null)
{ invOrg= pageContext.getParameter("invOrgIdFV").toString();}
System.out.println(pageContext.getParameter("configHeaderIdFV").toString()+"--"+pageContext.getParameter ("convertionItemFV").toString());
count=count-errorCount-1;
AM.addFilesDetails(configId,convItm,count,errorCount,fileName,ou,invOrg,fileId); }// end upload functionality


Tuesday, 25 February 2014


How to set read only property based on Value

in Query: decode(GConConfigLinesEO.RULE_TYPE,'STD','true','false') readonly

Create atribute in VO:

And set SPEL in Read Only Property:${oa.GConConfigLinesVO1.Readonly}
Uploading a file to perticuler location in server from Local mechine:


in PFR :
if(pageContext.getParameter("go")!=null){
upLoadFile( pageContext, webBean) ;
}
Now Wirite a custom method to upload file.

import below classes:

import java.io.File;
import java.io.FileOutputStream;
import oracle.jbo.domain.BlobDomain;
import java.io.InputStream;
import oracle.cabo.ui.data.DataObject;
import oracle.apps.fnd.framework.OAException;

public void upLoadFile(OAPageContext pageContext,OAWebBean webBean)
{ String filePath = "/oracle/DEV/apps/apps_st/appl/xxsea/12.0.0/data";
System.out.println("Default File Path---->"+filePath);

String fileUrl = null;
try
{
DataObject fileUploadData = pageContext.getNamedDataObject("MessageFileUpload");

//FileUploading is my MessageFileUpload Bean Id
if(fileUploadData!=null)
{
String uFileName = (String)fileUploadData.selectValue(null, "UPLOAD_FILE_NAME");
String contentType = (String) fileUploadData.selectValue(null, "UPLOAD_FILE_MIME_TYPE");
System.out.println("User File Name---->"+uFileName);

FileOutputStream output = null;
InputStream input = null;

BlobDomain uploadedByteStream = (BlobDomain)fileUploadData.selectValue(null, uFileName);
System.out.println("uploadedByteStream---->"+uploadedByteStream);

File file = new File("/oracle/DEV/apps/apps_st/appl/xxsea/12.0.0/data", uFileName);
System.out.println("File output---->"+file);

output = new FileOutputStream(file);

System.out.println("output----->"+output);
input = uploadedByteStream.getInputStream();

System.out.println("input---->"+input);
byte abyte0[] = new byte[0x19000];
int i;

while((i = input.read(abyte0)) > 0)
output.write(abyte0, 0, i);

output.close();
input.close();
}
}
catch(Exception ex)
{
throw new OAException(ex.getMessage(), OAException.ERROR);
} }

Calling Cuncorent Program from OAF Page.

In Application Module Create a custom method as below:
import below statements:


import java.util.Vector;
import oracle.apps.fnd.cp.request.ConcurrentRequest;
import oracle.apps.fnd.cp.request.RequestSubmissionException;
import oracle.apps.fnd.framework.OAException;
import oracle.apps.fnd.framework.server.OAApplicationModuleImpl;
import oracle.apps.fnd.framework.server.OADBTransaction;
import oracle.apps.fnd.framework.server.OAViewObjectImpl;
import oracle.jbo.Row;

// method to submit the cp
public int submitCPRequest(Number headerId) {

try {

OADBTransaction tx = (OADBTransaction)getDBTransaction();
java.sql.Connection pConncection = tx.getJdbcConnection();
ConcurrentRequest cr = new ConcurrentRequest(pConncection);

String applnName = "PO"; //Application that contains the concurrent program
String cpName = "POXCONST"; //Concurrent program name
String cpDesc = "Contract Status Report"; // concurrent Program description

// Pass the Arguments using vector
// Here i have added my parameter headerId to the vector and passed the vector to the concurrent program

Vector cpArgs = new Vector();
//cpArgs.addElement(headerId.toString());


// Calling the Concurrent Program

int requestId = cr.submitRequest(applnName, cpName, cpDesc, null, false, cpArgs);
tx.commit();

return requestId;

} catch (RequestSubmissionException e) {
OAException oe = new OAException(e.getMessage());
oe.setApplicationModule(this);
throw oe;

}
}

// end method to submit cp

//Calling above method
public int submitConcurrent Program(){

int reqid=submitCPRequest(1);
System.out.println("reqid"+reqid);
return reqid;

}


Monday, 17 February 2014

How to deployee OAF pages into Instaces

We can import OAF pages in two process:
1)From Jdev:
go to cmd prompt and change the directry to cd p6908968_R12_GENERIC\jdevbin\oaext\bin.
and run below command (before running please change the details).

example:
import D:\OAF\jdevhome\jdev\myprojects\test\oracle\apps\geogont\shopfloor\webui\test.xml -rootdir D:\OAF\jdevhome\jdev\myprojects -username apps -password welcomed1 -dbconnection "(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=))(CONNECT_DATA=(SID=)))"

2)Using linux:

Move the files into $JAVA_TOP/ and run the below example

java oracle.jrad.tools.xml.importer.XMLImporter $JAVA_TOP/xxmb/oracle/apps/xxcicms/contest/definition/webui/test.xml -rootdir $JAVA_TOP -username apps -password cmnewapps2013 -dbconnection "(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=))(CONNECT_DATA=(SID=)))"


Friday, 14 February 2014

setting alert in OAF




StringBuffer l_buffer = new StringBuffer();
String convertionType;
l_buffer.append("javascript:alert('"+convertionType+"')");
pageContext.putJavaScriptFunction("Name",l_buffer.toString());