/*
 * LoginService.java
 * 
 * Created on 2007.10.15., 20:53:11
 * 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hu.nir.nmail.services;

import hu.nir.nmail.dbm.DataManager;
import hu.nir.nmail.ejb.entity.NmailUser;
import hu.nir.nmail.ejb.stateless.NmailUserLoginManager;
import hu.nir.nmail.ejb.stateless.NmailUserManager;
import hu.nir.nmail.spring.beans.LoginData;
import hu.nir.nmail.utils.NmailUtility;
import java.util.Map;

/**
 *
 * @author attila
 */
public class LoginService implements NmailService {
    
    private DataManager dataManager;
    
    public Map<String, Object> processCommand(Object... commands) {
        LoginData loginData = null;
        for (Object command : commands) {
            if (command instanceof LoginData) {
                loginData = (LoginData) command;
            }
        }
        
        if (loginData == null) {
            return null;
        }
        
        NmailUserLoginManager nmailUserLoginManager = dataManager.getNmailUserLoginManager();
        Long userId = nmailUserLoginManager.getUserId(loginData.getLoginName(), loginData.getPassword());
        
        NmailUserManager nmailUserManager = dataManager.getNmailUserManager();
        NmailUser nmailUser = nmailUserManager.getNmailUser(userId);
        return NmailUtility.toMap("nmailUser", nmailUser);
    }

    public DataManager getDataManager() {
        return dataManager;
    }

    public void setDataManager(DataManager dataManager) {
        this.dataManager = dataManager;
    }
}
