Thursday, December 12, 2013

ADF : Insert a row at the end of a ViewObject

public String onRowCreate() {

 BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
 //access the name of the iterator the table is bound to. Its "allDepartmentsIterator"
 //in this sample
 DCIteratorBinding dciter = (DCIteratorBinding) bindings.get("allDepartmentsIterator");
 //access the underlying RowSetIterator
 RowSetIterator rsi = dciter.getRowSetIterator();
 //get handle to the last row
 Row lastRow = rsi.last();
 //obtain the index of the last row
 int lastRowIndex = rsi.getRangeIndexOf(lastRow);
 //create a new row
 Row newRow = rsi.createRow();
 //initialize the row
 newRow.setNewRowState(Row.STATUS_INITIALIZED);
 //add row to last index + 1 so it becomes last in the range set
 rsi.insertRowAtRangeIndex(lastRowIndex +1, newRow);
 //make row the current row so it is displayed correctly
 rsi.setCurrentRow(newRow);                        
 return null;
}

Friday, July 05, 2013

ADF MDS : Use MDS API to remove Customizations and/or merge Documents

import java.io.StringReader;


import java.io.StringWriter;

import java.util.Iterator;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import oracle.adf.share.ADFContext;
import oracle.adf.share.config.UserCC;

import oracle.apps.fnd.applcore.log.AppsLogger;

import oracle.mds.config.CustConfig;
import oracle.mds.core.ConcurrentMOChangeException;
import oracle.mds.core.MDSInstance;
import oracle.mds.core.MDSSession;
import oracle.mds.core.MOReference;
import oracle.mds.core.MetadataNotFoundException;
import oracle.mds.core.MetadataObject;
import oracle.mds.core.RestrictedSession;
import oracle.mds.core.SessionOptions;
import oracle.mds.core.ValidationException;
import oracle.mds.core.ValidationType;
import oracle.mds.cust.CacheHint;
import oracle.mds.cust.CustClassList;
import oracle.mds.cust.CustomizationClass;
import oracle.mds.exception.UnsupportedUpdateException;
import oracle.mds.internal.query.NameQueryImpl;
import oracle.mds.naming.ReferenceException;
import oracle.mds.persistence.MDSIOException;
import oracle.mds.query.ConditionFactory;
import oracle.mds.query.QueryResult;

import org.w3c.dom.DOMException;
import org.w3c.dom.Document;


import org.xml.sax.InputSource;

public class MDSOperations {

    public MDSOperations() {
        super();
    }

