Subversion Repositories general

Rev

Rev 1056 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package ak.hostadmiral.core.model;

import ak.hostadmiral.util.ModelException;
import ak.hostadmiral.util.ModelSecurityException;

/**
 *
 * @hibernate.class table="mailaliasdests"
 */
public class MailAliasDestination
        extends GeneralModelObject
{
        private MailAlias alias;
        private Mailbox   mailbox;
        private String    email;

        protected MailAliasDestination()
        {
        }

        /**
         *
         * @hibernate.many-to-one
         */
        public MailAlias getAlias()
        {
                return alias;
        }

        protected void setAlias(MailAlias alias)
        {
                this.alias = alias;
        }

        public void setAlias(User editor, MailAlias alias)
                throws ModelException
        {
                if(this.alias != null && !editableBy(editor))
                        throw new ModelSecurityException();

                this.alias = alias;
        }

        /**
         *
         * @hibernate.many-to-one
         */
        public Mailbox getMailbox()
        {
                return mailbox;
        }

        protected void setMailbox(Mailbox mailbox)
        {
                this.mailbox = mailbox;
        }

        public void setMailbox(User editor, Mailbox mailbox)
                throws ModelException
        {
                if(!editableBy(editor))
                        throw new ModelSecurityException();

                this.mailbox = mailbox;
        }

        /**
         *
         * @hibernate.property
         */
        public String getEmail()
        {
                return email;
        }

        protected void setEmail(String email)
        {
                this.email = email;
        }

        public void setEmail(User editor, String email)
                throws ModelException
        {
                if(!editableBy(editor))
                        throw new ModelSecurityException();

                this.email = email;
        }

        public String getTypeKey()
        {
                return ak.hostadmiral.core.resources.CoreResources.TYPE_MAIL_ALIAS_DESTINATION;
        }

        public String getIdentKey()
        {
                if(getMailbox() == null)
                        return ak.hostadmiral.core.resources.CoreResources.IDENT_MAIL_ALIAS_DESTINATION_EXTERNAL;
                else
                        return ak.hostadmiral.core.resources.CoreResources.IDENT_MAIL_ALIAS_DESTINATION_INTERNAL;
        }

        public Object[] getIdentParams()
        {
                if(getMailbox() == null)
                        return new Object[] { getEmail() };
                else
                        return new Object[] { getMailbox().getLogin(), getMailbox().getDomain().getName() };
        }

        public boolean viewableBy(User user)
        {
                return alias.viewableBy(user);
        }

        public boolean editableBy(User user)
        {
                return alias.mayChangeDestinations(user);
        }

        public boolean deleteableBy(User user)
        {
                return alias.mayChangeDestinations(user);
        }

        protected static boolean allowedToCreate(MailAliasDestinationManager manager, User editor)
                throws ModelException
        {
                return true;
        }

        public String toString()
        {
                return "MailAliasDestination id=[" + getId() + "] alias=["
                        + (alias == null ? "_none_" : alias.getAddress() + "@"
                                + (alias.getDomain() == null ? "_none_" : alias.getDomain().getName()))
                        + "] mailbox=[" + (mailbox == null ? "_none_" : mailbox.getLogin() + "@"
                                + (mailbox.getDomain() == null ? "_none_" : mailbox.getDomain().getName()))
                        + "] email=[" + (email == null ? "_none_" : email) + "]";
        }
}