Search in sources :

Example 1 with SessionInfo

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;
}
Also used : Email(org.apache.commons.mail.Email) UnifiedMap(org.eclipse.collections.impl.map.mutable.UnifiedMap) Logger(org.slf4j.Logger) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) InvestmentBased(com.github.robozonky.api.notifications.InvestmentBased) Collectors(java.util.stream.Collectors) FastList(org.eclipse.collections.impl.list.mutable.FastList) Event(com.github.robozonky.api.notifications.Event) Consumer(java.util.function.Consumer) Financial(com.github.robozonky.api.notifications.Financial) SessionInfo(com.github.robozonky.api.notifications.SessionInfo) Stream(java.util.stream.Stream) PortfolioOverview(com.github.robozonky.api.strategies.PortfolioOverview) SimpleEmail(org.apache.commons.mail.SimpleEmail) Map(java.util.Map) EventListener(com.github.robozonky.api.notifications.EventListener) EmailException(org.apache.commons.mail.EmailException) LoanBased(com.github.robozonky.api.notifications.LoanBased) Rating(com.github.robozonky.api.remote.enums.Rating) Defaults(com.github.robozonky.internal.api.Defaults) Collections(java.util.Collections) Email(org.apache.commons.mail.Email) SimpleEmail(org.apache.commons.mail.SimpleEmail) SimpleEmail(org.apache.commons.mail.SimpleEmail)

Example 2 with SessionInfo

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));
}
Also used : SessionInfo(com.github.robozonky.api.notifications.SessionInfo)

Example 3 with SessionInfo

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;
    }
}
Also used : RoboZonkyStartingEvent(com.github.robozonky.api.notifications.RoboZonkyStartingEvent) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) SystemExitServiceLoader(com.github.robozonky.util.SystemExitServiceLoader) Scheduler(com.github.robozonky.util.Scheduler) SessionInfo(com.github.robozonky.api.notifications.SessionInfo) UpdateMonitor(com.github.robozonky.app.version.UpdateMonitor) CommandLine(com.github.robozonky.app.configuration.CommandLine) Charset(java.nio.charset.Charset) Locale(java.util.Locale) Duration(java.time.Duration) Management(com.github.robozonky.app.management.Management) SystemExitService(com.github.robozonky.util.SystemExitService) Lifecycle(com.github.robozonky.app.runtime.Lifecycle) Optional(java.util.Optional) ReturnCode(com.github.robozonky.api.ReturnCode) InvestmentMode(com.github.robozonky.app.configuration.InvestmentMode) RoboZonkyStartingEvent(com.github.robozonky.api.notifications.RoboZonkyStartingEvent) UpdateMonitor(com.github.robozonky.app.version.UpdateMonitor) Management(com.github.robozonky.app.management.Management)

Example 4 with SessionInfo

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());
}
Also used : SessionInfo(com.github.robozonky.api.notifications.SessionInfo) ToStringBuilder(com.github.robozonky.internal.api.ToStringBuilder) Investor(com.github.robozonky.app.investing.Investor) Logger(org.slf4j.Logger) Events(com.github.robozonky.app.Events) ConfirmationProviderLoader(com.github.robozonky.common.extensions.ConfirmationProviderLoader) Authenticated(com.github.robozonky.app.authentication.Authenticated) Credentials(com.github.robozonky.common.secrets.Credentials) LoggerFactory(org.slf4j.LoggerFactory) Optional(java.util.Optional) SecretProvider(com.github.robozonky.common.secrets.SecretProvider) ConfirmationProvider(com.github.robozonky.api.confirmations.ConfirmationProvider) ToStringBuilder(com.github.robozonky.internal.api.ToStringBuilder) SessionInfo(com.github.robozonky.api.notifications.SessionInfo) Credentials(com.github.robozonky.common.secrets.Credentials) SecretProvider(com.github.robozonky.common.secrets.SecretProvider)

Example 5 with SessionInfo

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;
    }
}
Also used : EventListenerSupplier(com.github.robozonky.api.notifications.EventListenerSupplier) Logger(org.slf4j.Logger) Collection(java.util.Collection) ApiProvider(com.github.robozonky.common.remote.ApiProvider) LoggerFactory(org.slf4j.LoggerFactory) RawLoan(com.github.robozonky.api.remote.entities.RawLoan) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) SessionInfo(com.github.robozonky.api.notifications.SessionInfo) List(java.util.List) Stream(java.util.stream.Stream) RequestId(com.github.robozonky.api.confirmations.RequestId) EventListener(com.github.robozonky.api.notifications.EventListener) Optional(java.util.Optional) RoboZonkyTestingEvent(com.github.robozonky.api.notifications.RoboZonkyTestingEvent) Comparator(java.util.Comparator) ConfirmationProvider(com.github.robozonky.api.confirmations.ConfirmationProvider) SessionInfo(com.github.robozonky.api.notifications.SessionInfo) EventListener(com.github.robozonky.api.notifications.EventListener) RoboZonkyTestingEvent(com.github.robozonky.api.notifications.RoboZonkyTestingEvent)

Aggregations

SessionInfo (com.github.robozonky.api.notifications.SessionInfo)5 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Optional (java.util.Optional)3 ConfirmationProvider (com.github.robozonky.api.confirmations.ConfirmationProvider)2 EventListener (com.github.robozonky.api.notifications.EventListener)2 Collection (java.util.Collection)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 ReturnCode (com.github.robozonky.api.ReturnCode)1 RequestId (com.github.robozonky.api.confirmations.RequestId)1 Event (com.github.robozonky.api.notifications.Event)1 EventListenerSupplier (com.github.robozonky.api.notifications.EventListenerSupplier)1 Financial (com.github.robozonky.api.notifications.Financial)1 InvestmentBased (com.github.robozonky.api.notifications.InvestmentBased)1 LoanBased (com.github.robozonky.api.notifications.LoanBased)1 RoboZonkyStartingEvent (com.github.robozonky.api.notifications.RoboZonkyStartingEvent)1 RoboZonkyTestingEvent (com.github.robozonky.api.notifications.RoboZonkyTestingEvent)1 RawLoan (com.github.robozonky.api.remote.entities.RawLoan)1 Rating (com.github.robozonky.api.remote.enums.Rating)1