File Uplaod OAF To DB
File Uplaod OAF To DB
Scope
File Uploading Utility is Customized solution in which users
will able to upload file from their system to application server.
In this Utility, we segregate user’s data by different user
groups.
Framework
This utility is design in Oracle Application Framework (EBS
12.1.3) using Java as frontend and PLSQL as backend. This
utility is configured with Oracle 11g database & Oracle E-
Business 12.1.3 application server.
Setup
Quality Plan
For this utility we setup quality plan and Profile
Option. That are used to record setup transactions
and apply security options.
I (Figure: 1)
Profile Options
We create new profile option. That will be assign to
User and user can upload file using that Group.
This Profile option can be site / Application /
Responsibility level. Using this feature user will able
to access multiple Groups of data.
Function
Defined new function and assign this function to
menu in application. In this function we define our
OAFpage URL in it.
Database Scripts
-- Create table
create table STM_CUST.SRL_FND_ATTACHMENTS
(
transaction_id NUMBER,
filename VARCHAR2(200),
creation_date DATE,
created_by NUMBER,
last_updated_by NUMBER,
last_update_login NUMBER,
last_update_date DATE,
form_name VARCHAR2(100),
content_type VARCHAR2(200),
attachments_id NUMBER
)
Shell Scripts
--This script import our custom OAF page on server.
java oracle.jrad.tools.xml.importer.XMLImporter
$JAVA_TOP/SRL/oracle/apps/fnd/file/webui/page1.x
ml -rootdir $JAVA_TOP -username apps -password
PasswordOFApps -dbconnection
"(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)
(HOST=HostIP)(PORT=HostPort))
(CONNECT_DATA=(SID= PROD_SID)))"
Java Classes
package SRL.oracle.apps.fnd.file.webui;
import SRL.oracle.apps.fnd.file.server.FileSetupVOImpl;
import SRL.oracle.apps.fnd.file.server.FileSetupVORowImpl;
import SRL.oracle.apps.fnd.file.server.SrlFndAttachmentsViewImpl;
import SRL.oracle.apps.fnd.file.server.SrlFndAttachmentsViewRowImpl;
import SRL.oracle.apps.fnd.file.server.UploadFileAMImpl;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.SQLException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.OAException;
import oracle.apps.fnd.framework.server.OADBTransaction;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.OAWebBeanConstants;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
import oracle.apps.fnd.framework.webui.beans.form.OAFormValueBean;
import oracle.apps.fnd.framework.webui.beans.layout.OAHeaderBean;
import oracle.apps.fnd.framework.webui.beans.message.OAMessageStyledTextBean;
import oracle.apps.fnd.framework.webui.beans.message.OAMessageTextInputBean;
import oracle.cabo.ui.data.DataObject;
import oracle.ias.cache.CacheAccess;
import oracle.jbo.RowSetIterator;
import oracle.jbo.domain.BlobDomain;
import oracle.jbo.domain.Number;
/**
* Controller for ...
*/
public class FileController extends OAControllerImpl {
public static final String RCS_ID = "$Header$";
public static final boolean RCS_ID_RECORDED =
VersionInfo.recordClassVersion(RCS_ID, "%packagename%");
/**
* Layout and page setup logic for a region.
* @param pageContext the current OA page context
* @param webBean the web bean corresponding to the region
*/
public void processRequest(OAPageContext pageContext, OAWebBean webBean) {
super.processRequest(pageContext, webBean);
UploadFileAMImpl am =
(UploadFileAMImpl)pageContext.getApplicationModule(webBean);
FileSetupVOImpl fileStepUpV = (FileSetupVOImpl) am.getFileSetupVO1();
fileStepUpV.executeQuery();
/**
* Procedure to handle form submissions for form elements in
* a region.
* @param pageContext the current OA page context
* @param webBean the web bean corresponding to the region
*/
public void processFormRequest(OAPageContext pageContext,
OAWebBean webBean) {
///Super object
super.processFormRequest(pageContext, webBean);
UploadFileAMImpl am =
(UploadFileAMImpl)pageContext.getApplicationModule(webBean);
if (EventName.equals("UploadFileToDB")) {
this.UploadFileToDB(pageContext, webBean, am);
}
if (EventName.equals("Filename")) {
this.downlaodFileFromServer(pageContext,webBean,am);
}
//SubGroupName
if (EventName.equals("SubGroupName")) {
this.QueryDetails(pageContext,webBean,am);
}
///Save Data
if (setupRec==null)
{
throw new OAException("Please select any group from Header for upload
files.",OAException.ERROR);
}
//AttachmentFile Data
DataObject fileUploadData =
(DataObject)pageContext.getNamedDataObject("AddAttachmentFile");
String fileName =
(String)fileUploadData.selectValue(null, "UPLOAD_FILE_NAME");
if (fileName == null) {
throw new OAException("Please select attachment file for upload.",
OAException.ERROR);
}
if (referenceNumber.getValue(pageContext)!=null)
{
try {
rf=(String)referenceNumber.getValue(pageContext);
refNum = new Number(rf);
}
catch (NumberFormatException e) {
// TODO
throw new OAException("Please enter valid number in Reference
field..",OAException.ERROR);
}
catch (SQLException e) {
// TODO
throw new OAException(e.getMessage(),OAException.ERROR);
}
}
SrlFndAttachmentsViewImpl AttachmentVo =
(SrlFndAttachmentsViewImpl)am.getSrlFndAttachmentsView1();
AttachmentVo.executeQuery();
SrlFndAttachmentsViewRowImpl attachmentRow =
(SrlFndAttachmentsViewRowImpl)AttachmentVo.createRow(); //Create new
Record
AttachmentVo.insertRow(attachmentRow);
OADBTransaction DBT =
(OADBTransaction)am.getDBTransaction(); /// DB Transaction
Number Attachment_id =
new Number(DBT.getSequenceValue("SRL_FND_ATTACHMENT_SEQ")); //attachmentID
attachmentRow.setAttachmentsId(Attachment_id);
attachmentRow.setFilename(fileName);
attachmentRow.setFormName(setupRec.getSrlFileSetupId());
attachmentRow.setContentType((String)fileUploadData.selectValue(null,
"UPLOAD_FILE_MIME_TYPE"));
if (refNum!=null)
{
attachmentRow.setTransactionId(refNum); //assign Transaction ID
this.uploadFileToServer(pageContext, fileName,
createBlobDomain(fileUploadData),setupRec.getSrlFileServerPath());
///
this.Save(am);
try {
String pFileName =
(String)pfileUploadData.selectValue(null, "UPLOAD_FILE_NAME");
BlobDomain uploadedByteStream =
(BlobDomain)pfileUploadData.selectValue(null, pFileName);
// Get the input stream representing the data from the client
in = uploadedByteStream.getInputStream();
// create the BlobDomain datatype to store the data in the db
blobDomain = new BlobDomain();
// get the outputStream for hte BlobDomain
out = blobDomain.getBinaryOutputStream();
byte buffer[] = new byte[8192];
for (int bytesRead = 0;
(bytesRead = in.read(buffer, 0, 8192)) != -1; )
out.write(buffer, 0, bytesRead);
in.close();
} catch (IOException e) {
e.printStackTrace();
} catch (SQLException e) {
e.fillInStackTrace();
}
// return the filled BlobDomain
return blobDomain;
}
(HttpServletResponse)pageContex.getRenderingContext().getServletResponse();
///Read File
if (!fileToDownload.canRead()) {
throw new OAException("Not Able to read the file.");
}
response.setContentType(fileType);
response.setContentLength((int)fileToDownload.length());
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName
+ "\"");
InputStream in = null;
ServletOutputStream outs = null;
try {
outs = response.getOutputStream();
in = new BufferedInputStream(new FileInputStream(fileToDownload));
int ch;
while ((ch = in.read()) != -1) {
outs.write(ch);
}
} catch (IOException e) {
// TODO
e.printStackTrace();
} finally {
try {
outs.flush();
outs.close();
if (in != null) {
in.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
//Get SetUpRecord
FileSetupVORowImpl setupRec =
(FileSetupVORowImpl)this.Get_SetupID(pageContext,webBean,am);
// Variable of View
SrlFndAttachmentsViewImpl attachmentVO = (SrlFndAttachmentsViewImpl)
am.getSrlFndAttachmentsView1();
if (l_FV==null)
{
throw new OAException("Please select any group from Header for upload
files.",OAException.ERROR);
}
// Find the Record that is Select for Query Details Block and Upload
Attachment
//
for(int i=0;i<setupVO.getRowCount();i++)
{
/// Get Row
// (0-Last Record) where Record=Parameter /Return record/ else /Null/
setupVO_rec =(FileSetupVORowImpl)setupVO_Itr.getRowAtRangeIndex(i);
if (l_FV.equals(setupVO_rec.getSrlFileSetupId()))
{
return setupVO_rec;
}
}
return null;
}
//Set SetUpID
public void Set_SetupID (OAPageContext pageContext, OAWebBean webBean, String
SetupID)
{
//Set SetupID Value
OAFormValueBean FV = (OAFormValueBean) webBean.findChildRecursive("SetupID");
FV.setValue(pageContext,SetupID);
}
/*
* GetRowIterator : Get RowSetIterator of View Objetc ,incase RowSetIterator is
not assosiated then Create it.
* @Param ViewObjectIMP
* */
public RowSetIterator GetRowIterator(FileSetupVOImpl pViewObject)
{
if (pViewObject.getRowSetIterator() == null)
{
//Create New RowIterator
return pViewObject.createRowSetIterator("FileSetupVOImpl");
}
else
{
//Create Existing RowIterator
return pViewObject.getRowSetIterator();
}
}
}
User Manual
As you click on Sub Group second section “Attachment list” will show your sub group
name as highlighted and also it will show already entered records.