/*
   * Guaranteed to throw an exception no matter what the data integrity issue
   * is.
   */
  private void handleOfficeDataIntegrityIssues(
      final JsonCommand command, DataIntegrityViolationException dve) {

    Throwable realCause = dve.getMostSpecificCause();
    if (realCause.getMessage().contains("externalid_org")) {
      final String externalId = command.stringValueOfParameterNamed("externalId");
      throw new PlatformDataIntegrityException(
          "error.msg.office.duplicate.externalId",
          "Office with externalId `" + externalId + "` already exists",
          "externalId",
          externalId);
    } else if (realCause.getMessage().contains("name_org")) {
      final String name = command.stringValueOfParameterNamed("name");
      throw new PlatformDataIntegrityException(
          "error.msg.office.duplicate.name",
          "Office with name `" + name + "` already exists",
          "name",
          name);
    }

    logger.error(dve.getMessage(), dve);
    throw new PlatformDataIntegrityException(
        "error.msg.office.unknown.data.integrity.issue",
        "Unknown data integrity issue with resource.");
  }
Exemplo n.º 2
0
  public void testUpdateUser() throws Exception {
    User user = dao.get(1L);

    Address address = user.getAddress();
    address.setAddress1("new address");
    user.setTimeZone("US/Central");

    dao.saveUser(user);

    user = dao.get(1L);
    assertEquals(address, user.getAddress());
    assertEquals("new address", user.getAddress().getAddress1());
    assertEquals("US/Central", user.getTimeZone());

    // verify that violation occurs when adding new user with same username
    user.setId(null);

    endTransaction();

    try {
      dao.saveUser(user);
      // flush();
      fail("saveUser didn't throw DataIntegrityViolationException");
    } catch (DataIntegrityViolationException e) {
      assertNotNull(e);
      log.debug("expected exception: " + e.getMessage());
    }
  }
 private void handleCodeDataIntegrityIssues(
     JsonCommand command, DataIntegrityViolationException dve) {
   Throwable realCause = dve.getMostSpecificCause();
   LOGGER.error(dve.getMessage(), dve);
   throw new PlatformDataIntegrityException(
       "error.msg.cund.unknown.data.integrity.issue",
       "Unknown data integrity issue with resource: " + realCause.getMessage());
 }
  private void handleDataIntegrityIssues(
      final JsonCommand command, final DataIntegrityViolationException dve) {

    final Throwable realCause = dve.getMostSpecificCause();

    LOGGER.error(dve.getMessage(), dve);
    if (realCause.getMessage().contains("taxcode")) {
      throw new PlatformDataIntegrityException(
          "validation.error.msg.taxmap.taxcode.duplicate",
          "A taxcode with name'"
              + command.stringValueOfParameterNamed("taxCode")
              + "'already exists",
          command.stringValueOfParameterNamed("taxCode"));
    } else {
      throw new PlatformDataIntegrityException(
          "error.msg.could.unknown.data.integrity.issue",
          "Unknown data integrity issue with resource: " + dve.getMessage());
    }
  }
  private void handleDataIntegrityIssues(
      final JsonCommand element, final DataIntegrityViolationException dve) {

    Throwable realCause = dve.getMostSpecificCause();
    if (realCause.getMessage().contains("serial_no_constraint")) {
      throw new PlatformDataIntegrityException(
          "validation.error.msg.inventory.item.duplicate.serialNumber",
          "validation.error.msg.inventory.item.duplicate.serialNumber",
          "validation.error.msg.inventory.item.duplicate.serialNumber",
          "");
    }

    LOGGER.error(dve.getMessage(), dve);
  }
  private void handleDataIntegrityIssues(
      final JsonCommand element, final DataIntegrityViolationException dve) {

    Throwable realCause = dve.getMostSpecificCause();
    if (realCause.getMessage().contains("UK_PRICING_COMPKEY")) {
      throw new PlatformDataIntegrityException(
          "event.pricing.price.already.exist",
          "event.pricing.price.already.exist",
          "event.pricing.price.already.exist",
          "");
    }

    logger.error(dve.getMessage(), dve);
  }
  /**
   * @param command
   * @param dve
   */
  private void handleGLClosureIntegrityIssues(
      final JsonCommand command, final DataIntegrityViolationException dve) {
    final Throwable realCause = dve.getMostSpecificCause();
    if (realCause.getMessage().contains("office_id_closing_date")) {
      throw new GLClosureDuplicateException(
          command.longValueOfParameterNamed(GLClosureJsonInputParams.OFFICE_ID.getValue()),
          new LocalDate(
              command.DateValueOfParameterNamed(GLClosureJsonInputParams.CLOSING_DATE.getValue())));
    }

    logger.error(dve.getMessage(), dve);
    throw new PlatformDataIntegrityException(
        "error.msg.glClosure.unknown.data.integrity.issue",
        "Unknown data integrity issue with resource GL Closure: " + realCause.getMessage());
  }
Exemplo n.º 8
0
  public void addGame(Game game) throws GameServiceException {
    SimpleJdbcInsert insertGame = new SimpleJdbcInsert(getDataSource()).withTableName("games");
    Map<String, Object> gameParameters = new HashMap<String, Object>(5);
    gameParameters.put("gameid", game.getGameId());
    gameParameters.put("startTime", game.getStartTime());
    gameParameters.put("teamHomeid", game.getTeamHome().getTeamId());
    gameParameters.put("teamAwayid", game.getTeamAway().getTeamId());
    gameParameters.put("venueid", game.getVenue().getVenueId());

    try {
      insertGame.execute(gameParameters);
    } catch (DataIntegrityViolationException divex) {
      log.warning("Duplicate entry");
      throw new GameServiceException(divex.getMessage(), divex);
    }
  }
  /*
   * Guaranteed to throw an exception no matter what the data integrity issue
   * is.
   */
  private void handleDataIntegrityIssues(
      final DepositAccountCommand command, final DataIntegrityViolationException dve) {

    Throwable realCause = dve.getMostSpecificCause();
    if (realCause.getMessage().contains("deposit_acc_external_id")) {
      throw new PlatformDataIntegrityException(
          "error.msg.desposit.account.duplicate.externalId",
          "Deposit account with externalId " + command.getExternalId() + " already exists",
          "externalId",
          command.getExternalId());
    }

    logger.error(dve.getMessage(), dve);
    throw new PlatformDataIntegrityException(
        "error.msg.deposit.account.unknown.data.integrity.issue",
        "Unknown data integrity issue with resource.");
  }
Exemplo n.º 10
0
  private void initDatabase() {

    User enatis = new User();
    enatis.setUserName("ENatis");
    enatis.setPassword("123");
    enatis.setName("Edgardo Natis");
    enatis.setActive("1");
    enatis.setStatus(User.STATUS_OPEN);
    enatis.setServerId("1081EFAA375B683B01378991228E39CB");

    try {
      userRepository.save(enatis);

    } catch (DataIntegrityViolationException dive) {
      System.out.println("\nDatabase Error: " + dive.getMessage() + "\n");
    }
  }
  private void handleDataIntegrityIssues(
      final JsonCommand command, final DataIntegrityViolationException dve) {
    final Throwable realCause = dve.getMostSpecificCause();
    if (realCause.getMessage().contains("holiday_name")) {
      final String name = command.stringValueOfParameterNamed("name");
      throw new PlatformDataIntegrityException(
          "error.msg.holiday.duplicate.name",
          "Holiday with name `" + name + "` already exists",
          "name",
          name);
    }

    logger.error(dve.getMessage(), dve);
    throw new PlatformDataIntegrityException(
        "error.msg.office.unknown.data.integrity.issue",
        "Unknown data integrity issue with resource.");
  }
  @ExceptionHandler({DataIntegrityViolationException.class})
  public void constraintViolation(HttpServletResponse response, DataIntegrityViolationException ex)
      throws IOException {
    String message;
    Throwable cause = ex.getCause();
    if (cause instanceof ConstraintViolationException) {
      ConstraintViolationException cEx = (ConstraintViolationException) cause;
      message =
          "Application already contain sent data (Constraint "
              + cEx.getConstraintName()
              + " violates).";
    } else {
      message = ex.getMessage();
    }

    response.sendError(CONFLICT.value(), message);
  }
Exemplo n.º 13
0
  /** {@inheritDoc} */
  public User saveUser(User user) throws UserExistsException {

    if (user.getVersion() == null) {
      // if new user, lowercase userId
      user.setUsername(user.getUsername().toLowerCase());
    }

    // Get and prepare password management-related artifacts
    boolean passwordChanged = false;
    if (passwordEncoder != null) {
      // Check whether we have to encrypt (or re-encrypt) the password
      if (user.getVersion() == null) {
        // New user, always encrypt
        passwordChanged = true;
      } else {
        // Existing user, check password in DB
        String currentPassword = userDao.getUserPassword(user.getUsername());
        if (currentPassword == null) {
          passwordChanged = true;
        } else {
          if (!currentPassword.equals(user.getPassword())) {
            passwordChanged = true;
          }
        }
      }

      // If password was changed (or new user), encrypt it
      if (passwordChanged) {
        user.setPassword(passwordEncoder.encodePassword(user.getPassword(), null));
      }
    } else {
      log.warn("PasswordEncoder not set, skipping password encryption...");
    }

    try {
      return userDao.saveUser(user);
    } catch (DataIntegrityViolationException e) {
      // e.printStackTrace();
      log.warn(e.getMessage());
      throw new UserExistsException("User '" + user.getUsername() + "' already exists!");
    } catch (JpaSystemException e) { // needed for JPA
      // e.printStackTrace();
      log.warn(e.getMessage());
      throw new UserExistsException("User '" + user.getUsername() + "' already exists!");
    }
  }
  /*
   * Guaranteed to throw an exception no matter what the data integrity issue
   * is.
   */
  private void handleDataIntegrityIssues(
      final JsonCommand command, final DataIntegrityViolationException dve) {

    final Throwable realCause = dve.getMostSpecificCause();
    if (realCause.getMessage().contains("username_org")) {
      final String username = command.stringValueOfParameterNamed("username");
      final StringBuilder defaultMessageBuilder =
          new StringBuilder("User with username ").append(username).append(" already exists.");
      throw new PlatformDataIntegrityException(
          "error.msg.user.duplicate.username",
          defaultMessageBuilder.toString(),
          "username",
          username);
    }

    logger.error(dve.getMessage(), dve);
    throw new PlatformDataIntegrityException(
        "error.msg.unknown.data.integrity.issue", "Unknown data integrity issue with resource.");
  }
Exemplo n.º 15
0
  public void addFantasyTeam(FantasyTeam fantasyTeam) {
    JdbcTemplate queryFantasyTeams = new JdbcTemplate(this.getDataSource());
    int userId = fantasyTeam.getUserId();
    String sql1 = "SELECT * FROM fantasyteams WHERE userid = ?";
    boolean hasTeam = true;

    try {
      queryFantasyTeams.queryForObject(sql1, new Object[] {userId}, new FantasyTeamRowMapper());
    } catch (EmptyResultDataAccessException e) {
      hasTeam = false;
    }

    if (!hasTeam) {
      SimpleJdbcInsert insertToFantasyTeams =
          (new SimpleJdbcInsert(this.getDataSource())).withTableName("fantasyteams");

      String sql2 = "SELECT MAX(fantasyteamid) FROM fantasyteams";

      int nextId = 1;
      try {
        nextId += queryFantasyTeams.queryForObject(sql2, Integer.class);
      } catch (NullPointerException ignored) {
      }

      Map<String, Object> fantasyteamsParameters = new HashMap<String, Object>(2);
      fantasyteamsParameters.put("fantasyteamid", nextId);
      fantasyteamsParameters.put("userid", fantasyTeam.getUserId());

      try {
        insertToFantasyTeams.execute(fantasyteamsParameters);
      } catch (DataIntegrityViolationException dive) {
        this.log.warning(dive.getMessage());
      }

      for (int i = 1; i <= 11; ++i) {
        FantasyTeamReg reg = new FantasyTeamReg(nextId, 0, 0, i);
        fantasyTeamRegServiceData.addFantasyTeamReg(reg);
      }
    }
  }
 private void logAsErrorUnexpectedDataIntegrityException(
     final DataIntegrityViolationException dve) {
   logger.error(dve.getMessage(), dve);
 }
