// Path: src/java/com/idega/block/email/data/Message.java
// public interface Message extends IDOEntity, TreeableEntity, UniqueIDCapable {
// 	
// 	public String getSubject();
// 	public void setSubject(String subject);
// 	
// 	public InputStream getMessageContent();
// 	public void setMessageContent(InputStream content);
// 	
// 	public Timestamp getReceived();
// 	public void setReceived(Timestamp received);
// 
// 	public boolean isDeleted();
// 	public void setDeleted(boolean deleted);
// 	
// 	public String getSenderAdress();
// 	public void setSenderAddress(String senderAddress);
// 	
// 	public Collection<ICFile> getAttachments();
// 	public void addAttachment(ICFile attachment) throws IDOAddRelationshipException;
// 	public void removeAttachment(ICFile attachment) throws IDORemoveRelationshipException;
// }
// 
// Path: src/java/com/idega/block/email/mailing/list/data/MailingList.java
// public interface MailingList extends IDOEntity, TreeableEntity, UniqueIDCapable, MetaDataCapable {
// 
// 	public Collection<User> getSenders();
// 	public void addSender(User sender) throws IDOAddRelationshipException;
// 	public void removeSender(User sender) throws IDORemoveRelationshipException;
// 	
// 	public Collection<User> getSubscribers();
// 	public void addSubscriber(User subscriber) throws IDOAddRelationshipException;
// 	public void removeSubscriber(User subscriber) throws IDORemoveRelationshipException;
// 	
// 	public Collection<User> getWaitingList();
// 	public void addToWaitingList(User subscriber) throws IDOAddRelationshipException;
// 	public void removeFromWaitingList(User subscriber) throws IDORemoveRelationshipException;
// 	
// 	public String getName();
// 	public void setName(String name);
// 	
// 	public String getNameInLatinLetters();
// 	public void setNameInLatinLetters(String nameInLatinLetters);
// 	
// 	public boolean isPrivate();
// 	public void setPrivate(boolean privateMailingList);
// 
// 	public boolean isDeleted();
// 	public void setDeleted(boolean deleted);
// 	
// 	public String getSenderAddress();
// 	public void setSenderAddress(String senderAddress);
// 	
// 	public String getSenderName();
// 	public void setSenderName(String senderName);
// 	
// 	public void addMessage(Message message) throws IDOAddRelationshipException;
// 	public void removeMessage(Message message) throws IDORemoveRelationshipException;
// 	public Collection<Message> getMessages();
// }
// 
// Path: src/java/com/idega/block/email/mailing/list/data/MailingListHome.java
// public interface MailingListHome extends IDOHome {
// 
// 	public MailingList create() throws CreateException;
// 	
// 	public MailingList findByPrimaryKey(Object key) throws FinderException;
// 	
// 	public MailingList findByName(String name) throws FinderException;
// 	
// 	public MailingList findByNameInLatinLetters(String nameInLatinLetters) throws FinderException;
// 	
// 	public MailingList findByUniqueId(String uniqueId) throws FinderException;
// 	
// 	public Collection<MailingList> findAll() throws FinderException;
// 	
// 	public Collection<MailingList> findAllByUser(User user) throws FinderException;
// 	
// 	public Collection<MailingList> findAllUserIsWaitingToBeConfirmed(User user) throws FinderException;
// 	
// 	public Collection<MailingList> findAllListsUserIsNotInvolved(User user) throws FinderException;
// 	
// 	public Collection<MailingList> findMailingListsByIds(String[] ids) throws FinderException;
// }


import java.util.ArrayList;
import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.CreateException;
import javax.ejb.FinderException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import com.idega.block.email.data.Message;
import com.idega.block.email.mailing.list.data.MailingList;
import com.idega.block.email.mailing.list.data.MailingListHome;
import com.idega.business.IBOLookup;
import com.idega.business.IBOLookupException;
import com.idega.data.IDOAddRelationshipException;
import com.idega.data.IDOLookup;
import com.idega.data.IDOLookupException;
import com.idega.data.IDORemoveRelationshipException;
import com.idega.idegaweb.IWMainApplication;
import com.idega.user.business.UserBusiness;
import com.idega.user.data.User;
import com.idega.util.ArrayUtil;
import com.idega.util.ListUtil;
import com.idega.util.StringHandler;
import com.idega.util.StringUtil;
package com.idega.block.email.mailing.list.business;




