Thursday 27 September 2012

Creating role,user and grant role to user using OPSS



        JpsContextFactory ctxf = JpsContextFactory.getContextFactory();
        JpsContext ctx = ctxf.getContext();
        IdentityStoreService storeService = ctx.getServiceInstance(IdentityStoreService.class);
        IdentityStore idStore = storeService.getIdmStore();
        RoleManager rm=idStore.getRoleManager();
        rm.createRole("sampleRole");
        UserManager um=idStore.getUserManager();
        // creating user
       um.createUser("username", "password".toCharArray());

       //grant role to user

            if( um.isCreateUserSupported()){
             
            User u=idStore.searchUser(IdentityStore.SEARCH_BY_NAME,"username");
                                   
            Role role =idStore.searchRole(IdentityStore.SEARCH_BY_NAME,"sampleRole");
                 
            idStore.getRoleManager().grantRole(role,u.getPrincipal());
         
           }
       

Oracle ADF 11g interview questions


 Q : What are various components in ADF?
A : Oracle ADF has following components

·         ADF Business Components(Model)
·         ADF Faces (View)
·         ADF Taskflows(Controller)
Q : What is Oracle ADF?
A : Oracle ADF is an commercial java/j2ee framework, which is used to build enterprise applications.
It is one of the most comprehensive and advanced framework in market for J2EE

Q : What are the advantages of using ADF?
A : Following are the advantages of using :

·         It supports Rapid Application Development.
·         It is based on MVC architecture
·         Declarative Approach (XML Driven)
·         Secure
·         Reduces maintenance cost and time
·         SOA Enabled
Q : What is the return type of Service Methods?
A : Service Methods can return Scalar or Primitive Data types.

Q : Can Service Methods return type Void?
A : Yes, Service Methods can Return type Void

Q : Can Service Methods return Complex Data types?
A : No, service methods can return only primitive/scalar data types.

Q : Which component in ADF BC manages transaction ?
A : Application Module, manages transaction.

Q : Can an entity object be based on two Database Objects(tables/views) or two Webservices ?
A : No entity objects will always have one to one relationship with a database object or web service.

Q : Where is that we write business rules/validations in ADF and why?
A : We should be writing validations at Entity Object level, because they provide highest degree of reuse.

Q : What is Managed Bean?
A : Managed bean is a java class, which is initialized by JSF framework. It is primarily used to hold view and controller logic. It is also used to execute java code to be executed on a user action like Button Click.

Q : What are Backing Bean?
A : Backing beans are those managed beans which have 1:1 mapping with a page. They have getters and setters
for all the components in the related page.

Q : What is a Taskflow?
A : Taskflow is the controller of an ADF application, it provides us an declarative approach to define the control flow.  It is used to define the navigation between pages and various taskflow activites.

Q : What are the different types/categories of Taskflows ?
A :  Taskflows are of two categories : Bounded and UnBounded.

Q : What is the difference between Bounded and UnBounded taskflows?
A : Differences between Bounded and UnBounded taskflows :

·         Bounded taskflows can be secured but Unbounded can’t.
·         Bounded taskflows can accept parameter and return values but unbounded taskflows don’t support parameters
·         Bounded taskflows has a single entry point or a default activity but unbounded taskflows have multiple entry points.
·         Bounded taskflows can be called from other bounded/unbounded taskflows but unbounded cannot be called or reused.
·         Bounded taskflows support transactions unbounded don’t

Q : What are the various access scopes supported by ADF?
A : ADF Faces supports the following scopes

·         Application Scope
·         Session Scope
·         PageFlow Scope
·         Request Scope
·         BackingBean Scope.
Q: What is databindings.cpx file in ADF?
A:
In ADF web application as soon as you drop a databound component on your page a DataBindigs.cpx file gets created. You may wonder what it contains? So, here it is:

The DataBindings.cpx keeps track of the individual page definitions files used within the project, as well as the DataControls mapping to such things as ADF Business Components Application Modules.

Till Jdeveloper 10.1.3 release there was no way to have multiple DataBindings.cpx files which was very much desirable as the project the size grows and being worked by multiple teams. Jdeveloper 11g added this capability to have multiple DataBindings.cpx files.

There is a new file in 11g called adfm.xml which is used to keep track of all such DataBindings.cpx files in the system. So, when breaking your DataBindings.cpx you need to take care to create an entry in the adfm.xml. You also need to make sure to have unique application id attribute value for each entry.
Q: How to Skip Validation?
A: At view layer Keep immediate=true

Q : Describe life cycle of a ADF Page?
A : ADF page is an extension of JSF and has following phases in its lifecycle