Exemplo n.º 17
0
  @Override
  public void insert(
      String organizationId,
      String orderNumber,
      String orderId,
      String memberCode,
      String unifiedCustomerId,
      String tenantId,
      String settlementType,
      String settlementName,
      String settlementContents,
      BigDecimal itemAmount,
      BigDecimal fee,
      BigDecimal carriage,
      BigDecimal discount,
      BigDecimal orderAmount,
      BigDecimal grantPoint,
      BigDecimal usePoint,
      String mail,
      String postalCode,
      String state,
      String coupon,
      BigDecimal couponDiscount,
      String couponEventId,
      Date orderDate,
      Date cancelDate,
      BigDecimal sessionNumber,
      String affiliate,
      String status,
      String siteId,
      BigDecimal carriageHurry,
      BigDecimal giftAmount,
      String returnFlag,
      String exchangeFlag,
      String reserveFlag,
      Date updatedDate,
      String user) {
    // TODO Auto-generated method stub
    try {
      Parchase object = new Parchase();

      object.setId(new UUIDBean().generatePrimaryKey());
      object.setOrganizationId(organizationId);
      object.setOrderNumber(orderNumber);
      object.setOrderId(orderId);
      object.setMemberCode(memberCode);
      object.setUnifiedCustomerId(unifiedCustomerId);
      object.setTenantId(tenantId);
      object.setSettlementType(settlementType);
      object.setSettlementName(settlementName);
      object.setSettlementContents(settlementContents);
      object.setItemAmount(itemAmount);
      object.setFee(fee);
      object.setCarriage(carriageHurry);
      object.setDiscount(couponDiscount);
      object.setOrderAmount(orderAmount);
      object.setGrantPoint(grantPoint);
      object.setUsePoint(usePoint);
      object.setMail(mail);
      object.setPostalCode(postalCode);
      object.setState(state);
      object.setCoupon(coupon);
      object.setCouponDiscount(couponDiscount);
      object.setCouponEventId(couponEventId);
      object.setOrderDate(orderDate);
      object.setCancelDate(cancelDate);
      object.setSessionNumber(sessionNumber);
      object.setAffiliate(affiliate);
      object.setStatus(status);
      object.setSiteId(siteId);
      object.setCarriageHurry(carriageHurry);
      object.setGiftAmount(giftAmount);
      object.setReturnFlag(returnFlag);
      object.setExchangeFlag(exchangeFlag);
      object.setReserveFlag(reserveFlag);
      object.setUpdatedDate(updatedDate);
      object.setDeleteFlag(Boolean.FALSE);
      object.setCreateDate(new Date(System.currentTimeMillis()));
      object.setCreateUser(user);
      object.setAmendDate(new Date(System.currentTimeMillis()));
      object.setAmendUser(user);

      getHibernateTemplate().save(object);
      getHibernateTemplate().flush();
      getHibernateTemplate().clear();
    } catch (DataIntegrityViolationException e) {
      throw new ParchaseBusinessException(e.getMessage(), e);
    } catch (HibernateSystemException e) {
      throw new ParchaseRuntimeException(e);
    }
  }