Example #1
0
  /**
   * Builds the response to be shown.
   *
   * @param logMessageSetVO - Object of LogMessageSetVO containing errors/warnings to be shown.
   * @param isHTML - Whether response is in html format or not.
   * @return - The response string.
   */
  public static String buildResponse(LogMessageSetVO logMessageSetVO, boolean isHTML) {

    // Assume that eCodes contains a list of comma separated error/warning
    // codes
    // Get the Error message for each code and terminate it with <BR> in
    // case of HTML, else terminate with &

    StringBuffer err_buf = new StringBuffer();
    StringBuffer warn_buf = new StringBuffer();
    String errors = "";
    String notices = "";
    Set<LOGMESSAGE> errorSet = logMessageSetVO.getErrorsSet();
    Set<LOGMESSAGE> warningSet = logMessageSetVO.getWarningSet();

    for (Enum<LOGMESSAGE> error : errorSet) {
      // Error
      err_buf.append(error.toString());
    }
    for (Enum<LOGMESSAGE> warning : warningSet) {
      // Error
      err_buf.append(warning.toString());
    }

    if (err_buf.length() > 0)
      errors =
          (isHTML ? "<BR>" : "&")
              + "statusMessage="
              + err_buf.substring(0)
              + (isHTML ? "<BR>" : "&")
              + "statusCode="
              + Status.FAILURE.getCode();
    else errors = "statusMessage=" + Status.SUCCESS + "&statusCode=" + Status.SUCCESS.getCode();
    if (warn_buf.length() > 0)
      notices = (isHTML ? "<BR>" : "&") + "notice=" + warn_buf.substring(0);

    String otherMessages = logMessageSetVO.getOtherMessages();
    otherMessages = otherMessages == null ? "" : otherMessages;

    logger.info("Errors=" + errors);
    logger.info("Notices=" + notices);
    logger.info("Miscellaneous Messages=" + otherMessages);
    return errors + notices + otherMessages;
  }
Example #2
0
  /**
   * Checks the status of the server. Whether it is ready for saving the file or not.
   * ExportConfiguration.SAVEABSOLUTEPATH is pre-pended to the filename to test for folder and file
   * existence.
   *
   * @param fileName - name of the file in which data is going to be saved.
   * @return LogMessageSetVO - object of LogMessageSetVO containing errors/warnings.
   */
  public static LogMessageSetVO checkServerSaveStatus(String fileName) {
    LogMessageSetVO errorSetVO = new LogMessageSetVO();

    String pathToSaveFolder = ExportConfiguration.SAVEABSOLUTEPATH;

    // check whether directory exists
    // raise error and return
    File saveFolder = new File(pathToSaveFolder);
    if (!saveFolder.exists()) {
      errorSetVO.addError(LOGMESSAGE.E508);
    } else {
      // check if directory is writable or not
      if (!saveFolder.canWrite()) {
        errorSetVO.addError(LOGMESSAGE.E403);
      } else {
        // build filepath
        String completeFilePath = pathToSaveFolder + File.separator + fileName;
        File saveFile = new File(completeFilePath);

        // check whether file already exists
        if (saveFile.exists()) {
          errorSetVO.addWarning(LOGMESSAGE.W509);

          if (ExportConfiguration.OVERWRITEFILE) {
            errorSetVO.addWarning(LOGMESSAGE.W510);

            if (!saveFile.canWrite()) {
              errorSetVO.addError(LOGMESSAGE.E511);
            }
          } else {

            if (!ExportConfiguration.INTELLIGENTFILENAMING) {
              errorSetVO.addError(LOGMESSAGE.E512);
            }
          }
        }
      }
    }

    return errorSetVO;
  }