Пример #1
0
  /**
   * Tests transaction lookup
   *
   * @throws Exception an error occured
   */
  public void test1() throws Exception {
    ExecuteMatchHelper matchHelper = new ExecuteMatchHelper();
    String[] command = {"fileName=LookupTransaction1.txt", "fileType=generic"};
    List list = matchHelper.run(command);
    LookupTransactionHelper helper = new LookupTransactionHelper();
    // Get the update transaction
    MatchResult mr = (MatchResult) list.get(1);
    String transactionId = mr.getTransactionNumber();
    command = new String[] {"id=" + transactionId};
    TransactionSummary transSummary = helper.run(command);
    System.out.println("TransactionSummary:");
    System.out.println(transSummary.toString());

    // Test assertions
    log("Testing assertions.");
    TransactionObject transObj = transSummary.getTransactionObject();
    assertTrue(transObj.getTransactionNumber().equals(transactionId));
    assertTrue(transObj.getFunction().equals("Update"));
    EnterpriseObjectHistory rr = transSummary.getEnterpriseObjectHistory();
    EnterpriseObject beforeEO = rr.getBeforeEO1();
    EnterpriseObject afterEO = rr.getAfterEO();
    // Check SBR
    PersonObject beforePO = (PersonObject) beforeEO.getSBR().getObject();
    PersonObject afterPO = (PersonObject) afterEO.getSBR().getObject();
    assertTrue(beforePO.getLastName().equals("CIDON"));
    assertTrue(afterPO.getLastName().equals("CIDONE"));
    assertTrue(beforePO.getMStatus() == null);
    assertTrue(afterPO.getMStatus().equals("S"));
    // Check SO
    beforePO = (PersonObject) beforeEO.getSystemObject("SiteA", "0001").getObject();
    afterPO = (PersonObject) afterEO.getSystemObject("SiteA", "0001").getObject();
    assertTrue(beforePO.getLastName().equals("CIDON"));
    assertTrue(afterPO.getLastName().equals("CIDONE"));
    assertTrue(beforePO.getMStatus() == null);
    assertTrue(afterPO.getMStatus().equals("S"));
  }
