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

woko.ext.usermanagement.mail.BindingHelper Maven / Gradle / Ivy

There is a newer version: 2.4-beta7
Show newest version
package woko.ext.usermanagement.mail;

import woko.Woko;
import woko.ext.usermanagement.core.User;
import woko.mail.MailService;
import woko.mail.MailTemplate;

import java.util.HashMap;
import java.util.Map;

public final class BindingHelper {

    public static final String APP_NAME = "appName";
    public static final String USERNAME = "username";
    public static final String APP_URL = "appUrl";
    public static final String WOKO = "woko";
    public static final String USER = "user";

    @SuppressWarnings("unckeched")
    public static  T getBindingValueSafe(Map binding, String key) {
        T obj = (T)binding.get(key);
        if (obj==null) {
            throw new IllegalArgumentException(key + " not found in binding " + binding);
        }
        return obj;
    }

    public static String getAppName(Map binding) {
        return getBindingValueSafe(binding, APP_NAME);
    }

    public static String getUsername(Map binding) {
        return getBindingValueSafe(binding, USERNAME);
    }

    public static String getAppUrl(Map binding) {
        return getBindingValueSafe(binding, APP_URL);
    }

    public static  Map newBinding(Woko woko, T user, String appName, MailService mailService) {
        Map res = new HashMap();
        res.put(WOKO, woko);
        res.put(USER, user);
        res.put(USERNAME, user.getUsername());
        res.put(APP_NAME, appName);
        res.put(APP_URL, mailService.getAppUrl());
        return res;
    }

    public static Map createDefaultMailTemplates() {
        Map res = new HashMap();
        res.put(MailTemplateRegister.TEMPLATE_NAME, new MailTemplateRegister());
        res.put(MailTemplatePassword.TEMPLATE_NAME, new MailTemplatePassword());
        res.put(MailTemplateResetPassword.TEMPLATE_NAME, new MailTemplateResetPassword());
        res.put(MailTemplateAccountActivated.TEMPLATE_NAME, new MailTemplateAccountActivated());
        return res;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy