Wednesday 13 July 2011

OAF Date Convertion, Typed in Java and OAF

import java.util.*;
import java.text.*;
public class StringToDate {
   public static void main(String[] args)
{
 try
{   
String str_date="11-June-07";
         DateFormat formatter ;
     Date date ;
          formatter = new SimpleDateFormat("dd-MMM-yy");
              date = (Date)formatter.parse(str_date);   
               System.out.println("Today is " +date );
    } catch (ParseException e)
    {System.out.println("Exception :"+e);    }   
    
   }
}
------------------------

import java.text.SimpleDateFormat;
import java.text.DateFormat;
import oracle.jbo.domain.Date;

Date convertedDate = am.getOADBTransaction().getCurrentUserDate();//new Date();
String convertedDateString;
java.text.SimpleDateFormat displayDateFormat = new java.text.SimpleDateFormat ("MM/dd/yyyy");
convertedDateString = displayDateFormat.format(convertedDate.dateValue());
-----------------------------------------------

OAViewObject vo = (OAviewObject) getVo1();
row = vo.getCurrentRow();
Date value = row.getAttribute("Nameof the Date Attribute");

OADBTransaction transaction = getOADBTransaction();
long sysdate = transaction.getCurrentDBDate().dateValue().getTime();
long startDate = value.dateValue().getTime();//value is fetched in above code
if (startDate < sysdate)
{
    //Put your Logic here
}

------------------------------

   1.
      /*
   2.
        Convert date string from one format to another format using SimpleDateFormat
   3.
        This example shows how to convert format of a string containing date
   4.
        and time to other formats using Java SimpleDateFormat class.
   5.
      */
   6.
      
   7.
      import java.util.Date;
   8.
      import java.text.ParseException;
   9.
      import java.text.SimpleDateFormat;
  10.
      
  11.
      public class ConvertDateFormats {
  12.
      
  13.
      public static void main(String[] args) {
  14.
      
  15.
      //string containing date in one format
  16.
      String strDate = "12/12/07";
  17.
      
  18.
      try
  19.
      {
  20.
      //create SimpleDateFormat object with source string date format
  21.
      SimpleDateFormat sdfSource = new SimpleDateFormat("dd/MM/yy");
  22.
      
  23.
      //parse the string into Date object
  24.
      Date date = sdfSource.parse(strDate);
  25.
      
  26.
      //create SimpleDateFormat object with desired date format
  27.
      SimpleDateFormat sdfDestination = new SimpleDateFormat("MM-dd-yyyy hh:mm:ss");
  28.
      
  29.
      //parse the date into another format
  30.
      strDate = sdfDestination.format(date);
  31.
      
  32.
      System.out.println("Date is converted from dd/MM/yy format to MM-dd-yyyy hh:mm:ss");
  33.
      System.out.println("Converted date is : " + strDate);
  34.
      
  35.
      }
  36.
      catch(ParseException pe)
  37.
      {
  38.
      System.out.println("Parse Exception : " + pe);
  39.
      }
  40.
      }
  41.
      }
  42.
      
  43.
      /*
  44.
      Typical output would be
  45.
      Date is converted from dd/MM/yy format to MM-dd-yyyy hh:mm:ss
  46.
      Converted date is : 12-12-2007 12:00:00
  47.
      */

----------------------------------------

# Date date = (Date)oaapplicationmodule.findViewObject("AddNewAssignmentVO").first().getAttribute("StartDate"); 
# Date edate = (Date)oaapplicationmodule.findViewObject("AddNewAssignmentVO").first().getAttribute("EndDate"); 
#  
#  
# if (date != null && edate != null) 
#                        { 
#                         String Xs11 = oapagecontext.getOANLSServices().dateToString(date); 
#                         String Xs12 = oapagecontext.getOANLSServices().dateToString(edate); 
# }
-----------------

13-Jul-2010

Calendar calendar = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
String today = dateFormat.format(calendar.getTime());

-----------------------------------------

package oracle.apps.xxper.selfservice.appraisals.webui;

