merge pac-type tests

This commit is contained in:
Peter Hormanns 2013-04-29 20:01:09 +02:00
parent aa82ca8ad1
commit f602b24c13
34 changed files with 378 additions and 273 deletions

View File

@ -2,61 +2,69 @@
-- Table: basepacket
--
INSERT INTO basepacket (basepacket_code, description, sorting, valid, article_number)
VALUES ('DW/B', 'Dynamic-Web/Base', 300, true, 100);
VALUES ('PAC/DW', 'Dynamic-Web/Base', 300, true, 100);
INSERT INTO basepacket (basepacket_code, description, sorting, valid, article_number)
VALUES ('SW/B', 'Static-Web/Base', 400, true, 200);
VALUES ('PAC/SW', 'Static-Web/Base', 400, true, 200);
INSERT INTO basepacket (basepacket_code, description, sorting, valid, article_number)
VALUES ('WEB', 'Web/Base', 100, true, 300);
VALUES ('PAC/WEB', 'Web/Base', 100, true, 300);
INSERT INTO basepacket (basepacket_code, description, sorting, valid, article_number)
VALUES ('HIVE', 'Managed Server', 200, true, 400);
VALUES ('SRV/MGD', 'Managed Server', 200, true, 400);
--
-- Table: basecomponent
--
INSERT INTO basecomponent (basecomponent_code, description, sorting, valid)
VALUES ('TRAFFIC', 'Monatliches Datenvolumen in GB', 100, true);
VALUES ('MULTI', 'Monatliches Datenvolumen in GB', 100, true);
INSERT INTO basecomponent (basecomponent_code, description, sorting, valid)
VALUES ('QUOTA', 'Festplattenspeicherplatz in MB', 200, true);
VALUES ('TRAFFIC', 'Monatliches Datenvolumen in GB', 200, true);
INSERT INTO basecomponent (basecomponent_code, description, sorting, valid)
VALUES ('DAEMON', 'Nutzung eines eigenen Servers/Daemons', 300, true);
VALUES ('QUOTA', 'Festplattenspeicherplatz in MB', 300, true);
INSERT INTO basecomponent (basecomponent_code, description, sorting, valid)
VALUES ('MIRROR', 'Echtzeitspiegelung der Daten', 400, true);
VALUES ('DAEMON', 'Nutzung eines eigenen Servers/Daemons', 400, true);
INSERT INTO basecomponent (basecomponent_code, description, sorting, valid)
VALUES ('BACKUP', 'Nächtliches Backup', 500, true);
VALUES ('MIRROR', 'Echtzeitspiegelung der Daten', 500, true);
INSERT INTO basecomponent (basecomponent_code, description, sorting, valid)
VALUES ('BACKUP', 'Nächtliches Backup', 600, true);
--
-- Table: component
--
INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number)
SELECT basepacket_id, basecomponent_id, 128, 40960, 128, 128, 128, false, 101 FROM basepacket, basecomponent WHERE basepacket_code='DW/B' AND basecomponent_code='QUOTA';
SELECT basepacket_id, basecomponent_id, 1, 1, 1, 1, 1, false, 100 FROM basepacket, basecomponent WHERE basepacket_code='PAC/DW' AND basecomponent_code='MULTI';
INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number)
SELECT basepacket_id, basecomponent_id, 512, 40960, 512, 512, 512, false, 201 FROM basepacket, basecomponent WHERE basepacket_code='SW/B' AND basecomponent_code='QUOTA';
SELECT basepacket_id, basecomponent_id, 1, 1, 1, 1, 1, false, 200 FROM basepacket, basecomponent WHERE basepacket_code='PAC/SW' AND basecomponent_code='MULTI';
INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number)
SELECT basepacket_id, basecomponent_id, 512, 40960, 512, 512, 0, false, 301 FROM basepacket, basecomponent WHERE basepacket_code='WEB' AND basecomponent_code='QUOTA';
SELECT basepacket_id, basecomponent_id, 1, 1, 1, 1, 1, false, 300 FROM basepacket, basecomponent WHERE basepacket_code='PAC/WEB' AND basecomponent_code='MULTI';
INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number)
SELECT basepacket_id, basecomponent_id, 2, 40960, 2, 2, 2, false, 102 FROM basepacket, basecomponent WHERE basepacket_code='DW/B' AND basecomponent_code='TRAFFIC';
SELECT basepacket_id, basecomponent_id, 128, 40960, 128, 128, 128, false, 101 FROM basepacket, basecomponent WHERE basepacket_code='PAC/DW' AND basecomponent_code='QUOTA';
INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number)
SELECT basepacket_id, basecomponent_id, 4, 40960, 4, 4, 4, false, 202 FROM basepacket, basecomponent WHERE basepacket_code='SW/B' AND basecomponent_code='TRAFFIC';
SELECT basepacket_id, basecomponent_id, 512, 40960, 512, 512, 512, false, 201 FROM basepacket, basecomponent WHERE basepacket_code='PAC/SW' AND basecomponent_code='QUOTA';
INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number)
SELECT basepacket_id, basecomponent_id, 5, 40960, 5, 5, 0, false, 302 FROM basepacket, basecomponent WHERE basepacket_code='WEB' AND basecomponent_code='TRAFFIC';
SELECT basepacket_id, basecomponent_id, 512, 40960, 512, 512, 0, false, 301 FROM basepacket, basecomponent WHERE basepacket_code='PAC/WEB' AND basecomponent_code='QUOTA';
INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number)
SELECT basepacket_id, basecomponent_id, 0, 4, 0, 1, 0, false, 103 FROM basepacket, basecomponent WHERE basepacket_code='DW/B' AND basecomponent_code='DAEMON';
SELECT basepacket_id, basecomponent_id, 2, 40960, 2, 2, 2, false, 102 FROM basepacket, basecomponent WHERE basepacket_code='PAC/DW' AND basecomponent_code='TRAFFIC';
INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number)
SELECT basepacket_id, basecomponent_id, 0, 0, 0, 1, 0, false, 203 FROM basepacket, basecomponent WHERE basepacket_code='SW/B' AND basecomponent_code='DAEMON';
SELECT basepacket_id, basecomponent_id, 4, 40960, 4, 4, 4, false, 202 FROM basepacket, basecomponent WHERE basepacket_code='PAC/SW' AND basecomponent_code='TRAFFIC';
INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number)
SELECT basepacket_id, basecomponent_id, 0, 4, 0, 1, 0, false, 303 FROM basepacket, basecomponent WHERE basepacket_code='WEB' AND basecomponent_code='DAEMON';
SELECT basepacket_id, basecomponent_id, 5, 40960, 5, 5, 0, false, 302 FROM basepacket, basecomponent WHERE basepacket_code='PAC/WEB' AND basecomponent_code='TRAFFIC';
INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number)
SELECT basepacket_id, basecomponent_id, 0, 1, 1, 1, 1, false, 104 FROM basepacket, basecomponent WHERE basepacket_code='DW/B' AND basecomponent_code='MIRROR';
SELECT basepacket_id, basecomponent_id, 0, 4, 0, 1, 0, false, 103 FROM basepacket, basecomponent WHERE basepacket_code='PAC/DW' AND basecomponent_code='DAEMON';
INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number)
SELECT basepacket_id, basecomponent_id, 0, 1, 1, 1, 1, false, 204 FROM basepacket, basecomponent WHERE basepacket_code='SW/B' AND basecomponent_code='MIRROR';
SELECT basepacket_id, basecomponent_id, 0, 0, 0, 1, 0, false, 203 FROM basepacket, basecomponent WHERE basepacket_code='PAC/SW' AND basecomponent_code='DAEMON';
INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number)
SELECT basepacket_id, basecomponent_id, 0, 1, 1, 1, 1, false, 304 FROM basepacket, basecomponent WHERE basepacket_code='WEB' AND basecomponent_code='MIRROR';
SELECT basepacket_id, basecomponent_id, 0, 4, 0, 1, 0, false, 303 FROM basepacket, basecomponent WHERE basepacket_code='PAC/WEB' AND basecomponent_code='DAEMON';
INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number)
SELECT basepacket_id, basecomponent_id, 0, 1, 1, 1, 1, false, 105 FROM basepacket, basecomponent WHERE basepacket_code='DW/B' AND basecomponent_code='BACKUP';
SELECT basepacket_id, basecomponent_id, 0, 1, 1, 1, 1, false, 104 FROM basepacket, basecomponent WHERE basepacket_code='PAC/DW' AND basecomponent_code='MIRROR';
INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number)
SELECT basepacket_id, basecomponent_id, 0, 1, 1, 1, 1, false, 205 FROM basepacket, basecomponent WHERE basepacket_code='SW/B' AND basecomponent_code='BACKUP';
SELECT basepacket_id, basecomponent_id, 0, 1, 1, 1, 1, false, 204 FROM basepacket, basecomponent WHERE basepacket_code='PAC/SW' AND basecomponent_code='MIRROR';
INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number)
SELECT basepacket_id, basecomponent_id, 0, 1, 1, 1, 1, false, 305 FROM basepacket, basecomponent WHERE basepacket_code='WEB' AND basecomponent_code='BACKUP';
SELECT basepacket_id, basecomponent_id, 0, 1, 1, 1, 1, false, 304 FROM basepacket, basecomponent WHERE basepacket_code='PAC/WEB' AND basecomponent_code='MIRROR';
INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number)
SELECT basepacket_id, basecomponent_id, 0, 1, 1, 1, 1, false, 105 FROM basepacket, basecomponent WHERE basepacket_code='PAC/DW' AND basecomponent_code='BACKUP';
INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number)
SELECT basepacket_id, basecomponent_id, 0, 1, 1, 1, 1, false, 205 FROM basepacket, basecomponent WHERE basepacket_code='PAC/SW' AND basecomponent_code='BACKUP';
INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number)
SELECT basepacket_id, basecomponent_id, 0, 1, 1, 1, 1, false, 305 FROM basepacket, basecomponent WHERE basepacket_code='PAC/WEB' AND basecomponent_code='BACKUP';
--
-- Table: business_partner

View File

@ -3,7 +3,7 @@
-- JOIN unixuser on ( domain.domain_owner = unixuser.unixuser_id )
-- JOIN packet on ( unixuser.packet_id = packet.packet_id )
-- JOIN basepacket on ( packet.bp_id = basepacket.basepacket_id ), domain_option
-- WHERE basepacket.basepacket_code = 'DW/B'
-- WHERE basepacket.basepacket_code = 'PAC/DW'
-- AND domain_option.domain_option_name = 'php' ;
-- DELETE FROM domain__domain_option
@ -11,7 +11,7 @@
-- JOIN unixuser on ( domain.domain_owner = unixuser.unixuser_id )
-- JOIN packet on ( unixuser.packet_id = packet.packet_id )
-- JOIN basepacket on ( packet.bp_id = basepacket.basepacket_id )
-- WHERE basepacket.basepacket_code != 'DW/B'
-- WHERE basepacket.basepacket_code != 'PAC/DW'
-- AND domain__domain_option.domain_option_id = domain_option.domain_option_id
-- AND domain_option.domain_option_name = 'php' ;

View File

@ -15,6 +15,8 @@ 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 {
@ -54,6 +56,17 @@ public class MySqlDatabaseModuleImpl extends AbstractModuleImpl {
if (!pac.getName().equals(pacPrefix)) {
throw new HSAdminException("wrong database owner");
}
//TODO: Needs better implementation
String pacType = pac.getBasepac().getName();
if (!pacType.equals(Pac.PAC_WEB) && !pacType.equals(Pac.PAC_DW)) {
throw new HSAdminException("not allowed for this packet type");
}
//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")) {
throw new HSAdminException("included number of databases exceeded");
}
database.setPac(pac);
return super.add(newEntity);
}

View File

@ -15,6 +15,8 @@ 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();
@ -35,6 +37,17 @@ public class MySqlUserModuleImpl extends AbstractModuleImpl {
if (pac == null || !pac.isReadAllowedFor(loginUser)) {
throw new AuthorisationException(loginUser, "add", newEntity);
}
//TODO: Needs better implementation
String pacType = pac.getBasepac().getName();
if (!pacType.equals(Pac.PAC_WEB) && !pacType.equals(Pac.PAC_DW)) {
throw new HSAdminException("not allowed for this packet type");
}
//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")) {
throw new HSAdminException("included database users exceeded");
}
user.setPac(pac);
return super.add(newEntity);
}

View File

@ -15,6 +15,8 @@ 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) {
@ -51,6 +53,18 @@ public class PgSqlDatabaseModuleImpl extends AbstractModuleImpl {
}
if (!pac.getName().equals(pacPrefix)) {
throw new HSAdminException("wrong database owner");
}
//TODO: Needs better implementation
String pacType = pac.getBasepac().getName();
if (!pacType.equals(Pac.PAC_WEB) && !pacType.equals(Pac.PAC_DW)) {
throw new HSAdminException("not allowed for this packet type");
}
//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")) {
throw new HSAdminException("included databases exceeded");
}
database.setPac(pac);
return super.add(newEntity);

View File

