use of org.akaza.openclinica.bean.admin.TriggerBean in project OpenClinica by OpenClinica.
the class ViewJobServlet method processRequest.
@Override
protected void processRequest() throws Exception {
// TODO single stage servlet where we get the list of jobs
// and push them out to the JSP page
// related classes will be required to generate the table rows
// and eventually links to view and edit the jobs as well
FormProcessor fp = new FormProcessor(request);
// First we must get a reference to a scheduler
scheduler = getScheduler();
XsltTriggerService xsltTriggerSrvc = new XsltTriggerService();
// Scheduler sched = sfb.getScheduler();
Set<TriggerKey> triggerKeys = scheduler.getTriggerKeys(GroupMatcher.triggerGroupEquals(xsltTriggerSrvc.getTriggerGroupNameForExportJobs()));
String[] triggerNames = triggerKeys.stream().toArray(String[]::new);
// String[] triggerNames = scheduler.getJobNames(XsltTriggerService.TRIGGER_GROUP_NAME);
// logger.info("trigger list: "+triggerNames.length);
// logger.info("trigger names: "+triggerNames.toString());
ArrayList triggerBeans = new ArrayList();
for (String triggerName : triggerNames) {
Trigger trigger = scheduler.getTrigger(TriggerKey.triggerKey(triggerName, xsltTriggerSrvc.getTriggerGroupNameForExportJobs()));
try {
logger.debug("prev fire time " + trigger.getPreviousFireTime().toString());
logger.debug("next fire time " + trigger.getNextFireTime().toString());
logger.debug("final fire time: " + trigger.getFinalFireTime().toString());
} catch (NullPointerException npe) {
// could be nulls in the dates, etc
}
// logger.info(trigger.getDescription());
// logger.info("");//getJobDataMap()
TriggerBean triggerBean = new TriggerBean();
triggerBean.setFullName(trigger.getKey().getName());
triggerBean.setPreviousDate(trigger.getPreviousFireTime());
triggerBean.setNextDate(trigger.getNextFireTime());
if (trigger.getDescription() != null) {
triggerBean.setDescription(trigger.getDescription());
}
// setting: frequency, dataset name
JobDataMap dataMap = new JobDataMap();
DatasetDAO datasetDAO = new DatasetDAO(sm.getDataSource());
StudyDAO studyDao = new StudyDAO(sm.getDataSource());
if (trigger.getJobDataMap().size() > 0) {
dataMap = trigger.getJobDataMap();
int dsId = dataMap.getInt(ExampleSpringJob.DATASET_ID);
String periodToRun = dataMap.getString(ExampleSpringJob.PERIOD);
triggerBean.setPeriodToRun(periodToRun);
DatasetBean dataset = (DatasetBean) datasetDAO.findByPK(dsId);
triggerBean.setDataset(dataset);
triggerBean.setDatasetName(dataset.getName());
StudyBean study = (StudyBean) studyDao.findByPK(dataset.getStudyId());
triggerBean.setStudyName(study.getName());
// triggerBean.setStudyName(dataMap.getString(ExampleSpringJob.STUDY_NAME));
}
logger.debug("Trigger Priority: " + trigger.getKey().getName() + " " + trigger.getPriority());
if (scheduler.getTriggerState(TriggerKey.triggerKey(triggerName, XsltTriggerService.TRIGGER_GROUP_NAME)) == Trigger.TriggerState.PAUSED) {
triggerBean.setActive(false);
logger.debug("setting active to false for trigger: " + trigger.getKey().getName());
} else {
triggerBean.setActive(true);
logger.debug("setting active to TRUE for trigger: " + trigger.getKey().getName());
}
triggerBeans.add(triggerBean);
// our wrapper to show triggers
}
ArrayList allRows = TriggerRow.generateRowsFromBeans(triggerBeans);
EntityBeanTable table = fp.getEntityBeanTable();
String[] columns = { resword.getString("name"), resword.getString("previous_fire_time"), resword.getString("next_fire_time"), resword.getString("description"), resword.getString("period_to_run"), resword.getString("dataset"), resword.getString("study"), resword.getString("actions") };
table.setColumns(new ArrayList(Arrays.asList(columns)));
table.hideColumnLink(3);
table.hideColumnLink(7);
table.setQuery("ViewJob", new HashMap());
// table.addLink("", "CreateUserAccount");
table.setSortingColumnInd(0);
table.setRows(allRows);
table.computeDisplay();
request.setAttribute("table", table);
// throw new NullPointerException("faking an error here");
forwardPage(Page.VIEW_JOB);
}
use of org.akaza.openclinica.bean.admin.TriggerBean in project OpenClinica by OpenClinica.
the class ViewSingleJobServlet method processRequest.
@Override
protected void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
// changes to this servlet, we now look at group name too, tbh 05/2009
String triggerName = fp.getString("tname");
String gName = fp.getString("gname");
String groupName = "";
if (gName.equals("") || gName.equals("0")) {
groupName = XsltTriggerService.TRIGGER_GROUP_NAME;
} else {
// if (gName.equals("1")) {
groupName = TRIGGER_IMPORT_GROUP;
}
// << tbh 09/03/2009 #4143
scheduler = getScheduler();
Trigger trigger = scheduler.getTrigger(new TriggerKey(triggerName, groupName));
if (trigger == null) {
groupName = XsltTriggerService.TRIGGER_GROUP_NAME;
trigger = scheduler.getTrigger(new TriggerKey(triggerName.trim(), groupName));
}
// << tbh 09/03/2009 #4143
// above is a hack, if we add more trigger groups this will have
// to be redone
logger.debug("found trigger name: " + triggerName);
logger.debug("found group name: " + groupName);
TriggerBean triggerBean = new TriggerBean();
JobDataMap dataMap = new JobDataMap();
AuditEventDAO auditEventDAO = new AuditEventDAO(sm.getDataSource());
try {
triggerBean.setFullName(trigger.getKey().getName());
triggerBean.setPreviousDate(trigger.getPreviousFireTime());
triggerBean.setNextDate(trigger.getNextFireTime());
// >> set active here, tbh 10/08/2009
if (scheduler.getTriggerState(new TriggerKey(triggerName, groupName)) == Trigger.TriggerState.PAUSED) {
triggerBean.setActive(false);
logger.debug("setting active to false for trigger: " + trigger.getKey().getName());
} else {
triggerBean.setActive(true);
logger.debug("setting active to TRUE for trigger: " + trigger.getKey().getName());
}
// <<
if (trigger.getDescription() != null) {
triggerBean.setDescription(trigger.getDescription());
}
if (trigger.getJobDataMap().size() > 0) {
dataMap = trigger.getJobDataMap();
String contactEmail = dataMap.getString(XsltTriggerService.EMAIL);
logger.debug("found email: " + contactEmail);
// int dsId = new Integer(datasetId).intValue();
if (gName.equals("") || gName.equals("0")) {
String exportFormat = dataMap.getString(XsltTriggerService.EXPORT_FORMAT);
String periodToRun = dataMap.getString(ExampleSpringJob.PERIOD);
// int userId = new Integer(userAcctId).intValue();
int dsId = dataMap.getInt(ExampleSpringJob.DATASET_ID);
triggerBean.setExportFormat(exportFormat);
triggerBean.setPeriodToRun(periodToRun);
DatasetDAO datasetDAO = new DatasetDAO(sm.getDataSource());
DatasetBean dataset = (DatasetBean) datasetDAO.findByPK(dsId);
triggerBean.setDataset(dataset);
}
int userId = dataMap.getInt(ExampleSpringJob.USER_ID);
// need to set information, extract bean, user account bean
UserAccountDAO userAccountDAO = new UserAccountDAO(sm.getDataSource());
triggerBean.setContactEmail(contactEmail);
UserAccountBean userAccount = (UserAccountBean) userAccountDAO.findByPK(userId);
triggerBean.setUserAccount(userAccount);
ArrayList<AuditEventBean> triggerLogs = auditEventDAO.findAllByAuditTable(trigger.getKey().getName());
// set the table for the audit event beans here
ArrayList allRows = AuditEventRow.generateRowsFromBeans(triggerLogs);
EntityBeanTable table = fp.getEntityBeanTable();
String[] columns = { resword.getString("date_and_time"), resword.getString("action_message"), resword.getString("entity_operation"), // resword.getString("study_subject_ID"),
resword.getString("changes_and_additions"), resword.getString("actions") };
table.setColumns(new ArrayList(Arrays.asList(columns)));
table.setAscendingSort(false);
table.hideColumnLink(1);
table.hideColumnLink(3);
table.hideColumnLink(4);
table.setQuery("ViewSingleJob?tname=" + triggerName + "&gname=" + gName, new HashMap());
table.setRows(allRows);
table.computeDisplay();
request.setAttribute("table", table);
}
} catch (NullPointerException e) {
// TODO Auto-generated catch block
logger.debug(" found NPE " + e.getMessage());
e.printStackTrace();
}
// need to show the extract for which this runs, which files, etc
// in other words the job data map
request.setAttribute("triggerBean", triggerBean);
request.setAttribute("groupName", groupName);
forwardPage(Page.VIEW_SINGLE_JOB);
}
Aggregations