Rev 925 | Rev 961 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package ak.hostadmiral.core.model;
import java.util.Collection;
import ak.hostadmiral.util.ModelException;
import ak.hostadmiral.util.ModelSecurityException;
/**
*
* @hibernate.class table="mailaliases"
*/
public class MailAlias
extends GeneralModelObject
{
private String address;
private InetDomain domain;
private User owner;
private Collection destinations; // Collection(MailAliasDestintion)
protected MailAlias()
{
}
/**
*
* @hibernate.property
*/
public String getAddress()
{
return address;
}
protected void setAddress(String address)
{
this.address = address;
}
public void setAddress(User editor, String address)
throws ModelException
{
if(!editableBy(editor))
throw new ModelSecurityException();
this.address = address;
}
/**
*
* @hibernate.many-to-one
*/
public InetDomain getDomain()
{
return domain;
}
protected void setDomain(InetDomain domain)
{
this.domain = domain;
}
public void setDomain(User editor, InetDomain domain)
throws ModelException
{
if(!editableBy(editor))
throw new ModelSecurityException();
this.domain = domain;
}
/**
*
* @hibernate.many-to-one
*/
public User getOwner()
{
return owner;
}
protected void setOwner(User owner)
{
this.owner = owner;
}
public void setOwner(User editor, User owner)
throws ModelException
{
if(!editableBy(editor))
throw new ModelSecurityException();
this.owner = owner;
}
/**
* @return Collection(MailAliasDestination)
*
* @hibernate.bag inverse="true" cascade="all-delete-orphan"
* @hibernate.collection-key column="alias"
* @hibernate.collection-one-to-many class="ak.hostadmiral.core.model.MailAliasDestination"
*/
protected Collection getDestinations()
{
return destinations;
}
/**
* @return Collection(MailAliasDestination)
*/
public Collection getDestinations(User editor)
throws ModelException
{
if(mayChangeDestinations(editor))
return destinations;
else if(viewableBy(editor))
return java.util.Collections.unmodifiableCollection(destinations);
else
throw new ModelSecurityException();
}
/**
* @param destinations Collection(MailAliasDestination)
*/
protected void setDestinations(Collection destinations)
{
this.destinations = destinations;
}
public String getTypeKey()
{
return ak.hostadmiral.core.CoreResources.TYPE_MAIL_ALIAS;
}
public String getIdentKey()
{
return ak.hostadmiral.core.CoreResources.IDENT_MAIL_ALIAS;
}
public Object[] getIdentParams()
{
return new Object[] { getAddress(), getDomain().getName() };
}
public boolean viewableBy(User user)
{
return user.isSuperuser() || user.equals(domain.getOwner()) || user.equals(owner);
}
public boolean editableBy(User user)
{
return user.isSuperuser() || user.equals(domain.getOwner());
}
public boolean mayChangeDestinations(User user)
{
return user.isSuperuser() || user.equals(domain.getOwner()) || user.equals(owner);
}
public boolean deleteableBy(User user)
{
return user.isSuperuser() || user.equals(domain.getOwner());
}
protected static boolean allowedToCreate(MailAliasManager manager, User editor)
throws ModelException
{
return editor.isSuperuser()
|| InetDomainManager.getInstance().areInetDomainsAvailable(editor);
}
}