import com.sun.java.util.collections.HashMap;
import java.io.Serializable;
import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.apps.fnd.framework.OAException;
import oracle.apps.fnd.framework.webui.*;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
import oracle.apps.fnd.framework.webui.beans.form.OASubmitButtonBean;
import oracle.apps.fnd.framework.webui.beans.message.OAMessageCheckBoxBean;
import oracle.apps.per.selfservice.appraisals.ApprConstants;
import oracle.apps.per.selfservice.arch.webui.PerOAControllerImpl;
import oracle.apps.per.selfservice.common.webui.CommonCO;
import oracle.apps.per.selfservice.compgaps.Constants;
import oracle.apps.per.selfservice.appraisals.webui.MAFinalRatingsPageCO;
import oracle.apps.fnd.framework.server.OADBTransaction;
import oracle.apps.fnd.framework.OAViewObject;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import oracle.jbo.Row;
import oracle.apps.fnd.framework.webui.beans.message.OAMessageDateFieldBean;
import oracle.apps.per.selfservice.appraisals.server.AppraisalVORowImpl;

public class XXPERMAFinalRatingsPageCO extends MAFinalRatingsPageCO
{
public void processRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processRequest(pageContext, webBean);
writeLog("XXPER",pageContext,"Start PR XXPERMAFinalRatingsPageCO ");
OAMessageDateFieldBean dateBean =(OAMessageDateFieldBean) webBean.findChildRecursive("DeliveryDateTime");
if(dateBean !=null )
{
String dateBeanValue = (String) dateBean.getValue(pageContext) ;
writeLog("XXPER",pageContext,"dateBean Value "+dateBeanValue);
if(dateBeanValue !=null)
{
if(dateBeanValue.indexOf(".0") !=-1)
dateBeanValue = dateBeanValue.substring(0,dateBeanValue.length()-2);
writeLog("XXPER",pageContext,"dateBean Updated Value "+dateBeanValue);

String dateMaskQry = "SELECT value FROM V$NLS_Parameters WHERE parameter ='NLS_DATE_FORMAT'";
writeLog("XXPER",pageContext,"dateMaskQry "+dateMaskQry);
String dateMask = (String) executeSql(dateMaskQry, pageContext, webBean);
writeLog("XXPER",pageContext,"dateMask : "+dateMask);
String dateConvertQry = "select to_char(fnd_date.canonical_to_date('"dateBeanValue"') ,'"dateMask" HH24:MI:SS') from dual";
writeLog("XXPER",pageContext,"dateConvertQry "+dateConvertQry);
String convertedDateValue = (String) executeSql(dateConvertQry,pageContext,webBean);
writeLog("XXPER",pageContext,"convertedDateValue "+convertedDateValue);
if(convertedDateValue == null )
convertedDateValue = dateBeanValue;
dateBean.setValue(pageContext,convertedDateValue);
writeLog("XXPER",pageContext,"After set the value "+convertedDateValue);
setAttribute3(pageContext, convertedDateValue);
writeLog("XXPER",pageContext,"After set the VO value "+convertedDateValue);
}else
{
writeLog("XXPER",pageContext,"dateBean value is null from the bean Get the value from getAttribute3() method");
dateBeanValue = getAttribute3(pageContext);
dateBean.setValue(pageContext,dateBeanValue);
}
}else
{
writeLog("XXPER",pageContext,"dateBean is null ");
}

writeLog("XXPER",pageContext,"End PR XXPERMAFinalRatingsPageCO ");
}
public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{

writeLog("XXPER",pageContext,"Start PFR XXPERMAFinalRatingsPageCO ");
writeLog("XXPER",pageContext,"Event Param "+pageContext.getParameter(EVENT_PARAM));
OAMessageDateFieldBean dateBean =(OAMessageDateFieldBean) webBean.findChildRecursive("DeliveryDateTime");
if(dateBean !=null )
{
String dateBeanValue = (String) dateBean.getValue(pageContext) ;
if(dateBeanValue !=null)
{
if(dateBeanValue.indexOf(".0") !=-1)
dateBeanValue = dateBeanValue.substring(0,dateBeanValue.length()-2);
writeLog("XXPER",pageContext,"dateBean Updated Value "+dateBeanValue);

String dateMaskQry = "SELECT value FROM V$NLS_Parameters WHERE parameter ='NLS_DATE_FORMAT'";
writeLog("XXPER",pageContext,"dateMaskQry "+dateMaskQry);
String dateMask = (String) executeSql(dateMaskQry, pageContext, webBean);
writeLog("XXPER",pageContext,"dateMask : "+dateMask);
String dateConvertQry = "select to_char(fnd_date.canonical_to_date('"dateBeanValue"') ,'"dateMask" HH24:MI:SS') from dual";
//String dateConvertQry = "select fnd_date.string_to_canonical('"dateBeanValue"','"dateMask" HH24:MI:SS') from dual";

writeLog("XXPER",pageContext,"dateConvertQry "+dateConvertQry);
String convertedDateValue = (String) executeSql(dateConvertQry,pageContext,webBean);
writeLog("XXPER",pageContext,"convertedDateValue "+convertedDateValue);
if(convertedDateValue == null )
convertedDateValue = dateBeanValue;

dateBean.setValue(pageContext,convertedDateValue);
writeLog("XXPER",pageContext,"After set the value "+convertedDateValue);
setAttribute3(pageContext, convertedDateValue);
writeLog("XXPER",pageContext,"After set the VO value "+convertedDateValue);
}
}else
writeLog("XXPER",pageContext,"dateBean is null ");
writeLog("XXPER",pageContext,"End PFR XXPERMAFinalRatingsPageCO ");
super.processFormRequest(pageContext, webBean);
writeLog("XXPER",pageContext,"End PFR XXPERMAFinalRatingsPageCO (After Super Call )");
}
public void writeLog(String moduleName, OAPageContext pageContext, String diagText)
{
if(pageContext.isLoggingEnabled(OAWebBeanConstants.STATEMENT))
{
System.out.println(moduleName+" : "+diagText);
pageContext.writeDiagnostics(moduleName,diagText,OAWebBeanConstants.STATEMENT);
}
}
/**
*
* Method to execute SQL.
*/
public Object executeSql(String pSqlStmt, OAPageContext pageContext , OAWebBean webBean)
{

OADBTransaction tx = pageContext.getApplicationModule(webBean).getOADBTransaction();// (OADBTransaction)getOADBTransaction();
Object lObject = null;

// Create the callable statement
CallableStatement lCstmt = (CallableStatement)tx.createCallableStatement(pSqlStmt, 1);
ResultSet rs = null;
try
{
rs = lCstmt.executeQuery();
while(rs.next())
{
lObject = rs.getObject(1);
}
}
catch (Exception e)
{
//throw OAException.wrapperException(e);
}
finally
{
try {
if(rs!=null)
rs.close();
if(lCstmt != null)
lCstmt.close();
}
catch(Exception e) {
throw OAException.wrapperException(e);
}
}
return lObject;
} // executeSql
public void setAttribute3(OAPageContext pageContext, String dateValue)
{
OAApplicationModule rootAM = pageContext.getRootApplicationModule();
OAApplicationModule apprAM = (OAApplicationModule)rootAM.findApplicationModule("AppraisalsAM");
OAViewObject appraisalVO = (OAViewObject)apprAM.findViewObject("AppraisalVO");
writeLog("XXPER",pageContext,"appraisalVO "+appraisalVO);
if(appraisalVO !=null)
{
AppraisalVORowImpl appraisalVORow = (AppraisalVORowImpl) appraisalVO.getCurrentRow();
if(appraisalVORow !=null)
{
int attrCount = appraisalVO.getAttributeCount();
writeLog("XXPER",pageContext,"Attrbuute count "+attrCount);
String[] attributeNames = appraisalVORow.getAttributeNames();
appraisalVORow.setAttribute3(dateValue);
}
}

}
public String getAttribute3(OAPageContext pageContext)
{
OAApplicationModule rootAM = pageContext.getRootApplicationModule();
OAApplicationModule apprAM = (OAApplicationModule)rootAM.findApplicationModule("AppraisalsAM");
String attribute3Value = "N";
OAViewObject appraisalVO = (OAViewObject)apprAM.findViewObject("AppraisalVO");
writeLog("XXPER",pageContext,"appraisalVO "+appraisalVO);
if(appraisalVO !=null)
{
AppraisalVORowImpl appraisalVORow = (AppraisalVORowImpl) appraisalVO.getCurrentRow();
if(appraisalVORow !=null)
{
int attrCount = appraisalVO.getAttributeCount();
writeLog("XXPER",pageContext,"Attrbuute count "+attrCount);
String[] attributeNames = appraisalVORow.getAttributeNames();
writeLog("XXPER",pageContext," AppraisalId :- "+ appraisalVORow.getAppraisalId());
attribute3Value = (String)appraisalVORow.getAttribute3();
String attribute1Value = (String)appraisalVORow.getAttribute1();//getAttribute2
String attribute2Value = (String)appraisalVORow.getAttribute2();
writeLog("XXPER",pageContext," attribute3Value :- "+attribute3Value + " attribute1Value "+ attribute1Value +"attribute2Value "+attribute2Value);
}else
{
writeLog("XXPER",pageContext," appraisalVORow is null ");
}
}else
{
writeLog("XXPER",pageContext," appraisalVO is null ");
}
return attribute3Value;
}
}

--------------------------------------

1 comment: