Пример #1
0
  @Override
  public ChargeRS execute(ChargeRQ request) {
    operationDAO = (OperationDAO) getBean("operationDAO");
    bankAccountDAO = (BankAccountDAO) getBean("bankAccountDAO");
    cardDAO = (CardDAO) getBean("cardDAO");
    corporationDAO = (CorporationDAO) getBean("corporationDAO");
    operationFactory = (OperationFactory) getBean("operationFactoryBean");

    ChargeRS chargeRS = new ChargeRS();

    if (ChargeValidator.validate(request)) {
      double amount = request.getAmount();
      long fromBankAccountId = request.getFromBankAccount();
      long toCardId = request.getToCardAccount();
      Date processingDate = request.getDate();

      Operation operation =
          operationFactory.operationWithType(
              OperationTypeEnum.CHARGE, OperationStatusEnum.NEW_OPERATION);

      Card card = cardDAO.getById(toCardId);
      Corporation corporation = corporationDAO.getCorporationByName(EBANKING_CORPORATION_NAME);
      BankAccount bankAccount =
          bankAccountDAO.getByCurrencyAndName(card.getCardAccount().getCurrency(), corporation);

      operation.setTransactionAmount(amount);
      operation.setContractorAccount(bankAccount);
      operation.setCard(card);
      operation.setProcessingDate(processingDate);
      operation.setOperationKey("-");

      operationDAO.saveOrUpdate(operation);

      chargeRS.setSuccess(true);
    } else {
      chargeRS.setSuccess(false);
      chargeRS.setException("Bad request");
    }

    return chargeRS;
  }