use of org.akaza.openclinica.dao.submit.EventCRFDAO in project OpenClinica by OpenClinica.
the class RemoveStudyServlet method processRequest.
@Override
public void processRequest() throws Exception {
StudyDAO sdao = new StudyDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
int studyId = fp.getInt("id");
StudyBean study = (StudyBean) sdao.findByPK(studyId);
// find all sites
ArrayList sites = (ArrayList) sdao.findAllByParent(studyId);
// find all user and roles in the study, include ones in sites
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
ArrayList userRoles = udao.findAllByStudyId(studyId);
// find all subjects in the study, include ones in sites
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
ArrayList subjects = ssdao.findAllByStudy(study);
// find all events in the study, include ones in sites
StudyEventDefinitionDAO sefdao = new StudyEventDefinitionDAO(sm.getDataSource());
ArrayList definitions = sefdao.findAllByStudy(study);
String action = request.getParameter("action");
if (studyId == 0) {
addPageMessage(respage.getString("please_choose_a_study_to_remove"));
forwardPage(Page.STUDY_LIST_SERVLET);
} else {
if ("confirm".equalsIgnoreCase(action)) {
request.setAttribute("studyToRemove", study);
request.setAttribute("sitesToRemove", sites);
request.setAttribute("userRolesToRemove", userRoles);
request.setAttribute("subjectsToRemove", subjects);
request.setAttribute("definitionsToRemove", definitions);
forwardPage(Page.REMOVE_STUDY);
} else {
logger.info("submit to remove the study");
// change all statuses to unavailable
StudyDAO studao = new StudyDAO(sm.getDataSource());
study.setOldStatus(study.getStatus());
study.setStatus(Status.DELETED);
study.setUpdater(ub);
study.setUpdatedDate(new Date());
studao.update(study);
// remove all sites
for (int i = 0; i < sites.size(); i++) {
StudyBean site = (StudyBean) sites.get(i);
if (!site.getStatus().equals(Status.DELETED)) {
site.setOldStatus(site.getStatus());
site.setStatus(Status.AUTO_DELETED);
site.setUpdater(ub);
site.setUpdatedDate(new Date());
sdao.update(site);
}
}
// remove all users and roles
for (int i = 0; i < userRoles.size(); i++) {
StudyUserRoleBean role = (StudyUserRoleBean) userRoles.get(i);
logger.info("remove user role" + role.getName());
if (!role.getStatus().equals(Status.DELETED)) {
role.setStatus(Status.AUTO_DELETED);
role.setUpdater(ub);
role.setUpdatedDate(new Date());
udao.updateStudyUserRole(role, role.getUserName());
}
}
// YW << bug fix for that current active study has been deleted
if (study.getId() == currentStudy.getId()) {
currentStudy.setStatus(Status.DELETED);
currentRole.setStatus(Status.DELETED);
} else // (auto-removed)
if (currentStudy.getParentStudyId() == study.getId()) {
currentStudy.setStatus(Status.AUTO_DELETED);
// we may need handle this later?
currentRole.setStatus(Status.DELETED);
}
// remove all subjects
for (int i = 0; i < subjects.size(); i++) {
StudySubjectBean subject = (StudySubjectBean) subjects.get(i);
if (!subject.getStatus().equals(Status.DELETED)) {
subject.setStatus(Status.AUTO_DELETED);
subject.setUpdater(ub);
subject.setUpdatedDate(new Date());
ssdao.update(subject);
}
}
// remove all study_group_class
// changed by jxu on 08-31-06, to fix the problem of no study_id
// in study_group table
StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
// YW 09-27-2007, enable status updating for StudyGroupClassBean
ArrayList groups = sgcdao.findAllByStudy(study);
for (int i = 0; i < groups.size(); i++) {
StudyGroupClassBean group = (StudyGroupClassBean) groups.get(i);
if (!group.getStatus().equals(Status.DELETED)) {
group.setStatus(Status.AUTO_DELETED);
group.setUpdater(ub);
group.setUpdatedDate(new Date());
sgcdao.update(group);
// all subject_group_map
ArrayList subjectGroupMaps = sgmdao.findAllByStudyGroupClassId(group.getId());
for (int j = 0; j < subjectGroupMaps.size(); j++) {
SubjectGroupMapBean sgMap = (SubjectGroupMapBean) subjectGroupMaps.get(j);
if (!sgMap.getStatus().equals(Status.DELETED)) {
sgMap.setStatus(Status.AUTO_DELETED);
sgMap.setUpdater(ub);
sgMap.setUpdatedDate(new Date());
sgmdao.update(sgMap);
}
}
}
}
ArrayList groupClasses = sgcdao.findAllActiveByStudy(study);
for (int i = 0; i < groupClasses.size(); i++) {
StudyGroupClassBean gc = (StudyGroupClassBean) groupClasses.get(i);
if (!gc.getStatus().equals(Status.DELETED)) {
gc.setStatus(Status.AUTO_DELETED);
gc.setUpdater(ub);
gc.setUpdatedDate(new Date());
sgcdao.update(gc);
}
}
// remove all event definitions and event
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
for (int i = 0; i < definitions.size(); i++) {
StudyEventDefinitionBean definition = (StudyEventDefinitionBean) definitions.get(i);
if (!definition.getStatus().equals(Status.DELETED)) {
definition.setStatus(Status.AUTO_DELETED);
definition.setUpdater(ub);
definition.setUpdatedDate(new Date());
sefdao.update(definition);
ArrayList edcs = (ArrayList) edcdao.findAllByDefinition(definition.getId());
for (int j = 0; j < edcs.size(); j++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) edcs.get(j);
if (!edc.getStatus().equals(Status.DELETED)) {
edc.setStatus(Status.AUTO_DELETED);
edc.setUpdater(ub);
edc.setUpdatedDate(new Date());
edcdao.update(edc);
}
}
ArrayList events = (ArrayList) sedao.findAllByDefinition(definition.getId());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
for (int j = 0; j < events.size(); j++) {
StudyEventBean event = (StudyEventBean) events.get(j);
if (!event.getStatus().equals(Status.DELETED)) {
event.setStatus(Status.AUTO_DELETED);
event.setUpdater(ub);
event.setUpdatedDate(new Date());
sedao.update(event);
ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
for (int k = 0; k < eventCRFs.size(); k++) {
EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(k);
if (!eventCRF.getStatus().equals(Status.DELETED)) {
eventCRF.setOldStatus(eventCRF.getStatus());
eventCRF.setStatus(Status.AUTO_DELETED);
eventCRF.setUpdater(ub);
eventCRF.setUpdatedDate(new Date());
ecdao.update(eventCRF);
ArrayList itemDatas = iddao.findAllByEventCRFId(eventCRF.getId());
for (int a = 0; a < itemDatas.size(); a++) {
ItemDataBean item = (ItemDataBean) itemDatas.get(a);
if (!item.getStatus().equals(Status.DELETED)) {
item.setOldStatus(item.getStatus());
item.setStatus(Status.AUTO_DELETED);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
}
}
}
}
}
}
}
}
// for definitions
DatasetDAO datadao = new DatasetDAO(sm.getDataSource());
ArrayList dataset = datadao.findAllByStudyId(study.getId());
for (int i = 0; i < dataset.size(); i++) {
DatasetBean data = (DatasetBean) dataset.get(i);
if (!data.getStatus().equals(Status.DELETED)) {
data.setStatus(Status.AUTO_DELETED);
data.setUpdater(ub);
data.setUpdatedDate(new Date());
datadao.update(data);
}
}
addPageMessage(resexception.getString("this_study_has_been_removed_succesfully"));
forwardPage(Page.STUDY_LIST_SERVLET);
}
}
}
use of org.akaza.openclinica.dao.submit.EventCRFDAO in project OpenClinica by OpenClinica.
the class RemoveSubjectServlet method processRequest.
@Override
public void processRequest() throws Exception {
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
int subjectId = fp.getInt("id");
String action = fp.getString("action");
if (subjectId == 0 || StringUtil.isBlank(action)) {
addPageMessage(respage.getString("please_choose_a_subject_to_remove"));
forwardPage(Page.SUBJECT_LIST_SERVLET);
} else {
SubjectBean subject = (SubjectBean) sdao.findByPK(subjectId);
// find all study subjects
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
ArrayList studySubs = ssdao.findAllBySubjectId(subjectId);
// find study events
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
ArrayList events = sedao.findAllBySubjectId(subjectId);
if ("confirm".equalsIgnoreCase(action)) {
request.setAttribute("subjectToRemove", subject);
request.setAttribute("studySubs", studySubs);
request.setAttribute("events", events);
forwardPage(Page.REMOVE_SUBJECT);
} else {
logger.info("submit to remove the subject");
// change all statuses to deleted
subject.setStatus(Status.DELETED);
subject.setUpdater(ub);
subject.setUpdatedDate(new Date());
sdao.update(subject);
// remove subject references from study
for (int i = 0; i < studySubs.size(); i++) {
StudySubjectBean studySub = (StudySubjectBean) studySubs.get(i);
if (!studySub.getStatus().equals(Status.DELETED)) {
studySub.setStatus(Status.AUTO_DELETED);
studySub.setUpdater(ub);
studySub.setUpdatedDate(new Date());
ssdao.update(studySub);
}
}
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
for (int j = 0; j < events.size(); j++) {
StudyEventBean event = (StudyEventBean) events.get(j);
if (!event.getStatus().equals(Status.DELETED)) {
event.setStatus(Status.AUTO_DELETED);
event.setUpdater(ub);
event.setUpdatedDate(new Date());
sedao.update(event);
ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
for (int k = 0; k < eventCRFs.size(); k++) {
EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(k);
if (!eventCRF.getStatus().equals(Status.DELETED)) {
eventCRF.setStatus(Status.AUTO_DELETED);
eventCRF.setUpdater(ub);
eventCRF.setUpdatedDate(new Date());
ecdao.update(eventCRF);
// remove all the item data
ArrayList itemDatas = iddao.findAllByEventCRFId(eventCRF.getId());
for (int a = 0; a < itemDatas.size(); a++) {
ItemDataBean item = (ItemDataBean) itemDatas.get(a);
if (!item.getStatus().equals(Status.DELETED)) {
item.setStatus(Status.AUTO_DELETED);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
}
}
}
}
}
}
String emailBody = respage.getString("the_subject") + " " + subject.getUniqueIdentifier() + " " + respage.getString("has_been_removed_succesfully");
addPageMessage(emailBody);
// sendEmail(emailBody);
forwardPage(Page.SUBJECT_LIST_SERVLET);
}
}
}
use of org.akaza.openclinica.dao.submit.EventCRFDAO in project OpenClinica by OpenClinica.
the class RestoreCRFServlet method processRequest.
@Override
public void processRequest() throws Exception {
CRFDAO cdao = new CRFDAO(sm.getDataSource());
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
// checks which module the requests are from
String module = fp.getString(MODULE);
request.setAttribute(MODULE, module);
int crfId = fp.getInt("id", true);
String action = request.getParameter("action");
if (crfId == 0) {
addPageMessage(respage.getString("please_choose_a_CRF_to_restore"));
forwardPage(Page.CRF_LIST_SERVLET);
} else {
CRFBean crf = (CRFBean) cdao.findByPK(crfId);
ArrayList versions = cvdao.findAllByCRFId(crfId);
crf.setVersions(versions);
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
ArrayList edcs = (ArrayList) edcdao.findAllByCRF(crfId);
SectionDAO secdao = new SectionDAO(sm.getDataSource());
EventCRFDAO evdao = new EventCRFDAO(sm.getDataSource());
ArrayList eventCRFs = evdao.findAllByCRF(crfId);
if ("confirm".equalsIgnoreCase(action)) {
request.setAttribute("crfToRestore", crf);
request.setAttribute("eventCRFs", eventCRFs);
forwardPage(Page.RESTORE_CRF);
} else {
logger.info("submit to restore the crf");
crf.setStatus(Status.AVAILABLE);
crf.setUpdater(ub);
crf.setUpdatedDate(new Date());
cdao.update(crf);
for (int i = 0; i < versions.size(); i++) {
CRFVersionBean version = (CRFVersionBean) versions.get(i);
if (version.getStatus().equals(Status.AUTO_DELETED)) {
version.setStatus(Status.AVAILABLE);
version.setUpdater(ub);
version.setUpdatedDate(new Date());
cvdao.update(version);
ArrayList sections = secdao.findAllByCRFVersionId(version.getId());
for (int j = 0; j < sections.size(); j++) {
SectionBean section = (SectionBean) sections.get(j);
if (section.getStatus().equals(Status.AUTO_DELETED)) {
section.setStatus(Status.AVAILABLE);
section.setUpdater(ub);
section.setUpdatedDate(new Date());
secdao.update(section);
}
}
}
}
for (int i = 0; i < edcs.size(); i++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) edcs.get(i);
if (edc.getStatus().equals(Status.AUTO_DELETED)) {
edc.setStatus(Status.AVAILABLE);
edc.setUpdater(ub);
edc.setUpdatedDate(new Date());
edcdao.update(edc);
}
}
ItemDataDAO idao = new ItemDataDAO(sm.getDataSource());
for (int i = 0; i < eventCRFs.size(); i++) {
EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(i);
if (eventCRF.getStatus().equals(Status.AUTO_DELETED)) {
eventCRF.setStatus(Status.AVAILABLE);
eventCRF.setUpdater(ub);
eventCRF.setUpdatedDate(new Date());
evdao.update(eventCRF);
ArrayList items = idao.findAllByEventCRFId(eventCRF.getId());
for (int j = 0; j < items.size(); j++) {
ItemDataBean item = (ItemDataBean) items.get(j);
if (item.getStatus().equals(Status.AUTO_DELETED)) {
item.setStatus(Status.AVAILABLE);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
idao.update(item);
}
}
}
}
addPageMessage(respage.getString("the_CRF") + crf.getName() + " " + respage.getString("has_been_restored_succesfully"));
forwardPage(Page.CRF_LIST_SERVLET);
}
}
}
use of org.akaza.openclinica.dao.submit.EventCRFDAO in project OpenClinica by OpenClinica.
the class RestoreCRFVersionServlet method processRequest.
@Override
public void processRequest() throws Exception {
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
// checks which module the requests are from
String module = fp.getString(MODULE);
request.setAttribute(MODULE, module);
int versionId = fp.getInt("id", true);
String action = fp.getString("action");
if (versionId == 0) {
addPageMessage(respage.getString("please_choose_a_CRF_version_to_restore"));
forwardPage(Page.CRF_LIST_SERVLET);
} else {
if (StringUtil.isBlank(action)) {
addPageMessage(respage.getString("no_action_specified"));
forwardPage(Page.CRF_LIST_SERVLET);
return;
}
CRFVersionBean version = (CRFVersionBean) cvdao.findByPK(versionId);
SectionDAO secdao = new SectionDAO(sm.getDataSource());
EventCRFDAO evdao = new EventCRFDAO(sm.getDataSource());
// find all event crfs by version id
ArrayList eventCRFs = evdao.findAllByCRFVersion(versionId);
if ("confirm".equalsIgnoreCase(action)) {
request.setAttribute("versionToRestore", version);
request.setAttribute("eventCRFs", eventCRFs);
forwardPage(Page.RESTORE_CRF_VERSION);
} else {
logger.info("submit to restore the crf version");
// version
version.setStatus(Status.AVAILABLE);
version.setUpdater(ub);
version.setUpdatedDate(new Date());
cvdao.update(version);
// all sections
ArrayList sections = secdao.findAllByCRFVersionId(version.getId());
for (int j = 0; j < sections.size(); j++) {
SectionBean section = (SectionBean) sections.get(j);
if (section.getStatus().equals(Status.AUTO_DELETED)) {
section.setStatus(Status.AVAILABLE);
section.setUpdater(ub);
section.setUpdatedDate(new Date());
secdao.update(section);
}
}
// all item data related to event crfs
ItemDataDAO idao = new ItemDataDAO(sm.getDataSource());
for (int i = 0; i < eventCRFs.size(); i++) {
EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(i);
if (eventCRF.getStatus().equals(Status.AUTO_DELETED)) {
eventCRF.setStatus(Status.AVAILABLE);
eventCRF.setUpdater(ub);
eventCRF.setUpdatedDate(new Date());
evdao.update(eventCRF);
ArrayList items = idao.findAllByEventCRFId(eventCRF.getId());
for (int j = 0; j < items.size(); j++) {
ItemDataBean item = (ItemDataBean) items.get(j);
if (item.getStatus().equals(Status.AUTO_DELETED)) {
item.setStatus(Status.AVAILABLE);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
idao.update(item);
}
}
}
}
addPageMessage(respage.getString("the_CRF_version") + version.getName() + " " + respage.getString("has_been_restored_succesfully"));
forwardPage(Page.CRF_LIST_SERVLET);
}
}
}
use of org.akaza.openclinica.dao.submit.EventCRFDAO in project OpenClinica by OpenClinica.
the class CreateDatasetServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
String action = fp.getString("action");
if (StringUtil.isBlank(action)) {
// step 1 -- instructions, and continue button
session.setAttribute("newDataset", new DatasetBean());
session.setAttribute("allItems", new ArrayList());
session.setAttribute("crf", new CRFBean());
session.setAttribute("allSelectedItems", new ArrayList());
forwardPage(Page.CREATE_DATASET_1);
} else {
StudyBean studyWithEventDefs = currentStudy;
if (currentStudy.getParentStudyId() > 0) {
studyWithEventDefs = new StudyBean();
studyWithEventDefs.setId(currentStudy.getParentStudyId());
}
if ("begin".equalsIgnoreCase(action)) {
// step 2 -- select study events/crfs
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
StudyBean studyWithEventDefinitions = currentStudy;
if (currentStudy.getParentStudyId() > 0) {
studyWithEventDefinitions = new StudyBean();
studyWithEventDefinitions.setId(currentStudy.getParentStudyId());
}
ArrayList seds = seddao.findAllActiveByStudy(studyWithEventDefinitions);
CRFDAO crfdao = new CRFDAO(sm.getDataSource());
HashMap events = new LinkedHashMap();
for (int i = 0; i < seds.size(); i++) {
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seds.get(i);
ArrayList<CRFBean> crfs = (ArrayList<CRFBean>) crfdao.findAllActiveByDefinition(sed);
if (currentStudy.getParentStudyId() > 0) {
// sift through these CRFs and see which ones are hidden
HideCRFManager hideCRFs = HideCRFManager.createHideCRFManager();
crfs = hideCRFs.removeHiddenCRFBeans(studyWithEventDefinitions, sed, crfs, sm.getDataSource());
}
if (!crfs.isEmpty()) {
events.put(sed, crfs);
}
}
// datasets
if (events.isEmpty()) {
addPageMessage(respage.getString("not_have_study_definitions_assigned"));
forwardPage(Page.CREATE_DATASET_1);
} else {
crfdao = new CRFDAO(sm.getDataSource());
ItemDAO idao = new ItemDAO(sm.getDataSource());
ArrayList sedItemIds = CreateDatasetServlet.allSedItemIdsInStudy(events, crfdao, idao);
session.setAttribute("numberOfStudyItems", Integer.toString(sedItemIds.size()));
request.setAttribute("eventlist", events);
session.setAttribute(EVENTS_FOR_CREATE_DATASET, events);
session.setAttribute("newDataset", new DatasetBean());
session.setAttribute("allItems", new ArrayList());
session.setAttribute("crf", new CRFBean());
forwardPage(Page.CREATE_DATASET_2);
}
} else if ("beginsubmit".equalsIgnoreCase(action)) {
String saveItems = fp.getString(SAVE_BUTTON);
String saveContinue = fp.getString(SAVE_CONTINUE_BUTTON);
DatasetBean db = (DatasetBean) session.getAttribute("newDataset");
if (db == null) {
db = new DatasetBean();
}
extractIdsFromForm(db);
extractEventIds(db);
session.setAttribute("newDataset", db);
// +"");
if (!StringUtil.isBlank(saveItems)) {
request.setAttribute("eventlist", session.getAttribute(EVENTS_FOR_CREATE_DATASET));
// BWP 3095>>
String summary = respage.getString("you_have_selected") + " " + db.getItemIds().size() + " " + respage.getString("items_so_far");
summary += genAttMsg(db);
addPageMessage(summary);
int crfId = fp.getInt("crfId");
if (crfId > 0) {
// user choose a crf and select items
forwardPage(Page.CREATE_DATASET_2);
} else {
ArrayList sgclasses = (ArrayList) session.getAttribute("allSelectedGroups");
if (sgclasses == null || sgclasses.size() == 0) {
sgclasses = setUpStudyGroups();
}
session.setAttribute("allSelectedGroups", sgclasses);
request.setAttribute("allSelectedGroups", sgclasses);
// TODO push out list of subject groups here???
// form submitted from "view selected item ' or
// attribute page, so
// forward back to "view selected item " page
forwardPage(Page.CREATE_DATASET_VIEW_SELECTED);
}
} else {
if (db.getItemIds().size() == 0) {
request.setAttribute("eventlist", session.getAttribute(EVENTS_FOR_CREATE_DATASET));
addPageMessage(respage.getString("should_select_one_item_to_create_dataset"));
forwardPage(Page.CREATE_DATASET_2);
} else {
String summary = respage.getString("you_have_selected") + " " + db.getItemIds().size() + " " + respage.getString("items_totally_for_this_dataset");
summary += genAttMsg(db);
addPageMessage(summary);
// 0 means using
fp.addPresetValue("firstmonth", 0);
// default month
fp.addPresetValue("firstyear", 1900);
fp.addPresetValue("lastmonth", 0);
fp.addPresetValue("lastyear", 2100);
setPresetValues(fp.getPresetValues());
logger.warn("found preset values while setting date: " + fp.getPresetValues().toString());
request.setAttribute(BEAN_MONTHS, getMonths());
request.setAttribute(BEAN_YEARS, getYears());
forwardPage(Page.CREATE_DATASET_3);
}
}
} else if ("scopesubmit".equalsIgnoreCase(action)) {
ArrayList months = getMonths();
ArrayList years = getYears();
int firstMonth = fp.getInt("firstmonth");
int firstYear = fp.getInt("firstyear");
int lastMonth = fp.getInt("lastmonth");
int lastYear = fp.getInt("lastyear");
if (fp.getInt("firstmonth") == 0) {
// default value
firstMonth = 1;
}
if (fp.getInt("lastmonth") == 0) {
// default value
lastMonth = 12;
}
errors = new HashMap();
if (fp.getInt("firstmonth") > 0 && firstYear == 1900) {
Validator.addError(errors, "firstmonth", restext.getString("if_specify_month_also_specify_year"));
}
if (fp.getInt("lastmonth") > 0 && lastYear == 2100) {
Validator.addError(errors, "lastmonth", restext.getString("if_specify_month_also_specify_year"));
}
Date dateStart = getFirstDayOfMonth(firstYear, firstMonth);
Date dateEnd = getLastDayOfMonth(lastYear, lastMonth);
if (dateEnd.compareTo(dateStart) < 0) {
Validator.addError(errors, "firstmonth", restext.getString("the_from_should_be_come_before_to"));
}
if (!errors.isEmpty()) {
String[] fieldNames = { "firstmonth", "firstyear", "lastmonth", "lastyear" };
fp.setCurrentIntValuesAsPreset(fieldNames);
setInputMessages(errors);
addPageMessage(respage.getString("errors_in_submission_see_below"));
setPresetValues(fp.getPresetValues());
request.setAttribute(BEAN_MONTHS, getMonths());
request.setAttribute(BEAN_YEARS, getYears());
forwardPage(Page.CREATE_DATASET_3);
} else {
DatasetBean dsb = (DatasetBean) session.getAttribute("newDataset");
dsb.setDateStart(dateStart);
dsb.setDateEnd(dateEnd);
session.setAttribute("newDataset", dsb);
if (fp.getString("submit").equals(resword.getString("continue_to_apply_filter"))) {
// FilterDAO fdao = new FilterDAO(sm.getDataSource());
// Collection filters = fdao.findAll();
// TODO make findAllByProject
// request.setAttribute("filters",filters);
EntityBeanTable table = getFilterTable();
session.setAttribute("partOfCreateDataset", new Integer(1));
// to be used in createFiltersThree servlet, tbh
request.setAttribute("table", table);
forwardPage(Page.APPLY_FILTER);
} else {
request.setAttribute("statuses", Status.toActiveArrayList());
// YW, 2-20-2008 <<these attributes will show on the
// CREATE_DATASET_4
String temp = dsb.getODMMetaDataVersionOid();
request.setAttribute("mdvOID", temp != null && temp.length() > 0 ? temp : "v1.0.0");
temp = dsb.getODMMetaDataVersionName();
request.setAttribute("mdvName", temp != null && temp.length() > 0 ? temp : "MetaDataVersion_v1.0.0");
request.setAttribute("mdvPrevStudy", dsb.getODMPriorStudyOid());
request.setAttribute("mdvPrevOID", dsb.getODMPriorMetaDataVersionOid());
// YW >>
forwardPage(Page.CREATE_DATASET_4);
}
}
} else if ("specifysubmit".equalsIgnoreCase(action)) {
Validator v = new Validator(request);
v.addValidation("dsName", Validator.NO_BLANKS);
v.addValidation("dsName", Validator.NO_SEMI_COLONS_OR_COLONS);
v.addValidation("dsDesc", Validator.NO_BLANKS);
v.addValidation("dsStatus", Validator.IS_VALID_TERM, TermType.STATUS);
v.addValidation("dsName", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
v.addValidation("dsDesc", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 2000);
String mdvOID = fp.getString("mdvOID");
String mdvName = fp.getString("mdvName");
String mdvPrevStudy = fp.getString("mdvPrevStudy");
if (mdvPrevStudy != null && mdvPrevStudy.length() > 0) {
v.addValidation("mdvPrevOID", Validator.NO_BLANKS);
}
String mdvPrevOID = fp.getString("mdvPrevOID");
errors = v.validate();
String dsName = fp.getString("dsName");
if (!StringUtil.isBlank(dsName)) {
// YW, << 3-19-2008
if (dsName.contains("/") || dsName.contains("\\")) {
v.addError(errors, "dsName", restext.getString("slash_not_allowed"));
}
// 2-20-2008, no check for editing dataset
if (((DatasetBean) session.getAttribute("newDataset")).getId() <= 0) {
// YW >>
// logger.info("dsName" + fp.getString("dsName"));
DatasetDAO dsdao = new DatasetDAO(sm.getDataSource());
DatasetBean dsBean = (DatasetBean) dsdao.findByNameAndStudy(fp.getString("dsName").trim(), currentStudy);
if (dsBean.getId() > 0) {
Validator.addError(errors, "dsName", restext.getString("dataset_name_used_by_another_choose_unique"));
}
}
}
if (!errors.isEmpty()) {
String[] fieldNames = { "dsName", "dsDesc" };
fp.setCurrentStringValuesAsPreset(fieldNames);
fp.addPresetValue("dsStatusId", fp.getInt("dsStatus"));
fp.addPresetValue("mdvOID", mdvOID);
fp.addPresetValue("mdvName", mdvName);
fp.addPresetValue("mdvPrevStudy", mdvPrevStudy);
fp.addPresetValue("mdvPrevOID", mdvPrevOID);
addPageMessage(respage.getString("errors_in_submission_see_below"));
setInputMessages(errors);
setPresetValues(fp.getPresetValues());
request.setAttribute("statuses", Status.toActiveArrayList());
forwardPage(Page.CREATE_DATASET_4);
} else {
session.setAttribute("mdvOID", mdvOID);
session.setAttribute("mdvName", mdvName);
session.setAttribute("mdvPrevStudy", mdvPrevStudy);
session.setAttribute("mdvPrevOID", mdvPrevOID);
if (mdvPrevOID != null && mdvPrevOID.length() > 0 && (mdvPrevStudy == null || mdvPrevStudy.length() <= 0)) {
mdvPrevStudy = currentStudy.getId() + "";
}
DatasetBean dsb = (DatasetBean) session.getAttribute("newDataset");
dsb.setSQLStatement(dsb.generateQuery());
String dbName = SQLInitServlet.getField("dataBase");
if ("oracle".equals(dbName)) {
dsb.setSQLStatement(dsb.generateOracleQuery());
}
// TODO set up oracle syntax for the query, grab the
// database
// from the session manager and feed it to the dataset bean
// possibly done, tbh 1/4/2005
// TODO look for the filter here, re-create the sql
// statement
// and put it in here
// possibly done need to test, tbh 1/7/2005
FilterBean fb = (FilterBean) session.getAttribute("newFilter");
if (fb != null) {
// FilterDAO fDAO = new FilterDAO(sm.getDataSource());
dsb.setSQLStatement(dsb.getSQLStatement() + " " + fb.getSQLStatement());
}
// dataset if dataset name has been changed.
if (dsb.getId() > 0 && !dsb.getName().equals(fp.getString("dsName"))) {
dsb.setId(0);
}
// YW >>
dsb.setODMMetaDataVersionName(mdvName);
dsb.setODMMetaDataVersionOid(mdvOID);
dsb.setODMPriorMetaDataVersionOid(mdvPrevOID);
dsb.setODMPriorStudyOid(mdvPrevStudy);
dsb.setName(fp.getString("dsName"));
dsb.setDescription(fp.getString("dsDesc"));
dsb.setStatus(Status.get(fp.getInt("dsStatus")));
dsb.setDatasetItemStatus(DatasetItemStatus.get(fp.getInt("itemStatus")));
session.removeAttribute("partOfCreateDataset");
Date ddate = new SimpleDateFormat("MM/dd/yyyy").parse("01/01/1900");
// done to remove the set up of going to get the filter, tbh
// set up dataset here, grab primary key???!!!???
// added by jxu
request.setAttribute("defaultStart", local_df.parse(local_df.format(ddate)));
request.setAttribute("defaultEnd", getLastDayOfMonth(2100, 12));
session.setAttribute("newDataset", dsb);
forwardPage(Page.CONFIRM_DATASET);
}
} else if ("confirmall".equalsIgnoreCase(action)) {
String submit = fp.getString("btnSubmit");
logger.info("reached confirm all");
if (!resword.getString("confirm_and_save").equalsIgnoreCase(submit)) {
// we're going back, so we should not destroy the
// data we've created, tbh
// session.removeAttribute("newDataset");
// session.removeAttribute("newFilter");
forwardPage(Page.CREATE_DATASET_4);
} else {
DatasetDAO ddao = new DatasetDAO(sm.getDataSource());
DatasetBean dsb = (DatasetBean) session.getAttribute("newDataset");
dsb.setStudyId(this.currentStudy.getId());
dsb.setOwner(ub);
// dsb.setOwnerId(ub.getId());
//
// at this point, dataset itemId will still be kept
// uniquely.
dsb = finalUpateDatasetBean(dsb);
if (dsb.getId() == 0) {
// if the bean hasn't been created already that is...
logger.info("*** about to create the dataset bean");
dsb = (DatasetBean) ddao.create(dsb);
logger.info("created dataset bean: " + dsb.getId() + ", name: " + dsb.getName());
if (!dsb.isActive()) {
addPageMessage(restext.getString("problem_creating_dataset_try_again"));
forwardPage(Page.EXTRACT_DATASETS_MAIN);
}
} else // YW, 2-20-2008 << for editing existing dataset
if (dsb.getId() > 0) {
dsb = (DatasetBean) ddao.updateAll(dsb);
if (!dsb.isActive()) {
addPageMessage(restext.getString("problem_creating_dataset_try_again"));
forwardPage(Page.EXTRACT_DATASETS_MAIN);
}
dsb = (DatasetBean) ddao.updateGroupMap(dsb);
if (!dsb.isActive()) {
addPageMessage(restext.getString("problem_updating_subject_group_class_when_updating_dataset"));
forwardPage(Page.EXTRACT_DATASETS_MAIN);
}
}
// YW >>
logger.info("setting data set id here");
// may be easier to just set the dataset bean
// back into the session?
request.setAttribute("dataset", dsb);
forwardPage(Page.EXPORT_DATASETS);
}
} else {
// refine this bit to catch errors, hopefully
addPageMessage(restext.getString("creating_new_dataset_cancelled"));
forwardPage(Page.CREATE_DATASET_1);
}
}
}
Aggregations