Пример #2
0
  /**
   * @exception ValidationException when entry is not valid. This function validates the user input
   *     and builds the search object
   * @return the Audit search object
   */
  public AuditSearchObject getAuditSearchObject() throws ValidationException {
    AuditSearchObject auditSearchObject = new AuditSearchObject();

    // if user enters LID and SystemCode get the EUID and set it to the AuditSearchObject
    if (super.getUpdateableFeildsMap().get("LID") != null
        && super.getUpdateableFeildsMap().get("SystemCode") != null) {
      String LID = (String) super.getUpdateableFeildsMap().get("LID");
      String SystemCode = (String) super.getUpdateableFeildsMap().get("SystemCode");
      if (LID.trim().length() > 0 && SystemCode.trim().length() > 0) {
        try {
          // remove masking for LID field
          LID = LID.replaceAll("-", "");

          SystemObject so = masterControllerService.getSystemObject(SystemCode, LID);
          if (so == null) {
            errorMessage = bundle.getString("system_object_not_found_error_message");
            FacesContext.getCurrentInstance()
                .addMessage(
                    null,
                    new FacesMessage(FacesMessage.SEVERITY_ERROR, errorMessage, errorMessage));
            // mLogger.error("LID/SYSTEM CODE:: " + errorMessage);
            mLogger.info(mLocalizer.x("AUD018: LID/SYSTEM CODE : {0}", errorMessage));

          } else {
            EnterpriseObject eo = masterControllerService.getEnterpriseObjectForSO(so);
            auditSearchObject.setEUID(eo.getEUID());
          }
        } catch (Exception ex) {
          if (ex instanceof ValidationException) {
            mLogger.error(
                mLocalizer.x("AUD019: Service Layer Validation Exception has occurred"), ex);
            FacesContext.getCurrentInstance()
                .addMessage(
                    null,
                    new FacesMessage(
                        FacesMessage.SEVERITY_ERROR,
                        QwsUtil.getRootCause(ex).getMessage(),
                        exceptionMessaage));
          } else if (ex instanceof UserException) {
            mLogger.error(mLocalizer.x("AUD020: Service Layer User Exception occurred"), ex);
            FacesContext.getCurrentInstance()
                .addMessage(
                    null,
                    new FacesMessage(
                        FacesMessage.SEVERITY_ERROR,
                        QwsUtil.getRootCause(ex).getMessage(),
                        exceptionMessaage));
          } else if (!(ex instanceof ProcessingException)) {
            mLogger.error(mLocalizer.x("AUD021: Error  occurred"), ex);
            FacesContext.getCurrentInstance()
                .addMessage(
                    null,
                    new FacesMessage(
                        FacesMessage.SEVERITY_ERROR,
                        QwsUtil.getRootCause(ex).getMessage(),
                        exceptionMessaage));
          } else if (ex instanceof ProcessingException) {
            String exceptionMessage = QwsUtil.getRootCause(ex).getMessage();
            if (exceptionMessage.indexOf("stack trace") != -1) {
              String parsedString =
                  exceptionMessage.substring(0, exceptionMessage.indexOf("stack trace"));
              if (exceptionMessage.indexOf("message=") != -1) {
                parsedString =
                    parsedString.substring(
                        exceptionMessage.indexOf("message=") + 8, parsedString.length());
              }
              mLogger.error(
                  mLocalizer.x("AUD022: Service Layer Processing Exception occurred"), ex);
              FacesContext.getCurrentInstance()
                  .addMessage(
                      null,
                      new FacesMessage(
                          FacesMessage.SEVERITY_ERROR, parsedString, exceptionMessaage));
            } else {
              mLogger.error(mLocalizer.x("AUD023: Error  occurred"), ex);
              FacesContext.getCurrentInstance()
                  .addMessage(
                      null,
                      new FacesMessage(
                          FacesMessage.SEVERITY_ERROR, exceptionMessage, exceptionMessaage));
            }
          }
          return null;
        }
      }
    }

    // set EUID VALUE IF lid/system code not supplied
    if (super.getUpdateableFeildsMap().get("EUID") != null
        && super.getUpdateableFeildsMap().get("EUID").toString().trim().length() > 0) {
      auditSearchObject.setEUID((String) super.getUpdateableFeildsMap().get("EUID"));
      //          } else {
      //              auditSearchObject.setEUID(null);
    }

    // added as fix of bug with Id 113 on 21-10-08
    if (((super.getUpdateableFeildsMap().get("StartDate") != null)
            && (super.getUpdateableFeildsMap().get("StartDate").toString().trim().length() > 0))
        && ((super.getUpdateableFeildsMap().get("EndDate") != null)
            && (super.getUpdateableFeildsMap().get("EndDate").toString().trim().length() > 0))) {

      Date fromdate =
          DateUtil.string2Date(
              super.getUpdateableFeildsMap().get("StartDate").toString()
                  + ((super.getUpdateableFeildsMap().get("StartTime") != null
                          && super.getUpdateableFeildsMap()
                                  .get("StartTime")
                                  .toString()
                                  .trim()
                                  .length()
                              > 0)
                      ? " " + super.getUpdateableFeildsMap().get("StartTime").toString()
                      : " 00:00:00"));
      Date todate =
          DateUtil.string2Date(
              super.getUpdateableFeildsMap().get("EndDate").toString()
                  + ((super.getUpdateableFeildsMap().get("EndTime") != null
                          && super.getUpdateableFeildsMap()
                                  .get("EndTime")
                                  .toString()
                                  .trim()
                                  .length()
                              > 0)
                      ? " " + super.getUpdateableFeildsMap().get("EndTime").toString()
                      : " 23:59:59"));
      long startDate = fromdate.getTime();
      long endDate = todate.getTime();
      if (endDate < startDate) {
        errorMessage = bundle.getString("ERROR_INVALID_FROMDATE_RANGE");
        FacesContext.getCurrentInstance()
            .addMessage(
                null, new FacesMessage(FacesMessage.SEVERITY_ERROR, errorMessage, errorMessage));
        return null;
      }
    }

    String startTime = (String) super.getUpdateableFeildsMap().get("StartTime");
    String searchStartDate = (String) super.getUpdateableFeildsMap().get("StartDate");
    if (startTime != null && startTime.trim().length() > 0) {
      // if only time fields are entered validate for the date fields
      if ((searchStartDate != null && searchStartDate.trim().length() == 0)) {
        errorMessage = bundle.getString("enter_date_from");
        FacesContext.getCurrentInstance()
            .addMessage(
                null, new FacesMessage(FacesMessage.SEVERITY_ERROR, errorMessage, errorMessage));
        return null;
      }
    }

    // Set StartDate to the AuditSearchObject
    if (super.getUpdateableFeildsMap().get("StartDate") != null
        && super.getUpdateableFeildsMap().get("StartDate").toString().trim().length() > 0) {
      // append the time aling with date
      if (startTime != null && startTime.trim().length() > 0) {
        searchStartDate = searchStartDate + " " + startTime;
      } else {
        searchStartDate = searchStartDate + " 00:00:00";
      }

      Date date = DateUtil.string2Date(searchStartDate);
      if (date != null) {
        auditSearchObject.setCreateStartDate(new Timestamp(date.getTime()));
      }
    }

    String endTime = (String) super.getUpdateableFeildsMap().get("EndTime");
    String searchEndDate = (String) super.getUpdateableFeildsMap().get("EndDate");
    if (endTime != null && endTime.trim().length() > 0) {
      // if only time fields are entered validate for the date fields
      if ((searchEndDate != null && searchEndDate.trim().length() == 0)) {
        errorMessage = bundle.getString("enter_date_to");
        FacesContext.getCurrentInstance()
            .addMessage(
                null, new FacesMessage(FacesMessage.SEVERITY_ERROR, errorMessage, errorMessage));
        return null;
      }
    }

    // Set StartDate to the AuditSearchObject
    if (super.getUpdateableFeildsMap().get("EndDate") != null
        && super.getUpdateableFeildsMap().get("EndDate").toString().trim().length() > 0) {
      // append the time aling with date
      if (endTime != null && endTime.trim().length() > 0) {
        searchEndDate = searchEndDate + " " + endTime;
      } else {
        searchEndDate = searchEndDate + " 23:59:59";
      }
      Date date = DateUtil.string2Date(searchEndDate);
      if (date != null) {
        auditSearchObject.setCreateEndDate(new Timestamp(date.getTime()));
      }
    }
    // EndTime=, StartTime=, EndDate=, StartDate=, Function=null, SystemUser=, SystemCode=null,
    // LID=, EUID=
    if (super.getUpdateableFeildsMap().get("SystemUser") != null
        && super.getUpdateableFeildsMap().get("SystemUser").toString().trim().length() > 0) {
      auditSearchObject.setCreateUser((String) super.getUpdateableFeildsMap().get("SystemUser"));
    } else {
      auditSearchObject.setCreateUser(null);
    }

    if (super.getUpdateableFeildsMap().get("Function") != null
        && super.getUpdateableFeildsMap().get("Function").toString().trim().length() > 0) {
      auditSearchObject.setFunction((String) super.getUpdateableFeildsMap().get("Function"));
    } else {
      auditSearchObject.setFunction(null);
    }

    // Set to static values need clarification from prathiba
    // This will be revoked when login module is implemented.
    // auditSearchObject.setPageSize(ConfigManager.getInstance().getMatchingConfig().getItemPerSearchResultPage());
    // auditSearchObject.setMaxElements(ConfigManager.getInstance().getMatchingConfig().getMaxResultSize());

    // set max results and page size here
    auditSearchObject.setPageSize(super.getPageSize());
    auditSearchObject.setMaxElements(super.getMaxRecords());
    Date date = null;

    if (errorMessage != null && errorMessage.length() != 0) {
      throw new ValidationException(mLocalizer.t("AUD501: {0}", errorMessage));
    }
    return auditSearchObject;
  }