Get current date, time , timestamp in Java

You can get the current date time via following two classes – Date and Calendar. And, later use SimpleDateFormat class to convert the date into user friendly format.

-> Date() + SimpleDateFormat()

DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yy HH:mm:ss");
Date date = new Date();
System.out.println(dateFormat.format(date));

-> get the time

Date date = new Date();
System.out.println(date.getTime());

-> get the time stamp

Date date = new Date();
System.out.println(new Timestamp(date.getTime()));

You can define various format i.e

-> dd-MMM-yy HH:mm:ss
-> yyyy/MM/dd HH:mm:ss
-> yy/MM/dd HH:mm:ss

You can use as working code like

import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
 
 
public class GetCurrentDateTime {
  public static void main(String[] args) {
 
	   DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
	   //get current date time with Date()
	   Date date = new Date();
	   System.out.println(dateFormat.format(date));
            
           //get the time
           Date date = new Date();
	   System.out.println(new Timestamp(date.getTime()));

           // get the timestamp
 
  }
}

Dynamic Creation of cascading Lov in oracle ADF or model driven Lov in Oracle ADF.

Requirement – I am working on tricky requirement where i have two child component and one child LOV.How to do that?

Solution- Well if you have working knowledge of cascading LOV in then we pass bind parameter of parent LOV attribute in child LOV View Accessor(VA) . But in this scenario , we have two master LOV. then we will be doing by passing through managed bean, using Application module session .

What i have done.I have used HR schema .

I have 3 view object. one as country table of HR schema.One View object for location table.One view which have all transient attribute and consider to be main view object.

As i found this approach in Jobinesh’s blog- i write a custom method in applicationModuleImpl.java as below –

    public void setLocationIDSessionData(String locId){
          System.out.println("hello 232323&&&"+locId);
        this.getSession().getUserData().put("LocationId", locId);
        
      }

I have getUserData method of applicationModule interface which returns a java.util.Hashtable which may be used to store user specific context that is related to this application session.

Read all other method related to this
http://docs.oracle.com/cd/E12839_01/apirefs.1111/e10653/oracle/jbo/ApplicationModuleHandle.html

Ok, coming back to this requirement – I used a managed bean in backing bean scope where i executed the binding of applicationModuleImpl custom method as below –

    public void executec(String valueChangeEvent) {
    BindingContext bctx = BindingContext.getCurrent();
           BindingContainer bindings = bctx.getCurrentBindingsEntry();
           OperationBinding op =
               (OperationBinding)bindings.getOperationBinding("setLocationIDSessionData");
           op.getParamsMap().put("locId",valueChangeEvent);
           op.execute();
    }

Here we are passing the value of both LOV to locationId to custom applicationModuleImpl method.In both parent LOV , i create valuechangeEvent method , which get the current selected countryId and pass to custom applicationModuleImpl method. that is below –

    public void VC(ValueChangeEvent valueChangeEvent) {
      System.out.println("hello &&&"+valueChangeEvent.getNewValue());
      
       
        executec(valueChangeEvent.getNewValue().toString());
    }

    public void vc2(ValueChangeEvent valueChangeEvent) {
        System.out.println("hello &&&34343"+valueChangeEvent.getNewValue());
        executec(valueChangeEvent.getNewValue().toString());
    }

Now we have final task, we have to set the value of child lov bind parameter in child View Accessor as adf.userSession.userData.LocationId

That’s it.now we will run the jspx , which have all 3 lov.2 parent and one child LOV.
for displaying LOV , we need to click on create button.after click you can see all 3 LOVs.

After selecting county as CH from countryLov1 , we will see different values in location ID.

Now we will select country as IN from countryLov2 , we will see different values in location ID.

You can download the sample application here.

ModelDrivernCascadingLOVs

Happy coding with Vinay kumar in techartifact….

Using WebLogic Server Embedded LDAP

LDAP is widely used in webapplication for authorization .we have to set embedded weblogic LDAP server for setting up development enviroment.
First question we have – What is LDAP ?

LDAP is Lightweight Directory Access Protocol.LDAP is a protocol for accessing a directory. A directory contains objects; generally those related to users, groups, computers, printers and so on; company structure information (although frankly you can extend it and store anything in there).
LDAP gives you query methods to add, update and remove objects within a directory (and a bunch more, but those are the central ones).

-Connect to a directory (with varying levels of security)
-Read the entries in a directory
-Write entries in a directory
-Search a directory
-Rename entries in a directory
-Delete entries in a directory

IF you are reading about LDAP the you should also know –

what is directory
A directory is a type of hierarchical database. It is made up of entries, that have a globally unique name, and contain attributes that are named collections of data values. directories are optimised for fast look up, they have a strong security model and they scale well. Because they are a tree structure, different parts of the tree can be maintained by different directories and different administrators. The tree data structure also fits some cases much better than a relational database. (BTW – If you’re familiar with relational databases, ldap is conceptually similar to SQL.)

CONNECT TO WEBLOGIC SERVER EMBEDDED LDAP USING LDAP BROWSER-

WebLogic Server includes an embedded LDAP server that acts as the default security provider data store for the Default Authentication, Authorization, Credential Mapping, and Role Mapping providers.embedded LDAP server contains user, group, group membership, security role, security policy, and credential map information. By default, each WebLogic Server domain has an embedded LDAP server configured with the default values set for each type of information. The Default Authentication, Authorization, Credential Mapping, and Role Mapping providers use the embedded LDAP server as their data store.

In the WebLogic Server Administration Console, change the credential for the embedded LDAP server:

Expand Domain > Security > Embedded LDAP.

– In the Credential field, enter the new credential.

– In the Confirm Credential field, enter the new credential again.

– Click Save.

– Restart WebLogic Server.

Now we will be needing the LDAP browser to access it.There are multiple LDAP browser like

– OpenLDap -http://www.openldap.org/
– jxplorer – jxplorer.org

Following is connection parameter as below –

Hostname: Hostname of the WebLogic Server.
Port: WebLogic Admin Server port.
Base DN: This is the WebLogic domain name.
User DN: By default the Admin user DN is cn=Admin.
Password: Admin user password

1 In the LDAP browser, configure a new connection in the LDAP browser:

-Select the QuickConnect tab.

-Set the host field to localhost.

-Set the port field to 7001 (7002 if SSL is being used).

Set the Base DN field to dc=mydomain where mydomain is the name of the WebLogic Server domain you are using.

– Uncheck the Anonymous Bind option.

– Set the User DN field to cn=Admin.

– Set the Password field to the credential you specified in Step 2.

2 Click the new connection.

– Use the LDAP browser to navigate the hierarchy of the embedded LDAP server.

Now You can create users/groups .

Hope it helps ..happy coding with Vinay in techartifact ……