@Service
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class MailingListManagerImpl implements MailingListManager {

	private static final Logger LOGGER = Logger.getLogger(MailingListManagerImpl.class.getName());
	
	public MailingList createMailingList(String name) {
		if (StringUtil.isEmpty(name)) {
			LOGGER.warning("Name can not be empty!");
			return null;
		}
		
		MailingListHome mailingListHome = getMailingListHome();
		if (mailingListHome == null) {
			return null;
		}
		
		//	Creating new mailing list
		MailingList mailingList = null;
		try {
			mailingList = mailingListHome.create();
		} catch (CreateException e) {
			LOGGER.log(Level.WARNING, "Error creating mailing list: " + name, e);
		}
		if (mailingList == null) {
			return null;
		}
		
// Path: src/java/com/idega/block/email/data/Message.java
// public interface Message extends IDOEntity, TreeableEntity, UniqueIDCapable {
// 	
// 	public String getSubject();
// 	public void setSubject(String subject);
// 	
// 	public InputStream getMessageContent();
// 	public void setMessageContent(InputStream content);
// 	
// 	public Timestamp getReceived();
// 	public void setReceived(Timestamp received);
// 
// 	public boolean isDeleted();
// 	public void setDeleted(boolean deleted);
// 	
// 	public String getSenderAdress();
// 	public void setSenderAddress(String senderAddress);
// 	
// 	public Collection<ICFile> getAttachments();
// 	public void addAttachment(ICFile attachment) throws IDOAddRelationshipException;
// 	public void removeAttachment(ICFile attachment) throws IDORemoveRelationshipException;
// }
// 
// Path: src/java/com/idega/block/email/mailing/list/data/MailingList.java
// public interface MailingList extends IDOEntity, TreeableEntity, UniqueIDCapable, MetaDataCapable {
// 
// 	public Collection<User> getSenders();
// 	public void addSender(User sender) throws IDOAddRelationshipException;
// 	public void removeSender(User sender) throws IDORemoveRelationshipException;
// 	
// 	public Collection<User> getSubscribers();
// 	public void addSubscriber(User subscriber) throws IDOAddRelationshipException;
// 	public void removeSubscriber(User subscriber) throws IDORemoveRelationshipException;
// 	
// 	public Collection<User> getWaitingList();
// 	public void addToWaitingList(User subscriber) throws IDOAddRelationshipException;
// 	public void removeFromWaitingList(User subscriber) throws IDORemoveRelationshipException;
// 	
// 	public String getName();
// 	public void setName(String name);
// 	
// 	public String getNameInLatinLetters();
// 	public void setNameInLatinLetters(String nameInLatinLetters);
// 	
// 	public boolean isPrivate();
// 	public void setPrivate(boolean privateMailingList);
// 
// 	public boolean isDeleted();
// 	public void setDeleted(boolean deleted);
// 	
// 	public String getSenderAddress();
// 	public void setSenderAddress(String senderAddress);
// 	
// 	public String getSenderName();
// 	public void setSenderName(String senderName);
// 	
// 	public void addMessage(Message message) throws IDOAddRelationshipException;
// 	public void removeMessage(Message message) throws IDORemoveRelationshipException;
// 	public Collection<Message> getMessages();
// }
// 
// Path: src/java/com/idega/block/email/mailing/list/data/MailingListHome.java
// public interface MailingListHome extends IDOHome {
// 
// 	public MailingList create() throws CreateException;
// 	
// 	public MailingList findByPrimaryKey(Object key) throws FinderException;
// 	
// 	public MailingList findByName(String name) throws FinderException;
// 	
// 	public MailingList findByNameInLatinLetters(String nameInLatinLetters) throws FinderException;
// 	
// 	public MailingList findByUniqueId(String uniqueId) throws FinderException;
// 	
// 	public Collection<MailingList> findAll() throws FinderException;
// 	
// 	public Collection<MailingList> findAllByUser(User user) throws FinderException;
// 	
// 	public Collection<MailingList> findAllUserIsWaitingToBeConfirmed(User user) throws FinderException;
// 	
// 	public Collection<MailingList> findAllListsUserIsNotInvolved(User user) throws FinderException;
// 	
// 	public Collection<MailingList> findMailingListsByIds(String[] ids) throws FinderException;
// }


// Path: src/java/com/idega/block/email/mailing/list/business/MailingListManagerImpl.java
import java.util.ArrayList;
import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.CreateException;
import javax.ejb.FinderException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import com.idega.block.email.data.Message;
import com.idega.block.email.mailing.list.data.MailingList;
import com.idega.block.email.mailing.list.data.MailingListHome;
import com.idega.business.IBOLookup;
import com.idega.business.IBOLookupException;
import com.idega.data.IDOAddRelationshipException;
import com.idega.data.IDOLookup;
import com.idega.data.IDOLookupException;
import com.idega.data.IDORemoveRelationshipException;
import com.idega.idegaweb.IWMainApplication;
import com.idega.user.business.UserBusiness;
import com.idega.user.data.User;
import com.idega.util.ArrayUtil;
import com.idega.util.ListUtil;
import com.idega.util.StringHandler;
import com.idega.util.StringUtil;

package com.idega.block.email.mailing.list.business;




@Service
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class MailingListManagerImpl implements MailingListManager {

	private static final Logger LOGGER = Logger.getLogger(MailingListManagerImpl.class.getName());
	
	public MailingList createMailingList(String name) {
		if (StringUtil.isEmpty(name)) {
			LOGGER.warning("Name can not be empty!");
			return null;
		}
		
		MailingListHome mailingListHome = getMailingListHome();
		if (mailingListHome == null) {
			return null;
		}
		
		//	Creating new mailing list
		MailingList mailingList = null;
		try {
			mailingList = mailingListHome.create();
		} catch (CreateException e) {
			LOGGER.log(Level.WARNING, "Error creating mailing list: " + name, e);
		}
		if (mailingList == null) {
			return null;
		}
		
		mailingList.setName(name);