1.       Initialize Context: In this phase the adf page initializes the LifecycleContext with information that will be used during the Lifecycle.
2.       Prepare Model:  In this phase ui model is prepared and initialized. In this phase page parameters are set and methods in the executable section of the page definition of the ADF page are executed.
3.       Apply Input Values: This phase handles the request parameters. The values from the HTML are sent to the server  and applied to the page binding in page definitions.
4.       Validate Input Values:  This phase validates the values that were built in the Apply input values phase
5.       Update Model:  Validated values supplied from user are sent to ADF business components data model
6.       Validate Model Updates:  In this phase the business components will validate user supplied values.
7.       Invoke Application:  This phase will process the ui events stack built during the life cycle of page and also fire navigational events
8.       Prepare Render:  This is the final phase where HTML code is generated from the view tree.

Q: What is Association and Viewlink ?
A: They define the join or the link among EO’s and VO’s.Association defines link between EO’s.They can be considered as PrimaryKey/ForeignKey relationship between tables.
The Viewlink is for a VO.It defines the Join conditions.A viewlink can be based on an association or based on attributes,Basing viewlinks on associations have the same advantage of entity cache and few more which are unveiled later.







Wednesday 26 September 2012

Get Application Module object in Managed bean


FacesContext context = FacesContext.getCurrentInstance();

BindingContext bindingContext = BindingContext.getCurrent();

//open the dataBindings.cpx file and check for application module name inside data control usages

DCDataControl dc  = bindingContext.findDataControl("name_of_application_module in dataBindings.cpx");

AppModuleImpl appM = (AppModuleImpl)dc.getDataProvider();

Tuesday 11 September 2012

Date Format example in java


import java.text.*;
import java.util.*;

public class DateFormat {

  public static void main(String args[]) {

  String s;
  Format formatter;
  Date date = new Date();

  // 01/09/02
  formatter = new SimpleDateFormat("MM/dd/yy");
  s = formatter.format(date);
  System.out.println(s);

  // 01/09/02
  formatter = new SimpleDateFormat("dd/MM/yy");
  s = formatter.format(date);
  System.out.println(s);

  // 29-Jan-02
  formatter = new SimpleDateFormat("dd-MMM-yy");
  s = formatter.format(date);
  System.out.println(s);

  // 2002.01.29.08.36.33
  formatter = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss");
  s = formatter.format(date);
  System.out.println(s);

  // Tue, 09 Jan 2002 22:14:02 -0500
  formatter = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z");
  s = formatter.format(date);
  System.out.println(s);

  formatter = new SimpleDateFormat("EEEE, dd MMMM yyyy HH:mm:ss zzzz");
  s = formatter.format(date);
  System.out.println(s);
  }
}

Creating file in java



Following code is to create file "testfile.txt" in current directory.

import java.io.*;

public class SampleFile{
  public static void main(String[] args) throws IOException{
  File f=new File("testfile.txt");
  if(!f.exists()){
  f.createNewFile();
  System.out.println("New file \"myfile.txt\" has been created 
  to the current directory");
  }
  }
}

Oracle ADF 11g Creating Dependent LOV's

Create new Fusion web application

1. create entity object on Employee table.

2. Select only EmployeeId and DepartmentId attributes because we are creating dependent LOV on this two attributes.

3.Select View Object check box or create new view object with Employee entity.

4.Select Application Module check box or create new Application module and assign employee view object to it as shown below.


5. Create View Accessors on EmployeeId and DepartmentId. Click on View Accessors tab and add new shuttle the EmployeeVO and rename it to "EmpidVA"  as shown in below figure.


6. Similarly create view accessors on DepartmentID with name "DeptIdVA"

 7. In Employee View Object click on Attributes tab, select EmployeeId attribute click on list of values and select the options as shown in following images.


8. Select list attribute as EmployeeId


9. click on UI hints tab and shuttle the EmployeeId


10. Similarly create the list of values for DepartmentId Attribute.

11.Click on the Query Tab and create new view criteria


12. click on Add Item and select bind variable


13. Click on add symbol in parameter option, give the variable name as "bDeptId" and select data type as Integer click on ok.

14. Now go to the view Accessors and select "EmpVA" and click on edit symbol. Shuttle employee criteria and bind the parameters as shown below.



15. Run the application module and test the business component.



You can download the application. Dependentlov



Monday 10 September 2012

Convert java.util.Date to java.sql.Date

import java.sql.Date;
class sqlDate
{


//Method to convert  java.util.Date to java.sql.Date

public static Date UtilDateToSqlDate(java.util.Date utilDate) {
  Date sqlDate = null;
  if (utilDate != null)  sqlDate = new Date(utilDate.getTime());
  return sqlDate;
 }

// Method to convert java.sql.Date to java.util.Date

 public static java.util.Date SqlDateToUtilDate(Date sqlDate) {
  java.util.Date utilDate = null;
  if (sqlDate != null)  utilDate = new java.util.Date(sqlDate.getTime());
  return utilDate;
 }


public static void main(String args[])

{
java.util.Date d1 = new java.util.Date();
  System.out.println("Util Date : "+ d1);


java.sql.Date d2 =UtilDateToSqlDate(d1);
  System.out.println("Sql Date : " + d2);



java.util.Date d3= SqlDateToUtilDate(d2);
  System.out.println("Back to Util Date : "+ d3);
}


}