Search in sources :

Example 11 with ArchivedDatasetFileBean

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

the class ArchivedDatasetFileDAO method getEntityFromHashMap.

public Object getEntityFromHashMap(HashMap hm) {
    ArchivedDatasetFileBean fb = new ArchivedDatasetFileBean();
    fb.setId(((Integer) hm.get("archived_dataset_file_id")).intValue());
    fb.setDateCreated((Date) hm.get("date_created"));
    fb.setName((String) hm.get("name"));
    fb.setId(((Integer) hm.get("archived_dataset_file_id")).intValue());
    fb.setDatasetId(((Integer) hm.get("dataset_id")).intValue());
    fb.setExportFormatId(((Integer) hm.get("export_format_id")).intValue());
    fb.setFileReference((String) hm.get("file_reference"));
    fb.setRunTime(((Integer) hm.get("run_time")).doubleValue());
    fb.setFileSize(((Integer) hm.get("file_size")).intValue());
    fb.setOwnerId(((Integer) hm.get("owner_id")).intValue());
    UserAccountDAO uaDAO = new UserAccountDAO(this.ds);
    UserAccountBean owner = (UserAccountBean) uaDAO.findByPK(fb.getOwnerId());
    fb.setOwner(owner);
    return fb;
}
Also used : UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) ArchivedDatasetFileBean(org.akaza.openclinica.bean.extract.ArchivedDatasetFileBean)

Example 12 with ArchivedDatasetFileBean

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

the class CoreSecureController method decodeLINKURL.

private String decodeLINKURL(String successMsg, Integer datasetId) {
    ArchivedDatasetFileDAO asdfDAO = new ArchivedDatasetFileDAO(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)

Example 13 with ArchivedDatasetFileBean

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

the class ArchivedDatasetFileDAO method findByPK.

public EntityBean findByPK(int ID) {
    ArchivedDatasetFileBean fb = new ArchivedDatasetFileBean();
    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()) {
        fb = (ArchivedDatasetFileBean) this.getEntityFromHashMap((HashMap) it.next());
    }
    return fb;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArchivedDatasetFileBean(org.akaza.openclinica.bean.extract.ArchivedDatasetFileBean)

Example 14 with ArchivedDatasetFileBean

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

the class ArchivedDatasetFileDAO method findByDatasetIdByDate.

public ArrayList findByDatasetIdByDate(int did) {
    // ArchivedDatasetFileBean fb = new ArchivedDatasetFileBean();
    this.setTypesExpected();
    ArrayList al = new ArrayList();
    HashMap variables = new HashMap();
    variables.put(Integer.valueOf(1), Integer.valueOf(did));
    String sql = digester.getQuery("findByDatasetIdByDate");
    ArrayList alist = this.select(sql, variables);
    Iterator it = alist.iterator();
    while (it.hasNext()) {
        ArchivedDatasetFileBean fb = (ArchivedDatasetFileBean) this.getEntityFromHashMap((HashMap) it.next());
        al.add(fb);
    }
    return al;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArchivedDatasetFileBean(org.akaza.openclinica.bean.extract.ArchivedDatasetFileBean)

Example 15 with ArchivedDatasetFileBean

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

the class GenerateExtractFileService method createFile.

public int createFile(String zipName, ArrayList names, String dir, ArrayList contents, DatasetBean datasetBean, long time, ExportFormatBean efb, boolean saveToDB, UserAccountBean userBean) {
    ArchivedDatasetFileBean fbFinal = new ArchivedDatasetFileBean();
    // >> tbh #4915
    zipName = zipName.replaceAll(" ", "_");
    fbFinal.setId(0);
    BufferedWriter w = null;
    try {
        File complete = new File(dir);
        if (!complete.isDirectory()) {
            complete.mkdirs();
        }
        int totalSize = 0;
        ZipOutputStream z = new ZipOutputStream(new FileOutputStream(new File(complete, zipName + ".zip")));
        FileInputStream is = null;
        for (int i = 0; i < names.size(); i++) {
            String name = (String) names.get(i);
            // >> tbh #4915
            name = name.replaceAll(" ", "_");
            String content = (String) contents.get(i);
            File newFile = new File(complete, name);
            // totalSize = totalSize + (int)newFile.length();
            newFile.setLastModified(System.currentTimeMillis());
            w = new BufferedWriter(new FileWriter(newFile));
            w.write(content);
            w.close();
            logger.info("finished writing the text file...");
            // now, we write the file to the zip file
            is = new FileInputStream(newFile);
            logger.info("created zip output stream...");
            z.putNextEntry(new java.util.zip.ZipEntry(name));
            int bytesRead;
            byte[] buff = new byte[512];
            while ((bytesRead = is.read(buff)) != -1) {
                z.write(buff, 0, bytesRead);
                totalSize += 512;
            }
            z.closeEntry();
            //A. Hamid. 4910
            is.close();
            if (CoreResources.getField("dataset_file_delete").equalsIgnoreCase("true") || CoreResources.getField("dataset_file_delete").equals("")) {
                newFile.delete();
            }
        }
        logger.info("writing buffer...");
        // }
        z.flush();
        z.finish();
        z.close();
        if (is != null) {
            try {
                is.close();
            } catch (java.io.IOException ie) {
                ie.printStackTrace();
            }
        }
        logger.info("finished zipping up file...");
        // set up the zip to go into the database
        if (saveToDB) {
            ArchivedDatasetFileBean fb = new ArchivedDatasetFileBean();
            fb.setName(zipName + ".zip");
            fb.setFileReference(dir + zipName + ".zip");
            // current location of the file on the system
            fb.setFileSize(totalSize);
            // set the above to compressed size?
            fb.setRunTime((int) time);
            // need to set this in milliseconds, get it passed from above
            // methods?
            fb.setDatasetId(datasetBean.getId());
            fb.setExportFormatBean(efb);
            fb.setExportFormatId(efb.getId());
            fb.setOwner(userBean);
            fb.setOwnerId(userBean.getId());
            fb.setDateCreated(new Date(System.currentTimeMillis()));
            boolean write = true;
            ArchivedDatasetFileDAO asdfDAO = new ArchivedDatasetFileDAO(ds);
            if (write) {
                fbFinal = (ArchivedDatasetFileBean) asdfDAO.create(fb);
                logger.info("Created ADSFile!: " + fbFinal.getId() + " for " + zipName + ".zip");
            } else {
                logger.info("duplicate found: " + fb.getName());
            }
        }
    // created in database!
    } catch (Exception e) {
        logger.warn(e.getMessage());
        e.printStackTrace();
    } finally {
        if (w != null)
            try {
                w.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    }
    return fbFinal.getId();
}
Also used : ArchivedDatasetFileDAO(org.akaza.openclinica.dao.extract.ArchivedDatasetFileDAO) FileWriter(java.io.FileWriter) IOException(java.io.IOException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Date(java.util.Date) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) 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