Wednesday, June 27, 2018

Integrating Axios with Oracle JET

Having worked on some react stuff, I was wondering, if there was a way for us to  integrate something like Axios or any other custom npm modules within Oracle JET. We have recently started getting into Oracle JET and trying to understand how it works.
We were able to achieve  this by broadly following three steps:

  1. Install Axios and integrating it with Oracle JET, so that Require JS (the module loader that Oracle uses)loads Axios as other default modules that it loads.
A) installing Axios is straight forward npm -install axios --save
B) update the oraclejet-build.js file and include the copyCustomLibsToStaging like the below. I did this inside the web section of the file.
  copyCustomLibsToStaging: {
       fileList: [
        {
          cwd:'node_modules/axios/dist',
          src: ['*'],
          dest: 'web/js/libs/axios'
        }
       ]
      }
When we do the above and run build i.e ojet build, it would pick up axios module content with other default module content and copies it inside web/js/lib folders
C) Open the main.js and update the path section include the axios reference
paths:
  //injector:mainReleasePaths
  {
    'knockout': 'libs/knockout/knockout-3.4.0.debug',
    'jquery': 'libs/jquery/jquery-3.1.1',
    'jqueryui-amd': 'libs/jquery/jqueryui-amd-1.12.0',
    'promise': 'libs/es6-promise/es6-promise',
    'hammerjs': 'libs/hammer/hammer-2.0.8',
    'ojdnd': 'libs/dnd-polyfill/dnd-polyfill-1.0.0',
    'ojs': 'libs/oj/v3.2.0/debug',
    'ojL10n': 'libs/oj/v3.2.0/ojL10n',
    'ojtranslations': 'libs/oj/v3.2.0/resources',
    'text': 'libs/require/text',
    'signals': 'libs/js-signals/signals',
    'customElements': 'libs/webcomponents/CustomElements',
    'proj4': 'libs/proj4js/dist/proj4-src',
    'css': 'libs/require-css/css',
    'axios': 'libs/axios/axios'
  }
  
With the above two steps, we have  axios inside the Oracle JET. 
  1. Attaching the axios with viewmodel. Require.js uses 'define' function for loading data
