/**
* @see org.apache.lenya.cms.usecase.scheduling.UsecaseScheduler#schedule(org.apache.lenya.cms.usecase.Usecase,
* java.util.Date)
*/
public void schedule(Usecase usecase, Date date) {
JobScheduler scheduler = null;
try {
scheduler = (JobScheduler) this.manager.lookup(JobScheduler.ROLE);
Parameters parameters = new Parameters();
String[] names = usecase.getParameterNames();
for (int i = 0; i < names.length; i++) {
Object value = usecase.getParameter(names[i]);
if (value instanceof String) {
parameters.setParameter(names[i], (String) value);
} else {
getLogger().warn(
"Parameter [" + names[i] + "] = [" + value + "] ("
+ value.getClass().getName()
+ ") ignored, only string values are supported.");
}
}
Map objects = new HashMap();
objects.put(UsecaseCronJob.USECASE_NAME, usecase.getName());
objects.put(UsecaseCronJob.SOURCE_URL, usecase.getSourceURL());
String userId = "";
Request request = ContextHelper.getRequest(this.context);
Session session = request.getSession(false);
if (session != null) {
Identity identity = (Identity) session.getAttribute(Identity.class.getName());
if (identity != null) {
User user = identity.getUser();
if (user != null) {
userId = user.getId();
objects.put(UsecaseCronJob.USER_ID, userId);
}
Machine machine = identity.getMachine();
if (machine != null) {
objects.put(UsecaseCronJob.MACHINE_IP, machine.getIp());
}
}
}
String role = CronJob.class.getName() + "/usecase";
String name = getJobName(usecase, userId);
scheduler.fireJobAt(date, name, role, parameters, objects);
} catch (Exception e) {
getLogger().error("Could not create job: ", e);
throw new RuntimeException(e);
} finally {