2010-10-05 21:42:07 +02:00
|
|
|
package de.hsadmin.mods.email;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
2011-05-20 17:25:11 +02:00
|
|
|
import javax.persistence.EntityManager;
|
|
|
|
import javax.persistence.Query;
|
|
|
|
|
2010-10-05 21:42:07 +02:00
|
|
|
import de.hsadmin.core.model.AbstractEntity;
|
2011-05-20 16:25:45 +02:00
|
|
|
import de.hsadmin.core.model.AbstractModuleImpl;
|
|
|
|
import de.hsadmin.core.model.AuthorisationException;
|
2010-10-05 21:42:07 +02:00
|
|
|
import de.hsadmin.core.model.HSAdminException;
|
2011-05-20 17:25:11 +02:00
|
|
|
import de.hsadmin.mods.pac.Pac;
|
2010-10-05 21:42:07 +02:00
|
|
|
|
|
|
|
public class EMailAliasModuleImpl extends AbstractModuleImpl {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<AbstractEntity> search(Class<? extends AbstractEntity> entityClass,
|
|
|
|
String condition, String orderBy) throws HSAdminException {
|
|
|
|
if (orderBy == null || orderBy.length() == 0) {
|
2010-12-16 18:24:21 +01:00
|
|
|
orderBy = "ORDER BY obj.name ASC";
|
2010-10-05 21:42:07 +02:00
|
|
|
}
|
|
|
|
return super.search(entityClass, condition, orderBy);
|
|
|
|
}
|
2011-05-20 16:12:39 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public AbstractEntity add(AbstractEntity newEntity) throws HSAdminException {
|
|
|
|
EMailAlias alias = (EMailAlias) newEntity;
|
|
|
|
String name = alias.getName();
|
2011-05-20 17:25:11 +02:00
|
|
|
if (name.length() > 5 && (name.charAt(5) != '-') || name.length() == 6) {
|
2011-05-20 16:25:45 +02:00
|
|
|
throw new AuthorisationException(getLoginUser(), "add", newEntity);
|
2011-05-20 16:12:39 +02:00
|
|
|
}
|
2011-05-20 17:25:11 +02:00
|
|
|
EntityManager em = getTransaction().getEntityManager();
|
|
|
|
Query qPac = em.createQuery("SELECT obj FROM Pacs obj WHERE obj.name = :pacName");
|
|
|
|
qPac.setParameter("pacName", name.substring(0, 5));
|
|
|
|
Object singleResult = qPac.getSingleResult();
|
|
|
|
Pac pac = (Pac) singleResult;
|
|
|
|
if (pac == null || !pac.isReadAllowedFor(getLoginUser())) {
|
2011-05-20 16:25:45 +02:00
|
|
|
throw new AuthorisationException(getLoginUser(), "add", newEntity);
|
2011-05-20 16:12:39 +02:00
|
|
|
}
|
|
|
|
return super.add(newEntity);
|
|
|
|
}
|
2010-10-05 21:42:07 +02:00
|
|
|
|
|
|
|
}
|