Esempio n. 1
0
  private List<String> getInvestigationNameFromExcel(File excelFile) throws Exception {

    File tmpInvestigation =
        new File(System.getProperty("java.io.tmpdir") + File.separator + "tmpInvestigation.txt");
    if (tmpInvestigation.exists()) {
      boolean deleteSuccess = tmpInvestigation.delete();
      if (!deleteSuccess) {
        throw new Exception("Deletion of tmp file 'tmpInvestigation.txt' failed, cannot proceed.");
      }
    }
    boolean createSuccess = tmpInvestigation.createNewFile();
    if (!createSuccess) {
      throw new Exception("Creation of tmp file 'tmpInvestigation.txt' failed, cannot proceed.");
    }

    Workbook workbook = Workbook.getWorkbook(excelFile);
    for (Sheet sheet : workbook.getSheets()) {
      if (sheet.getName().toLowerCase().equals("investigation")) {
        writeSheetToFile(sheet, tmpInvestigation);
      }
    }

    List<String> names = XgapCommonImport.getInvestigationNameFromFile(tmpInvestigation);

    return names;
  }
Esempio n. 2
0
  public XgapExcelImport(File extractDir, Database db, boolean skipWhenDestExists)
      throws Exception {

    File excelFile = null;
    File dataDir = null;

    // at this point we are sure that:
    // 1) extractDir has 1 or 2 file objects
    // 2) one of these ends with '.xls'
    // 3) if two: one of these is called 'data'

    for (File f : extractDir.listFiles()) {
      if (f.getName().endsWith(".xls")) {
        excelFile = f;
      }
      if (f.getName().equals("data")) {
        // FIXME: test on all OS. Does this fix another Windows File
        // bug? does it break on other OS'es?
        dataDir = new File(f.getAbsolutePath());
      }
    }

    db.beginTx();

    try {
      ExcelImport.importAll(excelFile, db, new SimpleTuple(), false);

      if (dataDir != null) {
        List<String> investigationNames = getInvestigationNameFromExcel(excelFile);
        XgapCommonImport.importMatrices(investigationNames, db, false, dataDir, skipWhenDestExists);
      }

      db.commitTx();
    } catch (Exception e) {
      db.rollbackTx();
      throw (e);
    }
  }