All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.automatiko.engine.addons.usertasks.email.impl.DefaultEmailAddressResolver Maven / Gradle / Ivy

package io.automatiko.engine.addons.usertasks.email.impl;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

import jakarta.enterprise.context.ApplicationScoped;

import io.automatiko.engine.addons.usertasks.email.EmailAddressResolver;
import io.quarkus.arc.DefaultBean;

@DefaultBean
@ApplicationScoped
public class DefaultEmailAddressResolver implements EmailAddressResolver {

    private static final String EMAIL_REGEX = "^\\s*?(.+)@(.+?)\\s*$";
    private static final Pattern EMAIL_PATTERN = Pattern.compile(EMAIL_REGEX);

    @Override
    public Map resolve(Collection users, Collection groups) {
        Map emails = new HashMap<>();

        if (users != null) {
            users.stream().filter(s -> EMAIL_PATTERN.matcher(s).matches()).forEach(s -> emails.put(s, s));
        }
        if (groups != null) {
            groups.stream().filter(s -> EMAIL_PATTERN.matcher(s).matches()).forEach(s -> emails.put(s, s));
        }

        return emails;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy