Tuesday, August 21, 2012

A day on Python - Basics

Why Python: Provide better inegration with other language.

How to start Python: login to command promp and type python

Basic Syntax: Require tabs or equal number of spaces to make block.
No Declaration required.

a=10
a =>10
print a => 10

a="Hello\n how are u"
a => "Hello\n how are u"
print a => Hello
                how r u
print type(a) => 'str'

a=2+3j
print a.real and print a.imag
operators: ==,!=,<>, bitwise operators, += ,...

a=10
a is 10 => true
a is not 10 => false

a='hello'
'h' in a => true
'H' in a => false

which python => path and name of interpreter.

Create Script:
vi Script.py
#! /user/bin/

import Script.py => This will execute all the command defined outsids the functions
To import function use: from script import function/variable/*

Using modules::
help()
modules =>List of all modules

To write command in multiple lines:
a='''line1
line2
line3'''
print a => line1
                line2
                line3

Type Casting:
a='458'
b = int(a)

a="Part1"
b="and Part2"
a+' '+b => Part1 and Part2
s= a*2
print s => Part1Part1

If Statement
if a>10:
(tab) print "true"
(tab) print "If done"
else:
(tab) print "Else Part"
(press ctrl+D) to terminate the command if using on prompt

a=[1,2,3]
for var in a
(tab/space) print var
for i in range(1,10)
(tab/space) print var


Using else with while
i=2
a=10
while i<a:
  if  a%i ==0
    print "Not Prime"
    break
 i+=1
else:
   print "Prime" => This else will only be executed when the condition of while is false, not when break is called.

Taking inputs:
1) Integer inputs:
a = input("Enter Value")
Enter Value 10
a => 10
2) String/Char input:
a=raw_input("Enter")
Enter 10
a => '10'

List of Char/String to String
a=['a','b']
s= ''.join(a)
print s =>'ab'
Split again to list
list(s) => ['a','b']
a="hello"
list(a) => ['h','e','l','l','o']
a="Hello how r u"
a.split(' ') => ['Hello', 'how', 'r', 'u']

Concatinate:
a=[1,2,3,4]
a+[10,20] => [1,2,3,4,10,20]

Sorting
a=[1,2,5,4,3]
a.sotr() => [1,2,3,4,5]
a.reverse()
a.pop() => Delete last element and return that element
a.pop(index) => Delete element at index
a.remove(3) => Will remove elemement 3 itself (not at index 3)
a.append([1,2,3]) =>will append [1,2,3] as list at last position
a.insert(0,10) => insert at 0th index

Call be Value and Reference
a=[1,2,3]
b=a => by reference
c=a[:] => by value

Dictionary::
dict={key1:'Value', key2:Value}
dict.has_key(key1) => True
dick.get(key1) => Value
del dick[Key1] => Will delete Key1
d.keys() => Return all Keys
d.values()
d.items()
d.iterkeys() => To iterate over keys

Tuple: Unmodifiable list
a= 1,2,3 or a=(1,2,3)

Using Functions
def functionName(n):
(tab/space) function body

Exception Handling
try:
     body
except ExceptionType,msg
     print msg

Using Modules:
Math: This module provides map, reduce and filter

Saturday, August 18, 2012

Create Row as last row in table


Source: https://blogs.oracle.com/jdevotnharvest/entry/how_to_add_new_adf

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;
}  
For the table to show the newly created row after this ensure:

1. The table is configured to always show the current selected row by setting 
 its displayRow property to selected
2. The table is PPR'ed after the row is created, which can be done declarative 
using the PartialTriggers property of the table pointing to the ID of the command creating the new row

Friday, August 10, 2012

Oracle ADF Global Resource Bundle

Keeping resource bundle inside ViewController project will not allow the bundle to be updated at runtime. In order to update the resource bundle at runtime without redeploying the application or without restarting the server there are few options, some of them are listed below:

1) Keep the resource bundle string in database: This is already discussed in following post.

2) Keep resource bundle in custom location on weblogic server: This method requires the path of property file to be set in setDomainEnv.cmd file as follows

set JAVA_OPTIONS=%JAVA_OPTIONS% -DpropFileLoc=C:\bundleDir\MyBundle.properties

This property can be read in bean file using

       String propFilePath = System.getProperty("propFileLoc");

Now the bundle string can be read using either of following:

       InputStream iStream = this.getClass().getResourceAsStream(propFilePath );
OR
       InputStream iStream = new FileInputStream(propFilePath);

       prop.load(iStream );
       bundleText=prop.getProperty("bundleText");

The advantage of above way of accessing the bundle is that we can keep the bundle file at any custom location on the server.

3) Keep resource bundle file in Domain directory: This method does not require the setDomainEnv.cmd file to be changed. The file can directly be accessed using following code:

        InputStream is=new FileInputStream("./MyBundle.properties");
        Properties prop=new Properties();
        prop.load(is);
        prop.getProperty("bundleText");

Instead of writing bean for loading the resource bundle, we can write a servlet to read the property file and return the key value. On jspx page, the servlet can then be access from the component attributes like value or image as follow:

         <af:image id="i1" source="/myServlet?propName=bundleText"/>

Wednesday, August 8, 2012

Exception while creating Content repository connection

Upgraded to JDeveloper 11.1.1.6 and got below exception while creating content repository connection

Performing action Content Repository...[ from oracle.jdeveloper.appresources.ApplicationResourcesWindow ]
Exception while performing action Content Repository...
java.lang.NoClassDefFoundError: javax/jcr/Credentials
j.lang.Class.getDeclaredMethods0(Native Method)
j.lang.Class.privateGetDeclaredMethods(Class.java:2427)
j.lang.Class.getDeclaredMethod(Class.java:1935)
j.a.Component.isCoalesceEventsOverriden(Component.java:5974)
j.a.Component.access$500(Component.java:170)
j.a.Component$3.run(Component.java:5928)
j.a.Component$3.run(Component.java:5926)
j.security.AccessController.doPrivileged(Native Method)
j.a.Component.checkCoalescing(Component.java:5925)
j.a.Component.<init>(Component.java:5894)
j.a.Container.<init>(Container.java:251)
jx.s.JComponent.<init>(JComponent.java:570)
jx.s.JPanel.<init>(JPanel.java:65)
jx.s.JPanel.<init>(JPanel.java:92)
jx.s.JPanel.<init>(JPanel.java:100)
o.webcenter.content.internal.dt.connection.wizard.Adapter
.......
Caused by:
oracle.classloader.util.AnnotatedClassNotFoundException:

Missing class: javax.jcr.Credentials

Solution: Copy the JCR1.0 jar file in Middleware_Home/Jdeveloper/lib/java/api folder.

Monday, June 18, 2012

Webcenter Portal Cluster


pack.sh -domain=$MW_HOME/user_projects/domains/vfm2m_wc -template=/tmp/m2m_domain.jar -template_name=”M2M Domain” -managed=true

unpack.sh -domain=/home/oracle/Oracle/Middleware/user_projects/domains/vfm2m_wc -template=/tmp/m2m_domain.jar

Wednesday, June 13, 2012

Password Policy in OID


In general, establishing a password policy requires the following steps:

1) Create a password policy entry in the appropriate container and associate it with the pwdpolicy object. (Default entries exists when you first install Oracle Internet Directory.)
2) Create the desired policy by setting values for attributes defined under the pwdpolicy object class for the entry created in step 1.
3) Enable the policy by setting the orclepwdpolicynable attribute to 1. If this is not set to 1, Oracle Internet Directory ignores the policy.
4) Determine the subtree to be governed by the policy. Add and populate a pwdpolicysubentry attribute with the policy's DN, at the root of that subtree.

http://docs.oracle.com/cd/E25178_01/oid.1111/e10029/pwdpolicies.htm

Configuring redirection in OHS from http to https

In order to redirect the http requests coming to OHS to https , we can make following changes in httpd.conf file::

NameVirtualHost *:80
<VirtualHost *:80>
 ServerName "host name of the server sending the request"
 SeverAdmin your@Address
 RewriteEngine on
 RewriteOptions inherit
 Redirect permanent / https://"host name of the server":443
</VirtualHost>