At one of our clients we use identity triggers for joiners, movers and leavers. Joiners and Leavers are to be processed as soon as possible while a mover is only processed it all role assignment, events are processed and also after the latests aggregations to have an clear view on what has been changed during the move processing/reassignment of business roles.
I have created an identity mover trigger to store the identityName in a custom object and run a task at the end of the daily processing to really start the certification.
The code to start the certification from the task is:
Initialize the certification aka create a new certification Template function:
public CertificationDefinition initializeCertification (CertificationDefinition template, String name, String accReviewName, String accReviewShortName, Date date, String certOwner) throws GeneralException {
if (log.isDebugEnabled()) log.debug("in initialize cert");
//Cloning Certificate from existing template
XMLObjectFactory instance = XMLObjectFactory.getInstance();
CertificationDefinition newcert = (CertificationDefinition) instance.cloneWithoutId(template, (XMLReferenceResolver) context);
newcert.setCreated(date);
newcert.setModified(date);
newcert.setName(name);
newcert.setCertificationNameTemplate(name);
newcert.setNameTemplate(accReviewName);
newcert.setShortNameTemplate(accReviewShortName);
Attributes attrMap = newcert.getAttributes();
attrMap.put("owners", certOwner);
newcert.setAttributes(attrMap);
if (log.isDebugEnabled()) log.debug("newcert: " + newcert.toXml());
context.saveObject(newcert);
context.commitTransaction();
context.attach(newcert);
return newcert;
}
Schedule the certification function:
public void scheduleCertification (String certId, String name) throws Exception {
if (log.isDebugEnabled()) log.debug("in schedule cert");
TaskSchedule taskSchedule = new TaskSchedule();
taskSchedule.setName(name);
taskSchedule.setLauncher("spadmin");
taskSchedule.setArgument("certificationDefinitionId", certId);
taskSchedule.setArgument("executor", "Certification Manager");
taskSchedule.setArgument("resultName", "Certification executor");
TaskManager tm = new TaskManager(context);
TaskResult tr = tm.runSync(taskSchedule, new HashMap());
log.debug("taskresult: " + tr.calculateCompletionStatus().toString());
}
To call the above functions with some data:
- moverName = the name of the identity
- Certification Definition to clone : Mover Certification
Identity moverIdentity = context.getObjectByName(Identity.class, moverName);
moverIdentityName = moverIdentity.getDisplayName();
if (log.isDebugEnabled()) log.debug("Creating mover cert for "+ moverIdentityName);
Date today = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(today); // don't forget this if date is arbitrary e.g. 03-14-1879
int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH); // 14
int month = cal.get(Calendar.MONTH) + 1; // 3
int year = cal.get(Calendar.YEAR); // 2018
CertificationDefinition moverCertTemplate = context.getObject(CertificationDefinition.class, "Mover Certification");
String moverCertName = "Certification for Mover " + moverIdentityName + " " + year + "-" + month + "-" + dayOfMonth;
String accReviewName = "Certification for Mover " + moverIdentityName + " ("+ moverName + ") " + year + "-" + month + "-" + dayOfMonth;
String accReviewShortName = "Certification for Mover " + moverName + " " + year + "-" + month + "-" + dayOfMonth;
CertificationDefinition moverCertDef = initializeCertification(moverCertTemplate, moverCertName, accReviewName, accReviewShortName, today, "Mover certificeerders");
List certIdentitiesList = new ArrayList();
certIdentitiesList.add(moverName);
moverCertDef.setIdentitiesToCertify(certIdentitiesList);
scheduleCertification(moverCertName,"sched-"+moverCertName);
I hope this helps and provides creativity
– Remold