Ejemplo n.º 1
0
  /** Set the preferences for this import object. */
  public void setPrefs(Prefs prefs, DataObject db) throws Exception {
    Errors.logInfo("ImportData.setPrefs(...) started");
    this.pid = Integer.valueOf(prefs.pid).toString();
    this.isid = Integer.valueOf(prefs.isid).toString();
    this.ifid = Integer.valueOf(prefs.ifid).toString();
    this.upPath = prefs.upPath;
    this.systemFileName = prefs.fileName;
    this.updateMethod = prefs.updateMethod;
    this.connection = prefs.connection;
    this.conn_viss = prefs.connViss;
    this.sampleUnitId = prefs.sampleUnitId;
    this.speciesId = prefs.speciesId;
    this.userId = prefs.userId;

    this.db = db;

    debug();

    if (!updateMethod.equals("CREATE")
        && !updateMethod.equals("UPDATE")
        && !updateMethod.equals("CREATE_OR_UPDATE"))
      throw new Exception("UpdateMethod is not CREATE, UPDATE, CREATE_OR_UPDATE");

    Errors.logInfo("ImportData.setPrefs(...) ended");
  }
Ejemplo n.º 2
0
  /** Prints a debug information about the knowledge of this import module. */
  public void debug() {
    Errors.logInfo("ImportData.debug() started");

    if (connection == null) Errors.logDebug("connection is null");
    else Errors.logDebug("connection is not null");

    if (conn_viss == null) Errors.logDebug("conn_viss is null");
    else Errors.logDebug("conn_viss is not null");

    if (pid == null) Errors.logDebug("pid is null");
    else Errors.logDebug("pid=" + pid);

    if (isid == null) Errors.logDebug("isid is null");
    else Errors.logDebug("isid=" + isid);

    if (upPath == null) Errors.logDebug("upPath is null");
    else Errors.logDebug("upPath=" + upPath);

    Errors.logDebug("sampleUnitId=" + sampleUnitId);

    Errors.logDebug("speciesId=" + speciesId);

    if (userId == null) Errors.logDebug("userId is null");
    else Errors.logDebug("userId=" + userId);

    Errors.logDebug("level=" + level);

    Errors.logDebug("maxDev=" + maxDev);

    if (updateMethod == null) Errors.logDebug("updateMethod is null");
    else Errors.logDebug("updateMethod=" + updateMethod);

    Errors.logInfo("ImportData.debug() ended");
  }
Ejemplo n.º 3
0
  public boolean imp() {
    boolean res = false;
    String errMessage = null;

    DbImportFile dbInFile = new DbImportFile();
    DbPhenotype dbp = new DbPhenotype();
    String fullFileName = null;

    try {
      Errors.logInfo("CheckPhenotype started");
      // connection.setAutoCommit(false);
      dbInFile.setStatus(conn_viss, ifid, "0%");

      fullFileName = dbInFile.storeImportFileBLOB(conn_viss, ifid);

      FileHeader header = FileParser.scanFileHeader(fullFileName);
      FileParser fileParser = new FileParser(fullFileName);

      // Set status
      dbInFile.setStatus(conn_viss, ifid, "10%");

      // Ensure file format is list or matrix
      Assertion.assertMsg(
          header.formatTypeName().equalsIgnoreCase(FileTypeDefinition.LIST)
              || header.formatTypeName().equalsIgnoreCase(FileTypeDefinition.MATRIX),
          "Format type name should be list or matrix "
              + "but found found "
              + header.formatTypeName());

      // If file is a list
      if (header.formatTypeName().equalsIgnoreCase(FileTypeDefinition.LIST)) {
        fileParser.Parse(
            FileTypeDefinitionList.matchingDefinitions(
                FileTypeDefinition.PHENOTYPE, FileTypeDefinition.LIST));
        dbInFile.setStatus(conn_viss, ifid, "20%");

        if (updateMethod.equals("CREATE")) {
          dbp.CreatePhenotypesList(
              fileParser, connection, sampleUnitId, Integer.valueOf(userId).intValue());
        } else if (updateMethod.equals("UPDATE")) {
          dbp.UpdatePhenotypesList(
              fileParser, connection, sampleUnitId, Integer.valueOf(userId).intValue());
        } else if (updateMethod.equals("CREATE_OR_UPDATE")) {
          dbp.CreateOrUpdatePhenotypesList(
              fileParser, connection, sampleUnitId, Integer.valueOf(userId).intValue());
        }
      }

      // If file is a matrix
      else if (header.formatTypeName().equalsIgnoreCase(FileTypeDefinition.MATRIX)) {
        fileParser.Parse(
            FileTypeDefinitionList.matchingDefinitions(
                FileTypeDefinition.PHENOTYPE, FileTypeDefinition.MATRIX));
        dbInFile.setStatus(conn_viss, ifid, "20%");

        if (updateMethod.equals("CREATE")) {
          dbp.CreatePhenotypesMatrix(
              fileParser, connection, sampleUnitId, Integer.valueOf(userId).intValue());
        } else if (updateMethod.equals("UPDATE")) {
          dbp.UpdatePhenotypesMatrix(
              fileParser, connection, sampleUnitId, Integer.valueOf(userId).intValue());
        } else if (updateMethod.equals("CREATE_OR_UPDATE")) {
          dbp.CreateOrUpdatePhenotypesMatrix(
              fileParser, connection, sampleUnitId, Integer.valueOf(userId).intValue());
        }
      }
      errMessage = dbp.getErrorMessage();

      Assertion.assertMsg(errMessage == null || errMessage.trim().equals(""), errMessage);

      dbInFile.setStatus(conn_viss, ifid, "IMPORTED");

      // Add a message to the log
      dbInFile.addErrMsg(
          conn_viss,
          ifid,
          "File imported for sampling unit "
              + DbSamplingUnit.getSUName(conn_viss, Integer.toString(sampleUnitId)));
      res = true;

      Errors.logInfo("Check Phenotype ended");
    } catch (Exception e) {
      // Flag for error and set the errMessage if it has not been set
      // isOk = false;
      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();
      }
    }

    return res;
  }