    public void removeCustomizations() {
        MDSSession mdsReadSession =
            (MDSSession)ADFContext.getCurrent().getMDSSessionAsObject();
        MDSInstance mdsInstance =
            (MDSInstance)ADFContext.getCurrent().getMDSInstanceAsObject();
        MDSSession mdsWriteSession =
            mdsInstance.createSession(new SessionOptions(null, null,
                                                         CustConfig.NO_CUSTOMIZATIONS),
                                      null);
        String appUserFromDoc =
            ADFContext.getCurrent().getSecurityContext().getUserName();
        NameQueryImpl query =
            new NameQueryImpl(mdsReadSession, ConditionFactory.createNameCondition("/mypackage/mdssys/cust/User/"+appUserFromDoc,
                                                                                   "%ParamaterViewDef.xml.xml",
                                                                                   true));
        Iterator<QueryResult> result = query.execute();
        while (result.hasNext()) {
            try {
                QueryResult qr = result.next();
                String mdsDocFullName = qr.getAbsoluteName();
                String mdsDocName = qr.getResourceName().getLocalName();
                mdsReadSession.flushChanges(false,
                                             new ValidationType[] { ValidationType.RELATIONSHIP_VALIDATION });
             
                mdsReadSession.flushChanges(false,
                                             new ValidationType[] { ValidationType.RELATIONSHIP_VALIDATION });
             
                if (mdsDocFullName.startsWith("/mypackage/mdssys/cust/User/" +
                                              appUserFromDoc)) {
                 
                    String baseDocFilePath =
                        "/mypackage/" +
                        mdsDocName.substring(0, mdsDocName.lastIndexOf("."));
                 
                    CustomizationClass[] custClass =
                        new CustomizationClass[] { new MyUserCC("User",
                                                                 appUserFromDoc) };
                    CustClassList custCCList = new CustClassList(custClass);

                    MetadataObject mo11 =
                        mdsReadSession.getMetadataObject(baseDocFilePath,
                                                         custCCList, null);

                    Document mergedDoc = mo11.getDocument(true);
                    String mergedXMLStr = getXMLAsString(mergedDoc);                  

                    MOReference baseDocRef =
                        mdsWriteSession.getMOReference(baseDocFilePath);
                    MetadataObject baseMO =
                        mdsWriteSession.getMutableMO(baseDocRef);
                    Document baseDoc = baseMO.getDocument();
                    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                    DocumentBuilder builder;
                    builder = factory.newDocumentBuilder();
                    baseDoc = builder.parse(new InputSource(new StringReader(mergedXMLStr)));
                 
                    mdsWriteSession.deleteAllCustomizations(baseDocRef);
                    mdsWriteSession.deleteMetadataObject(baseDocRef);
                    mdsWriteSession.createMetadataObject(baseDocFilePath, baseDoc);

                    mdsWriteSession.flushChanges(false,
                                                 new ValidationType[] { ValidationType.RELATIONSHIP_VALIDATION });

                 
                    MetadataObject baseMO1 =
                        mdsReadSession.getMetadataObject(baseDocFilePath);
                    baseDoc = baseMO1.getDocument();
                 
                    mdsWriteSession.deleteAllCustomizations(baseDocRef);
                    mdsWriteSession.flushChanges(false,
                                                 new ValidationType[] { ValidationType.RELATIONSHIP_VALIDATION });
                }
            } catch (MetadataNotFoundException mnfe) {
            } catch (UnsupportedUpdateException uue) {
            } catch (MDSIOException mdsioe) {
            } catch (ReferenceException re) {
            } catch (ConcurrentMOChangeException cmoce) {
            } catch (DOMException dome) {
            } catch (ValidationException ve) {
            } catch (Exception e) {
            }
        }
    }
 
    private static String getXMLAsString(Document document) throws Exception{
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        //initialize StreamResult with File object to save to file
        StreamResult result = new StreamResult(new StringWriter());
        String xmlString = null;
        try {
            DOMSource source = new DOMSource(document);
            transformer.transform(source, result);
            xmlString = result.getWriter().toString();
         
        } catch (TransformerException te) {
        } catch (Exception e) {
             
        } finally {
            result.getWriter().close();
        }
        return xmlString;          
    }
}
/**
 *  Customization class for the User Layer only required at runtime.
 */
class MyUserCC extends UserCC {
    String layerName = "User";
    String layerValue = null;

    /**
     * Public Constructor
     */
    public MyUserCC() {
        super();
    }

    public MyUserCC(String layerName, String layerValue) {
        super();
        this.layerName = layerName;
        this.layerValue = layerValue;
    }

    /**
     * Getter method for CacheHint.
     * @return CacheHint.
     */
    public CacheHint getCacheHint() {
        return CacheHint.USER;
    }

    /**
     * Getter method for Name.
     * @return String Name
     */
    public String getName() {
        return "User";
    }

    /**
     * Getter method for value.
     * @param sess RestrictedSession
     * @param mo MetadataObject
     * @return String[] value.
     */
    public String[] getValue(RestrictedSession sess, MetadataObject mo) {
        return new String[] { this.layerValue };
    }

    /**
     * This method is used by level picker functionality to set the value for the level.
     *
     * @param value
     */
    public void setValue(String value) {
        // not required for constant value.
    }

}

Wednesday, May 08, 2013

WebApp-Collecting Page load time Statistics in Browser

window.performance.timing is a new DOM Object introduced by most of the new version of Browsers such as IE 8+, Safari 5+, Firefox 3.6+ & Chrome.

