// Path: src/java/is/idega/idegaweb/egov/message/data/MessageReceiver.java
// public interface MessageReceiver extends IDOEntity, User {
// 
// 	/**
// 	 * @see is.idega.idegaweb.egov.message.data.MessageReceiverBMPBean#receiveEmails
// 	 */
// 	public boolean receiveEmails();
// 
// 	/**
// 	 * @see is.idega.idegaweb.egov.message.data.MessageReceiverBMPBean#setReceiveEmails
// 	 */
// 	public void setReceiveEmails(boolean receiveEmails);
// 
// 	/**
// 	 * @see is.idega.idegaweb.egov.message.data.MessageReceiverBMPBean#receiveMessagesToBox
// 	 */
// 	public boolean receiveMessagesToBox();
// 
// 	/**
// 	 * @see is.idega.idegaweb.egov.message.data.MessageReceiverBMPBean#setReceiveMessagesToBox
// 	 */
// 	public void setReceiveMessagesToBox(boolean receiveMessages);
// }
// 
// Path: src/java/is/idega/idegaweb/egov/message/data/MessageReceiverHome.java
// public interface MessageReceiverHome extends IDOHome {
// 
// 	public MessageReceiver create() throws CreateException;
// 
// 	public MessageReceiver findByPrimaryKey(Object pk) throws FinderException;
// }


import is.idega.idegaweb.egov.message.data.MessageReceiver;
import is.idega.idegaweb.egov.message.data.MessageReceiverHome;
import java.util.Collection;
import javax.ejb.FinderException;
import com.idega.business.IBOSessionBean;
import com.idega.data.IDOLookup;
import com.idega.data.IDOLookupException;
import com.idega.idegaweb.IWPropertyList;
import com.idega.user.business.UserProperties;
import com.idega.user.data.User;
package is.idega.idegaweb.egov.message.business;





/**
 * @author Laddi
 * 
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates. To enable and disable the creation of type
 * comments go to Window>Preferences>Java>Code Generation.
 */
public class MessageSessionBean extends IBOSessionBean implements MessageSession {

	public static final String MESSAGE_PROPERTIES = "message_properties";
	public static final String USER_PROP_SEND_TO_MESSAGE_BOX = "msg_send_box";
	public static final String USER_PROP_SEND_TO_EMAIL = "msg_send_email";

	public boolean getIfUserCanReceiveEmails(User user) {
		return hasEmail(user) && getIfUserPreferesMessageByEmail();
	}

	private boolean hasEmail(User user) {
		Collection emails = user.getEmails();
// Path: src/java/is/idega/idegaweb/egov/message/data/MessageReceiver.java
// public interface MessageReceiver extends IDOEntity, User {
// 
// 	/**
// 	 * @see is.idega.idegaweb.egov.message.data.MessageReceiverBMPBean#receiveEmails
// 	 */
// 	public boolean receiveEmails();
// 
// 	/**
// 	 * @see is.idega.idegaweb.egov.message.data.MessageReceiverBMPBean#setReceiveEmails
// 	 */
// 	public void setReceiveEmails(boolean receiveEmails);
// 
// 	/**
// 	 * @see is.idega.idegaweb.egov.message.data.MessageReceiverBMPBean#receiveMessagesToBox
// 	 */
// 	public boolean receiveMessagesToBox();
// 
// 	/**
// 	 * @see is.idega.idegaweb.egov.message.data.MessageReceiverBMPBean#setReceiveMessagesToBox
// 	 */
// 	public void setReceiveMessagesToBox(boolean receiveMessages);
// }
// 
// Path: src/java/is/idega/idegaweb/egov/message/data/MessageReceiverHome.java
// public interface MessageReceiverHome extends IDOHome {
// 
// 	public MessageReceiver create() throws CreateException;
// 
// 	public MessageReceiver findByPrimaryKey(Object pk) throws FinderException;
// }


// Path: src/java/is/idega/idegaweb/egov/message/business/MessageSessionBean.java
import is.idega.idegaweb.egov.message.data.MessageReceiver;
import is.idega.idegaweb.egov.message.data.MessageReceiverHome;
import java.util.Collection;
import javax.ejb.FinderException;
import com.idega.business.IBOSessionBean;
import com.idega.data.IDOLookup;
import com.idega.data.IDOLookupException;
import com.idega.idegaweb.IWPropertyList;
import com.idega.user.business.UserProperties;
import com.idega.user.data.User;

package is.idega.idegaweb.egov.message.business;





/**
 * @author Laddi
 * 
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates. To enable and disable the creation of type
 * comments go to Window>Preferences>Java>Code Generation.
 */
public class MessageSessionBean extends IBOSessionBean implements MessageSession {

	public static final String MESSAGE_PROPERTIES = "message_properties";
	public static final String USER_PROP_SEND_TO_MESSAGE_BOX = "msg_send_box";
	public static final String USER_PROP_SEND_TO_EMAIL = "msg_send_email";

	public boolean getIfUserCanReceiveEmails(User user) {
		return hasEmail(user) && getIfUserPreferesMessageByEmail();
	}

	private boolean hasEmail(User user) {
		Collection emails = user.getEmails();
		return emails != null && !emails.isEmpty();