Thursday 11 December 2014

CALLING  XML REPOERTS    FROM  OAF PAGE THROUGH CONCURRENT PROGRAM



if("generatereport".equals(pageContext.getParameter("event"))){
    OADBTransactionImpl txn=(OADBTransactionImpl)am.getOADBTransaction();
             OAViewObject   vo = (OAViewObject)pageContext.getApplicationModule(webBean).findViewObject("AuctionHeadersAllVO"); //getting view object for AuctionHeadersAllVO
             String  DocumentNumber=(String)vo.getCurrentRow().getAttribute("DocumentNumber"); //getting document number from current row
             int DocumentNumber1=Integer.parseInt(DocumentNumber);
             pageContext.writeDiagnostics(this,"DocumentNumber in co:"+DocumentNumber,1); //display document number
             /* call the method which runs the concurrent program and returns request id*/
                 int req_id= submitCPRequest(DocumentNumber,txn);
                 if(pageContext.isLoggingEnabled(1))
                 {
                         pageContext.writeDiagnostics(this,"req_id in CO:"+req_id,1); //display request id
                 }

                  //Make application sleep for 15 seconds to finish the concurrent program
                 try
                             {
                              CallableStatement cal=txn.createCallableStatement("begin dbms_lock.sleep(20); end;",1);
                            
                               cal.execute();
                              cal.close();
                                   
                             }
                             catch(Exception e)
                             {
                               throw OAException.wrapperException(e);
                             }
             //Get the output file name from the backend table
                 String file_name=null;
                             try
                             {
                              CallableStatement cal=txn.createCallableStatement("begin select file_name into :1 from FND_CONC_REQ_OUTPUTS where concurrent_request_id=:2; end;",1);
                             cal.setInt(2,req_id);
                                
                               cal.registerOutParameter(1,Types.VARCHAR);
                               cal.execute();
                              file_name= cal.getString(1);
                              cal.close();
                               if(pageContext.isLoggingEnabled(1))
                               {
                              pageContext.writeDiagnostics(this,"file_name:"+file_name,1);
                               }
                             
                                    
                             }
                             catch(Exception e)
                             {
                               //throw OAException.wrapperException(e);
                               System.out.println("no data found");
                             }

             //Read data from output file and display

                 DataObject sessionDictionary = (DataObject)pageContext.getNamedDataObject("_SessionParameters");
                                 HttpServletResponse response = (HttpServletResponse)sessionDictionary.selectValue(null,"HttpServletResponse");
                 String contentDisposition = "attachment;filename="+DocumentNumber+".xls";
                             response.setHeader("Content-Disposition",contentDisposition);
                             response.setContentType("application/vnd.ms-excel");
                 
                 File f=new File(file_name);
                
                // File f=new File("/u02/PROD/inst/apps/MPPMCL_bb02/logs/appl/conc/out/XXMPP_SCM_NIT_PUB_TEMP_878237_1.PDF");
                 if(pageContext.isLoggingEnabled(1))
                 {
                 pageContext.writeDiagnostics(this,"output file:"+f,1);
                }
               try {
                     if(pageContext.isLoggingEnabled(1))
                     {
                     pageContext.writeDiagnostics(this,"in try block:",1);
                     }
                       OutputStream os = response.getOutputStream();
                       byte[] buf = new byte[8192];
                       InputStream is = new FileInputStream(f);
                       int c = 0;
                       while ((c = is.read(buf, 0, buf.length)) > 0) {
                           os.write(buf, 0, c);
                           os.flush();
                       }
                       os.close();
                       is.close();
                   } catch (IOException e) {
                       e.printStackTrace();
             }



}
    }
    public int submitCPRequest(String Rfq_num,OADBTransaction tx) {
    try {

    java.sql.Connection pConncection = tx.getJdbcConnection(); //get JDBC connection object

    ConcurrentRequest cr = new ConcurrentRequest(pConncection); // get the concurrentrequest object
    String applnName = "XXMPP"; //Application that contains the concurrent program

    String cpName = "XXMPPTEQTRPT"; //Concurrent program name

    String cpDesc = null; // concurrent Program description
    Vector cpArgs = new Vector(); //create an object for vector

    cpArgs.addElement(Rfq_num); //pass parameters by using vector
    try
    {
    cr.addLayout("XXMPP","XXMPPTEQTRPT","EN","US","EXCEL",null); //addlayout to the concurrent program
    }
    catch(Exception e)
    {
      throw OAException.wrapperException(e);
    }
   
    int requestId = cr.submitRequest(applnName, cpName, cpDesc, null, false, cpArgs); //call submitRequest method in ConcurrentRequest class
    tx.commit(); //commit
    return requestId; //return request id

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

Tuesday 2 December 2014

 HIDING DFF ATTRIBUTES  DYNAMICALLY






Processrequest
        OADescriptiveFlexBean dff=(OADescriptiveFlexBean)webBean.findChildRecursive("ActFlexField");
        dff.processFlex(pageContext);
        dff.mergeSegmentsWithParent(pageContext);


ppr

        OADescriptiveFlexBean dff=(OADescriptiveFlexBean)webBean.findChildRecursive("ActFlexField");

        dff.processFlex(pageContext);
        //OAMessageLovInputBean dff1=(OAMessageLovInputBean)dff.findChildRecursive("ActFlexField0");
       
        String strdff1=pageContext.getParameter("ActFlexField0");
        OAMessageLovInputBean dff2=(OAMessageLovInputBean)dff.findChildRecursive("ActFlexField1");
       
        if(pageContext.isLovEvent()){
        if("ActFlexField0".equals(pageContext.getParameter(SOURCE_PARAM))){
        if("No".equals(strdff1))
            dff2.setAttributeValue(RENDERED_ATTR,Boolean.TRUE);
           
            else
            dff2.setAttributeValue(RENDERED_ATTR,Boolean.FALSE);
        }
       
        }
    
HOW TO CRATE    VO   WITH   BOOLEAN TRANSIENT ATTRIBUTE



   OAViewDef viewdef=(OAViewDef)am.getOADBTransaction().createViewDef();
             
                viewdef.addTransientAttrDef(
        "TextDisable",               //Attr name
        "java.lang.Boolean",         //Java type
        null,                       //Default value
        false,                      //Not null
        AttributeDef.UPDATEABLE);   //Updateable
         OAViewObject vo=null;
             ViewObject  v=null;
             if(am!=null){
            v=am.findViewObject("xxBidFeeAmountVO1");
           
  
             }
            try{
              if(v==null){
                   vo=(OAViewObject)amImpl.createViewObject("xxBidFeeAmountVO1",viewdef);
                vo.setMaxFetchSize(0);
                        Row row = vo.createRow(); 
                        vo.insertRow(row);
                        Row row1=vo.first();
                        row1.setAttribute("TextDisable",Boolean.TRUE);
                    vo.executeQuery(); 
              }
           
            else
            {
            v.reset();
                v.setMaxFetchSize(0);
                        Row row = v.createRow(); 
                        v.insertRow(row);
                        Row row1=v.first();
                        row1.setAttribute("TextDisable",Boolean.TRUE);
                    v.executeQuery();
            }
            }
            catch(Exception e){
                throw new OAException("firse",OAException.ERROR);       
            }