public Optional<EmailNotificationTemplate> findTemplateFor(String reasonKey, Locale locale) {
        Objects.requireNonNull(reasonKey, "Notification reason must not be null");
        Objects.requireNonNull(locale, "Locale must not be null");
        Map<Locale, EmailNotificationTemplate> localeMap = reasonMap.get(reasonKey);
        if (localeMap == null || localeMap.isEmpty()) {
            LOGGER.debug("No email template found for reason {0}, including shorter paths", reasonKey);
            return Optional.empty();
        } else {
            List<Locale> bestMatchingLocale = Arrays.asList(
                    Locale.lookup(LanguageRange.parse(locale.toLanguageTag()), supportedLocales),
                    Locale.getDefault(),
                    new Locale("en") // TODO(msavy): config-based default language?
            );
            return bestMatchingLocale.stream()
                    .filter(Objects::nonNull)
                    .map(localeMap::get)
                    .filter(Objects::nonNull)
                    .findFirst();
        }
    }
Find an email template for a provided reason (longest prefix match wins).

@param reasonKey the reason to find a template for
@param locale the locale to resolve
@return template, if a suitable one is found, otherwise empty
manager/api/rest-impl/src/main/java/io/apiman/manager/api/notifications/email/SimpleMailNotificationService.java