コード例 #1
0
  @Override
  public void handleEvent(Event event) {
    Vector<File> rawFiles = ((ClinicalData) this.dataType).getRawFiles();
    Vector<String> siteIds = this.setOtherIdsUI.getSiteIds();
    Vector<String> visitNames = this.setOtherIdsUI.getVisitNames();

    // write in a new file
    File file =
        new File(
            this.dataType.getPath().toString()
                + File.separator
                + this.dataType.getStudy().toString()
                + ".columns.tmp");
    try {
      FileWriter fw = new FileWriter(file);
      BufferedWriter out = new BufferedWriter(fw);
      out.write(
          "Filename\tCategory Code\tColumn Number\tData Label\tData Label Source\tControlled Vocab Code\n");

      for (int i = 0; i < rawFiles.size(); i++) {

        // site identifier
        if (siteIds.elementAt(i).compareTo("") != 0) {
          int columnNumber =
              FileHandler.getHeaderNumber(rawFiles.elementAt(i), siteIds.elementAt(i));
          if (columnNumber != -1) {
            out.write(rawFiles.elementAt(i).getName() + "\t\t" + columnNumber + "\tSITE_ID\t\t\n");
          }
        }

        // visit name
        if (visitNames.elementAt(i).compareTo("") != 0) {
          int columnNumber =
              FileHandler.getHeaderNumber(rawFiles.elementAt(i), visitNames.elementAt(i));
          if (columnNumber != -1) {
            out.write(
                rawFiles.elementAt(i).getName() + "\t\t" + columnNumber + "\tVISIT_NAME\t\t\n");
          }
        }
      }
      // add lines from existing CMF
      try {
        BufferedReader br =
            new BufferedReader(new FileReader(((ClinicalData) this.dataType).getCMF()));
        String line = br.readLine();
        while ((line = br.readLine()) != null) {
          String[] s = line.split("\t", -1);
          if (s[3].compareTo("SITE_ID") != 0 && s[3].compareTo("VISIT_NAME") != 0) {
            out.write(line + "\n");
          }
        }
        br.close();
      } catch (Exception e) {
        this.setOtherIdsUI.displayMessage("Error: " + e.getLocalizedMessage());
        e.printStackTrace();
        out.close();
      }
      out.close();
      try {
        String fileName = ((ClinicalData) this.dataType).getCMF().getName();
        ((ClinicalData) this.dataType).getCMF().delete();
        File fileDest = new File(this.dataType.getPath() + File.separator + fileName);
        FileUtils.moveFile(file, fileDest);
        ((ClinicalData) this.dataType).setCMF(fileDest);
      } catch (IOException ioe) {
        this.setOtherIdsUI.displayMessage("File error: " + ioe.getLocalizedMessage());
        return;
      }

    } catch (Exception e) {
      this.setOtherIdsUI.displayMessage("Error: " + e.getLocalizedMessage());
      e.printStackTrace();
    }
    this.setOtherIdsUI.displayMessage("Column mapping file updated");
    WorkPart.updateSteps();
    WorkPart.updateFiles();
    UsedFilesPart.sendFilesChanged(dataType);
  }
コード例 #2
0
  @Override
  public void handleEvent(Event event) {
    this.selectRawFilesUI.openLoadingShell();
    new Thread() {
      public void run() {
        String[] paths = selectRawFilesUI.getPath().split(File.pathSeparator, -1);
        for (int i = 0; i < paths.length; i++) {
          String path = paths[i];
          if (path == null) {
            selectRawFilesUI.setIsLoading(false);
            return;
          }
          File rawFile = new File(path);
          if (rawFile.exists()) {
            if (rawFile.isFile()) {
              if (path.contains("%")) {
                selectRawFilesUI.setMessage("File name can not contain percent ('%') symbol.");
                selectRawFilesUI.setIsLoading(false);
                return;
              }
              String newPath =
                  dataType.getPath().getAbsolutePath() + File.separator + rawFile.getName();
              if (selectRawFilesUI.getFormat().compareTo("Tab delimited raw file") != 0
                  && selectRawFilesUI.getFormat().compareTo("SOFT") != 0) {
                selectRawFilesUI.setMessage("File format does not exist");
                selectRawFilesUI.setIsLoading(false);
                return;
              }
              if (selectRawFilesUI.getFormat().compareTo("SOFT") == 0) {
                File newFile = new File(newPath);
                if (newFile.exists()) {
                  selectRawFilesUI.setMessage("File has already been added");
                  selectRawFilesUI.setIsLoading(false);
                  return;
                } else {
                  if (createTabFileFromSoft(rawFile, newFile)) {
                    ((ClinicalData) dataType).addRawFile(newFile);
                    selectRawFilesUI.setMessage("File has been added");
                  }
                }
              } else if (selectRawFilesUI.getFormat().compareTo("Tab delimited raw file") == 0) {
                if (!checkTabFormat(rawFile)) {
                  selectRawFilesUI.setIsLoading(false);
                  return;
                }

                File copiedRawFile = new File(newPath);
                if (!copiedRawFile.exists()) {
                  try {
                    FileUtils.copyFile(rawFile, copiedRawFile);
                    ((ClinicalData) dataType).addRawFile(copiedRawFile);
                    selectRawFilesUI.setMessage("File has been added");
                  } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    selectRawFilesUI.setMessage("File error: " + e.getLocalizedMessage());
                    selectRawFilesUI.setIsLoading(false);
                    return;
                  }
                } else {
                  selectRawFilesUI.setMessage("File has already been added");
                  selectRawFilesUI.setIsLoading(false);
                  return;
                }
              }

            } else {
              selectRawFilesUI.setMessage("File is a directory");
              selectRawFilesUI.setIsLoading(false);
              return;
            }
          } else {
            selectRawFilesUI.setMessage("Path does no exist");
            selectRawFilesUI.setIsLoading(false);
            return;
          }
        }
        selectRawFilesUI.setIsLoading(false);
      }
    }.start();
    this.selectRawFilesUI.waitForThread();
    selectRawFilesUI.updateViewer();
    WorkPart.updateSteps();
    UsedFilesPart.sendFilesChanged(dataType);
  }