Search in sources :

Example 21 with ArchivedDatasetFileBean

use of org.akaza.openclinica.bean.extract.ArchivedDatasetFileBean in project OpenClinica by OpenClinica.

the class AccessFileServlet method processRequest.

@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    int fileId = fp.getInt("fileId");
    ArchivedDatasetFileDAO asdfdao = new ArchivedDatasetFileDAO(sm.getDataSource());
    DatasetDAO dsDao = new DatasetDAO(sm.getDataSource());
    ArchivedDatasetFileBean asdfBean = (ArchivedDatasetFileBean) asdfdao.findByPK(fileId);
    StudyDAO studyDao = new StudyDAO(sm.getDataSource());
    DatasetBean dsBean = (DatasetBean) dsDao.findByPK(asdfBean.getDatasetId());
    int parentId = currentStudy.getParentStudyId();
    if (//Logged in at study level
    parentId == 0) {
        StudyBean studyBean = (StudyBean) studyDao.findByPK(dsBean.getStudyId());
        //parent id of dataset created
        parentId = studyBean.getParentStudyId();
    }
    //logic: is parentId of the dataset created not equal to currentstudy? or is current study
    if (parentId != currentStudy.getId())
        if (dsBean.getStudyId() != currentStudy.getId()) {
            addPageMessage(respage.getString("no_have_correct_privilege_current_study") + respage.getString("change_study_contact_sysadmin"));
            // TODO
            throw new InsufficientPermissionException(Page.MENU_SERVLET, resexception.getString("not_allowed_access_extract_data_servlet"), "1");
        }
    // asdfBean.setWebPath(WEB_DIR+
    // asdfBean.getDatasetId()+
    // "/"+
    // asdfBean.getName());
    Page finalTarget = Page.EXPORT_DATA_CUSTOM;
    /*
         * if (asdfBean.getExportFormatId() ==
         * ExportFormatBean.EXCELFILE.getId()) { //
         * response.setContentType("application/octet-stream");
         * response.setHeader("Content-Disposition", "attachment; filename=" +
         * asdfBean.getName()); logger.info("found file name: "+
         * finalTarget.getFileName()); //
         * finalTarget.setFileName(asdfBean.getWebPath()); finalTarget =
         * Page.GENERATE_EXCEL_DATASET; } else {
         */
    logger.debug("found file reference: " + asdfBean.getFileReference() + " and file name: " + asdfBean.getName());
    if (asdfBean.getFileReference().endsWith(".zip")) {
        response.setHeader("Content-disposition", "attachment; filename=\"" + asdfBean.getName() + "\";");
        response.setContentType("application/zip");
    // response.setContentType("application/download");
    } else if (asdfBean.getFileReference().endsWith(".pdf")) {
        response.setHeader("Content-disposition", "attachment; filename=\"" + asdfBean.getName() + "\";");
        response.setContentType("application/pdf");
    // response.setContentType("application/download; application/pdf");
    } else if (asdfBean.getFileReference().endsWith(".csv")) {
        response.setHeader("Content-disposition", "attachment; filename=\"" + asdfBean.getName() + "\";");
        response.setContentType("text/csv");
    // response.setContentType("application/download; text/csv");
    } else if (asdfBean.getFileReference().endsWith(".xml")) {
        response.setHeader("Content-disposition", "attachment; filename=\"" + asdfBean.getName() + "\";");
        response.setContentType("text/xml");
    // response.setContentType("application/download; text/xml");
    } else if (asdfBean.getFileReference().endsWith(".html")) {
        response.setHeader("Content-disposition", "filename=\"" + asdfBean.getName() + "\";");
        response.setContentType("text/html; charset=utf-8");
    } else {
    // response.setContentType("text/plain");
    // to ensure backwards compatability to text files shown on server
    // not needed anymore? tbh 10/2010
    }
    finalTarget.setFileName("/WEB-INF/jsp/extract/generatedFileDataset.jsp");
    // }
    // finalTarget.setFileName(asdfBean.getWebPath());
    request.setAttribute("generate", asdfBean.getFileReference());
    response.setHeader("Pragma", "public");
    forwardPage(finalTarget);
}
Also used : ArchivedDatasetFileDAO(org.akaza.openclinica.dao.extract.ArchivedDatasetFileDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) DatasetBean(org.akaza.openclinica.bean.extract.DatasetBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) InsufficientPermissionException(org.akaza.openclinica.web.InsufficientPermissionException) Page(org.akaza.openclinica.view.Page) DatasetDAO(org.akaza.openclinica.dao.extract.DatasetDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) ArchivedDatasetFileBean(org.akaza.openclinica.bean.extract.ArchivedDatasetFileBean)

Example 22 with ArchivedDatasetFileBean

use of org.akaza.openclinica.bean.extract.ArchivedDatasetFileBean in project OpenClinica by OpenClinica.

the class SecureController method decodeLINKURL.

private String decodeLINKURL(String successMsg, Integer datasetId) {
    ArchivedDatasetFileDAO asdfDAO = new ArchivedDatasetFileDAO(sm.getDataSource());
    ArrayList<ArchivedDatasetFileBean> fileBeans = asdfDAO.findByDatasetId(datasetId);
    successMsg = successMsg.replace("$linkURL", "<a href=\"" + CoreResources.getField("sysURL.base") + "AccessFile?fileId=" + fileBeans.get(0).getId() + "\">here </a>");
    return successMsg;
}
Also used : ArchivedDatasetFileDAO(org.akaza.openclinica.dao.extract.ArchivedDatasetFileDAO) ArchivedDatasetFileBean(org.akaza.openclinica.bean.extract.ArchivedDatasetFileBean)

Aggregations

ArchivedDatasetFileBean (org.akaza.openclinica.bean.extract.ArchivedDatasetFileBean)22 ArchivedDatasetFileDAO (org.akaza.openclinica.dao.extract.ArchivedDatasetFileDAO)9 File (java.io.File)8 HashMap (java.util.HashMap)8 ArrayList (java.util.ArrayList)7 Date (java.util.Date)7 Iterator (java.util.Iterator)6 IOException (java.io.IOException)5 BufferedWriter (java.io.BufferedWriter)4 FileWriter (java.io.FileWriter)4 DatasetBean (org.akaza.openclinica.bean.extract.DatasetBean)4 FileInputStream (java.io.FileInputStream)3 FileOutputStream (java.io.FileOutputStream)3 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)3 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)3 ZipEntry (java.util.zip.ZipEntry)2 ZipFile (java.util.zip.ZipFile)2 ZipOutputStream (java.util.zip.ZipOutputStream)2 ExtractBean (org.akaza.openclinica.bean.extract.ExtractBean)2 TabReportBean (org.akaza.openclinica.bean.extract.TabReportBean)2