Saturday, September 10, 2016

Android Firebase - Google Sign in Authentication

Steps to Add Google SignIn to Firebase Android Project

1. Add project Dependencies in the Project Gradle file for Firebase Authentication and Google Play Services.

2. Add Google Services plugin dependency at bottom  of the Module App Gradle.
















3. Generate GoogleServices file(google-services.json) from Firebase Console (https://console.firebase.google.com/) for the app.

You will need to provide package name and sha1 key

generate SHA1 key using following on mac

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore -list -v -storepass android

4. Copy the file google-services.json under apps directory in android project.




5. Enable Google SignIn method from Firebase Console Project setting.




6. Add SignIn button in layout.xml



7. Modify Activity signature to implement OnClickListener and OnConnectFailedListener interface



8. Instantiate GoogleSignInOption object to request appropriate scope and instantiate GoogleAPIClient



9. Add OnClickListener on the sign in button and call Google SignIn intent



12. Process Google Intent SignIn activity result.



13. Handle result on success and failure.



References

https://www.youtube.com/watch?v=SXlidHy-Tb8
https://developers.google.com/android/guides/api-client
https://github.com/firebase/quickstart-android/tree/master/database/app/src/main/java/com/google/firebase/quickstart/database

Monday, October 5, 2015

User Token Authentication flow in Nodejs - Part 1


The following diagram shows the steps involved in authentication in nodejs. 

Token Authentication in Nodejs

Tuesday, February 10, 2015

Bootstrap 3 CSS Animation & Transition Effects

Animation Effects

Number of trending websites are now using CSS Animation library like Animate.css  for effects like dropIn, dropDown, fadeIn.

Lets add transition animation to  following element
<div id="header-text">This is text heading.</div>

All we have to do is to include Animation.css file in our page and then add following class to element
<div id="header-text" class="animated fadeIn">This is text heading.</div>

That's it!

Adding Animation effects on Scroll of page

Animation effect triggers even if page element is not visible on screen. We don't want animation to trigger when its not visible. We want to trigger animation when user scrolls the page and element is about to be displayed.

For that we can use WOW.js library. We need to initialize WOW object in our page and then we can add wow class which will give the desired result.

Blur Block when user user scrolls down from that element

We can set opacity of the element when user scrolls down the element. Based on size of window and scollTop position we can caculate opacity of the block.

function() {
var h = window.innerHeight;
$(window).on('scroll', function() {
var st = $(this).scrollTop();
$('#element').css('opacity', (1-st/h) );
});
},

 Show Spinner until all elements(images) are loaded

$(window).load(function() {
$('#status').delay(100).fadeOut('slow');
$('#preloader').delay(500).fadeOut('slow');
}

 In html add following

<div class="sk-spinner sk-spinner-wave">
<div class="sk-rect1"></div>
<div class="sk-rect2"></div>
<div class="sk-rect3"></div>
<div class="sk-rect4"></div>
<div class="sk-rect5"></div>
</div>

Along with css  style mentioned here

Tuesday, January 6, 2015

Automatically Generate SQL Loader Control File Script

Script to generate SQL Loader control file with all columns from the table_name and in the same order columns are created in table


<pre class="brush: sql">

SELECT COL_NAME, LOADER_TYPE
FROM (
SELECT 'LOAD DATA
APPEND
INTO TABLE ' || '&TABLE_NAME' || ' FIELDS TERMINATED BY ","
OPTIONALLY ENCLOSED BY ''"''
TRAILING NULLCOLS
('
COL_NAME,
' ' LOADER_TYPE,
-999 SORTING_N
FROM DUAL
UNION ALL
SELECT COLUMN_NAME COL_NAME,
DECODE (
COLUMN_NAME,
'CREATED_BY', '"FND_GLOBAL.USER_ID"',
'CREATION_DATE', 'SYSDATE',
'LAST_UPDATED_BY', '"FND_GLOBAL.USER_ID"',
'LAST_UPDATE_DATE', 'SYSDATE',
DECODE (
DATA_TYPE,
'TIMESTAMP(6)', 'TIMESTAMP "YYYY-MM-DD HH24:MI:SS.FF",',
'NUMBER', 'DECIMAL EXTERNAL,',
'VARCHAR2', 'CHAR "TRIM(:' || COLUMN_NAME || ')",',
'CHAR', 'CHAR',
'DATE', '"TO_DATE(SUBSTR(:'
|| COLUMN_NAME
|| ',1,19),''YYYY-MM-DD HH24:MI:SS'')",'))
LOADER_TYPE,
COLUMN_ID SORTING_N
FROM ALL_TAB_COLS
WHERE OWNER = UPPER ('&SCHEMA_NAME') AND TABLE_NAME = UPPER ('&TABLE_NAME')
UNION ALL
SELECT ')' COL_NAME, '' LOADER_TYPE, 10000 SORTING_N FROM DUAL
)
ORDER BY SORTING_N
</pre>

Monday, January 5, 2015

Understanding Bootstrap 3 Grid Layout System


  • Bootstrap is HTML, CSS, JS framework for developing responsive websites.
  • Bootstrap v3 uses mobile first approach. Layout is assumed to be designed for mobile devices i.e, for extra small view port. All element are stacked one over the other by default.
  • The grid (viewport) is divided into 12 equally spaced cells/columns.If we want some element to use two cell spaces we will mention col-xx-2 and you can give other element all remaining cell using col-xx-10. xx declares viewport
<div class ="row">
<div class="col-xs-2"> First 2</div>
<div class="col-xs-10"> Remaining 10</div>
</div>
  • When column class col-xs-6 is specified, it means that on extra small device screen, divide screen in half i.e, give six cell space to this element.
  • col-md-4 mean on medium size screen, give this element 4 column space.
  • <div class="col-xs-6 col-md-4"> means on extra small screen this element will take 6 column space and on medium size screen 4
<div class ="row">
<div class="col-xs-2"> First 2</div>
<div class="col-xs-10"> Remaining 10</div>
</div>


Rendering on Extra small device browser


 Rendering on Medium size screen[/caption]

  •  col-xx-n class adds padding of 15px on right and left. To counter that on right and left edge of a row, class "row" adds padding of -15px on left and right.
  •  .container class has one fixed width for each screen size(xs, md..) something like  @media (min-width: 992px) {
    .container {
    width: 970px;
    }
    }
    .container-fluid expands to fill available width.

Friday, January 2, 2015

AngularJS Example

Develop a simple app where web page link is provided as input and it will display screenshots of the web page.

  • AngularJS provides two-way data binding. If data model changes, view is updated i.e, DOM of the webpage will refresh with new data and if new value is entered in field, data model will update.
  • We can divide application into different components and AngularJS Dependency Injection mechanism will inject components into each other.
  • Accessing DOM should be done only in Directives. Directives are AngularJS markers which adds behaviour to DOM element. Directives are added to HTML template to add dynamic behavior.
<div  ng-repeat="c in book.notes track by $index">

<img ng-src="{{c}}" width="500" height="500">

</div>


  • ng-repeat is a directive which instantiates template once per item( variable c) in collection(book.notes Array)
  • If the value of book.notes =['link1.jpg','link2.jpg'] then view will be rendered with two div elements, one for each link in book.notes
  • <input ng-model="book.note" >
    ng-model directive stores/updates value of the input field. note is model field which will be updated based on input field.

HTML Template

Following is the HTML template we will use to display one input box which expects web page url and an add button which add link to image collection.

<div ng-app="notes" ng-controller="notesController as book">

<button ng-click="book.add()">Add</button>

<input min="0" ng-model="book.note" required >

<div ng-repeat="c in book.notes track by $index">

<img ng-src="{{c}}" width="500" height="500">





Controller View Model is defined in Controller file

angular.module('notes',[])

.controller('notesController',function(){

this.notes=[];

this.add=function (){

this.notes.push('http://screenshot.etf1.fr/?url='+this.note);

};


  • Controller is attached to DOM using ng-controller.
  • All properties and methods defined inside controller are available  in DOM where controller is attached. Properties are called view model and methods are called behaviour.
  • notes is a model and add is behaviour which is available in DOM where ng-controller="notesController" is added.

When Add button is clicked the notes model is updated and view is updated accordingly  because ng-repeat is based on notes model.

Complete HTML code and controller.js code

<html lang="en">

<head>

<meta charset="UTF-8">

<title>Example</title>

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js"></script>

<script src="controller.js"></script>

</head>

<body >

<div ng-app="notes" ng-controller="notesController as book">

<button ng-click="book.add()">Add</button>

<input min="0" ng-model="book.note" required >



<div class="col-xs-3" ng-repeat="c in book.notes track by $index">

<img ng-src="{{c}}" width="500" height="500"> </img>

</div>

</body>

</html>





Controller.js


angular.module('notes',[])

.controller('notesController',function(){

this.notes=[];

this.add=function (){

this.notes.push('http://screenshot.etf1.fr/?url='+this.note);

};

})

Developing Chrome Extension - How to Build First Chrome Extension

Let's develop a  simple chrome extension to modify some text on visited webpage.
Whenever Google website is visited we will modify all 'Google' text string on page to 'Foogle'.

Following files will be required to achieve this - manifest.json and inject.js

manifest.json

  • Manifest file is required for all extensions.

  • It defines meta data for Chrome.

  • All files & permissions should be declared here.

  • Resource files like images or other template files should be declared as "web_accessible_resources"



  • [sourcecode language="javascript"]

    {
    // required
    "manifest_version": 2
    "name": "Foogle Search",
    "version": "0.1",

    "content_scripts": [
    {
    "matches": ["https://www.google.com/*"],
    "js": ["inject.js"],
    "run_at": "document_end"
    }
    ],

    }

    [/sourcecode]

    "Foogle Search" is the name of chrome extension, and 0.1 is its version.
    content_scripts section tell chrome to insert javascript file inject.js in web pages which matches URL pattern google.com/*
    manifest_version is a mandatory field.


inject.js

  • Content Scripts execute in the context of the visited web page and can access and modify the DOM of the visited page.

  • Content Script do not have access to JavaScript variables or functions of visited web page. Content scripts are not aware of the JavaScript code of the visited page.

  • Since they run in context of webpage they cannot directly communicate with rest of the extension. Message passing is used for communication between content script and rest of the extension.

  • Content scripts can be injected every time a matching URL web page is visited  or can be inserted dynamically in the webpage based on some conditions. Cross Origin Permission should be specified in the later case.

  • Following javascript code searches for all occurrences of text 'Google' in web page and replaces it with 'Foogle'.



[sourcecode language="javascript"]

document.body.innerHTML = document.body.innerHTML.replace(new RegExp("Google", "g"), "Foogle");

[/sourcecode]

Now, to test the extension in brower

1. Open extensions option in Chrome. Type chrome://extensions/ in chrome tab
2. Enable Deverloper Mode checkbox.
3. Click on 'Load Unpackged Extension'
4. Select folder where you have saved extension files.

 

Tuesday, December 2, 2014

Supplier Conversion in Oracle Apps 11i / r12

If you can solve a problem with single SQL query instead of writing long PL/SQL procedure, you will sound as cool as Apple fans sound when criticizing Microsoft.

I enjoy challenge of solving problems with single SQL statements. Personally, I find code written using lots of cursor, loops, IF condition and exceptions too difficult to maintain.

Here is a Supplier conversion program that I wrote recently using mostly SQL statements.
Data File Validations
Doing null validation for staging table fields using single DML statement

One boring way to do validation is by using PL/SQL code. Open staging table cursor, check for each field value and update error message field.

But same thing can be achieved using single update statement.


UPDATE xxxav_sup_stg_tab xsst
SET vendor_error =
(SELECT DECODE (
a.err_msg,
NULL, NULL,
SUBSTR (a.err_msg, 1, LENGTH (a.err_msg) - 1)
|| ' SHOULD NOT BE NULL')
error_msg
FROM (SELECT DECODE (vendor_name,
NULL, ' Vendor Name,',
NULL)
|| DECODE (vendor_type_lookup_code,
NULL, ' Vendor Type lookup,',
NULL)
|| DECODE (vendor_site_code,
NULL, ' Vendor Site Code,',
NULL)
|| DECODE (vendor_type_dff,
NULL, ' Vendor Type DFF,',
NULL)
|| DECODE (lgcy_vendor_ref2,
NULL, 'Legacy Vendor REF2,',
NULL)
err_msg,
ROWID line_no
FROM xxxav_sup_stg_tab) a
WHERE a.line_no = xsst.ROWID);


The innermost SQL subquery will check each column for null value and if value is null it will concatenate all error messages and updates error_message column.

Duplicate Record Validation on staging table

If unique id is assigned to all rows in staging table, we can join


UPDATE xxxav_sup_stg_tab out
SET site_error =
site_error
|| ' Duplicate Line for vendor and site combination'
WHERE EXISTS
( SELECT vendor_name, vendor_site_code
FROM xxxav_sup_stg_tab inn
WHERE inn.vendor_name = out.vendor_name
AND inn.vendor_site_code = out.vendor_site_code
and inn.record_id <> out.record_id);


Staging Table Validations

Populate Derived Columns in Staging table


For almost all values that are inserted in interface tables, I like to keep one derived column in staging table like for vendor type  value coming in file, I will create one corresponding derived column o_vendor_type_lkp_code in staging table.
This ensure that we are inserting all validated column values in interface table and makes code easy to debug. This also helps to separate value derivation from error message updates.

Populate derived Column values using Single SQL statement





UPDATE xxxav_sup_stg_tab xsst
SET o_vendor_type_lookup =
DECODE (
xsst.vendor_type_lookup_code,
NULL, NULL,
(SELECT lookup_code
FROM po_lookup_codes
WHERE xsst.vendor_type_lookup_code IS NOT NULL
AND lookup_type = 'VENDOR TYPE'
AND (displayed_field) = xsst.vendor_type_lookup_code)),
o_tax_type =
DECODE (xsst.awt_group_name,
NULL, NULL,
(SELECT income_tax_type
FROM ap_income_tax_types aitt
WHERE 1 = 1
AND xsst.awt_group_name IS NOT NULL
AND xsst.awt_group_name) = (aitt.income_tax_type)),
o_inspection_flag =
DECODE (UPPER (xsst.match_option),
NULL, 'N',
'2-WAY', 'N',
'3-WAY', 'N',
'4-WAY', 'Y',
NULL),
o_receipt_required_flag =
DECODE (UPPER (xsst.match_option),
NULL, 'Y',
'2-WAY', 'N',
'3-WAY', 'Y',
'4-WAY', 'Y',
NULL)
WHERE o_vendor_id IS NULL;



 Update All validation Errors





UPDATE xxxav_sup_stg_tab xsst
-- oracle Name
SET vendor_error =
vendor_error
|| (SELECT ' Mismatch Vendor number and Name'
FROM po_vendors pv
WHERE pv.vendor_id = xsst.o_vendor_id
AND pv.segment1 <> xsst.oracle_vendor_number
AND xsst.o_vendor_id IS NOT NULL)
|| DECODE (
xsst.vendor_type_dff,
NULL, NULL,
DECODE (o_vendor_type,
NULL, ' Invalid Vendor Type',
NULL))
|| DECODE (
xsst.vendor_type_lookup_code,
NULL, NULL,
DECODE (o_vendor_type_lookup,
NULL, 'Invalid Vendor Type lookup code',
NULL))
|| DECODE (
xsst.awt_group_name,
NULL, NULL,
DECODE (xsst.o_tax_type,
NULL, ' Invalid AWT Group name',
NULL))
|| (SELECT ' Invalid Fedral Flag'
FROM DUAL
WHERE UPPER (xsst.federal_reportable_flag) NOT IN
('Y', 'N')
AND federal_reportable_flag IS NOT NULL)
|| (SELECT ' Invalid State Report Flag'
FROM DUAL
WHERE UPPER (xsst.state_reportable_flag) NOT IN
('Y', 'N')
AND state_reportable_flag IS NOT NULL)
|| DECODE (
UPPER (xsst.federal_reportable_flag),
'Y', DECODE (xsst.awt_group_name,
NULL, ' Missing Awt group name',
NULL),
NULL)
|| DECODE (
xsst.match_option,
NULL, NULL,
(SELECT ' Invalid Match Approval Level'
FROM DUAL
WHERE UPPER (xsst.match_option) NOT IN
('2-WAY', '3-WAY', '4-WAY')))
WHERE o_vendor_id IS NULL;


Keep Log function separate instead of hard coding fnd_file.put_line(fnd_file.LOG,v_message); or dbms_output.put_line();


PROCEDURE LOG (MESSAGE VARCHAR2)
AS
BEGIN
-- DBMS_OUTPUT.put_line (MESSAGE);
fnd_file.put_line (fnd_file.LOG, MESSAGE);
END;

Tuesday, July 29, 2014

Performance Tuning Oracle Reports and Programs

Here are some of the performance tuning tips and tricks that I have learned over time. Most of them will work some of the time and  some of them will work most of the time.

People often ask me - Have you tried using temporary table for Oracle reports which has performance issue or have I analysed trace file of reports. But the truth is that most of the time analysing current query in toad proves enough to find bottleneck of the program. I submit the Oracle report, and in toad window I monitor corresponding process to check for running SQL query. I watch the queries which are executing and the plan which is being used for the query. Queries which test your patience will be the queries which needs your attention. I start from these SQL statements and I try to Optimize them.

1) Do not use truncate function on database Date column instead use timestamp or explicit expression for date comparisons.

problems with date comparisons

Like  transaction_date of rcv_transactions is an indexed column, so if we use truncate on transaction_date, index will not be used.

Instead of trunc(transaction_date) = '12-JUL-2013' use transaction_date between to_date('12-JUL-2013 00:00:00','DD-MON-YYYY HH24:MI:SS') and to_date('12-JUL-2013 23:59:59','DD-MON-YYYY HH24:MI:SS')
similarly for creation_date of rcv_shipment_headers

2) Use same data type as index column type in expressions

If indexed column is number and expression uses string, index is used
if indexed column is string and number is used in expression , index is skipped

3) Use lexical parameters to build query, this will improve performance most of the time.

4) Using Index is not always good. People would often say index will lead to performance improvement. But using index of on large table instead of performing full table scan of small table may some time prove otherwise.
Modify query to use  full table scan of small table instead of using index on big table and check run time.

If temporary table is being used in report and some table join is used with large tables, do not use large table indexes instead force full table scan of temporary table.

5) When checking for existing values, like if  purchase order exists for a vendor
Use rownum in query. Instead of

select count(*) from po_headers_all where vendor_id = <>

use select 1 from po_headers_all where vendor_id = <> and rownum <2

6) Mention all column joins explicitly in SQL query.

7) Less cost doesn't always ensures improved performance

parent_transaction_id = -1 on rcv_transaction shows very less cost but takes lot of time similarly, queries with rownum <2 will show very less cost.

8) For excel reports, if post processing time is more, then generating delimited file using PL SQL package will improve performance.
To check for how much time  a program has spent in post processing,  check  fnd_concurrent_requests.PP_START_DATE column

9) Remember if report is run with trace enabled, queries will always perform hard bind.

We had a strange issue wherein after enabling trace, the program was completing faster. We could not find out the reason as to why this is happening, but I think it was related to hard bind performed each time.
The report was using bind variable and there are some known problem of bind variable peeking.

11) Using sub query in FROM clause is expensive Instead try using sub query in select clause with where condition if you want to select only few values in main select clause.

12) Do not user formula column which are header dependent at line level. header level details should be fetched only once.

13) Distinct clause is little tricky. Because even if query is wrong sometimes, it conceals the problem and presents correct output. If you have missed some join in a query with distinct clause, then it might give correct output, but performance is highly impacted.

I worked on one performance tuning of one report recently. It was taking huge time for one particular Org. I identified the query which was taking long time. When I analyzed the query I found that instead of using org dependent view, query was using _all table with no where condition for org_id. The output of report was coming as expected but in background the query was killing performance.

 

Sunday, March 16, 2014

How to get more Facebook Likes and Followers

This lazy weekend, while browsing for random stuff, I came across this website which allowed users to exchange likes, follow, comments for some popular social networking websites.

So, I decided to try it. To see if it actually works, I created an account on like4like.org and created one Pinterest account to verify it.

On this website, you have to give your profile link which you want others to follow, or to like. I provided my Pinterest page url, and then started following other users on Pinterest through this website.

In 2-3 minutes, I followed some 5-7 users and keenly refreshed my Pinterest page. To my surprise, I got my first follower in 4 min time. Now, I wanted to see how fast can I get followers so, I started following more users and within some 1 hour I had around 15 followers. Not Bad!

Exchanging back-links has been there for long time to improve Google page rank. And it was a successful method until one day, when Google decided to give negative score for black-hat SEO method. Well, for now this method works.

Saturday, March 15, 2014

Html5 Game Programming Tutorial for Beginners Part 2 - Keyboard and Bullets

In this part, we will load an image object, control its movement using keyboard, and then we will arm our hero with a loaded gun.

So, time to bring our hero in picture. I will load the image saved in my local folder.

Load Image



[code language="javascript"]
//create init function to initialize image loading
var img = new Image();
var imgLoaded = false;
img.onload = function() {
imgLoaded=true;
}
img.src = 'images/hero.png';
[/code]

After loading the image, we need to draw it on canvas

[code language="javascript"]context.drawImage(img,x,y);[/code]

Create Hero Object


To keep code sane, we will create hero object that will hold all properties and methods of hero. If you are new to Objects in javascript refer Working with objects

[code language="javascript"]
var hero = {
x: 50,
y: 50,
width:img.width,
height:img.height,
draw: function() {
if(imgLoaded){
context.drawImage(img,this.x,this.y);
}
}
};

[/code]

Friday, March 14, 2014

Html5 Game Programming Tutorial for Beginners Part 1 - Drawing on Canvas

I will document my learning of game programming here. I don't like writing long paragraphs so, I will just note necesary things here . Let's roll

Creating canvas 

Canvas is a rectangular space on page, which is blank until you draw something on it. We can draw stuff on canvas using JS.  

Now, lets go ahead and create a canvas and draw some text on it.

We can define canvas in  html page or we can create it using JS function.
In HTML

[code language="html"]

<canvas id="<span class=">myCanvas" width="500" height ="300">Canvas not supported</canvas></canvas>

[/code]

and save the canvas object in JS variable

[code language="javascript"]

canvas= document.getElementById("myCanvas");

[/code]

In JS

[code language="javascript"]

var canvas = document.createElement('canvas');
canvas.id = 'myCanvas';
canvas.width = 1224;
canvas.height = 768;

[/code]

Monday, October 28, 2013

Oracle Report Builder - Internal Error Code 600

While compiling program unit in report builder 6i, I got the below error message. The code is simple SQL statement like

select 1 into var from apps.wip_discrete_jobs;

ORA-00600 : internal error code, arguments [17069], [97056504], [] ,[] ..

But after changing the schema name from apps to wip the code compiled successfully.

Monday, September 9, 2013

Addiction of Social Gaming

Now a days people are just crazy about social network games. They spend whole day in virtual shops, farms, collecting virtual money to buy virtual stuff with which they achieve some goals that at last gives them, I consider, virtual pleasure.

I experienced similar thing when my brother was playing candy crush game on Facebook.  Suddenly he turned to me and said

"You get married!"

"What?.. What happened suddenly?"

"I was thinking it would be easy to get approval from 3rd person to reach next level"

*To cross some levels you need approval from 3 people in candy crush game.

Tuesday, May 14, 2013

BI / XML Publisher - Fixed number of records per page

Requirement
* Display fixed number of records per page.
* On each page, display header
* Display footer on last page
* In case if footer is spanning across pages, move one record(last record) to next page and display footer at bottom of the page.
Fig1. Pages others than last one

Fig2. Display Footer on last page


Fig 3. Special condition where footer spans across pages

Fig 4. To handle footer spanning across pages, move last record to next page and then display footer


Solution
Download complete template
code
(open it and save it as rtf)
Download sample data
XML Data is of form
<ROOT>
 <A>
  <B1>lineB11</B1>
  <B2>lineB12</B2>
  <B3>lineB13</B3>
  <B4>lineB14</B4>
 </A>
..
..
</ROOT>

Lets quickly freshen up our XML Publisher Reports knowledge

How to declare variables?
XSL variable declaration
<? variable : a ; number(1) ?>
XML Publisher variable declaration
<? xdoxslt:set_variable($_XDOCTX,'i',1) ?>

How to use conditional logic in template?
 <?if@inlines: [condition] ?>  [value]  <? end if ?>
Example
<?if@inlines: $a = 1 ?>   Text    <?end if?>
@Inline is used to print text on the same line, else its displayed on next line

How to use Looping constructs?
Looping for particular XML tag

for-each:current_group()
Looping n number of times<? for-each@inlines : xdoxslt:foreach_number ( $_XDOCTX,1,3,1) ?>This is an Example

<?end for-each?>


"This is and Example" text will be printed 3 times in same line(notice @inline).

Parameters for foreach_number function are same like C programming for loop - initial value, end value and increment value

How to use Page Breaks?Below tags work only in Word form field. Other declarations can be entered like normal text, but this tags should be put in Word Form field tag.

<xsl:attribute name="break-after">page
<xsl:attribute name="break-before">page

Use this inside inline IF condition to give appropriate page breaks.


Now, Lets solve our problem.

1. Decide Number of lines per page : There is no formula that works for all scenarios. Number of lines that need to be displayed per page has to be decided based on
header size,
font size and
other factors.

Create a simple for-each loop in table to find out how many rows a page can accommodate and assign that value to the variable nlpp.

Lets say after the header which I have decided(refer Fig1) a page can accommodate 46 records. Declare number of lines per page in a a variable nlpp

<?variable:nlpp;number(46)?>

2. Calculate total number of lines : Total number of lines coming in data can be calculated by using count() function on particular node. Assign that value to variable TOTLINES

Consider that records are coming inside A node(refer to sample data above), like for 4 records there will be 4 A nodes present in data.

<?xdoxslt:set_variable ($_XDOCTX,'TOTLINES',count(//A))?>

this will count number of A tags coming in data, and assign that value to TOTLINES variable.

3. Page Break after every nth row : After every 46th record we want to give a page break. We decided number of records that we want per page and based on that we have to insert page breaks.

Using for-each:tag, loop through all the records

<?for-each:A?> <?B1?> <end for-each>

To keep track of count of records, we will increment variable i value using following loop

<?for-each:A?>
<?xdoxslt:set_variable($_XDOCTX,'i',xdoxslt:get_variable($_XDOCTX,'i')+1)?>
<?B1?>
<?end for-each?>

It gets the current value of i using get variable, adds 1 to that and sets new value of i.

After each nlppv(same as variable nlpp with value 46) number of records we want page break.

Check value of counter variable. When 47the record is reached give page break using xsl break-before and reset the counter variable value to 1.

<?if@inlines : xdoxslt:get_variable($_XDOCTX,'i') = xdoxslt:get_variable($_XDOCTX,'nlppv') + 1 ?>
<?xsl:attribute name="break-before"> page </xsl:attribute>
<?xdoxslt:set_variable($_XDOCTX,'i',1)?>
<?end if ?>

Now we have code in place to display each record column value and code to make sure that after every nth page a page break is inserted.

Just add Footer after the loop condition and when all records are processed, a footer will be displayed after it. But we need to display footer section at bottom of the page, so we need to add spaces based on some logic.

Decide Number of Blank Lines to add to display footer at bottom of the page.
The same way we decided value of variable nlpp in step 1, we need to run some test and check how many records a page can accommodate along with footer section().

<!--?xdoxslt:set_variable($_XDOCTX,'ilast',70)?>
The last IF EF condition is outside of main loop to display records.

If number of records on the page(value of variable i after loop is complete) is less that the total number of records that the last page can accommodate along with footer section(ilast value), we need to insert blank lines.

Following code will display blank lines to make sure footer appears at bottom of the page.
<?if:xdoxslt:get_variable($_XDOCTX,’i’)
<  (xdoxslt:get_variable($_XDOCTX,’ilast’) - 1)?>
<?for-each:xdoxslt:foreach_number($_XDOCTX,1,xdoxslt:get_variable($_XDOCTX,'ilast') - xdoxslt:get_variable($_XDOCTX,'i'),1)?>


4. Special Scenario
that need to be handled
Footer coming across pages:  This scenario is for last page alone. We need to decide the number of records that can come in single page along with footer, without footer breaking across page.

Complete Code Explanation

Variable Declarations
<?variable:nlpp;number(46)?> -- number of lines that should be displayed per page before page break

<!--?xdoxslt:set_variable($_XDOCTX, 'page', 1)?> -- keeps track of page numbers

<!--?xdoxslt:set_variable($_XDOCTX, 'i', 0)?>        --- variable used for looping through all records

<!--?xdoxslt:set_variable ($_XDOCTX,'nlast', (xdoxslt:get_variable($_XDOCTX,'TOTLINES') mod $nlpp)) ?>         --calculate number of lines for last page

<!--?xdoxslt:set_variable($_XDOCTX, 'nlppv', $nlpp)?>     --xsl variable nlpp declared above just for convenience of using short variable name

<!--?xdoxslt:set_variable ($_XDOCTX,'tpage', ceiling (xdoxslt:get_variable($_XDOCTX,'TOTLINES') div $nlpp)) ?>    --calculate total number of pages based on number of records per page calculation

<!--?xdoxslt:set_variable ($_XDOCTX,'skip',0)?>
skip is used to handle the special scenario mentioned above. To prevent footer from coming across pages, move footer on next page along with one last record.

<!--?xdoxslt:set_variable($_XDOCTX,'ilast',70)?>
-- ilast is used to decide on number of spaces that should be displayed to display footer at bottom of page. ilast is number of records that can be displayed on a page with footer coming on that page.

<!--?if@inlines:xdoxslt:get_variable($_XDOCTX,'nlast') = 0?>
<!--?xdoxslt:set_variable($_XDOCTX,'nlast',$nlpp)?>
<?end if?>

If number of records for last page is more than what last page can accommodate along with footer then we need to page break on last record.
<!--?if@inlines:xdoxslt:get_variable($_XDOCTX,'nlast') >= xdoxslt:get_variable($_XDOCTX,'ilast')?>
<!--?xdoxslt:set_variable($_XDOCTX,'skip',1)?
<?end if?>

Looping through records
<!--?xdoxslt:set_variable($_XDOCTX,'i',xdoxslt:get_variable($_XDOCTX,'i')+1)?>

for special condition give page break just after second last record
<!--?if@inlines:xdoxslt:get_variable($_XDOCTX,'tpage') = xdoxslt:get_variable($_XDOCTX,'page')
and  xdoxslt:get_variable($_XDOCTX,'skip') =1
and  xdoxslt:get_variable($_XDOCTX,'i') = xdoxslt:get_variable($_XDOCTX,'skip_at')?>

<xsl:attribute name="break-after">page        

<?end if?>

--give page break after fixed number of lines per page
<!--?if@inlines:xdoxslt:get_variable($_XDOCTX,'i') = xdoxslt:get_variable($_XDOCTX,'nlppv') +1 ?>
<xsl:attribute name="break-before">page
<!--?xdoxslt:set_variable($_XDOCTX,'i',1)?>riable($_XDOCTX,'page')+1)?>
<?end if?>

--spaces to display footer at bottom of page
<!--?if:xdoxslt:get_variable($_XDOCTX,’i’)< (xdoxslt:get_variable($_XDOCTX,’ilast’) - 1)?>
<!--?for-each:xdoxslt:foreach_number($_XDOCTX,1,xdoxslt:get_variable($_XDOCTX,'ilast') -xdoxslt:get_variable($_XDOCTX,'CR'),1)?>
<?end for-each?>
<?end if?>

Wednesday, March 27, 2013

Signal 11 Error in Oracle Report

Unhandled Exceptions in Oracle report results in generic signal 11 error, most of the time.

Identifying the cause
Run the report in Oracle report builder with correct input parameter values.
Navigation : File->Generate to File->XML

If report errors with signal 11 in oracle apps,  then running the report in report builder will throw exception with meaningful error message.

Reason


  • There is no provision for handling exceptions in main query block in Oracle report,  so if main block query has some issue,  it will result in signal 11 error or some warning, without showing meaningful error message. Mostly,  the reason main query block fails is because of :
    exact fetch returns more than one requested number of rows :  select sub-query in main query block returning multiple rows or user defined function throwing exception.
    numeric or value error : to_number function on alphanumeric column or joining two different data type columns.



  • Unhandled exceptions in report triggers
    validation trigger or after parameter form trigger or any other trigger having incorrect select queries or variable assignments which are not handled in exception block.

Monday, March 18, 2013

Writer's Block

crazyloud:  "Hey, How are you?"
"Struggling."  said lazycloud engrossed in his thoughts.  "suffering from Writer's Block."
"But you are not a writer." said crazyloud.
lazycloud: "Yes, I am."

crazyloud bewilderedly asked  "But you have never written anything."
"Because, I am experiencing Writers Block." snapped lazycloud.
crazyloud: "Like what, Since birth?"
lazycloud : "Yeah. I scribbled few words when I was a  kid, and then writer's block hit me, and  someone suggested that I try doing other things, and not think about it. So I forgot about it."
crazyloud : "And now after 30 years you realized that you are in Writers-Block phase"
lazycloud  : "Well, Now you know."

After moments pause

crazyloud : "Do you want to go out, and discover something that might inspire you."
lazyloud : "I don't need no Inspiration, I only need something to stimulate my mind."
crazyloud : "Well, that is the definition of Inspiration."
lazycloud " Oh! Okay."

crazyloud : "Hey, I have got something you might be interested in; Our company is coming with this, new social networking website, and we are looking for some really cool tag lines. Can you come up with something?"
lazycloud: "Why not. Let me think."
lazycloud:  "What about - A platform to find yourself HOT and SE...". Before lazycloud could complete crazycloud interrupts.
lazycloud "What?"
crazyloud "Its SNW, here we... blah blah.... not some fake dating or po*no website.You know."
lazycloud :"I thought that's what social networking websites are for."
lazycloud : "I didn't know they meant real social network by that. You know what, We should really talk often."

lazycloud : "No worries. I'll think of something else."
lazycloud:  "What about-  "Now flaunting has got a style. Get a real life." and then "Chance for nerds, geeks, losers to increase their social quotient, and Bitc*es to .."
crazyloud : "Wait ... Wait..  I think the first part is Okay, but  you know, we are actually targeting normal people so, nerd ,losers and ...those are  not really needed here. We need something more Creative, imaginative ... something Magical."
lazycloud: "Well, I am a writer not some....... Investment Banker or something.. I don't give a damn for these things."
"Of course, Writers don't need those qualities." said crazyloud sarcastically.
"Well, you are not incompetent enough to argue with me." said lazycloud with some pride.

Monday, February 18, 2013

Implementing Supplier Bank Account Approval in Oracle 11i

Overview

Employees who have access to Bank Account form can deliberately assign suppliers to a bank account for one’s advantage. Implementing Supplier Bank Account Approval process can eliminate fraud.

Business Need
  • Supplier Bank Account setup should be temporarily end dated after new supplier assignment or change in existing supplier assignment. No further changes should be allowed for submitted supplier assignment until approval (refer Figure 1 and 2).
  • Approver should be notified by email for changes in supplier assignment (Figure 3).
  • Approver can either approve or reject
    • After Approve, supplier assignment should become active.
    • After Reject, it should be on hold, but submitter should be allowed further changes.

Wednesday, January 30, 2013

Web scrapping using Jsoup

Download latest jsoup jar file (Download Link).

Compile code with appropriate class path value, like

javac -cp "C:\jsoup-1.7.1.jar"  "TestClass.java"

java  -cp  "C:\jsoup-1.7.1.jar"  TestClass

Simple Example using Jsoup to connect to server using login credentials and then retrieving specific page.

[sourcecode language="java"]

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.Connection;
import java.io.IOException;
import org.jsoup.Connection.Method;
import java.util.HashMap;
import java.util.Map;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

public class TestClass
{
public static void main(String args[]) throws IOException
{

Document doc = Jsoup.connect("<URL>").get();

Elements viewState = doc.select("input[name=__VIEWSTATE");
Elements eventValidation = doc.select("input[name=__EVENTVALIDATION]");

Map<String,String> allFields = new HashMap<String,String>();
allFields.put("__VIEWSTATE", viewState.val());
allFields.put("__EVENTVALIDATION", eventValidation.val());
allFields.put("txtLogin", "<USERNAME>");
allFields.put("txtPassword",   "<PASSWORD>");
allFields.put("butSubmit",   "Sign In");

System.out.println(allFields);

Connection.Response res = Jsoup.connect("<URL2>")
.userAgent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.21 (KHTML, like Gecko) Chrome/19.0.1042.0 Safari/535.21")
.data(allFields)
.method(Method.POST).
execute();

String sessionId = res.cookie("<COOKIENAME>");

System.out.println(sessionId);

Document doc2  = Jsoup.connect("URL3")
.cookie("ASP.NET_SessionId", sessionId)
.timeout(0)
.get();

System.out.println(doc2.html());

}
}

[/sourcecode]