define( [array], object );
[Array] is a list of modules that this module depends on.
We will have to  add axios as well to list of  default viewmodel dependencies
Like below
define(['ojs/ojcore', 'knockout','jquery','axios', 'promise', 'ojs/ojknockout', 'ojs/ojmodel', 'ojs/ojtable', 'ojs/ojcheckboxset',
'ojs/ojcollectiontabledatasource', 'ojs/ojinputnumber',
'ojs/ojinputtext', 'ojs/ojdialog', 'ojs/ojbutton','ojs/ojarraytabledatasource']
Oracle JET has  lot of function hooks that run at various points while a module is being brought in or dismissed. handleActivated is one such hook that can be used to load data from an external source and have the module wait to build its view until the data has arrived. The basic criteria is that the method should return a promise. This where we will make the call using axios and then attach  result  to the knockout components as shown below. This works well and data gets loaded.
function DashboardViewModel() {
    //  console.log("results"+ result.data);
      var self = this;
      self.users = ko.observableArray();
       this.dataprovider =new oj.ArrayTableDataSource(self.users, {idAttribute: 'id'});
/**
       * Optional ViewModel method invoked when this ViewModel is about to be
       * used for the View transition.  The application can put data fetch logic
       * here that can return a Promise which will delay the handleAttached function
       * call below until the Promise is resolved.
       * @param {Object} info - An object with the following key-value pairs:
       * @param {Node} info.element - DOM element or where the binding is attached. This may be a 'virtual' element (comment node).
       * @param {Function} info.valueAccessor - The binding's value accessor.
       * @return {Promise|undefined} - If the callback returns a Promise, the next phase (attaching DOM) will be delayed until
       * the promise is resolved
       */
      self.handleActivated = function(info) {
        // Implement if needed
      return  axios.get('https://jsonplaceholder.typicode.com/posts/').then(function(result){
        result.data.forEach(function(user){
             self.users.push(user);
           });
        })
      };


Great we have axios that can we used now inside oracle JET . Feel much more confident.
Time to move to oracle JET common model

Monday, March 24, 2014

How to set up ADF Task Flow Tester

One of interesting thing that has come out is ADF Task Flow Tester. This allows us to run our task flows in project without having to restart the applications. One major problems of working with 11.1.1 versions is that we  cannot run task flows by passing different parameters without having to restart the task flow. This thereby increases the development time.

ADF Task Flow Tester is easier way of running the project once and then work with different task flow in the project all at once without having to restart.

Below I show you the steps to get this running.

  1. Download the ADF Task Flow Tester from the link give above.
  2. Go to "check for updates" in the Help menu of Jdev and install ADF Task Flow Tester
 
 
3. Go to View Controller Project properties and add Task Tester Library to you project
 
    4. From the 'Run' menu choose 'Active Run Configuration' option select 'Task Flow Tester'.
    5. We could run our project directly now. Once done the Task Flow tester will list all the task flows inside your project. Select the task flow, pass parameters and test.

Monday, March 17, 2014

How to perform Remote Memory Profiling for ADF Application


Performing memory profiling for ADF applications is a very important step that we usually miss during our ADF Application development life cycle.  We can find potential bottle necks inside our application like query getting lots of unrequired rows, lots of unwanted objects instance lying around and not getting clean up etc.

There are lots of memory profilers in the market. The most useful memory profiler w.r.t to ADF applications is the default memory profiler that comes with jdev installation. This gives us  a top down view (i.e from ADF to java ) of memory then a bottom up view that other memory profilers give us.

Approach:

The way we did memory profiling for our application
  • Deploy the application EAR pointing to something close to real time DB/OID on the intergrated weblogic. Try and make it as close as real time. 
  • Enabling the Intergrated weblogic for remote memory profiling on a specific port.
  • Start the jdev memory profiler client on the same port .
Steps for enabling Intergrated weblogic for remote memory profiling
Step 1
Edit File : C:\jdev_work\system11.1.1.5.37.60.13\DefaultDomain\bin\startWeblogic.cmd
Copy the below two lines before
-----------------------------------------------
set REMOTE_DEBUG_JAVA_OPTIONS=-Xdebug -Xnoagent -agentpath:C:\Oracle\Middleware\jdeveloper\jdev\lib\profiler16.dll=jarpath=C:\Oracle\Middleware\jdeveloper\jdev\lib\profiler-agent.jar,enable=m,startup=connect  -agentlib:profiler16=port=4000,jarpath=C:\Oracle\Middleware\jdeveloper\jdev\lib\profiler-agent.jar,startup=connect,mem
set JAVA_OPTIONS=%SAVE_JAVA_OPTIONS% %REMOTE_DEBUG_JAVA_OPTIONS%
-----------------------------------------------
set SAVE_JAVA_OPTIONS=


Step 2
When you start the weblogic server, you will see something like this in the logs.

Starting WLS with line:
C:\Oracle\MIDDLE~1\JDK160~1\bin\java -client   -Xms256m -Xmx512m -XX:CompileThreshold=8000 -XX:PermSize=128m  -XX:MaxPermSize=512m -Dweblogic.Name=DefaultServer -Djava.security.policy=C:\Oracle\MIDDLE~1\WLSERV~1.3\server\lib\weblogic.policy -agentlib:jdwp=transport=dt_socket,server=y,address=52702 -Djavax.net.ssl.trustStore=C:\Oracle\Middleware\wlserver_10.3\server\lib\DemoTrust.jks -Djbo.debugoutput=console -Dweblogic.nodemanager.ServiceEnabled=true  -Xverify:none  -da -Dplatform.home=C:\Oracle\MIDDLE~1\WLSERV~1.3 -Dwls.home=C:\Oracle\MIDDLE~1\WLSERV~1.3\server -Dweblogic.home=C:\Oracle\MIDDLE~1\WLSERV~1.3\server  -Djps.app.credential.overwrite.allowed=true -Dcommon.components.home=C:\Oracle\MIDDLE~1\ORACLE~1 -Djrf.version=11.1.1 -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger -Ddomain.home=C:\JDEV_W~1\SYSTEM~1.13\DEFAUL~1 -Djrockit.optfile=C:\Oracle\MIDDLE~1\ORACLE~1\modules\oracle.jrf_11.1.1\jrocket_optfile.txt -Doracle.server.config.dir=C:\JDEV_W~1\SYSTEM~1.13\DEFAUL~1\config\FMWCON~1\servers\DefaultServer -Doracle.domain.config.dir=C:\JDEV_W~1\SYSTEM~1.13\DEFAUL~1\config\FMWCON~1  -Digf.arisidbeans.carmlloc=C:\JDEV_W~1\SYSTEM~1.13\DEFAUL~1\config\FMWCON~1\carml  -Digf.arisidstack.home=C:\JDEV_W~1\SYSTEM~1.13\DEFAUL~1\config\FMWCON~1\arisidprovider -Doracle.security.jps.config=C:\JDEV_W~1\SYSTEM~1.13\DEFAUL~1\config\fmwconfig\jps-config.xml -Doracle.deployed.app.dir=C:\JDEV_W~1\SYSTEM~1.13\DEFAUL~1\servers\DefaultServer\tmp\_WL_user -Doracle.deployed.app.ext=\- -Dweblogic.alternateTypesDirectory=C:\Oracle\MIDDLE~1\ORACLE~1\modules\oracle.ossoiap_11.1.1,C:\Oracle\MIDDLE~1\ORACLE~1\modules\oracle.oamprovider_11.1.1 -Djava.protocol.handler.pkgs=oracle.mds.net.protocol  -Dweblogic.jdbc.remoteEnabled=false -Dwsm.repository.path=C:\JDEV_W~1\SYSTEM~1.13\DEFAUL~1\oracle\store\gmds   -Dweblogic.management.discover=true  -Dwlw.iterativeDev= -Dwlw.testConsole= -Dwlw.logErrorsToConsole= -Dweblogic.ext.dirs=C:\Oracle\MIDDLE~1\patch_wls1035\profiles\default\sysext_manifest_classpath;C:\Oracle\MIDDLE~1\patch_jdev1111\profiles\default\sysext_manifest_classpath -Xdebug -Xnoagent -agentpath:C:\Oracle\Middleware\jdeveloper\jdev\lib\profiler16.dll=jarpath=C:\Oracle\Middleware\jdeveloper\jdev\lib\profiler-agent.jar,enable=m,startup=connect  -agentlib:profiler16=port=4000,jarpath=C:\Oracle\Middleware\jdeveloper\jdev\lib\profiler-agent.jar,startup=connect,mem  weblogic.Server
Agent_Onload
Agent_Onload
Listening for transport dt_socket at address: 52702
Debugger connected to local process.
Profiler 11.1.1.5381 (090522.0635)for JDK 1.6
Profiler waiting for connection on port 4000


 

Step 3 :


Start the profiler agent
Select the view controller, which you want to profile,
Click Run->Attach to -> Memory Profilee,
For Remote profiling, select the 2nd option "Attach to Remote Process " and give the host details.  Leave the port number to 4000, as the profiler agent runs on port number 4000.


Step 4
Once the profiler is started, you should see the continuiton of the weblogic logs as
Profiler connected
 
Step 5
Simply open the browser and login, you can see the memory profiling parameters in the profiler window.


Happy Memory Profiling !!!!!