1 files added
1 files deleted
32 files modified
| | |
| | | -- 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 |
| | |
| | | -- 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 |
| | |
| | | -- 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' ; |
| | | |
| | |
| | | |
| | | 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 { |
| | |
| | | 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); |
| | | } |
| | |
| | | |
| | | 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(); |
| | |
| | | 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); |
| | | } |
| | |
| | | |
| | | 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) { |
| | |
| | | } |
| | | 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); |
| | |
| | | |
| | | 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(); |
| | |
| | | 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); |
| | | } |
| | |
| | | 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 |
| | |
| | | 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 |
| | |
| | | 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, |
| | |
| | | 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); |
| | | } |
| | | |
| | |
| | | |
| | | 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 { |
| | |
| | | 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); |
| | | } |
| | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | import javax.persistence.Column; |
| | |
| | | @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; |
| | | |
| | |
| | | @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); |
| | |
| | | @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) { |
| | |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | |
| | | public void setbasePac(BasePac basePac) { |
| | | this.basePac = basePac; |
| | | if (basePac != null) { |
| | | this.basePacId = basePac.id(); |
| | | } |
| | | } |
| | | |
| | | public BaseComponent getBaseComponent() { |
| | |
| | | |
| | | public void setBaseComponent(BaseComponent baseComponent) { |
| | | this.baseComponent = baseComponent; |
| | | if (baseComponent != null) { |
| | | this.baseComponentId = baseComponent.id(); |
| | | } |
| | | } |
| | | |
| | | public Pac getPac() { |
| | |
| | | |
| | | public void setPac(Pac pac) { |
| | | this.pac = pac; |
| | | if (pac != null) { |
| | | this.pacId = pac.id(); |
| | | } |
| | | } |
| | | |
| | | public int getQuantity() { |
| | |
| | | |
| | | public void setCancelled(Date cancelled) { |
| | | 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; |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | 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; |
| | | } |
| | | |
| | | } |
| | |
| | | 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"); |
| | |
| | | } |
| | | |
| | | @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); |
| | |
| | | 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); |
| | |
| | | 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(); |
| | |
| | | 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( |
| | |
| | | package de.hsadmin.mods.user; |
| | | |
| | | import static javax.persistence.FetchType.EAGER; |
| | | import static javax.persistence.GenerationType.SEQUENCE; |
| | | |
| | | 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; |
| | |
| | | |
| | | @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) |
| | |
| | | |
| | | public class UnixUserModuleImpl extends AbstractModuleImpl { |
| | | |
| | | private static final int UNIXUSERS_PER_MULTI_OPTION = 50; |
| | | |
| | | public UnixUserModuleImpl() { |
| | | } |
| | | |
| | |
| | | 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); |
| | |
| | | |
| | | 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); |
| | | |
| | |
| | | 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); |
| | | } |
| | |
| | | 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"); |
| | |
| | | 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); |
| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | @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()); |
| | |
| | | } |
| | | |
| | | @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"); |
| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | @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); |
| | |
| | | } |
| | | |
| | | @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"); |
| | |
| | | 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(); |
| | |
| | | } |
| | | |
| | | @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)) { |
| | |
| | | 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(); |
| | |
| | | } |
| | | |
| | | @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)) { |
| | |
| | | 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 { |
| | |
| | | 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) { |
| | |
| | | } |
| | | |
| | | @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) { |
| | |
| | | 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(); |
| | |
| | | } |
| | | |
| | | @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"); |
| | |
| | | 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(); |
| | |
| | | } |
| | | |
| | | @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"); |
| | |
| | | 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; |
| | |
| | | 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())); |
| | |
| | | } |
| | | |
| | | @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"); |
| | |
| | | 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"); |
| | |
| | | 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(); |
| | |
| | | } |
| | | |
| | | @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"); |
| | |
| | | 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(); |
| | |
| | | } |
| | | |
| | | @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"); |
| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | @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(); |
| | |
| | | } |
| | | |
| | | @Override |
| | | protected void map2entity(Map<String, Object> setParams, AbstractEntity entity) { |
| | | protected void map2entity(Transaction tx, Map<String, Object> setParams, AbstractEntity entity) { |
| | | // never used |
| | | } |
| | | |
| | |
| | | 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 { |
| | |
| | | } |
| | | |
| | | @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()); |
| | |
| | | } |
| | | |
| | | @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)) { |
| | |
| | | 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()), |
New file |
| | |
| | | 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; |
| | | } |
| | | |
| | | } |
| | |
| | | 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"); |
| | |
| | | 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()), |
| | |
| | | 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()), |