Beispiel #1
0
  public boolean check() {
    Errors.logDebug("CheckVariables started");
    boolean res = false;
    DbImportFile dbInFile = new DbImportFile();
    String fullFileName = "";
    String checkFileName = "";
    String errMessage = null;

    try {
      // Create the variable
      DbVariable dbVariable = new DbVariable();

      dbInFile.setStatus(conn_viss, ifid, "0%");

      // Store the file on server filesystem
      fullFileName = dbInFile.storeImportFileBLOB(conn_viss, ifid);
      checkFileName = fullFileName + "_checked";

      FileHeader header = FileParser.scanFileHeader(fullFileName);
      String type = header.formatTypeName().toUpperCase();
      char delimiter = header.delimiter().charValue();

      FileParser fileParser = new FileParser(fullFileName);
      fileParser.Parse(
          FileTypeDefinitionList.matchingDefinitions(
              FileTypeDefinition.VARIABLE, FileTypeDefinition.LIST));

      // Write out the result to a new file
      FileWriter fileOut = new FileWriter(checkFileName);
      fileOut.write(
          header.objectTypeName()
              + "/"
              + header.formatTypeName()
              + "/"
              + header.version()
              + "/"
              + header.delimiter()
              + "\n");

      String titles[] = fileParser.columnTitles();
      for (int j = 0; j < titles.length; j++) {
        fileOut.write(titles[j] + delimiter);
      }
      fileOut.write("\n");

      String errorMsg = "";
      errorMsg = checkList(fileParser, fileOut, delimiter);
      fileOut.close();

      /*
       * Save the file to database
       */
      dbInFile.saveCheckedFile(conn_viss, ifid, checkFileName);

      if (errorMsg.startsWith("ERROR:")) {
        res = false;
        dbInFile.setStatus(conn_viss, ifid, "ERROR");

        // Add a message to the log
        dbInFile.addErrMsg(
            conn_viss,
            ifid,
            "File checked failed for sampling unit "
                + DbSamplingUnit.getSUName(conn_viss, Integer.toString(sampleUnitId))
                + ". <br>"
                + errorMsg);
        Errors.logDebug("ErrorMsg=" + errorMsg);
      } else if (errorMsg.startsWith("WARNING:")) {
        dbInFile.setStatus(conn_viss, ifid, "WARNING");
        res = true;

        // Add a message to the log
        dbInFile.addErrMsg(conn_viss, ifid, "Warnings exists: " + errorMsg);
      } else {
        dbInFile.setStatus(conn_viss, ifid, "CHECKED");
        res = true;

        // Add a message to the log
        dbInFile.addErrMsg(
            conn_viss,
            ifid,
            "File checked for sampling unit "
                + DbSamplingUnit.getSUName(conn_viss, Integer.toString(sampleUnitId))
                + ".<br>"
                + errorMsg);
      }

      /*
      if (errorMsg.length()>0)
      {
          res = false;
          dbInFile.setStatus(conn_viss,ifid,"ERROR");
          // Add a message to the log
          dbInFile.addErrMsg(conn_viss,ifid,"File failed the check for sampling unit "+DbSamplingUnit.getSUName(conn_viss,Integer.toString(sampleUnitId)) +"<br>"+errorMsg);
      }
      else
      {
          res = true;
          dbInFile.setStatus(conn_viss,ifid,"CHECKED");
          // Add a message to the log
          dbInFile.addErrMsg(conn_viss,ifid,"File checked for sampling unit "+DbSamplingUnit.getSUName(conn_viss,Integer.toString(sampleUnitId)) +"<br>"+errorMsg);
      }*/
    } catch (Exception e) {
      dbInFile.setStatus(conn_viss, ifid, "ERROR");

      // Add a message to the log
      dbInFile.addErrMsg(conn_viss, ifid, e.getMessage());

      e.printStackTrace(System.err);
      if (errMessage == null) {
        errMessage = e.getMessage();
      }
    } finally {
      try {
        /*
         * Delete files uploaded
         */
        File tmp = new File(checkFileName);
        tmp.delete();

        tmp = new File(fullFileName);
        tmp.delete();
      } catch (Exception ignore) {
      }
    }

    Errors.logDebug("CheckVariables completed");
    return res;
  }
