@SuppressWarnings("unused") @CommandHandler public void handle(CancelTransactionCommand cmd) { if (type == TransactionType.BUY) { apply(new BuyTransactionCancelledEvent(transactionId, amountOfItems, amountOfExecutedItems)); } else if (type == TransactionType.SELL) { apply(new SellTransactionCancelledEvent(transactionId, amountOfItems, amountOfExecutedItems)); } }
@CommandHandler public void handle(ReserveCashCommand cmd) { TransactionId transactionId = cmd.getTransactionId(); long amountToReserve = cmd.getAmountOfMoneyToReserve(); if (amountOfMoney >= amountToReserve) { apply(new CashReservedEvent(portfolioId, transactionId, amountToReserve)); } else { apply(new CashReservationRejectedEvent(portfolioId, transactionId, amountToReserve)); } }
/** * Stars a Task. * * @param command star Task */ @CommandHandler void on(StarTaskCommand command) { apply(new TaskStarredEvent(command.getId())); }
@CommandHandler public Company(CreateCompanyCommand cmd) { long companyValue = cmd.getCompanyValue(); if (companyValue < 0) { throw new IllegalArgumentException("Company value should be a positive number"); } long amountOfShares = cmd.getAmountOfShares(); if (amountOfShares < 0) { throw new IllegalArgumentException("Amount of shares should be a positive number"); } apply(new CompanyCreatedEvent(cmd.getCompanyId(), cmd.getCompanyName(), companyValue, amountOfShares)); }
@CommandHandler public void handle(ConfirmCashReservationCommand cmd) { apply(new CashReservationConfirmedEvent(portfolioId, cmd.getTransactionId(), cmd.getAmountOfMoneyToConfirmInCents())); }
@CommandHandler public Customer(SignUpCustomerCommand command) { Assert.isTrue(command.getEmail().contains("@"), () -> "Email must be valid."); apply(new CustomerSignedUpEvent(command.getId(), command.getEmail())); }
@CommandHandler public void handle(ConfirmItemReservationForPortfolioCommand cmd) { apply(new ItemReservationConfirmedForPortfolioEvent(portfolioId, cmd.getOrderBookId(), cmd.getTransactionId(), cmd.getAmountOfItemsToConfirm())); }
@CommandHandler public User(CreateUserCommand cmd) { apply(new UserCreatedEvent(cmd.getUserId(), cmd.getName(), cmd.getUsername(), hashOf(cmd.getPassword().toCharArray()))); }
@CommandHandler public void handle(CancelItemReservationForPortfolioCommand cmd) { apply(new ItemReservationCancelledForPortfolioEvent( portfolioId, cmd.getOrderBookId(), cmd.getTransactionId(), cmd.getAmountOfItemsToCancel())); }
/** * Modifies a Task title. * * @param command modify Task title */ @CommandHandler void on(ModifyTaskTitleCommand command) { assertNotCompleted(); apply(new TaskTitleModifiedEvent(command.getId(), command.getTitle())); }
@CommandHandler public void handle(ConfirmItemReservationForPortfolioCommand cmd) { apply(new ItemReservationConfirmedForPortfolioEvent(portfolioId, cmd.getOrderBookId(), cmd.getTransactionId(), cmd.getAmountOfItemsToConfirm())); }
@CommandHandler public void handle(ModifyMenuItemCommand command) { Assert.state(active, () -> "Item is inactive."); Assert.isFalse(command.getDescription().isEmpty(), () -> "Description must be present."); apply(new MenuItemModifiedEvent(id, command.getDescription(), command.getPrice())); }
@CommandHandler public Company(CreateCompanyCommand cmd) { apply(new CompanyCreatedEvent( cmd.getCompanyId(), cmd.getCompanyName(), cmd.getCompanyValue(), cmd.getAmountOfShares() )); }
@CommandHandler public BankTransfer(CreateBankTransferCommand command) { apply(new BankTransferCreatedEvent(command.getBankTransferId(), command.getSourceBankAccountId(), command.getDestinationBankAccountId(), command.getAmount())); }
@CommandHandler public Transaction(StartBuyTransactionCommand cmd) { apply(new BuyTransactionStartedEvent(cmd.getTransactionId(), cmd.getOrderBookId(), cmd.getPortfolioId(), cmd.getTradeCount(), cmd.getPricePerItem())); }
@CommandHandler public Transaction(StartSellTransactionCommand cmd) { apply(new SellTransactionStartedEvent(cmd.getTransactionId(), cmd.getOrderBookId(), cmd.getPortfolioId(), cmd.getTradeCount(), cmd.getPricePerItem())); }
@CommandHandler public Transaction(StartSellTransactionCommand cmd) { apply(new SellTransactionStartedEvent(cmd.getTransactionId(), cmd.getOrderBookId(), cmd.getPortfolioId(), cmd.getTradeCount(), cmd.getPricePerItem())); }
@CommandHandler public void handle(CreateSellOrderCommand cmd) { apply(new SellOrderPlacedEvent(orderBookId, cmd.getOrderId(), cmd.getTransactionId(), cmd.getTradeCount(), cmd.getItemPrice(), cmd.getPortfolioId())); executeTrades(); }
@CommandHandler public void on(AddItemToOrderCommand command) { checkStatus(); Assert.isTrue(command.getQuantity() > 0, () -> "Must add at least one item."); apply(new ItemAddedToOrderEvent(id, command.getOrderItemId(), command.getMenuItemId(), command.getPrice(), command.getQuantity())); }