Sometimes you need to programmatically close reconciliation events such as if you enabled “sequence recon” in the resource object. I was also required to send a notification to the administrator to alert him is a trusted source reconciliation event failed to process.
Since OIM does not provide any facility to do either of these tasks, I wrote a schedule task to meet this requirement. The task will send an email to the administrator after a specified interval defined with a task attribute) from the trusted source reconciliation task.
Since OIM does not provide any facility to do either of these tasks, I wrote a schedule task to meet this requirement. The task will send an email to the administrator after a specified interval defined with a task attribute) from the trusted source reconciliation task.
import java.util.HashMap;
import Thor.API.tcResultSet;
import Thor.API.Operations.tcITResourceInstanceOperationsIntf;
import Thor.API.Operations.tcReconciliationOperationsIntf;
import com.thortech.util.logging.Logger;
import com.thortech.xl.dataaccess.tcDataProvider;
import com.thortech.xl.dataaccess.tcDataSet;
import com.thortech.xl.dataobj.util.tcEmailNotificationUtil;
import com.thortech.xl.scheduler.tasks.SchedulerBaseTask;
public class ReconFailureNotification extends SchedulerBaseTask
{
private tcITResourceInstanceOperationsIntf itResObj=null;
private tcReconciliationOperationsIntf reconintf = null;
private static Logger logger = Logger.getLogger(“MYSCHTASKS”);
private String username;
private long obj_key;
public void init()
{
tcDataProvider db = super.getDataBase();
reconintf = (tcReconciliationOperationsIntf)getUtility(“Thor.API.Operations.tcReconciliationOperationsIntf”);
}
public void execute()
{
try
{
String mQuery1 = “SELECT OBJ_KEY FROM OBJ WHERE OBJ_NAME = ‘PSFT_ER_RO’”;
tcDataSet obj_set = new tcDataSet();
obj_set.setQuery(db, mQuery1);
obj_set.executeQuery();
obj_set.goToRow(0);
obj_key = obj_set.getLong(“OBJ_KEY”);
String interval = getAttribute(“Interval”);
String mQuery2 = “SELECT RCE_KEY FROM RCE WHERE SYSDATE – RCE_CREATE < ” + interval + “/1440 AND RCE_STATUS != ‘Event Linked’ AND RCE_STATUS != ‘Event Closed’ AND OBJ_KEY = ” + obj_key ;
tcDataSet recon_events = new tcDataSet();
recon_events.setQuery(db, mQuery2);
recon_events.executeQuery();
if (recon_events.getTotalRowCount() > 0 )
{
long orf_key;
String mQuery3 = “SELECT ORF_KEY FROM ORF WHERE ORF_FIELDNAME = ‘Users.ConsolNo’” ;
tcDataSet orf_set = new tcDataSet();
orf_set.setQuery(db, mQuery3);
orf_set.executeQuery();
orf_key = orf_set.getLong(“ORF_KEY”);
StringBuilder body = new StringBuilder();
body.append(“The following reconciliation events have failed:\n\n”);
for (int i = 0; i < recon_events.getTotalRowCount(); i++)
{
long rce_key;
String rcd_value = “Not found”;
recon_events.goToRow(i);
rce_key = recon_events.getLong(“RCE_KEY”);
String mQuery4 = “SELECT RCD_VALUE FROM RCD WHERE RCE_KEY = ” + rce_key + ” AND ORF_KEY = ” + orf_key + ” ORDER BY RCE_KEY ASC” ;
tcDataSet rcd_set = new tcDataSet();
rcd_set.setQuery(db, mQuery4);
rcd_set.executeQuery();
if (rcd_set.getTotalRowCount() > 0 )
{
rcd_value = rcd_set.getString(“RCD_VALUE”);
}
body.append(“Event number: ” + rce_key + “\t\t” + “Consolidated number: ” + rcd_value + “\n\n”);
reconintf.closeReconciliationEvent(rce_key);
}
itResObj = (tcITResourceInstanceOperationsIntf)getUtility(“Thor.API.Operations.tcITResourceInstanceOperationsIntf”);
HashMap hashmap1 = new HashMap();
hashmap1.put(“IT Resources.Name”,”Email Server”);
tcResultSet emailServerITRes = itResObj.findITResourceInstances(hashmap1);
long svrKey = emailServerITRes.getLongValue(“IT Resources.Key”);
tcResultSet emailServerConnParams = itResObj.getITResourceInstanceParameters(svrKey);
for(int i = 0; i < emailServerConnParams.getTotalRowCount(); i++)
{
emailServerConnParams.goToRow(i);
String s1 = emailServerConnParams.getStringValue(“IT Resources Type Parameter.Name”);
if(s1.trim().equals(“User Login”))
{
username= emailServerConnParams.getStringValue(“IT Resources Type Parameter Value.Value”);
logger.debug(“Sender = ” + username);
if (username.equals(“”))
{
logger.debug(“Sender not provided”);
}
}
}
tcEmailNotificationUtil sendMail = new tcEmailNotificationUtil(db);
sendMail.setBody(body.toString());
sendMail.setSubject(“Reconciliation failure”);
sendMail.setFromAddress(username);
String splitarr[] = getAttribute(“Recipients”).split(“,”);
for (int j = 0 ; j < splitarr.length; j++)
{
sendMail.sendEmail(splitarr[j]);
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
No comments:
Post a Comment