import Thor.API.Operations.tcUserOperationsIntf;
import com.thortech.util.logging.Logger;
import com.thortech.xl.dataaccess.tcDataSetException;
import com.thortech.xl.dataobj.tcDataSet;
import com.thortech.xl.scheduler.tasks.SchedulerBaseTask;
import java.sql.Date;
import java.util.Calendar;
public class RevokeOIMUser extends SchedulerBaseTask
{
private static Logger logger = Logger.getLogger(“MYSCHTASKS”);
private static final String strClass = “RevokeOIMUsers”;
private int iNoOfDays;
private String noOfDays;
private final String INTERFACE_NAME_USER =
“Thor.API.Operations.tcUserOperationsIntf”;
private tcUserOperationsIntf userOperIntf = null;
String[] statuses = null;
public void init()
{
final String strMethod = “Init()”;
logger.info(“RevokeOIMUsers.Init()”);
try
{
noOfDays = getAttribute(“No. of Days”);
userOperIntf =
(tcUserOperationsIntf)getUtility(INTERFACE_NAME_USER);
iNoOfDays = Integer.parseInt(noOfDays);
}
catch (Exception ex)
{
logger.error(“Exception in ” + strClass + “.” + strMethod + “: “,
ex);
}
}
public void execute()
{
logger.info(“RevokeOIMUsers.Execute()”);
StringBuffer sb = new StringBuffer();
sb.append(“select usr_login, usr_key, usr_end_date “);
sb.append(” from usr where usr_status = ‘Disabled’”);
logger.debug(“RevokeOIMUsers/execute Query to be executed is ” +
sb.toString());
tcDataSet dateDataSet = new tcDataSet();
dateDataSet.setQuery(getDataBase(), sb.toString());
try
{
dateDataSet.executeQuery();
int rowCount = dateDataSet.getRowCount();
logger.debug(“Number of disabled users” + rowCount);
// for each record
for (int i = 0; i < rowCount; i++)
{
//Exit the process if the task is stopped manually
if (isStopped())
{
logger.error(“RevokeOIMUsers execute() : Schedule task has been manually stopped”);
return;
}
dateDataSet.goToRow(i);
try
{
Date endDate = dateDataSet.getDate(“usr_end_date”);
if ((endDate.toString()).compareToIgnoreCase(“1970-01-01″) >
0)
{
logger.debug(“RevokeOIMUsers/execute End Date of the User is ” +
endDate);
// Check if Revoke Date is Before Current Date
java.util.Date curDate = MYDateUtil.getCurrentDate();
java.util.Date cDate = MYDateUtil.stripTime(curDate);
logger.debug(“RevokeOIMUsers/execute Stripped Current Date:” +
cDate);
java.util.Date revokeDate =
MYDateUtil.addTime(endDate, Calendar.DATE,
iNoOfDays);
if (revokeDate.before(cDate))
{
long userKey = dateDataSet.getLong(“usr_key”);
userOperIntf.deleteUser(userKey);
}
}
}
catch (Exception ex)
{
logger.error(“Error in RevokeOIMUsers/execute — = “, ex);
continue;
}
}
}
catch (tcDataSetException e)
{
logger.error(“Error in RevokeOIMUsers/execute — = “, e);
}
}
}
Saturday, February 5, 2011
حذف OIM disabled users
Subscribe to:
Post Comments (Atom)
Hi Selim,
ReplyDeleteThis is Madhu.Your blog helping me alot to try some use cases.
Now I need some help for disabling users and I am making use of your code.
In the code u mentioned about
java.util.Date curDate = MYDateUtil.getCurrentDate();
java.util.Date cDate = MYDateUtil.stripTime(curDate);
The Class MYDateUtil is not is not reffered in your code.
Plz share your MYDateUtil code or give some idea what MYDateUtil class is trying to achieve
Regards,
Madhu