use of org.akaza.openclinica.service.extract.GenerateExtractFileService in project OpenClinica by OpenClinica.
the class ExampleSpringJob method executeInternal.
@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
// need to generate a Locale so that user beans and other things will
// generate normally
Locale locale = new Locale("en-US");
ResourceBundleProvider.updateLocale(locale);
ResourceBundle pageMessages = ResourceBundleProvider.getPageMessagesBundle();
// logger.debug("--");
// logger.debug("-- executing a job " + message + " at " + new
// java.util.Date().toString());
JobDataMap dataMap = context.getMergedJobDataMap();
SimpleTrigger trigger = (SimpleTrigger) context.getTrigger();
try {
ApplicationContext appContext = (ApplicationContext) context.getScheduler().getContext().get("applicationContext");
String studySubjectNumber = ((CoreResources) appContext.getBean("coreResources")).getField("extract.number");
coreResources = (CoreResources) appContext.getBean("coreResources");
ruleSetRuleDao = (RuleSetRuleDao) appContext.getBean("ruleSetRuleDao");
dataSource = (DataSource) appContext.getBean("dataSource");
mailSender = (OpenClinicaMailSender) appContext.getBean("openClinicaMailSender");
AuditEventDAO auditEventDAO = new AuditEventDAO(dataSource);
// Scheduler scheduler = context.getScheduler();
// JobDetail detail = context.getJobDetail();
// jobDetailBean = (JobDetailBean) detail;
/*
* data map here should coincide with the job data map found in
* CreateJobExportServlet, with the following code: jobDataMap = new
* JobDataMap(); jobDataMap.put(DATASET_ID, datasetId);
* jobDataMap.put(PERIOD, period); jobDataMap.put(EMAIL, email);
* jobDataMap.put(TAB, tab); jobDataMap.put(CDISC, cdisc);
* jobDataMap.put(SPSS, spss);
*/
String alertEmail = dataMap.getString(EMAIL);
String localeStr = dataMap.getString(LOCALE);
if (localeStr != null) {
locale = new Locale(localeStr);
ResourceBundleProvider.updateLocale(locale);
pageMessages = ResourceBundleProvider.getPageMessagesBundle();
}
int dsId = dataMap.getInt(DATASET_ID);
String tab = dataMap.getString(TAB);
String cdisc = dataMap.getString(CDISC);
String cdisc12 = dataMap.getString(CDISC12);
if (cdisc12 == null) {
cdisc12 = "0";
}
String cdisc13 = dataMap.getString(CDISC13);
if (cdisc13 == null) {
cdisc13 = "0";
}
String cdisc13oc = dataMap.getString(CDISC13OC);
if (cdisc13oc == null) {
cdisc13oc = "0";
}
String spss = dataMap.getString(SPSS);
int userId = dataMap.getInt(USER_ID);
int studyId = dataMap.getInt(STUDY_ID);
// String datasetId = dataMap.getString(DATASET_ID);
// int dsId = new Integer(datasetId).intValue();
// String userAcctId = dataMap.getString(USER_ID);
// int userId = new Integer(userAcctId).intValue();
// why the flip-flop? if one property is set to 'true' we can
// see jobs in another screen but all properties have to be
// strings
logger.debug("-- found the job: " + dsId + " dataset id");
// for (Iterator it = dataMap.entrySet().iterator(); it.hasNext();)
// {
// java.util.Map.Entry entry = (java.util.Map.Entry) it.next();
// Object key = entry.getKey();
// Object value = entry.getValue();
// // logger.debug("-- found datamap property: " + key.toString() +
// // " : " + value.toString());
// }
HashMap fileName = new HashMap<String, Integer>();
if (dsId > 0) {
// trying to not throw an error if there's no dataset id
DatasetDAO dsdao = new DatasetDAO(dataSource);
DatasetBean datasetBean = (DatasetBean) dsdao.findByPK(dsId);
StudyDAO studyDao = new StudyDAO(dataSource);
UserAccountDAO userAccountDAO = new UserAccountDAO(dataSource);
// hmm, three lines in the if block DRY?
String generalFileDir = "";
String generalFileDirCopy = "";
String exportFilePath = SQLInitServlet.getField("exportFilePath");
String pattern = "yyyy" + File.separator + "MM" + File.separator + "dd" + File.separator + "HHmmssSSS" + File.separator;
SimpleDateFormat sdfDir = new SimpleDateFormat(pattern);
generalFileDir = DATASET_DIR + datasetBean.getId() + File.separator + sdfDir.format(new java.util.Date());
if (!"".equals(exportFilePath)) {
generalFileDirCopy = SQLInitServlet.getField("filePath") + exportFilePath + File.separator;
}
// logger.debug("-- created the following dir: " +
// generalFileDir);
long sysTimeBegin = System.currentTimeMillis();
// set up the user bean here, tbh
// logger.debug("-- gen tab file 00");
userBean = (UserAccountBean) userAccountDAO.findByPK(userId);
// needs to also be captured by the servlet, tbh
// logger.debug("-- gen tab file 00");
generateFileService = new GenerateExtractFileService(dataSource, coreResources, ruleSetRuleDao);
// logger.debug("-- gen tab file 00");
// tbh #5796 - covers a bug when the user changes studies, 10/2010
StudyBean activeStudy = (StudyBean) studyDao.findByPK(studyId);
StudyBean parentStudy = new StudyBean();
logger.debug("active study: " + studyId + " parent study: " + activeStudy.getParentStudyId());
if (activeStudy.getParentStudyId() > 0) {
// StudyDAO sdao = new StudyDAO(sm.getDataSource());
parentStudy = (StudyBean) studyDao.findByPK(activeStudy.getParentStudyId());
} else {
parentStudy = activeStudy;
// covers a bug in tab file creation, tbh 01/2009
}
logger.debug("-- found extract bean ");
ExtractBean eb = generateFileService.generateExtractBean(datasetBean, activeStudy, parentStudy);
MessageFormat mf = new MessageFormat("");
StringBuffer message = new StringBuffer();
StringBuffer auditMessage = new StringBuffer();
// use resource bundle page messages to generate the email, tbh
// 02/2009
// message.append(pageMessages.getString("html_email_header_1")
// + " " + alertEmail +
// pageMessages.getString("html_email_header_2") + "<br/>");
message.append("<p>" + pageMessages.getString("email_header_1") + " " + EmailEngine.getAdminEmail() + " " + pageMessages.getString("email_header_2") + " Job Execution " + pageMessages.getString("email_header_3") + "</p>");
message.append("<P>Dataset: " + datasetBean.getName() + "</P>");
message.append("<P>Study: " + activeStudy.getName() + "</P>");
message.append("<p>" + pageMessages.getString("html_email_body_1") + datasetBean.getName() + pageMessages.getString("html_email_body_2") + SQLInitServlet.getField("sysURL") + pageMessages.getString("html_email_body_3") + "</p>");
// logger.debug("-- gen tab file 00");
if ("1".equals(tab)) {
logger.debug("-- gen tab file 01");
fileName = generateFileService.createTabFile(eb, sysTimeBegin, generalFileDir, datasetBean, activeStudy.getId(), parentStudy.getId(), generalFileDirCopy, userBean);
message.append("<p>" + pageMessages.getString("html_email_body_4") + " " + getFileNameStr(fileName) + pageMessages.getString("html_email_body_4_5") + SQLInitServlet.getField("sysURL.base") + "AccessFile?fileId=" + getFileIdInt(fileName) + pageMessages.getString("html_email_body_3") + "</p>");
// MessageFormat mf = new MessageFormat("");
// mf.applyPattern(pageMessages.getString(
// "you_can_access_tab_delimited"));
// Object[] arguments = { getFileIdInt(fileName) };
// auditMessage.append(mf.format(arguments));
// auditMessage.append(
// "You can access your tab-delimited file <a href='AccessFile?fileId="
// + getFileIdInt(fileName) + "'>here</a>.<br/>");
auditMessage.append(pageMessages.getString("you_can_access_tab_delimited") + getFileIdInt(fileName) + pageMessages.getString("access_end"));
}
if ("1".equals(cdisc)) {
String odmVersion = "oc1.2";
fileName = generateFileService.createODMFile(odmVersion, sysTimeBegin, generalFileDir, datasetBean, activeStudy, generalFileDirCopy, eb, activeStudy.getId(), parentStudy.getId(), studySubjectNumber, true, true, true, null, userBean);
logger.debug("-- gen odm file");
message.append("<p>" + pageMessages.getString("html_email_body_4") + " " + getFileNameStr(fileName) + pageMessages.getString("html_email_body_4_5") + SQLInitServlet.getField("sysURL.base") + "AccessFile?fileId=" + getFileIdInt(fileName) + pageMessages.getString("html_email_body_3") + "</p>");
// MessageFormat mf = new MessageFormat("");
// mf.applyPattern(pageMessages.getString(
// "you_can_access_odm_12"));
// Object[] arguments = { getFileIdInt(fileName) };
// auditMessage.append(mf.format(arguments));
// auditMessage.append(
// "You can access your ODM 1.2 w/OpenClinica Extension XML file <a href='AccessFile?fileId="
// + getFileIdInt(fileName)
// + "'>here</a>.<br/>");
auditMessage.append(pageMessages.getString("you_can_access_odm_12") + getFileIdInt(fileName) + pageMessages.getString("access_end"));
}
if ("1".equals(cdisc12)) {
String odmVersion = "1.2";
fileName = generateFileService.createODMFile(odmVersion, sysTimeBegin, generalFileDir, datasetBean, activeStudy, generalFileDirCopy, eb, activeStudy.getId(), parentStudy.getId(), studySubjectNumber, true, true, true, null, userBean);
logger.debug("-- gen odm file 1.2 default");
message.append("<p>" + pageMessages.getString("html_email_body_4") + " " + getFileNameStr(fileName) + pageMessages.getString("html_email_body_4_5") + SQLInitServlet.getField("sysURL.base") + "AccessFile?fileId=" + getFileIdInt(fileName) + pageMessages.getString("html_email_body_3") + "</p>");
// mf.applyPattern(pageMessages.getString(
// "you_can_access_odm_12_xml"));
// Object[] arguments = { getFileIdInt(fileName) };
// auditMessage.append(mf.format(arguments));
// // auditMessage.append(
// "You can access your ODM 1.2 XML file <a href='AccessFile?fileId="
// + getFileIdInt(fileName) + "'>here</a>.<br/>");
auditMessage.append(pageMessages.getString("you_can_access_odm_12_xml") + getFileIdInt(fileName) + pageMessages.getString("access_end"));
}
if ("1".equals(cdisc13)) {
String odmVersion = "1.3";
fileName = generateFileService.createODMFile(odmVersion, sysTimeBegin, generalFileDir, datasetBean, activeStudy, generalFileDirCopy, eb, activeStudy.getId(), parentStudy.getId(), studySubjectNumber, true, true, true, null, userBean);
logger.debug("-- gen odm file 1.3");
message.append("<p>" + pageMessages.getString("html_email_body_4") + " " + getFileNameStr(fileName) + pageMessages.getString("html_email_body_4_5") + SQLInitServlet.getField("sysURL.base") + "AccessFile?fileId=" + getFileIdInt(fileName) + pageMessages.getString("html_email_body_3") + "</p>");
// MessageFormat mf = new MessageFormat("");
// mf.applyPattern(pageMessages.getString(
// "you_can_access_odm_13"));
// Object[] arguments = { getFileIdInt(fileName) };
// auditMessage.append(mf.format(arguments));
// auditMessage.append(
// "You can access your ODM 1.3 XML file <a href='AccessFile?fileId="
// + getFileIdInt(fileName) + "'>here</a>.<br/>");
auditMessage.append(pageMessages.getString("you_can_access_odm_13") + getFileIdInt(fileName) + pageMessages.getString("access_end"));
}
if ("1".equals(cdisc13oc)) {
String odmVersion = "oc1.3";
fileName = generateFileService.createODMFile(odmVersion, sysTimeBegin, generalFileDir, datasetBean, activeStudy, generalFileDirCopy, eb, activeStudy.getId(), parentStudy.getId(), studySubjectNumber, true, true, true, null, userBean);
logger.debug("-- gen odm file 1.3 oc");
message.append("<p>" + pageMessages.getString("html_email_body_4") + " " + getFileNameStr(fileName) + pageMessages.getString("html_email_body_4_5") + SQLInitServlet.getField("sysURL.base") + "AccessFile?fileId=" + getFileIdInt(fileName) + pageMessages.getString("html_email_body_3") + "</p>");
// MessageFormat mf = new MessageFormat("");
// mf.applyPattern(pageMessages.getString(
// "you_can_access_odm_13_xml"));
// Object[] arguments = { getFileIdInt(fileName) };
// auditMessage.append(mf.format(arguments));
// auditMessage.append(
// "You can access your ODM 1.3 w/OpenClinica Extension XML file <a href='AccessFile?fileId="
// + getFileIdInt(fileName)
// + "'>here</a>.<br/>");
auditMessage.append(pageMessages.getString("you_can_access_odm_13_xml") + getFileIdInt(fileName) + pageMessages.getString("access_end"));
}
if ("1".equals(spss)) {
SPSSReportBean answer = new SPSSReportBean();
fileName = generateFileService.createSPSSFile(datasetBean, eb, activeStudy, parentStudy, sysTimeBegin, generalFileDir, answer, generalFileDirCopy, userBean);
logger.debug("-- gen spss file");
message.append("<p>" + pageMessages.getString("html_email_body_4") + " " + getFileNameStr(fileName) + pageMessages.getString("html_email_body_4_5") + SQLInitServlet.getField("sysURL.base") + "AccessFile?fileId=" + getFileIdInt(fileName) + pageMessages.getString("html_email_body_3") + "</p>");
// MessageFormat mf = new MessageFormat("");
// mf.applyPattern(pageMessages.getString(
// "you_can_access_spss"));
// Object[] arguments = { getFileIdInt(fileName) };
// auditMessage.append(mf.format(arguments));
// auditMessage.append(
// "You can access your SPSS files <a href='AccessFile?fileId="
// + getFileIdInt(fileName) + "'>here</a>.<br/>");
auditMessage.append(pageMessages.getString("you_can_access_spss") + getFileIdInt(fileName) + pageMessages.getString("access_end"));
}
// wrap up the message, and send the email
message.append("<p>" + pageMessages.getString("html_email_body_5") + "</P><P>" + pageMessages.getString("email_footer"));
try {
mailSender.sendEmail(alertEmail.trim(), pageMessages.getString("job_ran_for") + " " + datasetBean.getName(), message.toString(), true);
} catch (OpenClinicaSystemException ose) {
// Do Nothing, In the future we might want to have an email
// status added to system.
}
TriggerBean triggerBean = new TriggerBean();
triggerBean.setDataset(datasetBean);
triggerBean.setUserAccount(userBean);
triggerBean.setFullName(trigger.getName());
auditEventDAO.createRowForExtractDataJobSuccess(triggerBean, auditMessage.toString());
} else {
TriggerBean triggerBean = new TriggerBean();
// triggerBean.setDataset(datasetBean);
triggerBean.setUserAccount(userBean);
triggerBean.setFullName(trigger.getName());
auditEventDAO.createRowForExtractDataJobFailure(triggerBean);
// logger.debug("-- made it here for some reason, ds id: "
// + dsId);
}
// logger.debug("-- generated file: " + fileNameStr);
// dataSource.
} catch (Exception e) {
// TODO Auto-generated catch block -- ideally should generate a fail
// msg here, tbh 02/2009
logger.debug("-- found exception: " + e.getMessage());
e.printStackTrace();
}
}
use of org.akaza.openclinica.service.extract.GenerateExtractFileService in project OpenClinica by OpenClinica.
the class ExportDatasetServlet method processRequest.
@Override
public void processRequest() throws Exception {
DatasetDAO dsdao = new DatasetDAO(sm.getDataSource());
ArchivedDatasetFileDAO asdfdao = new ArchivedDatasetFileDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
GenerateExtractFileService generateFileService = new GenerateExtractFileService(sm.getDataSource(), (CoreResources) SpringServletAccess.getApplicationContext(context).getBean("coreResources"), (RuleSetRuleDao) SpringServletAccess.getApplicationContext(context).getBean("ruleSetRuleDao"));
String action = fp.getString("action");
int datasetId = fp.getInt("datasetId");
int adfId = fp.getInt("adfId");
if (datasetId == 0) {
try {
DatasetBean dsb = (DatasetBean) session.getAttribute("newDataset");
datasetId = dsb.getId();
logger.info("dataset id was zero, trying session: " + datasetId);
} catch (NullPointerException e) {
e.printStackTrace();
logger.info("tripped over null pointer exception");
}
}
DatasetBean db = (DatasetBean) dsdao.findByPK(datasetId);
StudyDAO sdao = new StudyDAO(sm.getDataSource());
StudyBean study = (StudyBean) sdao.findByPK(db.getStudyId());
checkRoleByUserAndStudy(ub, study.getParentStudyId(), study.getId());
// Checks if the study is current study or child of current study
if (study.getId() != currentStudy.getId() && study.getParentStudyId() != currentStudy.getId()) {
addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
forwardPage(Page.MENU_SERVLET);
return;
}
/**
* @vbc 08/06/2008 NEW EXTRACT DATA IMPLEMENTATION get study_id and
* parentstudy_id int currentstudyid = currentStudy.getId(); int
* parentstudy = currentStudy.getParentStudyId(); if (parentstudy >
* 0) { // is OK } else { // same parentstudy = currentstudyid; } //
*/
int currentstudyid = currentStudy.getId();
// YW 11-09-2008 << modified logic here.
int parentstudy = currentstudyid;
// YW 11-09-2008 >>
StudyBean parentStudy = new StudyBean();
if (currentStudy.getParentStudyId() > 0) {
// StudyDAO sdao = new StudyDAO(sm.getDataSource());
parentStudy = (StudyBean) sdao.findByPK(currentStudy.getParentStudyId());
}
ExtractBean eb = generateFileService.generateExtractBean(db, currentStudy, parentStudy);
if (StringUtil.isBlank(action)) {
loadList(db, asdfdao, datasetId, fp, eb);
forwardPage(Page.EXPORT_DATASETS);
} else if ("delete".equalsIgnoreCase(action) && adfId > 0) {
boolean success = false;
ArchivedDatasetFileBean adfBean = (ArchivedDatasetFileBean) asdfdao.findByPK(adfId);
File file = new File(adfBean.getFileReference());
if (!file.canWrite()) {
addPageMessage(respage.getString("write_protected"));
} else {
success = file.delete();
if (success) {
asdfdao.deleteArchiveDataset(adfBean);
addPageMessage(respage.getString("file_removed"));
} else {
addPageMessage(respage.getString("error_removing_file"));
}
}
loadList(db, asdfdao, datasetId, fp, eb);
forwardPage(Page.EXPORT_DATASETS);
} else {
logger.info("**** found action ****: " + action);
String generateReport = "";
// generate file, and show screen export
// String generalFileDir = DATASET_DIR + db.getId() +
// File.separator;
// change this up, so that we don't overwrite anything
String pattern = "yyyy" + File.separator + "MM" + File.separator + "dd" + File.separator + "HHmmssSSS" + File.separator;
SimpleDateFormat sdfDir = new SimpleDateFormat(pattern);
String generalFileDir = DATASET_DIR + db.getId() + File.separator + sdfDir.format(new java.util.Date());
String fileName = "";
db.setName(db.getName().replaceAll(" ", "_"));
Page finalTarget = Page.GENERATE_DATASET;
finalTarget = Page.EXPORT_DATA_CUSTOM;
// now display report according to format specified
// TODO revise final target to set to fileReference????
long sysTimeBegin = System.currentTimeMillis();
int fId = 0;
if ("sas".equalsIgnoreCase(action)) {
// generateReport =
// dsdao.generateDataset(db,
// ExtractBean.SAS_FORMAT,
// currentStudy,
// parentStudy);
long sysTimeEnd = System.currentTimeMillis() - sysTimeBegin;
String SASFileName = db.getName() + "_sas.sas";
// logger.info("found data set: "+generateReport);
generateFileService.createFile(SASFileName, generalFileDir, generateReport, db, sysTimeEnd, ExportFormatBean.TXTFILE, true, ub);
logger.info("created sas file");
request.setAttribute("generate", generalFileDir + SASFileName);
finalTarget.setFileName(generalFileDir + SASFileName);
fileName = SASFileName;
// won't work since page creator is private
} else if ("odm".equalsIgnoreCase(action)) {
String odmVersion = fp.getString("odmVersion");
String ODMXMLFileName = "";
// DRY
// HashMap answerMap = generateFileService.createODMFile(odmVersion, sysTimeBegin, generalFileDir, db, this.currentStudy, "");
HashMap answerMap = generateFileService.createODMFile(odmVersion, sysTimeBegin, generalFileDir, db, this.currentStudy, "", eb, currentStudy.getId(), currentStudy.getParentStudyId(), "99", true, true, true, null, ub);
for (Iterator it = answerMap.entrySet().iterator(); it.hasNext(); ) {
java.util.Map.Entry entry = (java.util.Map.Entry) it.next();
Object key = entry.getKey();
Object value = entry.getValue();
ODMXMLFileName = (String) key;
Integer fileID = (Integer) value;
fId = fileID.intValue();
}
fileName = ODMXMLFileName;
request.setAttribute("generate", generalFileDir + ODMXMLFileName);
logger.debug("+++ set the following: " + generalFileDir + ODMXMLFileName);
// send a link with the SQL file? put the generated SQL file with the dataset?
if (fp.getString("xalan") != null) {
XalanTriggerService xts = new XalanTriggerService();
String propertiesPath = SQLInitServlet.getField("filePath");
// the trick there, we need to open up the zipped file and get at the XML
openZipFile(generalFileDir + ODMXMLFileName + ".zip");
// need to find out how to copy this xml file from /bin to the generalFileDir
SimpleTrigger simpleTrigger = xts.generateXalanTrigger(propertiesPath + File.separator + "ODMReportStylesheet.xsl", ODMXMLFileName, generalFileDir + "output.sql", db.getId());
scheduler = getScheduler();
JobDetailBean jobDetailBean = new JobDetailBean();
jobDetailBean.setGroup(xts.TRIGGER_GROUP_NAME);
jobDetailBean.setName(simpleTrigger.getName());
jobDetailBean.setJobClass(org.akaza.openclinica.web.job.XalanStatefulJob.class);
jobDetailBean.setJobDataMap(simpleTrigger.getJobDataMap());
// need durability?
jobDetailBean.setDurability(true);
jobDetailBean.setVolatility(false);
try {
Date dateStart = scheduler.scheduleJob(jobDetailBean, simpleTrigger);
logger.info("== found job date: " + dateStart.toString());
} catch (SchedulerException se) {
se.printStackTrace();
}
}
} else if ("txt".equalsIgnoreCase(action)) {
// generateReport =
// dsdao.generateDataset(db,
// ExtractBean.TXT_FORMAT,
// currentStudy,
// parentStudy);
// eb = dsdao.getDatasetData(eb, currentstudyid, parentstudy);
String TXTFileName = "";
HashMap answerMap = generateFileService.createTabFile(eb, sysTimeBegin, generalFileDir, db, currentstudyid, parentstudy, "", ub);
// and of course DRY
for (Iterator it = answerMap.entrySet().iterator(); it.hasNext(); ) {
java.util.Map.Entry entry = (java.util.Map.Entry) it.next();
Object key = entry.getKey();
Object value = entry.getValue();
TXTFileName = (String) key;
Integer fileID = (Integer) value;
fId = fileID.intValue();
}
fileName = TXTFileName;
request.setAttribute("generate", generalFileDir + TXTFileName);
// finalTarget.setFileName(generalFileDir+TXTFileName);
logger.debug("+++ set the following: " + generalFileDir + TXTFileName);
} else if ("html".equalsIgnoreCase(action)) {
// html based dataset browser
TabReportBean answer = new TabReportBean();
eb = dsdao.getDatasetData(eb, currentstudyid, parentstudy);
eb.getMetadata();
eb.computeReport(answer);
request.setAttribute("dataset", db);
request.setAttribute("extractBean", eb);
finalTarget = Page.GENERATE_DATASET_HTML;
} else if ("spss".equalsIgnoreCase(action)) {
SPSSReportBean answer = new SPSSReportBean();
// removed three lines here and put them in generate file
// service, createSPSSFile method. tbh 01/2009
eb = dsdao.getDatasetData(eb, currentstudyid, parentstudy);
eb.getMetadata();
eb.computeReport(answer);
// System.out.println("*** isShowCRFversion:
// "+db.isShowCRFversion());
// TODO in the spirit of DRY, if this works we need to remove
// lines 443-776 in this servlet, tbh 01/2009
String DDLFileName = "";
HashMap answerMap = generateFileService.createSPSSFile(db, eb, currentStudy, parentStudy, sysTimeBegin, generalFileDir, answer, "", ub);
// hmm, DRY?
for (Iterator it = answerMap.entrySet().iterator(); it.hasNext(); ) {
java.util.Map.Entry entry = (java.util.Map.Entry) it.next();
Object key = entry.getKey();
Object value = entry.getValue();
DDLFileName = (String) key;
Integer fileID = (Integer) value;
fId = fileID.intValue();
}
request.setAttribute("generate", generalFileDir + DDLFileName);
logger.debug("+++ set the following: " + generalFileDir + DDLFileName);
} else if ("csv".equalsIgnoreCase(action)) {
CommaReportBean answer = new CommaReportBean();
eb = dsdao.getDatasetData(eb, currentstudyid, parentstudy);
eb.getMetadata();
eb.computeReport(answer);
long sysTimeEnd = System.currentTimeMillis() - sysTimeBegin;
// logger.info("found data set: "+generateReport);
String CSVFileName = db.getName() + "_comma.txt";
fId = generateFileService.createFile(CSVFileName, generalFileDir, answer.toString(), db, sysTimeEnd, ExportFormatBean.CSVFILE, true, ub);
fileName = CSVFileName;
logger.info("just created csv file");
request.setAttribute("generate", generalFileDir + CSVFileName);
// finalTarget.setFileName(generalFileDir+CSVFileName);
} else if ("excel".equalsIgnoreCase(action)) {
// HSSFWorkbook excelReport = dsdao.generateExcelDataset(db,
// ExtractBean.XLS_FORMAT,
// currentStudy,
// parentStudy);
long sysTimeEnd = System.currentTimeMillis() - sysTimeBegin;
// TODO this will change and point to a created excel
// spreadsheet, tbh
String excelFileName = db.getName() + "_excel.xls";
// fId = this.createFile(excelFileName,
// generalFileDir,
// excelReport,
// db, sysTimeEnd,
// ExportFormatBean.EXCELFILE);
// logger.info("just created csv file, for excel output");
// response.setHeader("Content-disposition","attachment;
// filename="+CSVFileName);
// logger.info("csv file name: "+CSVFileName);
finalTarget = Page.GENERATE_EXCEL_DATASET;
// response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=" + db.getName() + "_excel.xls");
request.setAttribute("generate", generalFileDir + excelFileName);
logger.info("set 'generate' to :" + generalFileDir + excelFileName);
fileName = excelFileName;
// excelReport.write(stream);
// stream.flush();
// stream.close();
// finalTarget.setFileName(WEB_DIR+db.getId()+"/"+excelFileName);
}
// <%@page contentType="application/vnd.ms-excel"%>
if (!finalTarget.equals(Page.GENERATE_EXCEL_DATASET) && !finalTarget.equals(Page.GENERATE_DATASET_HTML)) {
// to catch all the others and try to set a new path for file
// capture
// tbh, 4-18-05
// request.setAttribute("generate",finalTarget.getFileName());
// TODO changing path to show refresh page, then window with
// link to download file, tbh 06-08-05
// finalTarget.setFileName(
// "/WEB-INF/jsp/extract/generatedFileDataset.jsp");
finalTarget.setFileName("" + "/WEB-INF/jsp/extract/generateMetadataCore.jsp");
// also set up table here???
asdfdao = new ArchivedDatasetFileDAO(sm.getDataSource());
ArchivedDatasetFileBean asdfBean = (ArchivedDatasetFileBean) asdfdao.findByPK(fId);
// *** do we need this below? tbh
ArrayList newFileList = new ArrayList();
newFileList.add(asdfBean);
// request.setAttribute("filelist",newFileList);
ArrayList filterRows = ArchivedDatasetFileRow.generateRowsFromBeans(newFileList);
EntityBeanTable table = fp.getEntityBeanTable();
// sort by date
table.setSortingIfNotExplicitlySet(3, false);
String[] columns = { resword.getString("file_name"), resword.getString("run_time"), resword.getString("file_size"), resword.getString("created_date"), resword.getString("created_by") };
table.setColumns(new ArrayList(Arrays.asList(columns)));
table.hideColumnLink(0);
table.hideColumnLink(1);
table.hideColumnLink(2);
table.hideColumnLink(3);
table.hideColumnLink(4);
// table.setQuery("ExportDataset?datasetId=" +db.getId(), new
// HashMap());
// trying to continue...
// session.setAttribute("newDataset",db);
request.setAttribute("dataset", db);
request.setAttribute("file", asdfBean);
table.setRows(filterRows);
table.computeDisplay();
request.setAttribute("table", table);
// *** do we need this above? tbh
}
logger.info("set first part of 'generate' to :" + generalFileDir);
logger.info("found file name: " + finalTarget.getFileName());
// String del = CoreResources.getField("dataset_file_delete");
// if (del.equalsIgnoreCase("true") || del.equals("")) {
// File deleteFile = new File(generalFileDir + fileName);
// deleteFile.delete();
// }
forwardPage(finalTarget);
}
}
Aggregations