Here is a sample Code snippet which can be used in ADF JSPX/JSFF pages through a JavaScript function.



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"></meta>
    <title>PageLoadStatsTestPage</title>
    <script  language="javascript">
        function processTiming()
        {
        var navTimeAvailable, performanceTiming;
        navTimeAvailable = window.performance || window.msPerformance || window.webkitPerformance || window.mozPerformance;
        if(navTimeAvailable && navTimeAvailable.timing && navTimeAvailable.navigation) {
            performanceTiming = window.performance.timing;
                        connectEnd = performanceTiming.connectEnd;
                        connectStart = performanceTiming.connectStart;
                        domComplete = performanceTiming.domComplete;
                        domContentLoadedEventEnd = performanceTiming.domContentLoadedEventStart;
                        domContentLoadedEventStart = performanceTiming.domContentLoadedEventStart;
                        domInteractive = performanceTiming.domInteractive;
                        domLoading  =   performanceTiming.domLoading;
                        domainLookupEnd =   performanceTiming.domainLookupEnd;
                        domainLookupStart   =   performanceTiming.domainLookupStart;
                        fetchStart  =   performanceTiming.fetchStart;
                        loadEventEnd    =   performanceTiming.unloadEventEnd;
                        loadEventStart  =   performanceTiming.unloadEventStart;
                        navigationStart =   performanceTiming.navigationStart;
                        redirectEnd =   performanceTiming.redirectEnd;
                        redirectStart   =   performanceTiming.redirectStart;
                        requestStart    =  performanceTiming.requestStart;
                        responseEnd =   performanceTiming.responseEnd;
                        responseStart   =   performanceTiming.responseStart;
                        secureConnectionStart   =   performanceTiming.secureConnectionStart;
                        unloadEventEnd  =   performanceTiming.unloadEventEnd;
                        unloadEventStart    =   performanceTiming.unloadEventStart;
                }

            var timeStats = "connectEnd="+connectEnd+"\n"+"connectStart="+connectStart+"\n"+"domComplete="+domComplete+"\n"+"domContentLoadedEventEnd="+domContentLoadedEventEnd+"\n"+
                            "domContentLoadedEventStart="+domContentLoadedEventStart+"\n"+"domInteractive="+domInteractive+"\n"+"domLoading="+domLoading+"\n"+"domainLookupEnd="+domainLookupEnd+"\n"+
                            "domainLookupStart="+domainLookupStart+"\n"+"fetchStart="+fetchStart+"\n"+"loadEventEnd="+loadEventEnd+"\n"+"loadEventStart="+loadEventStart+"\n"+
                            "navigationStart="+navigationStart+"\n"+"redirectEnd="+redirectEnd+"\n"+"redirectStart="+redirectStart+"\n"+"requestStart="+requestStart+"\n"+
                            "responseEnd="+responseEnd+"\n"+"responseStart="+responseStart+"\n"+"secureConnectionStart="+secureConnectionStart+"\n"+"unloadEventEnd="+unloadEventEnd+"\n"+
                            "unloadEventStart="+unloadEventStart+"\n"+
                            "";
            alert(timeStats);
        }
    </script>
  </head>
  <body onload="processTiming();"></body>
</html>

Sunday, March 24, 2013

WLST sample commands for MDS docs



  • $MW_HOME/oracle_common/common/bin/wlst.sh (AdminServer HostPort)
  • exportMetadata(application='',server='', toLocation='/tmp',  docs='/oracle/apps/atk/homePage/**') ;
  • deleteMetadata(application='',server='', docs='/oracle/apps/atk/homePage/fuse/**');


Monday, February 18, 2013

JDev..SSLException .. Certificate Error ... Hostname Verification

Sometimes, in JDEV, during development, when we access any HTTPS URL for some feature(e.g. Accessing a REST Webservice URL or accessing an SSL enabled URL using java.net.HttpURLConnection Object), we come  across

SSLException .. Certificate Error ... Hostname Verification

This is NOT any error, this is desired.

To solve this in JDEV(Note, in Standalone WLS, you need to run the KeyTool.exe from MW_HOME)

  • Tools->Preferences->Credentials
  • Credential Names  Dropdown->Select "HTTPS Credential"
  • In the field, "Client Trusted Certificate KeyStore", browse and give the full path to
  • $MW_HOME/jdk160_24/jre/lib/security/cacerts

Save and re-run the App(You need to restart Integrated server)