@Test void mapsAsPlainString() { CreateOrderCommand command = service.map(Trade.builder() .client(new Client()) .currencyFrom(TradingCurrency.Monero) .currencyTo(TradingCurrency.Bitcoin) .openingPrice(new BigDecimal("10.000")) .openingAmount(new BigDecimal("2E+1")) .build()); assertThat(command.getPrice()).isEqualTo("10"); assertThat(command.getAmount()).isEqualTo("20"); }
public CreateOrderCommand map(Trade trade) { CreateOrderCommand comm = CreateOrderCommand.builder() .clientName(trade.getClient().getName()) .currencyFrom(trade.getCurrencyFrom().getCode()) .currencyTo(trade.getCurrencyTo().getCode()) .price(cleanBigDecimal(trade.getOpeningPrice())) .amount(cleanBigDecimal(trade.getOpeningAmount())) .id(trade.getId()) .orderId(trade.getId()) .build(); if (!validator.validate(comm).isEmpty() || 0 == comm.getAmount().compareTo(BigDecimal.ZERO)) { log.error("Validation issue {}", comm); throw new RejectionException(Reason.VALIDATION_FAIL); } return comm; }
TradeCreationService { public CreateOrderCommand map(Trade trade) { CreateOrderCommand comm = CreateOrderCommand.builder() .clientName(trade.getClient().getName()) .currencyFrom(trade.getCurrencyFrom().getCode()) .currencyTo(trade.getCurrencyTo().getCode()) .price(cleanBigDecimal(trade.getOpeningPrice())) .amount(cleanBigDecimal(trade.getOpeningAmount())) .id(trade.getId()) .orderId(trade.getId()) .build(); if (!validator.validate(comm).isEmpty() || 0 == comm.getAmount().compareTo(BigDecimal.ZERO)) { log.error("Validation issue {}", comm); throw new RejectionException(Reason.VALIDATION_FAIL); } return comm; } }
TradeCreationService { public CreateOrderCommand map(Trade trade) { CreateOrderCommand comm = CreateOrderCommand.builder() .clientName(trade.getClient().getName()) .currencyFrom(trade.getCurrencyFrom().getCode()) .currencyTo(trade.getCurrencyTo().getCode()) .price(cleanBigDecimal(trade.getOpeningPrice())) .amount(cleanBigDecimal(trade.getOpeningAmount())) .id(trade.getId()) .orderId(trade.getId()) .build(); if (!validator.validate(comm).isEmpty() || 0 == comm.getAmount().compareTo(BigDecimal.ZERO)) { log.error("Validation issue {}", comm); throw new RejectionException(Reason.VALIDATION_FAIL); } return comm; } TradeCreationService(
            @Qualifier(TRADE_MACHINE_SERVICE) StateMachineService<TradeStatus, TradeEvent> stateMachineService,
            CurrentTimestamp currentTimestamp, TradeRepository tradeRepository,
            Validator validator, BalanceService balanceService, TotalAmountTradeLimiter amountTradeLimiter,
            WalletRepository walletRepository); }
TradeCreationService { public CreateOrderCommand map(Trade trade) { CreateOrderCommand comm = CreateOrderCommand.builder() .clientName(trade.getClient().getName()) .currencyFrom(trade.getCurrencyFrom().getCode()) .currencyTo(trade.getCurrencyTo().getCode()) .price(cleanBigDecimal(trade.getOpeningPrice())) .amount(cleanBigDecimal(trade.getOpeningAmount())) .id(trade.getId()) .orderId(trade.getId()) .build(); if (!validator.validate(comm).isEmpty() || 0 == comm.getAmount().compareTo(BigDecimal.ZERO)) { log.error("Validation issue {}", comm); throw new RejectionException(Reason.VALIDATION_FAIL); } return comm; } TradeCreationService(
            @Qualifier(TRADE_MACHINE_SERVICE) StateMachineService<TradeStatus, TradeEvent> stateMachineService,
            CurrentTimestamp currentTimestamp, TradeRepository tradeRepository,
            Validator validator, BalanceService balanceService, TotalAmountTradeLimiter amountTradeLimiter,
            WalletRepository walletRepository); @Transactional TradeDto createTradeNoSideValidation(Trade dependsOn, ClientConfig cfg, BigDecimal price, BigDecimal amount,
                                                boolean isSell, boolean validateBalance); @Transactional TradeDto createTrade(Trade dependsOn, ClientConfig cfg, BigDecimal price, BigDecimal amount, boolean isSell,
                                boolean validateBalance); CreateOrderCommand map(Trade trade); }
TradeCreationService { public CreateOrderCommand map(Trade trade) { CreateOrderCommand comm = CreateOrderCommand.builder() .clientName(trade.getClient().getName()) .currencyFrom(trade.getCurrencyFrom().getCode()) .currencyTo(trade.getCurrencyTo().getCode()) .price(cleanBigDecimal(trade.getOpeningPrice())) .amount(cleanBigDecimal(trade.getOpeningAmount())) .id(trade.getId()) .orderId(trade.getId()) .build(); if (!validator.validate(comm).isEmpty() || 0 == comm.getAmount().compareTo(BigDecimal.ZERO)) { log.error("Validation issue {}", comm); throw new RejectionException(Reason.VALIDATION_FAIL); } return comm; } TradeCreationService(
            @Qualifier(TRADE_MACHINE_SERVICE) StateMachineService<TradeStatus, TradeEvent> stateMachineService,
            CurrentTimestamp currentTimestamp, TradeRepository tradeRepository,
            Validator validator, BalanceService balanceService, TotalAmountTradeLimiter amountTradeLimiter,
            WalletRepository walletRepository); @Transactional TradeDto createTradeNoSideValidation(Trade dependsOn, ClientConfig cfg, BigDecimal price, BigDecimal amount,
                                                boolean isSell, boolean validateBalance); @Transactional TradeDto createTrade(Trade dependsOn, ClientConfig cfg, BigDecimal price, BigDecimal amount, boolean isSell,
                                boolean validateBalance); CreateOrderCommand map(Trade trade);  }