I'll Get My Coat

Identity Management? I'll Get My Coat...


Wednesday Dec 05, 2007

Java Date Comparisons In Identity Manager

During my POC rounds I often come up against Identity Management requirements to manipulate date strings, for example, a contract hire date coming from a HR feed inside a CSV file, when should this user be provisioned? When should this user be deprovisioned? How long should this compliance violation be mitigated? I'm often re-writing the same piece of logic so the logic implies that others using Sun Identity Manager are doing similar, so I'll post my contribution to this blog mainly to stop me loosing it all the time (doh)... So here's the java version with the code logic adapter to XPRESS. Just to note that from within Identity Manager both Java and XPRESS can be called so you're free to select your poison ..
 

import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
 public class DateTestEADS{
public static void main (String args[]){
String dateString = "31.10.2007";
Calendar todayCal = Calendar.getInstance();
Date todayDate = todayCal.getTime();
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy") ;

// Parse the date
try {
Date endDate = format.parse(dateString);
System.out.println("Original string: " + dateString);
System.out.println("Parsed date : " + endDate.toString());
System.out.println("Todays date : " + todayDate);
Calendar endCal = new GregorianCalendar();
endCal.setTime(endDate);boolean result = endCal.after(todayCal);
System.out.println("Q:Is the date " + dateString + ", after today? A:"+result);
}
catch(ParseException pe) {
System.out.println("ERROR: could not parse date in string \"" + dateString + "\"") ;
}
}
}

Here's the same logic in XPRESS

 

<RuleArgument name='dateString' value='31.12.2007'>
    <Comments>A date such as "31.10.2007" as a string</Comments>
    <String>31.12.2007</String>
  </RuleArgument>
  <block>
    <defvar name='todayCal'/>
    <defvar name='todayDate'/>
    <defvar name='endDate'/>
    <defvar name='endCal'/>
    <defvar name='format'/>
    <set name='todayCal'>
      <invoke name='getInstance' class='java.util.Calendar'/>
    </set>
    <set name='endCal'>
      <new class='java.util.GregorianCalendar'/>
    </set>
    <set name='todayDate'>
      <invoke name='getTime'>
        <ref>todayCal</ref>
      </invoke>
    </set>
    <set name='format'>
      <new class='java.text.SimpleDateFormat'>
        <s>dd.MM.yyyy</s>
      </new>
    </set>
    <block name='parse the date'>
      <set name='endDate'>
        <invoke name='parse'>
          <ref>format</ref>
          <ref>dateString</ref>
        </invoke>
      </set>
      <invoke name='setTime'>
        <ref>endCal</ref>
        <ref>endDate</ref>
      </invoke>
      <invoke name='after'>
        <ref>endCal</ref>
        <ref>todayCal</ref>
      </invoke>
    </block>
  </block>




Today's Page Hits: 44

attachmate date desktop dsee firefox global grenoble identity identity+manager identitymanager java management manager plugin rbac rbacx roles secure sgd solaris sun test vauu webservices xpress