private void processReasonMap(Path root, String localeTag, ReasonMap reasonMapFromFile) {
            String reason = "";
        try {
            for (Entry<String, EmailTemplateFileEntry> entry : reasonMapFromFile.entrySet()) {
                reason = entry.getKey();
                EmailTemplateFileEntry fileEntry = entry.getValue();
                EmailNotificationTemplate tpl = new EmailNotificationTemplate();
                tpl.setNotificationReason(reason);
                tpl.setLocale(localeTag);
                tpl.setSubject(fileEntry.subject());
                tpl.setHtmlBody(Files.readString(root.getParent().resolve(fileEntry.html())));
                tpl.setPlainBody(Files.readString(root.getParent().resolve(fileEntry.plain())));
                tpl.setCategory(fileEntry.category());
                Locale locale = Locale.forLanguageTag(localeTag);
                reasonMap.computeIfAbsent(reason, (val) -> new HashMap<>(5)).put(locale, tpl);
                // For each category we now have multiple locales, so we have an extra layer before we get to our list of notification templates.
                Map<Locale, List<EmailNotificationTemplate>> catLocales = categoryToTemplateMap.computeIfAbsent(tpl.getCategory(), val -> new HashMap<>());
                // Instantiate the list if not already there. We have: category -> locale -> list<templates>
                catLocales.computeIfAbsent(locale, val -> new ArrayList<>()).add(tpl);
                LOGGER.trace("Adding template ({0}): reason {1} -> {2}", locale, tpl.getNotificationReason(), tpl);
                LOGGER.trace("Adding template ({0}): category {1} -> {2}", locale, tpl.getCategory(), tpl);
            }
        } catch (IOException ioe) {
            LOGGER.error(ioe, "An IO exception occurred attempting to process an email template. Reason code: {0}. Locale: {1}.", reason, localeTag);
            throw new UncheckedIOException(ioe);
        }
    }
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