extract multioption constants to one place

This commit is contained in:
Peter Hormanns 2013-05-23 11:29:29 +02:00
parent 3d76b55147
commit e26b0e5cc0
7 changed files with 22 additions and 18 deletions

View File

@ -0,0 +1,10 @@
package de.hsadmin.hostsharing;
public class MultiOption {
public static final int DATABASEUSERS_PER_OPTION = 25;
public static final int DATABASES_PER_OPTION = 25;
public static final int EMAIL_ITEMS_PER_OPTION = 250;
public static final int UNIXUSERS_PER_OPTION = 50;
}

View File

@ -10,13 +10,12 @@ import de.hsadmin.core.model.AbstractModuleImpl;
import de.hsadmin.core.model.AuthorisationException;
import de.hsadmin.core.model.HSAdminException;
import de.hsadmin.core.model.Transaction;
import de.hsadmin.hostsharing.MultiOption;
import de.hsadmin.mods.pac.Pac;
import de.hsadmin.mods.user.UnixUser;
public class MySqlDatabaseModuleImpl extends AbstractModuleImpl {
private static final int DBS_PER_MULTI_OPTION = 25;
@Override
public List<AbstractEntity> search(Class<? extends AbstractEntity> entityClass,
String condition, String orderBy) throws HSAdminException {
@ -64,7 +63,7 @@ public class MySqlDatabaseModuleImpl extends AbstractModuleImpl {
//TODO: Needs better implementation
Query qDatabases = em.createQuery("SELECT obj FROM Database obj WHERE obj.pac.id = :pacId");
qDatabases.setParameter("pacId", pac.getId());
if (qDatabases.getResultList().size() >= DBS_PER_MULTI_OPTION * pac.getQuantityByComponentName("MULTI")) {
if (qDatabases.getResultList().size() >= MultiOption.DATABASES_PER_OPTION * pac.getQuantityByComponentName("MULTI")) {
throw new HSAdminException("included number of databases exceeded");
}
database.setPac(pac);

View File

@ -10,13 +10,12 @@ import de.hsadmin.core.model.AbstractModuleImpl;
import de.hsadmin.core.model.AuthorisationException;
import de.hsadmin.core.model.HSAdminException;
import de.hsadmin.core.model.Transaction;
import de.hsadmin.hostsharing.MultiOption;
import de.hsadmin.mods.pac.Pac;
import de.hsadmin.mods.user.UnixUser;
public class MySqlUserModuleImpl extends AbstractModuleImpl {
private static final int DBUSERS_PER_MULTI_OPTION = 25;
@Override
public AbstractEntity add(AbstractEntity newEntity) throws HSAdminException {
Transaction transaction = getTransaction();
@ -45,7 +44,7 @@ public class MySqlUserModuleImpl extends AbstractModuleImpl {
//TODO: Needs better implementation
Query qDatabaseUsers = em.createQuery("SELECT obj FROM DatabaseUser obj WHERE obj.pac.id = :pacId");
qDatabaseUsers.setParameter("pacId", pac.getId());
if (qDatabaseUsers.getResultList().size() >= DBUSERS_PER_MULTI_OPTION * pac.getQuantityByComponentName("MULTI")) {
if (qDatabaseUsers.getResultList().size() >= MultiOption.DATABASEUSERS_PER_OPTION * pac.getQuantityByComponentName("MULTI")) {
throw new HSAdminException("included database users exceeded");
}
user.setPac(pac);

View File

@ -10,13 +10,12 @@ import de.hsadmin.core.model.AbstractModuleImpl;
import de.hsadmin.core.model.AuthorisationException;
import de.hsadmin.core.model.HSAdminException;
import de.hsadmin.core.model.Transaction;
import de.hsadmin.hostsharing.MultiOption;
import de.hsadmin.mods.pac.Pac;
import de.hsadmin.mods.user.UnixUser;
public class PgSqlDatabaseModuleImpl extends AbstractModuleImpl {
private static final int DBS_PER_MULTI_OPTION = 25;
@Override
public List<AbstractEntity> search(Class<? extends AbstractEntity> entityClass, String condition, String orderBy) throws HSAdminException {
if (orderBy == null || orderBy.length() == 0) {
@ -63,7 +62,7 @@ public class PgSqlDatabaseModuleImpl extends AbstractModuleImpl {
//TODO: Needs better implementation
Query qDatabases = em.createQuery("SELECT obj FROM Database obj WHERE obj.pac.id = :pacId");
qDatabases.setParameter("pacId", pac.getId());
if (qDatabases.getResultList().size() >= DBS_PER_MULTI_OPTION * pac.getQuantityByComponentName("MULTI")) {
if (qDatabases.getResultList().size() >= MultiOption.DATABASES_PER_OPTION * pac.getQuantityByComponentName("MULTI")) {
throw new HSAdminException("included databases exceeded");
}
database.setPac(pac);

View File

@ -9,13 +9,12 @@ import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.AbstractModuleImpl;
import de.hsadmin.core.model.AuthorisationException;
import de.hsadmin.core.model.HSAdminException;
import de.hsadmin.hostsharing.MultiOption;
import de.hsadmin.mods.pac.Pac;
import de.hsadmin.mods.user.UnixUser;
public class PgSqlUserModuleImpl extends AbstractModuleImpl {
private static final int DBUSERS_PER_MULTI_OPTION = 5;
@Override
public AbstractEntity add(AbstractEntity newEntity) throws HSAdminException {
UnixUser loginUser = getTransaction().getLoginUser();
@ -40,7 +39,7 @@ public class PgSqlUserModuleImpl extends AbstractModuleImpl {
//TODO: Needs better implementation
Query qDatabaseUsers = em.createQuery("SELECT obj FROM DatabaseUser obj WHERE obj.pac.id = :pacId");
qDatabaseUsers.setParameter("pacId", pac.getId());
if (qDatabaseUsers.getResultList().size() >= DBUSERS_PER_MULTI_OPTION * pac.getQuantityByComponentName("MULTI")) {
if (qDatabaseUsers.getResultList().size() >= MultiOption.DATABASEUSERS_PER_OPTION * pac.getQuantityByComponentName("MULTI")) {
throw new HSAdminException("included database users exceeded");
}
user.setPac(pac);

View File

@ -10,13 +10,12 @@ import de.hsadmin.core.model.AbstractModuleImpl;
import de.hsadmin.core.model.AuthorisationException;
import de.hsadmin.core.model.HSAdminException;
import de.hsadmin.core.model.Transaction;
import de.hsadmin.hostsharing.MultiOption;
import de.hsadmin.mods.pac.Pac;
import de.hsadmin.mods.user.UnixUser;
public class EMailAliasModuleImpl extends AbstractModuleImpl {
private static final int UNIXUSERS_PER_MULTI_OPTION = 250;
@Override
public List<AbstractEntity> search(Class<? extends AbstractEntity> entityClass,
String condition, String orderBy) throws HSAdminException {
@ -56,7 +55,7 @@ public class EMailAliasModuleImpl extends AbstractModuleImpl {
qEmailAliases.setParameter("pacId", pac.getId());
Query qEmailAddresses = em.createQuery("SELECT obj FROM EMailAddresses obj WHERE obj.domain.user.pac.id = :pacId");
qEmailAddresses.setParameter("pacId", pac.getId());
if (qEmailAliases.getResultList().size() + qEmailAddresses.getResultList().size() >= UNIXUSERS_PER_MULTI_OPTION * pac.getQuantityByComponentName("MULTI")) {
if (qEmailAliases.getResultList().size() + qEmailAddresses.getResultList().size() >= MultiOption.EMAIL_ITEMS_PER_OPTION * pac.getQuantityByComponentName("MULTI")) {
throw new HSAdminException("included email addresses/aliases exceeded");
}
alias.setPac(pac);

View File

@ -11,12 +11,11 @@ import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.AbstractModuleImpl;
import de.hsadmin.core.model.HSAdminException;
import de.hsadmin.core.model.Transaction;
import de.hsadmin.hostsharing.MultiOption;
import de.hsadmin.mods.pac.Pac;
public class UnixUserModuleImpl extends AbstractModuleImpl {
private static final int UNIXUSERS_PER_MULTI_OPTION = 50;
public UnixUserModuleImpl() {
}
@ -135,7 +134,7 @@ public class UnixUserModuleImpl extends AbstractModuleImpl {
//TODO: Needs better implementation
Query qUnixUsers = em.createQuery("SELECT obj FROM UnixUsers obj WHERE obj.id = :pacId");
qUnixUsers.setParameter("pacId", pac.getId());
if (qUnixUsers.getResultList().size() >= UNIXUSERS_PER_MULTI_OPTION * pac.getQuantityByComponentName("MULTI")) {
if (qUnixUsers.getResultList().size() >= MultiOption.UNIXUSERS_PER_OPTION * pac.getQuantityByComponentName("MULTI")) {
throw new HSAdminException("included unix users exceeded");
}
// don't move this up, it will update the new entity still with wrong