@ -14,6 +14,8 @@ 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();
@ -30,6 +32,17 @@ public class PgSqlUserModuleImpl extends AbstractModuleImpl {
if (pac == null || !pac.isReadAllowedFor(loginUser)) {
throw new AuthorisationException(loginUser, "add", newEntity);
}
//TODO: Needs better implementation
String pacType = pac.getBasepac().getName();
if (!pacType.equals(Pac.PAC_WEB) && !pacType.equals(Pac.PAC_DW)) {
throw new HSAdminException("not allowed for this packet type");
}
//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")) {
throw new HSAdminException("included database users exceeded");
}
user.setPac(pac);
return super.add(newEntity);
}

View File

@ -20,15 +20,15 @@ import de.hsadmin.mods.user.UnixUser;
public class DomainModuleImpl extends AbstractModuleImpl {
public static final String DOMOPT_GREYLISTING = "greylisting";
public static final String DOMOPT_MULTIVIEWS = "multiviews";
public static final String DOMMULTIVIEWS = "multiviews";
public static final String DOMOPT_INDEXES = "indexes";
public static final String DOMOPT_HTDOCSFALLBACK = "htdocsfallback";
public static final String DOMOPT_INCLUDES = "includes";
public static final String DOMOPT_BACKUPFOREXTERNALMX = "backupmxforexternalmx";
public static final String[] ALL_DOMOPTS = new String[] { DOMOPT_GREYLISTING, DOMOPT_MULTIVIEWS,
public static final String[] ALL_DOMOPTS = new String[] { DOMOPT_GREYLISTING, DOMMULTIVIEWS,
DOMOPT_INDEXES, DOMOPT_HTDOCSFALLBACK, DOMOPT_INCLUDES, DOMOPT_BACKUPFOREXTERNALMX };
public static final String[] DEFAULT_DOMOPTS = new String[] { DOMOPT_GREYLISTING, DOMOPT_MULTIVIEWS,
public static final String[] DEFAULT_DOMOPTS = new String[] { DOMOPT_GREYLISTING, DOMMULTIVIEWS,
DOMOPT_INDEXES, DOMOPT_HTDOCSFALLBACK, DOMOPT_INCLUDES };
@Override
@ -102,8 +102,16 @@ public class DomainModuleImpl extends AbstractModuleImpl {
if (admin == null || admin.getName() == null || admin.getName().length() == 0) {
throw new HSAdminException("domain admin required");
}
// Standard domainoptions setzen. TODO: Alle defaults über eigene Klasse aus der Datenbank holen.
EntityManager em = getTransaction().getEntityManager();
Query userQuery = em.createQuery("SELECT u FROM UnixUsers u WHERE u.name = :username");
userQuery.setParameter("username", admin.getName());
admin = (UnixUser) userQuery.getSingleResult();
//TODO: Needs better implementation
String pacType = admin.getPac().getBasepac().getName();
if (!pacType.equals(Pac.PAC_WEB) && !pacType.equals(Pac.PAC_DW) && !pacType.equals(Pac.PAC_SW)) {
throw new HSAdminException("not allowed for this packet type");
}
// Standard domainoptions setzen. TODO: Alle defaults über eigene Klasse aus der Datenbank holen.
UnixUser loginUser = getTransaction().getLoginUser();
if (!loginUser.hasHostmasterRole()) {
// search for domains superior to dom

View File

@ -11,10 +11,13 @@ import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.HSAdminException;
import de.hsadmin.core.model.Transaction;
import de.hsadmin.mods.dom.Domain;
import de.hsadmin.mods.pac.Pac;
import de.hsadmin.mods.user.UnixUser;
public class EMailAddressModuleImpl extends AbstractModuleImpl {
private static final int EMAIL_PER_MULTI_OPTION = 250;
@Override
public List<AbstractEntity> search(Class<? extends AbstractEntity> entityClass,
String condition, String orderBy) throws HSAdminException {
@ -51,6 +54,19 @@ public class EMailAddressModuleImpl extends AbstractModuleImpl {
if (dom.isPacDomain() && !loginUser.hasHostmasterRole()) {
throw new AuthorisationException(loginUser, "add", adr);
}
//TODO: Needs better implementation
String pacType = dom.getUser().getPac().getBasepac().getName();
if (!pacType.equals(Pac.PAC_WEB) && !pacType.equals(Pac.PAC_DW) && !pacType.equals(Pac.PAC_SW)) {
throw new HSAdminException("not allowed for this packet type");
}
//TODO: Needs better implementation
Query qEmailAliases = em.createQuery("SELECT obj FROM EMailAliases obj WHERE obj.pac.id = :pacId");
qEmailAliases.setParameter("pacId", dom.getUser().getPac().getId());
Query qEmailAddresses = em.createQuery("SELECT obj FROM EMailAddresses obj WHERE obj.domain.user.pac.id = :pacId");
qEmailAddresses.setParameter("pacId", dom.getUser().getPac().getId());
if (qEmailAliases.getResultList().size() + qEmailAddresses.getResultList().size() >= EMAIL_PER_MULTI_OPTION * dom.getUser().getPac().getQuantityByComponentName("MULTI")) {
throw new HSAdminException("included email addresses/aliases exceeded");
}
return super.add(newEntity);
}

View File

@ -15,6 +15,8 @@ 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 {
@ -44,6 +46,19 @@ public class EMailAliasModuleImpl extends AbstractModuleImpl {
if (!name.startsWith(pac.getName())) {
throw new AuthorisationException(loginUser, "add", newEntity);
}
//TODO: Needs better implementation
String pacType = pac.getBasepac().getName();
if (!pacType.equals(Pac.PAC_WEB) && !pacType.equals(Pac.PAC_DW) && !pacType.equals(Pac.PAC_SW)) {
throw new HSAdminException("not allowed for this packet type");
}
//TODO: Needs better implementation
Query qEmailAliases = em.createQuery("SELECT obj FROM EMailAliases obj WHERE obj.pac.id = :pacId");
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")) {
throw new HSAdminException("included email addresses/aliases exceeded");
}
alias.setPac(pac);
return super.add(newEntity);
}

View File

@ -8,7 +8,6 @@ import static javax.persistence.GenerationType.SEQUENCE;
import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.persistence.Column;
@ -37,10 +36,10 @@ import de.hsadmin.mods.user.UnixUser;
@AnnModuleImpl(de.hsadmin.mods.pac.PacModuleImpl.class)
public class Pac extends AbstractEntity implements Serializable {
public static final String PAC_WEB_BASE = "WEB";
public static final String PAC_HIVE = "HIVE";
public static final String PAC_DW_BASE = "DW/B";
public static final String PAC_SW_BASE = "SW/B";
public static final String PAC_DW = "PAC/DW";
public static final String PAC_SW = "PAC/SW";
public static final String PAC_WEB = "PAC/WEB";
public static final String PAC_SRV = "SRV/MGD";
private static final long serialVersionUID = 1L;
@ -88,26 +87,16 @@ public class Pac extends AbstractEntity implements Serializable {
@Transient
private BasePac basepac;
public Pac() {
basepac = new BasePac();
curINetAddr = new INetAddress();
hive = new Hive();
}
public Pac(String name, Customer cust, BasePac basePac, Hive hive) {
this.name = name;
this.customer = cust;
this.hive = hive;
this.created = new Date();
this.curINetAddr = hive.getInetAddr();
initPacComponents(basePac);
}
protected void initPacComponents(BasePac basePac) {
public void initPacComponents(EntityManager em, BasePac aBasePac) {
Query qBasepac = em.createQuery("SELECT b FROM BasePacs b WHERE b.valid = :valid AND b.name = :name");
qBasepac.setParameter("valid", Boolean.TRUE);
qBasepac.setParameter("name", aBasePac.getName());
basepac = (BasePac) qBasepac.getSingleResult();
setBasepac(basepac);
pacComponents = new HashSet<PacComponent>();
Date today = new Date();
for (Component comp : basePac.getComponents()) {
PacComponent pacComp = new PacComponent(basePac,
for (Component comp : basepac.getComponents()) {
PacComponent pacComp = new PacComponent(basepac,
comp.getBaseComponent(), this, comp.getDefaultQuantity(),
today, null);
pacComponents.add(pacComp);
@ -117,11 +106,6 @@ public class Pac extends AbstractEntity implements Serializable {
@Override
public void initialize(EntityManager em, UnixUser loginUser) {
super.initialize(em, loginUser);
Query qBasepac = em.createQuery("SELECT b FROM BasePacs b WHERE b.valid = :valid ORDER BY b.name");
qBasepac.setParameter("valid", Boolean.TRUE);
List<?> resultList = qBasepac.getResultList();
basepac = (BasePac) resultList.get(0);
initPacComponents(basepac);
}
public static String createQueryFromStringKey(String humanKey) {
@ -293,4 +277,13 @@ public class Pac extends AbstractEntity implements Serializable {
public void setFree(boolean free) {
this.free = free;
}
public int getQuantityByComponentName(String componentName) {
PacComponent multi = getPacComponent(componentName);
if (multi == null) {
return 0;
} else {
return multi.getQuantity();
}
}
}

View File

@ -21,25 +21,16 @@ public class PacComponent implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name="packet_id", insertable=false, updatable=false, columnDefinition = "integer")
private long pacId;
@Id
@Column(name="basepacket_id", insertable=false, updatable=false, columnDefinition = "integer")
private long basePacId;
@Id
@Column(name="basecomponent_id", insertable=false, updatable=false, columnDefinition = "integer")
private long baseComponentId;
@ManyToOne
@JoinColumn(name = "packet_id")
private Pac pac;
@Id
@ManyToOne
@JoinColumn(name = "basecomponent_id")
private BaseComponent baseComponent;
@Id
@ManyToOne
@JoinColumn(name = "basepacket_id")
private BasePac basePac;
@ -61,17 +52,8 @@ public class PacComponent implements Serializable {
public PacComponent(BasePac basePac, BaseComponent baseComp, Pac pac,
int quantity, Date created, Date cancelled) {
this.basePac = basePac;
if (basePac != null) {
this.basePacId = basePac.id();
}
this.pac = pac;
if (pac != null) {
this.pacId = pac.id();
}
this.baseComponent = baseComp;
if (baseComponent != null) {
this.baseComponentId = baseComp.id();
}
this.quantity = quantity;
this.created = created;
this.cancelled = cancelled;
@ -83,9 +65,6 @@ public class PacComponent implements Serializable {
public void setbasePac(BasePac basePac) {
this.basePac = basePac;
if (basePac != null) {
this.basePacId = basePac.id();
}
}
public BaseComponent getBaseComponent() {
@ -94,9 +73,6 @@ public class PacComponent implements Serializable {
public void setBaseComponent(BaseComponent baseComponent) {
this.baseComponent = baseComponent;
if (baseComponent != null) {
this.baseComponentId = baseComponent.id();
}
}
public Pac getPac() {
@ -105,9 +81,6 @@ public class PacComponent implements Serializable {
public void setPac(Pac pac) {
this.pac = pac;
if (pac != null) {
this.pacId = pac.id();
}
}
public int getQuantity() {
@ -134,28 +107,4 @@ public class PacComponent implements Serializable {
this.cancelled = cancelled;
}
public void setPacId(long pacId) {
this.pacId = pacId;
}
public long getPacId() {
return pacId;
}
public void setBaseComponentId(long baseComponentId) {
this.baseComponentId = baseComponentId;
}
public long getBaseComponentId() {
return baseComponentId;
}
public void setBasePacId(long basePacId) {
this.basePacId = basePacId;
}
public long getBasePacId() {
return basePacId;
}
}

View File

@ -8,46 +8,46 @@ public class PacComponentId implements Serializable {
private static final long serialVersionUID = 1L;
private long pacId;
private long basePacId;
private long baseComponentId;
private long pac;
private long basePac;
private long baseComponent;
@Override
public boolean equals(Object obj) {
if (obj != null && obj instanceof PacComponentId) {
PacComponentId other = (PacComponentId) obj;
return getPacId() == other.getPacId() && getBaseComponentId() == other.getBaseComponentId() && getBasePacId() == other.getBasePacId();
return getPac() == other.getPac() && getBaseComponent() == other.getBaseComponent() && getBasePac() == other.getBasePac();
}
return false;
}
@Override
public int hashCode() {
return (new Long(getPacId() ^ getBaseComponentId() ^ getBasePacId() % Integer.MAX_VALUE)).intValue();
return (new Long(getPac() ^ getBaseComponent() ^ getBasePac() % Integer.MAX_VALUE)).intValue();
}
public void setPacId(long pacId) {
this.pacId = pacId;
public void setPac(long pacId) {
this.pac = pacId;
}
public long getPacId() {
return pacId;
public long getPac() {
return pac;
}
public void setBaseComponentId(long baseComponentId) {
this.baseComponentId = baseComponentId;
public void setBaseComponent(long baseComponentId) {
this.baseComponent = baseComponentId;
}
public long getBaseComponentId() {
return baseComponentId;
public long getBaseComponent() {
return baseComponent;
}
public void setBasePacId(long basePacId) {
this.basePacId = basePacId;
public void setBasePac(long basePacId) {
this.basePac = basePacId;
}
public long getBasePacId() {
return basePacId;
public long getBasePac() {
return basePac;
}
}

View File

@ -45,7 +45,6 @@ public class PacModuleImpl extends AbstractModuleImpl {
qBasepac.setParameter("valid", Boolean.TRUE);
basepac = (BasePac) qBasepac.getSingleResult();
pac.setBasepac(basepac);
pac.initPacComponents(basepac);
INetAddress curINetAddr = pac.getCurINetAddr();
if (curINetAddr == null || curINetAddr.getInetAddr() == null || curINetAddr.getInetAddr().length() == 0) {
throw new HSAdminException("curinetaddr required");
@ -111,8 +110,7 @@ public class PacModuleImpl extends AbstractModuleImpl {
}
@Override
public AbstractEntity update(AbstractEntity entity)
throws HSAdminException {
public AbstractEntity update(AbstractEntity entity) throws HSAdminException {
UnixUser loginUser = getTransaction().getLoginUser();
if (!(entity instanceof Pac)) {
throw new AuthorisationException(loginUser, "update", entity);

View File

@ -25,7 +25,7 @@ public class PacProcessorFactory implements EntityProcessorFactory {
EntityManager em, T entity) throws ProcessorException {
Pac pac = (Pac) entity;
String basepacName = pac.getBasepac().getName();
if (basepacName.equals(Pac.PAC_WEB_BASE) || basepacName.equals(Pac.PAC_DW_BASE) || basepacName.equals(Pac.PAC_SW_BASE)) {
if (basepacName.equals(Pac.PAC_WEB) || basepacName.equals(Pac.PAC_DW) || basepacName.equals(Pac.PAC_SW)) {
String pacName = pac.getName();
Hive hive = pac.getHive();
UnixUser unixUser = getPacAdminUser(pac);
@ -79,7 +79,7 @@ public class PacProcessorFactory implements EntityProcessorFactory {
throws ProcessorException {
Pac pac = (Pac) entity;
String basepacName = pac.getBasepac().getName();
if (basepacName.equals(Pac.PAC_WEB_BASE) || basepacName.equals(Pac.PAC_DW_BASE) || basepacName.equals(Pac.PAC_SW_BASE)) {
if (basepacName.equals(Pac.PAC_WEB) || basepacName.equals(Pac.PAC_DW) || basepacName.equals(Pac.PAC_SW)) {
return createSetQuotaProc(pac);
} else {
return new NullProcessor();
@ -90,7 +90,7 @@ public class PacProcessorFactory implements EntityProcessorFactory {
public <T extends AbstractEntity> Processor createDeleteProcessor(EntityManager em, T entity) throws ProcessorException {
Pac pac = (Pac) entity;
String basepacName = pac.getBasepac().getName();
if (basepacName.equals(Pac.PAC_WEB_BASE) || basepacName.equals(Pac.PAC_DW_BASE) || basepacName.equals(Pac.PAC_SW_BASE)) {
if (basepacName.equals(Pac.PAC_WEB) || basepacName.equals(Pac.PAC_DW) || basepacName.equals(Pac.PAC_SW)) {
Hive hive = pac.getHive();
WaitingTasksProcessor waiting = new WaitingTasksProcessor(createDelUserProc(pac.getName()));
waiting.appendProcessor(pac.getHiveName(), new CompoundProcessor(

View File

@ -1,6 +1,5 @@
package de.hsadmin.mods.user;
import static javax.persistence.FetchType.EAGER;
import static javax.persistence.GenerationType.SEQUENCE;
import java.io.Serializable;
@ -8,6 +7,7 @@ import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
@ -50,7 +50,7 @@ public class UnixUser extends AbstractEntity implements Serializable {
@AnnFieldIO(validation="[a-z0-9]*", rw=ReadWriteAccess.WRITEONCE)
@JoinColumn(name = "packet_id", columnDefinition = "integer", updatable=false)
@ManyToOne(fetch = EAGER)
@ManyToOne(fetch = FetchType.LAZY)
private Pac pac;
@AnnFieldIO(validation="[a-zA-Z0-9\\_\\-\\.\\,\\ ]*", rw=ReadWriteAccess.READWRITE)

View File

@ -15,6 +15,8 @@ import de.hsadmin.mods.pac.Pac;
public class UnixUserModuleImpl extends AbstractModuleImpl {
private static final int UNIXUSERS_PER_MULTI_OPTION = 50;
public UnixUserModuleImpl() {
}
@ -125,7 +127,17 @@ public class UnixUserModuleImpl extends AbstractModuleImpl {
throw new AuthorisationException(loginUser, "add", newUnixUser, "userId");
}
}
//TODO: Needs better implementation
String pacType = pac.getBasepac().getName();
if (!pacType.equals(Pac.PAC_WEB) && !pacType.equals(Pac.PAC_DW) && !pacType.equals(Pac.PAC_SW)) {
throw new HSAdminException("not allowed for this packet type");
}
//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")) {
throw new HSAdminException("included unix users exceeded");
}
// don't move this up, it will update the new entity still with wrong
// userid!
newUnixUser.setPac(pac);

View File

@ -21,9 +21,9 @@ public abstract class AbstractRemote implements IRemote {
protected abstract Class<? extends AbstractEntity> getEntityClass();
protected abstract void entity2map(AbstractEntity entity, Map<String, Object> resultMap);
protected abstract void entity2map(Transaction tx, AbstractEntity entity, Map<String, Object> resultMap);
protected abstract void map2entity(Map<String, Object> setParams, AbstractEntity entity) throws HSAdminException;
protected abstract void map2entity(Transaction tx, Map<String, Object> setParams, AbstractEntity entity) throws HSAdminException;
protected abstract void regularizeKeys(Map<String, String> whereParams);
@ -43,7 +43,7 @@ public abstract class AbstractRemote implements IRemote {
ArrayList<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
for (AbstractEntity e : list) {
HashMap<String, Object> entry = new HashMap<String, Object>();
entity2map(e, entry);
entity2map(transaction, e, entry);
if (e.isReadAllowedFor(unixUser)) {
result.add(entry);
}
@ -72,12 +72,12 @@ public abstract class AbstractRemote implements IRemote {
getEntityClass().getConstructor();
AbstractEntity entity = constructor.newInstance();
module.initialize(entity);
map2entity(setParams, entity);
map2entity(transaction, setParams, entity);
transaction.beginTransaction();
AbstractEntity insertedEntity = module.add(entity);
transaction.commitTransaction();
HashMap<String, Object> entry = new HashMap<String, Object>();
entity2map(insertedEntity, entry);
entity2map(transaction, insertedEntity, entry);
return entry;
} else {
throw new AuthenticationException("authentication failed");
@ -146,10 +146,10 @@ public abstract class AbstractRemote implements IRemote {
for (AbstractEntity update : list) {
if (update.isWriteAllowedFor(unixUser)) {
transaction.detach(update);
map2entity(setParams, update);
map2entity(transaction, setParams, update);
update = module.update(update);
HashMap<String, Object> entry = new HashMap<String, Object>();
entity2map(update, entry);
entity2map(transaction, update, entry);
result.add(entry);
} else {
throw new AuthorisationException(unixUser, "update", update);

View File

@ -5,6 +5,7 @@ import java.util.Map;
import java.util.Set;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.Transaction;
import de.hsadmin.core.util.TextUtil;
import de.hsadmin.mods.cust.BankAccount;
import de.hsadmin.mods.cust.Contact;
@ -18,8 +19,7 @@ public class CustomerRemote extends AbstractRemote {
}
@Override
protected void entity2map(AbstractEntity entity,
Map<String, Object> resultMap) {
protected void entity2map(Transaction tx, AbstractEntity entity, Map<String, Object> resultMap) {
Customer cust = (Customer) entity;
resultMap.put("id", Long.toString(cust.getId()));
resultMap.put("membercode", cust.getName());
@ -79,7 +79,7 @@ public class CustomerRemote extends AbstractRemote {
}
@Override
protected void map2entity(Map<String, Object> setParams,
protected void map2entity(Transaction tx, Map<String, Object> setParams,
AbstractEntity entity) {
Customer cust = (Customer) entity;
String idStr = (String) setParams.get("id");

View File

@ -8,6 +8,7 @@ import java.util.Map;
import java.util.Set;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.Transaction;
import de.hsadmin.core.util.TextUtil;
import de.hsadmin.mods.dom.Domain;
import de.hsadmin.mods.dom.DomainOption;
@ -21,7 +22,7 @@ public class DomainRemote extends AbstractRemote {
}
@Override
protected void entity2map(AbstractEntity entity, Map<String, Object> resultMap) {
protected void entity2map(Transaction tx, AbstractEntity entity, Map<String, Object> resultMap) {
Domain dom = (Domain) entity;
String id = Long.toString(dom.getId());
resultMap.put("id", id);
@ -49,7 +50,7 @@ public class DomainRemote extends AbstractRemote {
}
@Override
protected void map2entity(Map<String, Object> setParams, AbstractEntity entity) {
protected void map2entity(Transaction tx, Map<String, Object> setParams, AbstractEntity entity) {
Domain dom = (Domain) entity;
String name = (String) setParams.get("name");
String user = (String) setParams.get("user");

View File

@ -6,13 +6,14 @@ import java.util.Map;
import java.util.StringTokenizer;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.Transaction;
import de.hsadmin.mods.dom.Domain;
import de.hsadmin.mods.email.EMailAddress;
public class EMailAddressRemote extends AbstractRemote {
@Override
protected void entity2map(AbstractEntity entity, Map<String, Object> map) {
protected void entity2map(Transaction tx, AbstractEntity entity, Map<String, Object> map) {
EMailAddress adr = (EMailAddress) entity;
long id = adr.getId();
String domain = adr.getDomain().getName();
@ -42,7 +43,7 @@ public class EMailAddressRemote extends AbstractRemote {
}
@Override
protected void map2entity(Map<String, Object> map, AbstractEntity entity) {
protected void map2entity(Transaction tx, Map<String, Object> map, AbstractEntity entity) {
EMailAddress adr = (EMailAddress) entity;
String localpart = (String) map.get("localpart");
if (assertNotNull(localpart)) {

View File

@ -6,12 +6,13 @@ import java.util.Map;
import java.util.StringTokenizer;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.Transaction;
import de.hsadmin.mods.email.EMailAlias;
public class EMailAliasRemote extends AbstractRemote {
@Override
protected void entity2map(AbstractEntity entity, Map<String, Object> map) {
protected void entity2map(Transaction tx, AbstractEntity entity, Map<String, Object> map) {
EMailAlias alias = (EMailAlias) entity;
String id = Long.toString(alias.getId());
String name = alias.getName();
@ -34,7 +35,7 @@ public class EMailAliasRemote extends AbstractRemote {
}
@Override
protected void map2entity(Map<String, Object> map, AbstractEntity entity) {
protected void map2entity(Transaction tx, Map<String, Object> map, AbstractEntity entity) {
EMailAlias alias = (EMailAlias) entity;
String name = (String) map.get("name");
if (assertNotNull(name)) {

View File

@ -10,6 +10,7 @@ import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.AnnFieldIO;
import de.hsadmin.core.model.HSAdminException;
import de.hsadmin.core.model.ReadWriteAccess;
import de.hsadmin.core.model.Transaction;
import de.hsadmin.core.util.ReflectionUtil;
public abstract class GenericAbstractRemote extends AbstractRemote {
@ -21,7 +22,7 @@ public abstract class GenericAbstractRemote extends AbstractRemote {
protected abstract void regularizeKeys(Map<String, String> whereParams);
@Override
protected void entity2map(AbstractEntity entity, Map<String, Object> resultMap) {
protected void entity2map(Transaction tx, AbstractEntity entity, Map<String, Object> resultMap) {
Class<? extends AbstractEntity> entityClass = getEntityClass();
Field[] fields = entityClass.getDeclaredFields();
for (Field f : fields) {
@ -37,7 +38,7 @@ public abstract class GenericAbstractRemote extends AbstractRemote {
}
@Override
protected void map2entity(Map<String, Object> paramsMap, AbstractEntity entity) throws HSAdminException {
protected void map2entity(Transaction tx, Map<String, Object> paramsMap, AbstractEntity entity) throws HSAdminException {
Class<? extends AbstractEntity> entityClass = getEntityClass();
Set<String> keySet = paramsMap.keySet();
for (String key : keySet) {

View File

@ -3,12 +3,13 @@ package de.hsadmin.remote;
import java.util.Map;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.Transaction;
import de.hsadmin.mods.db.MySqlDatabase;
public class MysqlDbRemote extends AbstractRemote {
@Override
protected void entity2map(AbstractEntity entity, Map<String, Object> map) {
protected void entity2map(Transaction tx, AbstractEntity entity, Map<String, Object> map) {
MySqlDatabase db = (MySqlDatabase) entity;
String id = Long.toString(db.getId());
String name = db.getName();
@ -32,7 +33,7 @@ public class MysqlDbRemote extends AbstractRemote {
}
@Override
protected void map2entity(Map<String, Object> map, AbstractEntity entity) {
protected void map2entity(Transaction tx, Map<String, Object> map, AbstractEntity entity) {
MySqlDatabase db = (MySqlDatabase) entity;
db.setInstance("mysql");
String name = (String) map.get("name");

View File

@ -3,12 +3,13 @@ package de.hsadmin.remote;
import java.util.Map;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.Transaction;
import de.hsadmin.mods.db.MySqlUser;
public class MysqlUserRemote extends AbstractRemote {
@Override
protected void entity2map(AbstractEntity entity, Map<String, Object> map) {
protected void entity2map(Transaction tx, AbstractEntity entity, Map<String, Object> map) {
MySqlUser user = (MySqlUser) entity;
String id = Long.toString(user.getId());
String name = user.getName();
@ -28,7 +29,7 @@ public class MysqlUserRemote extends AbstractRemote {
}
@Override
protected void map2entity(Map<String, Object> map, AbstractEntity entity) {
protected void map2entity(Transaction tx, Map<String, Object> map, AbstractEntity entity) {
MySqlUser user = (MySqlUser) entity;
user.setInstance("mysql");
String name = (String) map.get("name");

View File

@ -6,6 +6,8 @@ import java.util.Map;
import java.util.Set;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.HSAdminException;
import de.hsadmin.core.model.Transaction;
import de.hsadmin.core.util.TextUtil;
import de.hsadmin.mods.cust.Customer;
import de.hsadmin.mods.pac.BasePac;
@ -17,7 +19,7 @@ import de.hsadmin.mods.pac.PacComponent;
public class PacRemote extends AbstractRemote {
@Override
protected void entity2map(AbstractEntity entity, Map<String, Object> resultMap) {
protected void entity2map(Transaction tx, AbstractEntity entity, Map<String, Object> resultMap) {
Pac pac = (Pac) entity;
resultMap.put("name", pac.getName());
resultMap.put("id", Long.toString(pac.getId()));
@ -48,7 +50,7 @@ public class PacRemote extends AbstractRemote {
}
@Override
protected void map2entity(Map<String, Object> setParams, AbstractEntity entity) {
protected void map2entity(Transaction tx, Map<String, Object> setParams, AbstractEntity entity) throws HSAdminException {
Pac pac = (Pac) entity;
BasePac basePac = pac.getBasepac();
String basePacName = (String) setParams.get("basepac");
@ -92,11 +94,16 @@ public class PacRemote extends AbstractRemote {
hive.setName(hiveName);
pac.setHive(hive);
}
pac.initPacComponents(tx.getEntityManager(), basePac);
Object componentsObj = setParams.get("components");
if (componentsObj != null && componentsObj instanceof Map) {
Map<?, ?> componentsMap = (Map<?, ?>) componentsObj;
for (Object key : componentsMap.keySet()) {
pac.getPacComponent(key.toString()).setQuantity(Integer.parseInt(componentsMap.get(key).toString()));
PacComponent pacComponent = pac.getPacComponent(key.toString());
if (pacComponent == null) {
throw new HSAdminException("component " + key.toString() + " not found");
}
pacComponent.setQuantity(Integer.parseInt(componentsMap.get(key).toString()));
}
}
Object nameParamObj = setParams.get("name");

View File

@ -3,12 +3,13 @@ package de.hsadmin.remote;
import java.util.Map;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.Transaction;
import de.hsadmin.mods.db.PgSqlDatabase;
public class PgsqlDbRemote extends AbstractRemote {
@Override
protected void entity2map(AbstractEntity entity, Map<String, Object> map) {
protected void entity2map(Transaction tx, AbstractEntity entity, Map<String, Object> map) {
PgSqlDatabase db = (PgSqlDatabase) entity;
String id = Long.toString(db.getId());
String name = db.getName();
@ -32,7 +33,7 @@ public class PgsqlDbRemote extends AbstractRemote {
}
@Override
protected void map2entity(Map<String, Object> map, AbstractEntity entity) {
protected void map2entity(Transaction tx, Map<String, Object> map, AbstractEntity entity) {
PgSqlDatabase db = (PgSqlDatabase) entity;
db.setInstance("pgsql");
String name = (String) map.get("name");

View File

@ -3,12 +3,13 @@ package de.hsadmin.remote;
import java.util.Map;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.Transaction;
import de.hsadmin.mods.db.PgSqlUser;
public class PgsqlUserRemote extends AbstractRemote {
@Override
protected void entity2map(AbstractEntity entity, Map<String, Object> map) {
protected void entity2map(Transaction tx, AbstractEntity entity, Map<String, Object> map) {
PgSqlUser user = (PgSqlUser) entity;
String id = Long.toString(user.getId());
String name = user.getName();
@ -28,7 +29,7 @@ public class PgsqlUserRemote extends AbstractRemote {
}
@Override
protected void map2entity(Map<String, Object> map, AbstractEntity entity) {
protected void map2entity(Transaction tx, Map<String, Object> map, AbstractEntity entity) {
PgSqlUser user = (PgSqlUser) entity;
user.setInstance("pgsql");
String name = (String) map.get("name");

View File

@ -4,6 +4,7 @@ import java.util.Date;
import java.util.Map;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.Transaction;
import de.hsadmin.core.qserv.QueueTask;
import de.hsadmin.core.qserv.QueueTask.QueueTaskStatus;
import de.hsadmin.core.util.TextUtil;
@ -17,7 +18,7 @@ public class QueueTaskRemote extends AbstractRemote {
}
@Override
protected void entity2map(AbstractEntity entity, Map<String, Object> resultMap) {
protected void entity2map(Transaction tx, AbstractEntity entity, Map<String, Object> resultMap) {
QueueTask task = (QueueTask) entity;
resultMap.put("id", Long.toString(task.getId()));
QueueTaskStatus status = task.getStatus();
@ -38,7 +39,7 @@ public class QueueTaskRemote extends AbstractRemote {
}
@Override
protected void map2entity(Map<String, Object> setParams, AbstractEntity entity) {
protected void map2entity(Transaction tx, Map<String, Object> setParams, AbstractEntity entity) {
// never used
}

View File

@ -3,6 +3,7 @@ package de.hsadmin.remote;
import java.util.Map;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.Transaction;
import de.hsadmin.mods.user.UnixUser;
public class UnixUserRemote extends AbstractRemote {
@ -13,7 +14,7 @@ public class UnixUserRemote extends AbstractRemote {
}
@Override
protected void entity2map(AbstractEntity entity, Map<String, Object> map) {
protected void entity2map(Transaction tx, AbstractEntity entity, Map<String, Object> map) {
UnixUser user = (UnixUser) entity;
map.put("id", Long.toString(user.getId()));
map.put("name", user.getName());
@ -33,7 +34,7 @@ public class UnixUserRemote extends AbstractRemote {
}
@Override
protected void map2entity(Map<String, Object> map, AbstractEntity entity) {
protected void map2entity(Transaction tx, Map<String, Object> map, AbstractEntity entity) {
UnixUser user = (UnixUser) entity;
String id = (String) map.get("id");
if (assertNotNull(id)) {

View File

@ -1,99 +0,0 @@
package de.hsadmin.processor;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import de.hsadmin.core.qserv.Processor;
import de.hsadmin.core.qserv.ProcessorException;
import de.hsadmin.mods.cust.Customer;
import de.hsadmin.mods.pac.BasePac;
import de.hsadmin.mods.pac.Hive;
import de.hsadmin.mods.pac.Pac;
import de.hsadmin.mods.pac.PacProcessorFactory;
public class PacProcessor {
private static EntityManagerFactory emFactory;
private EntityManager entityManager;
private PacProcessorFactory pacProcFactory;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
emFactory = Persistence.createEntityManagerFactory("hsadmin");
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
emFactory.close();
}
@Before
public void setUp() throws Exception {
entityManager = emFactory.createEntityManager();
pacProcFactory = new PacProcessorFactory();
}
@After
public void tearDown() throws Exception {
if (entityManager != null) {
entityManager.close();
}
}
@Test
public void createCreateProcessor() {
Customer cust = findCustomer("hsh00-hsh");
assertNotNull(cust);
BasePac basepac = findBasePacDW();
assertNotNull(basepac);
Hive hive = findHive("h99");
assertNotNull(hive);
try {
Processor processor = pacProcFactory.createCreateProcessor(entityManager, new Pac("pac01", cust, basepac, hive));
System.out.println(processor.toString());
} catch (ProcessorException e) {
fail(e.getMessage());
}
}
private BasePac findBasePacDW() {
Query basepacQuery = entityManager.createQuery("SELECT b FROM BasePacs b WHERE b.name = :basepacName AND b.valid = :valid");
basepacQuery.setParameter("basepacName", "PAC/WEB");
basepacQuery.setParameter("valid", Boolean.TRUE);
return (BasePac) basepacQuery.getSingleResult();
}
private Customer findCustomer(String name) {
Query custQuery = entityManager.createQuery("SELECT c FROM Customers c WHERE c.name = :custName");
custQuery.setParameter("custName", name);
return (Customer) custQuery.getSingleResult();
}
private Hive findHive(String name) {
Query hiveQuery = entityManager.createQuery("SELECT h FROM Hives h WHERE h.name = :hiveName");
hiveQuery.setParameter("hiveName", name);
return (Hive) hiveQuery.getSingleResult();
}
@Test
public void createUpdateProcessor() {
fail("Not yet implemented");
}
@Test
public void createDeleteProcessor() {
fail("Not yet implemented");
}
}

View File

@ -79,7 +79,7 @@ public class InitDataTest {
setParams.put("name", "aaa00");
setParams.put("hive", "h99");
setParams.put("customer", "hsh00-aaa");
setParams.put("basepac", Pac.PAC_WEB_BASE);
setParams.put("basepac", Pac.PAC_WEB);
setParams.put("curinetaddr", "176.9.242.74");
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),

View File

@ -0,0 +1,135 @@
package de.hsadmin.remote;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.HashMap;
import java.util.Map;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import de.hsadmin.core.util.Config;
import de.hsadmin.mods.pac.Pac;
public class PacMigrationTest {
private static final String MODULE = "pac";
private XmlRpcClient client;
private RemoteCASHelper cas;
private Config config;
@Before
public void setUp() throws Exception {
client = RemoteTestHelper.getClient();
cas = new RemoteCASHelper();
config = Config.getInstance();
}
@After
public void tearDown() throws Exception {
client = null;
cas = null;
}
@Test
public void testCreate() {
int count = getPacsCount();
String user = "ad";
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, Object> setParams = new HashMap<String, Object>();
setParams.put("name", "aaa04");
setParams.put("hive", "h99");
setParams.put("customer", config.getProperty("accountprefix.customer") + "-aaa");
setParams.put("basepac", Pac.PAC_DW);
setParams.put("curinetaddr", "176.9.242.77");
HashMap<String, String> components = new HashMap<String, String>();
components.put("QUOTA", "512");
components.put("TRAFFIC", "5");
components.put("DAEMON", "1");
setParams.put("components", components);
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
setParams };
try {
Object execute = client.execute(MODULE + ".add", params);
assertTrue(execute instanceof Map<?, ?>);
} catch (XmlRpcException e) {
fail(e.getMessage());
}
assertEquals(count + 1, getPacsCount());
setParams = new HashMap<String, Object>();
Map<String, String> whereParams = new HashMap<String, String>();
setParams.put("password", "test123");
whereParams.put("name", "aaa04");
params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
setParams, whereParams };
try {
client.execute("user.update", params);
} catch (XmlRpcException e) {
fail(e.getMessage());
}
}
@Test
public void testUpdate() {
String user = "ad";
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, Object> setParams = new HashMap<String, Object>();
Map<String, String> components = new HashMap<String, String>();
setParams.put("basepac", Pac.PAC_WEB);
setParams.put("components", components);
components.put("QUOTA", "1024");
components.put("TRAFFIC", "5");
Map<String, String> whereParams = new HashMap<String, String>();
whereParams.put("name", "aaa04");
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
setParams, whereParams };
try {
Object execute = client.execute(MODULE + ".update", params);
assertNotNull(execute);
params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
whereParams };
execute = client.execute(MODULE + ".search", params);
assertNotNull(execute);
assertTrue(execute instanceof Object[]);
Object[] untypedResultArray = (Object[]) execute;
assertEquals(1, untypedResultArray.length);
assertTrue(untypedResultArray[0] instanceof Map<?,?>);
@SuppressWarnings("unchecked")
Map<String, ?> pacResultMap = (Map<String, ?>) untypedResultArray[0];
assertEquals(Pac.PAC_WEB, pacResultMap.get("basepac"));
} catch (XmlRpcException e) {
fail(e.getMessage());
}
}
private int getPacsCount() {
int count = 0;
String user = "hsh00-aaa";
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>();
whereParams.put("customer", config.getProperty("accountprefix.customer") + "-aaa");
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
whereParams };
try {
Object execute = client.execute(MODULE + ".search", params);
Object[] result = (Object[]) execute;
count = result.length;
} catch (XmlRpcException e) {
fail(e.getMessage());
}
return count;
}
}

View File

@ -93,7 +93,7 @@ public class PacTest {
setParams.put("name", "aaa01");
setParams.put("hive", "h99");
setParams.put("customer", config.getProperty("accountprefix.customer") + "-aaa");
setParams.put("basepac", Pac.PAC_WEB_BASE);
setParams.put("basepac", Pac.PAC_WEB);
setParams.put("curinetaddr", "176.9.242.76");
HashMap<String, String> components = new HashMap<String, String>();
components.put("QUOTA", "512");

View File

@ -47,7 +47,7 @@ public class SSLCertDomainTest {
setParams.put("name", "aaa02");
setParams.put("hive", "h99");
setParams.put("customer", config.getProperty("accountprefix.customer") + "-aaa");
setParams.put("basepac", Pac.PAC_WEB_BASE);
setParams.put("basepac", Pac.PAC_WEB);
setParams.put("curinetaddr", "176.9.242.77");
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
@ -78,7 +78,7 @@ public class SSLCertDomainTest {
setParams.put("name", "aaa03");
setParams.put("hive", "h99");
setParams.put("customer", config.getProperty("accountprefix.customer") + "-aaa");
setParams.put("basepac", Pac.PAC_DW_BASE);
setParams.put("basepac", Pac.PAC_DW);
setParams.put("curinetaddr", "176.9.242.78");
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),