use of com.github.robozonky.api.notifications.SessionInfo in project robozonky by RoboZonky.
the class AbstractEmailingListener method createNewEmail.
private static Email createNewEmail(final NotificationProperties properties, final SessionInfo session) throws EmailException {
final Email email = new SimpleEmail();
email.setCharset(Defaults.CHARSET.displayName());
email.setHostName(properties.getSmtpHostname());
email.setSmtpPort(properties.getSmtpPort());
email.setStartTLSRequired(properties.isStartTlsRequired());
email.setSSLOnConnect(properties.isSslOnConnectRequired());
email.setAuthentication(properties.getSmtpUsername(), properties.getSmtpPassword());
final String sessionName = session.getName().map(n -> "RoboZonky '" + n + "'").orElse("RoboZonky");
email.setFrom(properties.getSender(), sessionName);
email.addTo(properties.getRecipient());
return email;
}
use of com.github.robozonky.api.notifications.SessionInfo in project robozonky by RoboZonky.
the class JmxListenerServiceTest method handleEvent.
private <T extends Event> void handleEvent(final T event) {
final JmxListenerService service = new JmxListenerService();
final EventListenerSupplier<T> r = service.findListener((Class<T>) event.getClass());
final EventListener<T> listener = r.get().get();
listener.handle(event, new SessionInfo(USERNAME));
}
use of com.github.robozonky.api.notifications.SessionInfo in project robozonky by RoboZonky.
the class App method execute.
private static ReturnCode execute(final InvestmentMode mode) {
App.SHUTDOWN_HOOKS.register(() -> Optional.of((r) -> Scheduler.inBackground().close()));
Events.fire(new RoboZonkyStartingEvent());
try {
ensureLiveness();
Scheduler.inBackground().submit(new UpdateMonitor(), Duration.ofDays(1));
App.SHUTDOWN_HOOKS.register(new Management(LIFECYCLE));
final String sessionName = Events.getSessionInfo().flatMap(SessionInfo::getName).orElse(null);
App.SHUTDOWN_HOOKS.register(new RoboZonkyStartupNotifier(sessionName));
return mode.apply(LIFECYCLE);
} catch (final Throwable t) {
LOGGER.error("Caught unexpected exception, terminating daemon.", t);
return ReturnCode.ERROR_UNEXPECTED;
}
}
use of com.github.robozonky.api.notifications.SessionInfo in project robozonky by RoboZonky.
the class OperatingMode method configure.
public Optional<InvestmentMode> configure(final CommandLine cli, final Authenticated auth) {
final SecretProvider secretProvider = auth.getSecretProvider();
final boolean isDryRun = cli.getTweaksFragment().isDryRunEnabled();
// initialize SessionInfo before the robot potentially sends the first notification
Events.initialize(new SessionInfo(secretProvider.getUsername(), cli.getName(), isDryRun));
// and now initialize the chosen mode of operation
return cli.getConfirmationFragment().getConfirmationCredentials().map(value -> new Credentials(value, secretProvider)).map(credentials -> this.getZonkyProxyBuilder(credentials, secretProvider)).orElse(Optional.of(new Investor.Builder())).map(builder -> {
if (isDryRun) {
LOGGER.info("RoboZonky is doing a dry run. It will not invest any real money.");
builder.asDryRun();
}
builder.asUser(secretProvider.getUsername());
return this.getInvestmentMode(cli, auth, builder);
}).orElse(Optional.empty());
}
use of com.github.robozonky.api.notifications.SessionInfo in project robozonky by RoboZonky.
the class Checker method notifications.
public static boolean notifications(final String username, final List<EventListenerSupplier<RoboZonkyTestingEvent>> refreshables) {
final Collection<EventListener<RoboZonkyTestingEvent>> listeners = refreshables.stream().flatMap(r -> r.get().map(Stream::of).orElse(Stream.empty())).collect(Collectors.toSet());
if (listeners.size() > 0) {
final SessionInfo sessionInfo = new SessionInfo(username);
final RoboZonkyTestingEvent evt = new RoboZonkyTestingEvent();
listeners.forEach(l -> l.handle(evt, sessionInfo));
return true;
} else {
return false;
}
}
Aggregations