use of org.akaza.openclinica.bean.submit.CRFVersionBean in project OpenClinica by OpenClinica.
the class RuleSetServiceTest method getRuleSetsByCrfStudyAndStudyEventDefinition.
// @pgawade 08-NOV-2010 Commented out the test
// "testFilterRuleSetsByStudyEventOrdinal" temporarily. Krikor will look
// into this.
// public void testFilterRuleSetsByStudyEventOrdinal() {
// List<RuleSetBean> ruleSets = getRuleSets();
// StudyEventDAO studyEventDao = new StudyEventDAO(getDataSource());
// StudyEventBean studyEventBean = (StudyEventBean)
// studyEventDao.findByPK(1);
//
// RuleSetServiceInterface instance = (RuleSetServiceInterface)
// getContext().getBean("ruleSetService");
// List<RuleSetBean> ruleSets1 =
// instance.filterRuleSetsByStudyEventOrdinal(ruleSets, studyEventBean);
//
// assertEquals("Expressions Size inside this RuleSet should be 1", 1,
// ruleSets1.get(0).getExpressions().size());
// assertEquals("Expression Value should be SE_ED2REPEA[1].F_CONC_V20.IG_CONC_CONCOMITANTMEDICATIONS.I_CONC_CON_MED_NAME",
// "SE_ED2REPEA[1].F_CONC_V20.IG_CONC_CONCOMITANTMEDICATIONS.I_CONC_CON_MED_NAME",
// ruleSets1.get(0).getExpressions().get(0).getValue());
// }
//
// @pgawade 08-NOV-2010 Commented out the test
// "testFilterRuleSetsByStudyEventOrdinalWithALL" temporarily. Krikor will
// look into this.
// public void testFilterRuleSetsByStudyEventOrdinalWithALL() {
// List<RuleSetBean> ruleSets = getRuleSets();
// StudyEventDAO studyEventDao = new StudyEventDAO(getDataSource());
// StudyEventBean studyEventBean = (StudyEventBean)
// studyEventDao.findByPK(2);
//
// RuleSetServiceInterface instance = (RuleSetServiceInterface)
// getContext().getBean("ruleSetService");
// ruleSets.get(0).getTarget().setValue("SE_ED2REPEA[ALL].F_CONC_V20.IG_CONC_CONCOMITANTMEDICATIONS.I_CONC_CON_MED_NAME");
// List<RuleSetBean> ruleSets2 =
// instance.filterRuleSetsByStudyEventOrdinal(ruleSets, studyEventBean);
//
// assertEquals("Expressions Size inside this RuleSet should be 1", 1,
// ruleSets2.get(0).getExpressions().size());
// assertEquals("Expression Value should be SE_ED2REPEA[2].F_CONC_V20.IG_CONC_CONCOMITANTMEDICATIONS.I_CONC_CON_MED_NAME",
// "SE_ED2REPEA[2].F_CONC_V20.IG_CONC_CONCOMITANTMEDICATIONS.I_CONC_CON_MED_NAME",
// ruleSets2.get(0).getExpressions().get(0).getValue());
// }
private List<RuleSetBean> getRuleSetsByCrfStudyAndStudyEventDefinition() {
StudyDAO studyDao = new StudyDAO(getDataSource());
StudyBean study = (StudyBean) studyDao.findByPK(1);
assertNotNull(study);
StudyEventDefinitionDAO studyEventDefinitionDao = new StudyEventDefinitionDAO(getDataSource());
StudyEventDefinitionBean studyEventDefinition = (StudyEventDefinitionBean) studyEventDefinitionDao.findByPK(2);
assertNotNull(studyEventDefinition);
CRFVersionDAO crfVersionDao = new CRFVersionDAO(getDataSource());
CRFVersionBean crfVersion = (CRFVersionBean) crfVersionDao.findByPK(2);
assertNotNull(crfVersion);
RuleSetServiceInterface instance = (RuleSetServiceInterface) getContext().getBean("ruleSetService");
List<RuleSetBean> ruleSets = instance.getRuleSetsByCrfStudyAndStudyEventDefinition(study, studyEventDefinition, crfVersion);
return ruleSets;
}
use of org.akaza.openclinica.bean.submit.CRFVersionBean in project OpenClinica by OpenClinica.
the class DownloadVersionSpreadSheetServlet method processRequest.
@Override
public void processRequest() throws Exception {
String dir = SQLInitServlet.getField("filePath") + "crf" + File.separator + "new" + File.separator;
// YW 09-10-2007 << Now CRF_Design_Template_v2.xls is located at
// $CATALINA_HOME/webapps/OpenClinica-instanceName/properties
FormProcessor fp = new FormProcessor(request);
String crfIdString = fp.getString(CRF_ID);
int crfVersionId = fp.getInt(CRF_VERSION_ID);
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
CRFVersionBean version = (CRFVersionBean) cvdao.findByPK(crfVersionId);
boolean isTemplate = fp.getBoolean("template");
String excelFileName = crfIdString + version.getOid() + ".xls";
// aha, what if it's the old style? next line is for backwards compat,
// tbh 07/2008
File excelFile = null;
String oldExcelFileName = crfIdString + version.getName() + ".xls";
if (isTemplate) {
// excelFile = new File(dir + CRF_VERSION_TEMPLATE);
excelFile = getCoreResources().getFile(CRF_VERSION_TEMPLATE, "crf" + File.separator + "original" + File.separator);
excelFileName = CRF_VERSION_TEMPLATE;
// FileOutputStream fos = new FileOutputStream(excelFile);
// IOUtils.copy(getCoreResources().getInputStream(CRF_VERSION_TEMPLATE), fos);
// IOUtils.closeQuietly(fos);
} else {
excelFile = new File(dir + excelFileName);
// backwards compat
File oldExcelFile = new File(dir + oldExcelFileName);
if (oldExcelFile.exists() && oldExcelFile.length() > 0) {
if (!excelFile.exists() || excelFile.length() <= 0) {
// if the old name exists and the new name does not...
excelFile = oldExcelFile;
excelFileName = oldExcelFileName;
}
}
}
logger.info("looking for : " + excelFile.getName());
if (!excelFile.exists() || excelFile.length() <= 0) {
addPageMessage(respage.getString("the_excel_is_not_available_on_server_contact"));
forwardPage(Page.CRF_LIST_SERVLET);
} else {
response.setHeader("Content-disposition", "attachment; filename=\"" + excelFileName + "\";");
response.setContentType("application/vnd.ms-excel");
response.setHeader("Pragma", "public");
ServletOutputStream op = response.getOutputStream();
DataInputStream in = null;
try {
response.setContentType("application/vnd.ms-excel");
response.setHeader("Pragma", "public");
response.setContentLength((int) excelFile.length());
byte[] bbuf = new byte[(int) excelFile.length()];
in = new DataInputStream(new FileInputStream(excelFile));
int length;
while ((in != null) && ((length = in.read(bbuf)) != -1)) {
op.write(bbuf, 0, length);
}
in.close();
op.flush();
op.close();
} catch (Exception ee) {
ee.printStackTrace();
} finally {
if (in != null) {
in.close();
}
if (op != null) {
op.close();
}
}
}
}
use of org.akaza.openclinica.bean.submit.CRFVersionBean in project OpenClinica by OpenClinica.
the class BatchCRFMigrationServlet method processRequest.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
ArrayList<CRFVersionBean> crfVersionList = null;
ArrayList<FormLayoutBean> formLayoutList = null;
ArrayList<StudyEventDefinitionBean> eventList = null;
ArrayList<StudyBean> siteList = null;
// checks which module the requests are from, manage or admin
String module = fp.getString(MODULE);
request.setAttribute(MODULE, module);
int crfId = fp.getInt(CRF_ID);
if (crfId == 0) {
addPageMessage(respage.getString("please_choose_a_CRF_to_view"));
forwardPage(Page.CRF_LIST);
} else {
CRFDAO cdao = new CRFDAO(sm.getDataSource());
// CRFVersionDAO vdao = new CRFVersionDAO(sm.getDataSource());
FormLayoutDAO fldao = new FormLayoutDAO(sm.getDataSource());
CRFBean crf = (CRFBean) cdao.findByPK(crfId);
request.setAttribute("crfName", crf.getName());
// ArrayList<CRFVersionBean> versions = (ArrayList<CRFVersionBean>) vdao.findAllByCRF(crfId);
ArrayList<FormLayoutBean> formLayouts = (ArrayList<FormLayoutBean>) fldao.findAllByCRF(crfId);
crfVersionList = new ArrayList<CRFVersionBean>();
formLayoutList = new ArrayList<FormLayoutBean>();
for (FormLayoutBean version : formLayouts) {
if (version.getStatus().isAvailable())
formLayoutList.add(version);
}
// for (CRFVersionBean version : versions) {
// if (version.getStatus().isAvailable())
// crfVersionList.add(version);
// }
// crf.setVersions(crfVersionList);
crf.setFormLayouts(formLayoutList);
ArrayList<StudyBean> listOfSites = (ArrayList<StudyBean>) sdao().findAllByParent(currentStudy.getId());
siteList = new ArrayList<StudyBean>();
StudyBean studyBean = new StudyBean();
studyBean.setOid(currentStudy.getOid());
studyBean.setName(resterm.getString("Study_Level_Subjects_Only"));
siteList.add(studyBean);
for (StudyBean s : listOfSites) {
if (s.getStatus().isAvailable()) {
siteList.add(s);
}
}
ArrayList<StudyEventDefinitionBean> listOfDefn = seddao().findAllByStudy(currentStudy);
eventList = new ArrayList<StudyEventDefinitionBean>();
for (StudyEventDefinitionBean d : listOfDefn) {
if (d.getStatus().isAvailable()) {
eventList.add(d);
}
}
// if coming from change crf version -> display message
String crfVersionChangeMsg = fp.getString("isFromCRFVersionBatchChange");
if (crfVersionChangeMsg != null && !crfVersionChangeMsg.equals("")) {
addPageMessage(crfVersionChangeMsg);
}
request.setAttribute("study", currentStudy);
request.setAttribute("siteList", siteList);
request.setAttribute("eventList", eventList);
request.setAttribute(CRF, crf);
forwardPage(Page.BATCH_CRF_MIGRATION);
}
}
use of org.akaza.openclinica.bean.submit.CRFVersionBean in project OpenClinica by OpenClinica.
the class DeleteEventCRFServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
int studySubId = fp.getInt(STUDY_SUB_ID, true);
int eventCRFId = fp.getInt(EVENT_CRF_ID);
String action = request.getParameter("action");
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
StudyDAO sdao = new StudyDAO(sm.getDataSource());
if (eventCRFId == 0) {
addPageMessage(respage.getString("please_choose_an_event_CRF_to_delete"));
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
} else {
EventCRFBean eventCRF = (EventCRFBean) ecdao.findByPK(eventCRFId);
StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
request.setAttribute("studySub", studySub);
// construct info needed on view event crf page
CRFDAO cdao = new CRFDAO(sm.getDataSource());
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
int crfVersionId = eventCRF.getCRFVersionId();
CRFBean cb = cdao.findByVersionId(crfVersionId);
eventCRF.setCrf(cb);
CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(crfVersionId);
eventCRF.setCrfVersion(cvb);
// then get the definition so we can call
// DisplayEventCRFBean.setFlags
int studyEventId = eventCRF.getStudyEventId();
StudyEventBean event = (StudyEventBean) sedao.findByPK(studyEventId);
int studyEventDefinitionId = sedao.getDefinitionIdFromStudyEventId(studyEventId);
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(studyEventDefinitionId);
event.setStudyEventDefinition(sed);
request.setAttribute("event", event);
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
StudyBean study = (StudyBean) sdao.findByPK(studySub.getStudyId());
EventDefinitionCRFBean edc = edcdao.findByStudyEventDefinitionIdAndCRFId(study, studyEventDefinitionId, cb.getId());
DisplayEventCRFBean dec = new DisplayEventCRFBean();
dec.setEventCRF(eventCRF);
dec.setFlags(eventCRF, ub, currentRole, edc.isDoubleEntry());
// find all item data
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
dnDao = new DiscrepancyNoteDAO(sm.getDataSource());
ArrayList<ItemDataBean> itemData = iddao.findAllByEventCRFId(eventCRF.getId());
request.setAttribute("items", itemData);
if ("confirm".equalsIgnoreCase(action)) {
request.setAttribute("displayEventCRF", dec);
forwardPage(Page.DELETE_EVENT_CRF);
} else {
logger.info("submit to delete the event CRF from event");
// OC-6303 Deleting Event CRF resets Show / Hide logic
// delete records from DynamicItemForm and DynamicItemGroup
// getDynamicsItemFormMetadataDao().delete(eventCRFId);
// getDynamicsItemGroupMetadataDao().delete(eventCRFId);
eventCRF.setOldStatus(eventCRF.getStatus());
eventCRF.setStatus(Status.RESET);
eventCRF.setUpdater(ub);
ecdao.update(eventCRF);
for (ItemDataBean itemdata : itemData) {
// OC-6343 Rule behaviour must be reset if an Event CRF is deleted
// delete the records from ruleActionRunLogDao
List<RuleActionRunLogBean> ruleActionRunLog = getRuleActionRunLogDao().findAllItemData(itemdata.getId());
if (ruleActionRunLog.size() != 0) {
getRuleActionRunLogDao().delete(itemdata.getId());
}
// OC-6344 Notes & Discrepancies must be set to "closed" when event CRF is deleted
// parentDiscrepancyNoteList is the list of the parent DNs records only
ArrayList<DiscrepancyNoteBean> parentDiscrepancyNoteList = getDnDao().findParentNotesOnlyByItemData(itemdata.getId());
for (DiscrepancyNoteBean parentDiscrepancyNote : parentDiscrepancyNoteList) {
if (parentDiscrepancyNote.getResolutionStatusId() != 4) {
// if the DN's resolution status is
// not set to Closed
String description = resword.getString("dn_auto-closed_description");
String detailedNotes = resword.getString("dn_auto_closed_detailed_notes");
// create new DN record , new DN Map record , also update the parent record
createDiscrepancyNoteBean(description, detailedNotes, itemdata.getId(), study, ub, parentDiscrepancyNote);
}
}
iddao = new ItemDataDAO(sm.getDataSource());
ifmdao = new ItemFormMetadataDAO(sm.getDataSource());
ItemDataBean idBean = (ItemDataBean) iddao.findByPK(itemdata.getId());
ItemFormMetadataBean ifmBean = ifmdao.findByItemIdAndCRFVersionId(idBean.getItemId(), crfVersionId);
// Updating Dn_item_data_map actovated column into false for the existing DNs
ArrayList<DiscrepancyNoteBean> dnBeans = getDnDao().findExistingNotesForItemData(itemdata.getId());
if (dnBeans.size() != 0) {
DiscrepancyNoteBean dnBean = new DiscrepancyNoteBean();
dnBean.setEntityId(itemdata.getId());
dnBean.setActivated(false);
getDnDao().updateDnMapActivation(dnBean);
}
// Default Values are not addressed
itemdata.setValue("");
itemdata.setOldStatus(itemdata.getStatus());
itemdata.setOwner(ub);
itemdata.setStatus(Status.AVAILABLE);
itemdata.setUpdater(ub);
iddao.updateUser(itemdata);
iddao.update(itemdata);
}
// OC-6291 event_crf status change
eventCRF.setOldStatus(eventCRF.getStatus());
eventCRF.setStatus(Status.AVAILABLE);
eventCRF.setUpdater(ub);
ecdao.update(eventCRF);
if (event.getSubjectEventStatus().isCompleted() || event.getSubjectEventStatus().isSigned()) {
event.setSubjectEventStatus(SubjectEventStatus.DATA_ENTRY_STARTED);
event.setUpdater(ub);
sedao = new StudyEventDAO(sm.getDataSource());
sedao.update(event);
}
String emailBody = respage.getString("the_event_CRF") + cb.getName() + respage.getString("has_been_deleted_from_the_event") + event.getStudyEventDefinition().getName() + ". " + respage.getString("has_been_deleted_from_the_event_cont");
addPageMessage(emailBody);
// sendEmail(emailBody);
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
}
}
}
use of org.akaza.openclinica.bean.submit.CRFVersionBean in project OpenClinica by OpenClinica.
the class CreateCRFVersionServlet method processRequest.
@SuppressWarnings("unchecked")
@Override
public void processRequest() throws Exception {
resetPanel();
panel.setStudyInfoShown(true);
CRFDAO cdao = new CRFDAO(sm.getDataSource());
CRFVersionDAO vdao = new CRFVersionDAO(sm.getDataSource());
EventDefinitionCRFDAO edao = new EventDefinitionCRFDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
// checks which module the requests are from
String module = fp.getString(MODULE);
// keep the module in the session
session.setAttribute(MODULE, module);
request.setAttribute("xformEnabled", CoreResources.getField("xform.enabled"));
String action = request.getParameter("action");
CRFVersionBean version = (CRFVersionBean) session.getAttribute("version");
if (StringUtil.isBlank(action)) {
logger.debug("action is blank");
request.setAttribute("version", version);
forwardPage(Page.CREATE_CRF_VERSION);
} else if ("confirm".equalsIgnoreCase(action)) {
String dir = SQLInitServlet.getField("filePath");
if (!new File(dir).exists()) {
logger.debug("The filePath in datainfo.properties is invalid " + dir);
addPageMessage(resword.getString("the_filepath_you_defined"));
forwardPage(Page.CREATE_CRF_VERSION);
// BWP 01/13/2009 >>
return;
// >>
}
// All the uploaded files will be saved in filePath/crf/original/
String theDir = dir + "crf" + File.separator + "original" + File.separator;
if (!new File(theDir).isDirectory()) {
new File(theDir).mkdirs();
logger.debug("Made the directory " + theDir);
}
// MultipartRequest multi = new MultipartRequest(request, theDir, 50 * 1024 * 1024);
String tempFile = "";
try {
tempFile = uploadFile(theDir, version);
} catch (CRFReadingException crfException) {
Validator.addError(errors, "excel_file", crfException.getMessage());
String msg = crfException.getMessage();
request.setAttribute("formMessages", errors);
forwardPage(Page.CREATE_CRF_VERSION);
return;
} catch (Exception e) {
//
logger.warn("*** Found exception during file upload***");
e.printStackTrace();
}
session.setAttribute("tempFileName", tempFile);
// provided and/or not xls format
if (errors.isEmpty()) {
String s = ((NewCRFBean) session.getAttribute("nib")).getVersionName();
if (s.length() > 255) {
Validator.addError(errors, "excel_file", resword.getString("the_version_CRF_version_more_than_255"));
} else if (s.length() <= 0) {
Validator.addError(errors, "excel_file", resword.getString("the_VERSION_column_was_blank"));
}
version.setName(s);
if (version.getCrfId() == 0) {
version.setCrfId(fp.getInt("crfId"));
}
session.setAttribute("version", version);
}
if (!errors.isEmpty()) {
logger.debug("has validation errors ");
request.setAttribute("formMessages", errors);
forwardPage(Page.CREATE_CRF_VERSION);
} else {
CRFBean crf = (CRFBean) cdao.findByPK(version.getCrfId());
ArrayList versions = (ArrayList) vdao.findAllByCRF(crf.getId());
for (int i = 0; i < versions.size(); i++) {
CRFVersionBean version1 = (CRFVersionBean) versions.get(i);
if (version.getName().equals(version1.getName())) {
// version already exists
logger.debug("Version already exists; owner or not:" + ub.getId() + "," + version1.getOwnerId());
if (ub.getId() != version1.getOwnerId()) {
// not owner
addPageMessage(respage.getString("CRF_version_try_upload_exists_database") + version1.getOwner().getName() + respage.getString("please_contact_owner_to_delete"));
forwardPage(Page.CREATE_CRF_VERSION);
return;
} else {
// owner,
ArrayList definitions = edao.findByDefaultVersion(version1.getId());
if (!definitions.isEmpty()) {
// used in
// definition
request.setAttribute("definitions", definitions);
forwardPage(Page.REMOVE_CRF_VERSION_DEF);
return;
} else {
// not used in definition
int previousVersionId = version1.getId();
version.setId(previousVersionId);
session.setAttribute("version", version);
session.setAttribute("previousVersionId", new Integer(previousVersionId));
forwardPage(Page.REMOVE_CRF_VERSION_CONFIRM);
return;
}
}
}
}
// didn't find same version in the DB,let user upload the excel
// file
logger.debug("didn't find same version in the DB,let user upload the excel file.");
// List excelErr =
// ((ArrayList)request.getAttribute("excelErrors"));
List excelErr = (ArrayList) session.getAttribute("excelErrors");
logger.debug("excelErr.isEmpty()=" + excelErr.isEmpty());
if (excelErr != null && excelErr.isEmpty()) {
addPageMessage(resword.getString("congratulations_your_spreadsheet_no_errors"));
forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PREVIEW);
} else {
logger.debug("OpenClinicaException thrown, forwarding to CREATE_CRF_VERSION_CONFIRM.");
forwardPage(Page.CREATE_CRF_VERSION_CONFIRM);
}
return;
}
} else if ("confirmsql".equalsIgnoreCase(action)) {
NewCRFBean nib = (NewCRFBean) session.getAttribute("nib");
if (nib != null && nib.getItemQueries() != null) {
request.setAttribute("openQueries", nib.getItemQueries());
} else {
request.setAttribute("openQueries", new HashMap());
}
boolean canDelete = false;
// check whether need to delete previous version
Boolean deletePreviousVersion = (Boolean) session.getAttribute("deletePreviousVersion");
Integer previousVersionId = (Integer) session.getAttribute("previousVersionId");
if (deletePreviousVersion != null && deletePreviousVersion.equals(Boolean.TRUE) && previousVersionId != null && previousVersionId.intValue() > 0) {
logger.debug("Need to delete previous version");
// whether we can delete
canDelete = canDeleteVersion(previousVersionId.intValue());
if (!canDelete) {
logger.debug("but cannot delete previous version");
if (session.getAttribute("itemsHaveData") == null && session.getAttribute("eventsForVersion") == null) {
addPageMessage(respage.getString("you_are_not_owner_some_items_cannot_delete"));
}
if (session.getAttribute("itemsHaveData") == null) {
session.setAttribute("itemsHaveData", new ArrayList());
}
if (session.getAttribute("eventsForVersion") == null) {
session.setAttribute("eventsForVersion", new ArrayList());
}
forwardPage(Page.CREATE_CRF_VERSION_NODELETE);
return;
}
ArrayList<ItemBean> nonSharedItems = (ArrayList<ItemBean>) vdao.findNotSharedItemsByVersion(previousVersionId.intValue());
// htaycher: here is the trick we need to put in nib1.setItemQueries()
// update statements for shared items and insert for nonShared that were just deleted 5927
HashMap item_table_statements = new HashMap();
ArrayList<String> temp = new ArrayList<String>(nonSharedItems.size());
for (ItemBean item : nonSharedItems) {
temp.add(item.getName());
item_table_statements.put(item.getName(), nib.getBackupItemQueries().get(item.getName()));
}
for (String item_name : (Set<String>) nib.getItemQueries().keySet()) {
// check if item shared
if (!temp.contains(item_name)) {
item_table_statements.put(item_name, nib.getItemQueries().get(item_name));
}
}
// statements to run
if (!nonSharedItems.isEmpty()) {
request.setAttribute("openQueries", item_table_statements);
}
// htaycher: put all statements in
nib.setItemQueries(item_table_statements);
session.setAttribute("nib", nib);
}
// submit
logger.debug("commit sql");
NewCRFBean nib1 = (NewCRFBean) session.getAttribute("nib");
if (nib1 != null) {
try {
if (canDelete) {
nib1.deleteInsertToDB();
} else {
nib1.insertToDB();
}
request.setAttribute("queries", nib1.getQueries());
// YW << for add a link to "View CRF Version Data Entry".
// For this purpose, CRFVersion id is needed.
// So the latest CRFVersion Id of A CRF Id is it.
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
ArrayList crfvbeans = new ArrayList();
logger.debug("CRF-ID [" + version.getCrfId() + "]");
int crfVersionId = 0;
String versionOID = null;
if (version.getCrfId() != 0) {
crfvbeans = cvdao.findAllByCRFId(version.getCrfId());
CRFVersionBean cvbean = (CRFVersionBean) crfvbeans.get(crfvbeans.size() - 1);
crfVersionId = cvbean.getId();
versionOID = cvbean.getOid();
for (Iterator iter = crfvbeans.iterator(); iter.hasNext(); ) {
cvbean = (CRFVersionBean) iter.next();
if (crfVersionId < cvbean.getId()) {
crfVersionId = cvbean.getId();
}
}
}
// Not needed; crfVersionId will be autoboxed in Java 5
// this was added for the old CVS java compiler
Integer cfvID = new Integer(crfVersionId);
if (cfvID == 0) {
cfvID = cvdao.findCRFVersionId(nib1.getCrfId(), nib1.getVersionName());
}
CRFVersionBean finalVersion = (CRFVersionBean) cvdao.findByPK(cfvID);
version.setCrfId(nib1.getCrfId());
version.setOid(finalVersion.getOid());
CRFBean crfBean = (CRFBean) cdao.findByPK(version.getCrfId());
crfBean.setUpdatedDate(version.getCreatedDate());
crfBean.setUpdater(ub);
cdao.update(crfBean);
// workaround to get a correct file name below, tbh 06/2008
request.setAttribute("crfVersionId", cfvID);
// YW >>
// return those properties to initial values
session.removeAttribute("version");
session.removeAttribute("eventsForVersion");
session.removeAttribute("itemsHaveData");
session.removeAttribute("nib");
session.removeAttribute("deletePreviousVersion");
session.removeAttribute("previousVersionId");
// save new version spreadsheet
String tempFile = (String) session.getAttribute("tempFileName");
if (tempFile != null) {
logger.debug("*** ^^^ *** saving new version spreadsheet" + tempFile);
try {
String dir = SQLInitServlet.getField("filePath");
File f = new File(dir + "crf" + File.separator + "original" + File.separator + tempFile);
// check to see whether crf/new/ folder exists
// inside, if not,
// creates
// the crf/new/ folder
String finalDir = dir + "crf" + File.separator + "new" + File.separator;
if (!new File(finalDir).isDirectory()) {
logger.debug("need to create folder for excel files" + finalDir);
new File(finalDir).mkdirs();
}
// String newFile = version.getCrfId() +
// version.getName() + ".xls";
String newFile = version.getCrfId() + version.getOid() + ".xls";
logger.debug("*** ^^^ *** new file: " + newFile);
File nf = new File(finalDir + newFile);
logger.debug("copying old file " + f.getName() + " to new file " + nf.getName());
copy(f, nf);
// ?
} catch (IOException ie) {
logger.debug("==============");
addPageMessage(respage.getString("CRF_version_spreadsheet_could_not_saved_contact"));
}
}
session.removeAttribute("tempFileName");
session.removeAttribute(MODULE);
session.removeAttribute("excelErrors");
session.removeAttribute("htmlTab");
forwardPage(Page.CREATE_CRF_VERSION_DONE);
} catch (OpenClinicaException pe) {
logger.debug("--------------");
session.setAttribute("excelErrors", nib1.getErrors());
// request.setAttribute("excelErrors", nib1.getErrors());
forwardPage(Page.CREATE_CRF_VERSION_ERROR);
}
} else {
forwardPage(Page.CREATE_CRF_VERSION);
}
} else if ("delete".equalsIgnoreCase(action)) {
logger.debug("user wants to delete previous version");
List excelErr = (ArrayList) session.getAttribute("excelErrors");
logger.debug("for overwrite CRF version, excelErr.isEmpty()=" + excelErr.isEmpty());
if (excelErr != null && excelErr.isEmpty()) {
addPageMessage(resword.getString("congratulations_your_spreadsheet_no_errors"));
// should be moved to excelErr != null block
session.setAttribute("deletePreviousVersion", Boolean.TRUE);
forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PREVIEW);
} else {
// should be moved to excelErr != null
session.setAttribute("deletePreviousVersion", Boolean.FALSE);
// block
logger.debug("OpenClinicaException thrown, forwarding to CREATE_CRF_VERSION_CONFIRM.");
forwardPage(Page.CREATE_CRF_VERSION_CONFIRM);
}
}
}
Aggregations