I have right this code some help to check if this ok or should I change something. i did not try this
import sailpoint.object.Identity;
import sailpoint.object.Link;
import java.util.Date;
import sailpoint.object.Policy;
import sailpoint.object.PolicyViolation;
import sailpoint.object.CertificationLink;
import sailpoint.api.IdentityService;
import sailpoint.tools.GeneralException;
import sailpoint.tools.Message;
import java.text.SimpleDateFormat;
import java.text.DateFormat;
import java.util.*;
/**
*return a date 90 days before today.
*/
private Date getDateNDaysAgo(int numDays) {
Calendar cal = Calendar.getInstance();
Date returnDate = null;
cal.add(Calendar.DATE, -(numDays));
returnDate = cal.getTime();
return (returnDate);
}
/**
* Checks if the first date is before the second date ignoring time.
**/
public static boolean isBeforeDay(Date date1, Date date2) {
if (date1 == null || date2 == null) {
throw new IllegalArgumentException("The dates must not be null");
}
Calendar cal1 = Calendar.getInstance();
cal1.setTime(date1);
Calendar cal2 = Calendar.getInstance();
cal2.setTime(date2);
if (cal1 == null || cal2 == null) {
throw new IllegalArgumentException("The dates must not be null");
}
if (cal1.get(Calendar.ERA) < cal2.get(Calendar.ERA)) return true;
if (cal1.get(Calendar.ERA) > cal2.get(Calendar.ERA)) return false;
if (cal1.get(Calendar.YEAR) < cal2.get(Calendar.YEAR)) return true;
if (cal1.get(Calendar.YEAR) > cal2.get(Calendar.YEAR)) return false;
return cal1.get(Calendar.DAY_OF_YEAR) < cal2.get(Calendar.DAY_OF_YEAR);
}
CertificationLink certificationLink = identity.getLatestCertification();
System.out.println("Latest Certification Link of Identity: " + certificationLink);
Date certificationCompletionDate = certificationLink.getCompleted();
//throwing Null at the above line
Date testDate = getDateNDaysAgo(90);
if (isBeforeDay(certificationCompletionDate, testDate)) {
v = new PolicyViolation();
v.setActive(true);
v.setIdentity(identity);
v.setPolicy(policy);
v.setConstraint(constraint);
v.setDescription("[Last Login Date is more than 90 days ago.]");
v.setStatus(sailpoint.object.PolicyViolation.Status.Open);
}
return v;
}