Beispiel #2
0
  public boolean check() {
    Errors.logDebug("CheckPhenotype started");

    boolean res = false;

    String errMessage = null;
    FileWriter fileOut = null;
    DbImportFile dbInFile = new DbImportFile();

    String fullFileName = "";
    String checkFileName = "";
    try {
      dbInFile.setStatus(conn_viss, ifid, "0%");

      fullFileName = dbInFile.storeImportFileBLOB(conn_viss, ifid);
      checkFileName = fullFileName + "_checked";

      // Create the Phenotype
      DbPhenotype dbPhenotype = new DbPhenotype();

      FileHeader header = FileParser.scanFileHeader(fullFileName);
      String type = header.formatTypeName().toUpperCase();
      char delimiter = header.delimiter().charValue();

      // AbstractValueFileParser fp = null;
      FileParser fp = null;

      if (type.equals("LIST")) {
        fp = new FileParser(fullFileName);
        fp.Parse(
            FileTypeDefinitionList.matchingDefinitions(
                FileTypeDefinition.PHENOTYPE, FileTypeDefinition.LIST));
      } else if (type.equals("MATRIX")) {
        fp = new FileParser(fullFileName);
        fp.Parse(
            FileTypeDefinitionList.matchingDefinitions(
                FileTypeDefinition.PHENOTYPE, FileTypeDefinition.MATRIX));
      }

      // Write out the result to a new file
      fileOut = new FileWriter(checkFileName);
      fileOut.write(
          header.objectTypeName()
              + "/"
              + header.formatTypeName()
              + "/"
              + header.version()
              + "/"
              + header.delimiter()
              + "\n");

      String titles[] = fp.columnTitles();
      for (int j = 0; j < titles.length; j++) {
        fileOut.write(titles[j] + delimiter);
      }
      fileOut.write("\n");

      // Garbage collect the unused variables
      header = null;
      // fullFileName = null;
      // checkFileName = null;

      // Fix to upper case
      updateMethod = updateMethod.toUpperCase();

      Vector fatalErrors = new Vector();

      if (type.equals("LIST")) checkListTitles(titles, fatalErrors);
      else checkMatrixTitles(titles, fatalErrors);

      writeTitleErrors(fileOut, fatalErrors);

      String indId;

      if (titles[0].equals("IDENTITY")) indId = "IDENTITY";
      else indId = "Alias";

      String errMsg = "";
      if (type.equals("LIST")) errMsg = checkList((FileParser) fp, fileOut, delimiter, indId);
      // errMsg = checkList((FileParser)fp, fatalErrors,fileOut,delimiter,indId);
      else if (type.equals("MATRIX"))
        errMsg = checkMatrix((FileParser) fp, fatalErrors, fileOut, delimiter, indId);

      // Close the file
      fileOut.close();

      /*
       * Save the file to database
       */
      dbInFile.saveCheckedFile(conn_viss, ifid, checkFileName);

      // Get the error message from the database object. If it is set an
      // error occured during the operation so an error is thrown.
      // errMessage = dbIndividual.getErrorMessage();
      // Assertion.assertMsg(errMessage == null ||
      //                     errMessage.trim().equals(""), errMessage);

      if (errMsg.startsWith("ERROR:")) {
        dbInFile.setStatus(conn_viss, ifid, "ERROR");
        res = false;
      } else if (errMsg.startsWith("WARNING:")) {
        dbInFile.setStatus(conn_viss, ifid, "WARNING");
        res = true;
      } else {
        dbInFile.setStatus(conn_viss, ifid, "CHECKED");
        res = true;
      }

      // Add a message to the log
      dbInFile.addErrMsg(
          conn_viss,
          ifid,
          "File checked for sampling unit "
              + DbSamplingUnit.getSUName(conn_viss, Integer.toString(sampleUnitId))
              + "<br>\n"
              + errMsg);

    } catch (Exception e) {
      // Flag for error and set the errMessage if it has not been set
      // isOk = false;
      dbInFile.setStatus(conn_viss, ifid, "ERROR");
      // dbInFile.UpdateImportFile(connection,null,null,e.getMessage(),Integer.parseInt(ifid),Integer.parseInt(userId));

      // Add a message to the log
      dbInFile.addErrMsg(conn_viss, ifid, e.getMessage());

      e.printStackTrace(System.err);
      if (errMessage == null) {
        errMessage = e.getMessage();
      }
    } finally {
      try {

        /*
         * Delete temporary file
         */
        File tmp = new File(fullFileName);
        tmp.delete();
        tmp = null;

        tmp = new File(checkFileName);
        tmp.delete();
        tmp = null;
      } catch (Exception ignore) {
      }
    }

    Errors.logDebug("CheckPhenotype completed");

    return res;
  }