use of org.akaza.openclinica.bean.extract.DatasetBean 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.extract.DatasetBean 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);
}
use of org.akaza.openclinica.bean.extract.DatasetBean in project OpenClinica by OpenClinica.
the class DatasetDAO method initialDatasetData.
/**
* Initialize itemMap, itemIds, itemDefCrf and groupIds for a DatasetBean
*
* @param db
* @return
* @author ywang (Feb., 2008)
*/
public DatasetBean initialDatasetData(int datasetId) {
ItemDAO idao = new ItemDAO(ds);
DatasetBean db = (DatasetBean) findByPK(datasetId);
String sql = db.getSQLStatement();
sql = sql.split("study_event_definition_id in")[1];
String[] ss = sql.split("and item_id in");
String sedIds = ss[0];
String[] sss = ss[1].split("and");
String itemIds = sss[0];
this.setDefinitionCrfItemTypesExpected();
logger.debug("begin to execute GetDefinitionCrfItemSql");
ArrayList alist = select(getDefinitionCrfItemSql(sedIds, itemIds));
Iterator it = alist.iterator();
while (it.hasNext()) {
HashMap row = (HashMap) it.next();
ItemBean ib = (ItemBean) idao.getEntityFromHashMap(row);
Integer defId = (Integer) row.get("sed_id");
String defName = (String) row.get("sed_name");
String crfName = (String) row.get("crf_name");
Integer itemId = ib.getId();
String key = defId + "_" + itemId;
if (!db.getItemMap().containsKey(key)) {
ib.setSelected(true);
ib.setDefName(defName);
ib.setCrfName(crfName);
ib.setDatasetItemMapKey(key);
// contains study_event_definition_ids
if (!db.getEventIds().contains(defId)) {
db.getEventIds().add(defId);
}
db.getItemIds().add(itemId);
db.getItemDefCrf().add(ib);
db.getItemMap().put(key, ib);
}
}
db.setSubjectGroupIds(getGroupIds(db.getId()));
return db;
}
use of org.akaza.openclinica.bean.extract.DatasetBean in project OpenClinica by OpenClinica.
the class DatasetDAO method findByPK.
public EntityBean findByPK(int ID) {
DatasetBean eb = new DatasetBean();
this.setTypesExpected();
HashMap variables = new HashMap();
variables.put(Integer.valueOf(1), Integer.valueOf(ID));
String sql = digester.getQuery("findByPK");
ArrayList alist = this.select(sql, variables);
Iterator it = alist.iterator();
if (it.hasNext()) {
eb = (DatasetBean) this.getEntityFromHashMap((HashMap) it.next());
} else {
logger.warn("found no object: " + sql + " " + ID);
}
return eb;
}
use of org.akaza.openclinica.bean.extract.DatasetBean in project OpenClinica by OpenClinica.
the class DatasetDAO method getEntityFromHashMap.
public Object getEntityFromHashMap(HashMap hm) {
DatasetBean eb = new DatasetBean();
this.setEntityAuditInformation(eb, hm);
eb.setDescription((String) hm.get("description"));
eb.setStudyId(((Integer) hm.get("study_id")).intValue());
eb.setName((String) hm.get("name"));
eb.setId(((Integer) hm.get("dataset_id")).intValue());
eb.setSQLStatement((String) hm.get("sql_statement"));
eb.setNumRuns(((Integer) hm.get("num_runs")).intValue());
eb.setDateStart((Date) hm.get("date_start"));
eb.setDateEnd((Date) hm.get("date_end"));
eb.setApproverId(((Integer) hm.get("approver_id")).intValue());
eb.setDateLastRun((Date) hm.get("date_last_run"));
eb.setShowEventEnd(((Boolean) hm.get("show_event_end")).booleanValue());
eb.setShowEventStart(((Boolean) hm.get("show_event_start")).booleanValue());
eb.setShowEventLocation(((Boolean) hm.get("show_event_location")).booleanValue());
eb.setShowSubjectDob(((Boolean) hm.get("show_subject_dob")).booleanValue());
eb.setShowSubjectGender(((Boolean) hm.get("show_subject_gender")).booleanValue());
eb.setShowEventStatus(((Boolean) hm.get("show_event_status")).booleanValue());
eb.setShowSubjectStatus(((Boolean) hm.get("show_subject_status")).booleanValue());
eb.setShowSubjectUniqueIdentifier(((Boolean) hm.get("show_subject_unique_id")).booleanValue());
eb.setShowSubjectAgeAtEvent(((Boolean) hm.get("show_subject_age_at_event")).booleanValue());
eb.setShowCRFstatus(((Boolean) hm.get("show_crf_status")).booleanValue());
eb.setShowCRFversion(((Boolean) hm.get("show_crf_version")).booleanValue());
eb.setShowCRFinterviewerName(((Boolean) hm.get("show_crf_int_name")).booleanValue());
eb.setShowCRFinterviewerDate(((Boolean) hm.get("show_crf_int_date")).booleanValue());
eb.setShowSubjectGroupInformation(((Boolean) hm.get("show_group_info")).booleanValue());
// eb.setShowDiscrepancyInformation(((Boolean)
// hm.get("show_disc_info")).booleanValue());
// do we want to find group info here? looks like the best place for
// non-repeats...
// if (eb.isShowSubjectGroupInformation()) {
eb.setSubjectGroupIds(getGroupIds(eb.getId()));
// }
eb.setODMMetaDataVersionName((String) hm.get("odm_metadataversion_name"));
eb.setODMMetaDataVersionOid((String) hm.get("odm_metadataversion_oid"));
eb.setODMPriorStudyOid((String) hm.get("odm_prior_study_oid"));
eb.setODMPriorMetaDataVersionOid((String) hm.get("odm_prior_metadataversion_oid"));
eb.setShowSubjectSecondaryId((Boolean) hm.get("show_secondary_id"));
int isId = ((Integer) hm.get("dataset_item_status_id")).intValue();
isId = isId > 0 ? isId : 1;
DatasetItemStatus dis = DatasetItemStatus.get(isId);
eb.setDatasetItemStatus(dis);
return eb;
}
Aggregations