use of com.github.robozonky.api.notifications.SellingStartedEvent in project robozonky by RoboZonky.
the class Selling method sell.
private void sell(final Portfolio portfolio, final SellStrategy strategy, final Authenticated auth) {
final PortfolioOverview overview = portfolio.calculateOverview();
final Set<InvestmentDescriptor> eligible = portfolio.getActiveForSecondaryMarketplace().parallel().map(i -> getDescriptor(i, auth)).collect(Collectors.toSet());
Events.fire(new SellingStartedEvent(eligible, overview));
final Collection<Investment> investmentsSold = strategy.recommend(eligible, overview).peek(r -> Events.fire(new SaleRecommendedEvent(r))).map(r -> auth.call(zonky -> processInvestment(zonky, r))).flatMap(o -> o.map(Stream::of).orElse(Stream.empty())).collect(Collectors.toSet());
Events.fire(new SellingCompletedEvent(investmentsSold, portfolio.calculateOverview()));
}
use of com.github.robozonky.api.notifications.SellingStartedEvent in project robozonky by RoboZonky.
the class JmxListenerService method newListener.
private static <T extends Event> EventListener<T> newListener(final Class<T> eventType) {
if (Objects.equals(eventType, ExecutionStartedEvent.class)) {
return (event, sessionInfo) -> callOnPortfolio(bean -> bean.handle((ExecutionStartedEvent) event));
} else if (Objects.equals(eventType, ExecutionCompletedEvent.class)) {
return (event, sessionInfo) -> {
final ExecutionCompletedEvent evt = (ExecutionCompletedEvent) event;
callOnRuntime(bean -> bean.handle(evt, sessionInfo));
callOnPortfolio(bean -> bean.handle(evt));
};
} else if (Objects.equals(eventType, SellingStartedEvent.class)) {
return (event, sessionInfo) -> callOnPortfolio(bean -> bean.handle((SellingStartedEvent) event));
} else if (Objects.equals(eventType, SellingCompletedEvent.class)) {
return (event, sessionInfo) -> callOnPortfolio(bean -> bean.handle((SellingCompletedEvent) event));
} else if (Objects.equals(eventType, PurchasingStartedEvent.class)) {
return (event, sessionInfo) -> callOnPortfolio(bean -> bean.handle((PurchasingStartedEvent) event));
} else if (Objects.equals(eventType, PurchasingCompletedEvent.class)) {
return (event, sessionInfo) -> callOnPortfolio(bean -> bean.handle((PurchasingCompletedEvent) event));
} else if (Objects.equals(eventType, InvestmentDelegatedEvent.class)) {
return (event, sessionInfo) -> callOnOperations(bean -> bean.handle((InvestmentDelegatedEvent) event));
} else if (Objects.equals(eventType, InvestmentRejectedEvent.class)) {
return (event, sessionInfo) -> callOnOperations(bean -> bean.handle((InvestmentRejectedEvent) event));
} else if (Objects.equals(eventType, InvestmentMadeEvent.class)) {
return (event, sessionInfo) -> callOnOperations(bean -> bean.handle((InvestmentMadeEvent) event));
} else if (Objects.equals(eventType, SaleOfferedEvent.class)) {
return (event, sessionInfo) -> callOnOperations(bean -> bean.handle((SaleOfferedEvent) event));
} else if (Objects.equals(eventType, InvestmentPurchasedEvent.class)) {
return (event, sessionInfo) -> callOnOperations(bean -> bean.handle((InvestmentPurchasedEvent) event));
} else {
return null;
}
}
Aggregations