Arbeit am member-Modul

This commit is contained in:
Peter Hormanns 2010-10-04 17:44:49 +00:00
parent 4dd9894b86
commit a6c4debb06
38 changed files with 793 additions and 335 deletions

View File

@ -13,7 +13,7 @@ import java.util.Map;
import de.hsadmin.cliClientConnector.CLIClientConnectorServlet.FunctionNotKnownException; import de.hsadmin.cliClientConnector.CLIClientConnectorServlet.FunctionNotKnownException;
import de.hsadmin.cliClientConnector.CLIClientConnectorServlet.UnknownModuleException; import de.hsadmin.cliClientConnector.CLIClientConnectorServlet.UnknownModuleException;
import de.hsadmin.core.model.Entity; import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.ModuleInterface; import de.hsadmin.core.model.ModuleInterface;
/** /**
@ -98,7 +98,7 @@ public class ArgumentParser {
} else if( type.equals("java.util.Set") ) { } else if( type.equals("java.util.Set") ) {
val = "<Set>"; val = "<Set>";
} else try { } else try {
Entity v = (Entity)value; AbstractEntity v = (AbstractEntity)value;
val = v.createStringKey(); val = v.createStringKey();
if( deep && !foundObjects.contains(v) ) { if( deep && !foundObjects.contains(v) ) {
foundObjects.add(v); foundObjects.add(v);

View File

@ -16,7 +16,7 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import de.hsadmin.core.model.Entity; import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.GenericModuleImpl; import de.hsadmin.core.model.GenericModuleImpl;
import de.hsadmin.core.model.ModuleInterface; import de.hsadmin.core.model.ModuleInterface;
import de.hsadmin.core.model.TicketAuthentication; import de.hsadmin.core.model.TicketAuthentication;
@ -210,7 +210,7 @@ public class CLIClientConnectorServlet extends HttpServlet {
String kname = hasGetter(eType, k); String kname = hasGetter(eType, k);
if (kname != null) { if (kname != null) {
rval += (first ? "" : " and ") rval += (first ? "" : " and ")
+ "(obj." + Entity.escapeString(kname) + " = '" + Entity.escapeString(where.get(k)) + "')"; + "(obj." + AbstractEntity.escapeString(kname) + " = '" + AbstractEntity.escapeString(where.get(k)) + "')";
first = false; first = false;
} }
} }
@ -250,7 +250,7 @@ public class CLIClientConnectorServlet extends HttpServlet {
Transaction transaction = module.getTransaction(); Transaction transaction = module.getTransaction();
transaction.beginTransaction(); transaction.beginTransaction();
try { try {
Method m = module.getClass().getMethod("add", Entity.class); Method m = module.getClass().getMethod("add", AbstractEntity.class);
Object o = cls.newInstance(); Object o = cls.newInstance();
setValues(o, set, module); setValues(o, set, module);
m.invoke(module, o); m.invoke(module, o);
@ -278,11 +278,11 @@ public class CLIClientConnectorServlet extends HttpServlet {
} }
// / checks wheather all 'oids' are in 'list' // / checks wheather all 'oids' are in 'list'
private void checkOids(List<Entity> list, List<String> oids) { private void checkOids(List<AbstractEntity> list, List<String> oids) {
List<String> oidsNotFound = new ArrayList<String>(); List<String> oidsNotFound = new ArrayList<String>();
for (String id : oids) { for (String id : oids) {
boolean found = false; boolean found = false;
for (Entity e : list) { for (AbstractEntity e : list) {
String foundKey = e.createStringKey(); String foundKey = e.createStringKey();
if (foundKey.equals(id)) { if (foundKey.equals(id)) {
found = true; found = true;
@ -310,12 +310,12 @@ public class CLIClientConnectorServlet extends HttpServlet {
try { try {
Method m = module.getClass().getMethod("search", Class.class, Method m = module.getClass().getMethod("search", Class.class,
String.class, String.class); String.class, String.class);
List<Entity> list = (List<Entity>) m.invoke(module, cls, List<AbstractEntity> list = (List<AbstractEntity>) m.invoke(module, cls,
buildQuery(cls, where, oids), null); buildQuery(cls, where, oids), null);
checkOids(list, oids); checkOids(list, oids);
Method m2 = module.getClass().getMethod("update", Entity.class); Method m2 = module.getClass().getMethod("update", AbstractEntity.class);
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
Entity entity = list.get(i); AbstractEntity entity = list.get(i);
tx.detach(entity); tx.detach(entity);
setValues(entity, set, module); setValues(entity, set, module);
m2.invoke(module, entity); m2.invoke(module, entity);
@ -341,10 +341,10 @@ public class CLIClientConnectorServlet extends HttpServlet {
try { try {
Method m = Method m =
module.getClass().getMethod("search", Class.class, String.class, String.class); module.getClass().getMethod("search", Class.class, String.class, String.class);
List<Entity> list = List<AbstractEntity> list =
(List<Entity>) m.invoke(module, cls, buildQuery(cls, where, oids), null); (List<AbstractEntity>) m.invoke(module, cls, buildQuery(cls, where, oids), null);
checkOids(list, oids); checkOids(list, oids);
Method m2 = module.getClass().getMethod("delete", Entity.class); Method m2 = module.getClass().getMethod("delete", AbstractEntity.class);
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
Object o = list.get(i); Object o = list.get(i);
m2.invoke(module, o); m2.invoke(module, o);

View File

@ -9,7 +9,7 @@ import javax.persistence.EntityManager;
import de.hsadmin.mods.user.UnixUser; import de.hsadmin.mods.user.UnixUser;
public abstract class Entity { public abstract class AbstractEntity {
/** /**
* trims whitespace from both ends, but a null remains null. * trims whitespace from both ends, but a null remains null.
@ -137,7 +137,7 @@ public abstract class Entity {
* @param entity * @param entity
* @return * @return
*/ */
public boolean sameIdAs(Entity entity) { public boolean sameIdAs(AbstractEntity entity) {
if (entity == null) if (entity == null)
return false; return false;
if (getClass() != entity.getClass()) if (getClass() != entity.getClass())
@ -183,7 +183,7 @@ public abstract class Entity {
* @param em * @param em
* @param loginUser * @param loginUser
*/ */
public Entity merge(EntityManager em, UnixUser loginUser) { public AbstractEntity merge(EntityManager em, UnixUser loginUser) {
return em.merge(this); return em.merge(this);
} }
@ -228,7 +228,7 @@ public abstract class Entity {
* JBoss 5.1. * JBoss 5.1.
* This is just for testing, it does not use the proper class loader! * This is just for testing, it does not use the proper class loader!
*/ */
public <T extends Entity> T replicate() { public <T extends AbstractEntity> T replicate() {
try { try {
ByteArrayOutputStream baOut = new ByteArrayOutputStream(); ByteArrayOutputStream baOut = new ByteArrayOutputStream();
ObjectOutputStream oOut = new ObjectOutputStream(baOut); ObjectOutputStream oOut = new ObjectOutputStream(baOut);

View File

@ -39,7 +39,7 @@ public abstract class AbstractModuleImpl implements ModuleInterface {
* @return * @return
*/ */
private String restrict(Class<?> entityClass, UnixUser loginUser, String condition) { private String restrict(Class<?> entityClass, UnixUser loginUser, String condition) {
String restriction = Entity.restriction(entityClass, loginUser); String restriction = AbstractEntity.restriction(entityClass, loginUser);
if (restriction == null) if (restriction == null)
return condition; return condition;
if (condition != null && condition.length() > 0) if (condition != null && condition.length() > 0)
@ -53,13 +53,13 @@ public abstract class AbstractModuleImpl implements ModuleInterface {
return transaction; return transaction;
} }
public Entity initialize(Entity newEntity) public AbstractEntity initialize(AbstractEntity newEntity)
throws AuthorisationException { throws AuthorisationException {
newEntity.initialize(transaction.getEntityManager(), getLoginUser()); newEntity.initialize(transaction.getEntityManager(), getLoginUser());
return newEntity; return newEntity;
} }
public Entity add(Entity newEntity) throws HSAdminException { public AbstractEntity add(AbstractEntity newEntity) throws HSAdminException {
// get the user who is logged in // get the user who is logged in
UnixUser loginUser = getLoginUser(); UnixUser loginUser = getLoginUser();
@ -95,8 +95,8 @@ public abstract class AbstractModuleImpl implements ModuleInterface {
return newEntity; return newEntity;
} }
public Entity find(Class<? extends Entity> entityClass, Object key) throws HSAdminException { public AbstractEntity find(Class<? extends AbstractEntity> entityClass, Object key) throws HSAdminException {
Entity entity = transaction.getEntityManager().find(entityClass, key); AbstractEntity entity = transaction.getEntityManager().find(entityClass, key);
// check rights // check rights
UnixUser loginUser = getLoginUser(); UnixUser loginUser = getLoginUser();
@ -106,7 +106,7 @@ public abstract class AbstractModuleImpl implements ModuleInterface {
return entity; return entity;
} }
public Entity findByString(Class<? extends Entity> entityClass, String key) throws HSAdminException { public AbstractEntity findByString(Class<? extends AbstractEntity> entityClass, String key) throws HSAdminException {
// find a static method which creates the query // find a static method which creates the query
java.lang.reflect.Method method = null; java.lang.reflect.Method method = null;
try { try {
@ -117,7 +117,7 @@ public abstract class AbstractModuleImpl implements ModuleInterface {
method = null; method = null;
} }
Entity entity; AbstractEntity entity;
if (method == null) if (method == null)
entity = transaction.getEntityManager().find(entityClass, key); entity = transaction.getEntityManager().find(entityClass, key);
else { else {
@ -131,7 +131,7 @@ public abstract class AbstractModuleImpl implements ModuleInterface {
} }
// perform the query // perform the query
List<Entity> result = search(entityClass, query, null); List<AbstractEntity> result = search(entityClass, query, null);
if (result.size() > 1) if (result.size() > 1)
throw new javax.persistence.NonUniqueResultException(); throw new javax.persistence.NonUniqueResultException();
if (result.size() == 0) if (result.size() == 0)
@ -147,7 +147,7 @@ public abstract class AbstractModuleImpl implements ModuleInterface {
return entity; return entity;
} }
public List<Entity> search(Class<? extends Entity> entityClass, String condition, String orderBy) throws HSAdminException { public List<AbstractEntity> search(Class<? extends AbstractEntity> entityClass, String condition, String orderBy) throws HSAdminException {
// restrict query // restrict query
UnixUser loginUser = getLoginUser(); UnixUser loginUser = getLoginUser();
condition = restrict(entityClass, loginUser, condition); condition = restrict(entityClass, loginUser, condition);
@ -161,7 +161,7 @@ public abstract class AbstractModuleImpl implements ModuleInterface {
// Fix problem with queries WHERE .. AND (FALSE) -- pe // Fix problem with queries WHERE .. AND (FALSE) -- pe
if (condition != null && condition.contains("AND (FALSE)")) { if (condition != null && condition.contains("AND (FALSE)")) {
return new LinkedList<Entity>(); return new LinkedList<AbstractEntity>();
} }
if (orderBy != null) { if (orderBy != null) {
@ -181,12 +181,12 @@ public abstract class AbstractModuleImpl implements ModuleInterface {
// do query // do query
try { try {
List<?> res = query.getResultList(); List<?> res = query.getResultList();
List<Entity> ret = new LinkedList<Entity>(); List<AbstractEntity> ret = new LinkedList<AbstractEntity>();
// remove entities where login user has no access rights // remove entities where login user has no access rights
for (Object entity : res) { for (Object entity : res) {
if (entity instanceof Entity) { if (entity instanceof AbstractEntity) {
Entity returnedEntity = (Entity) entity; AbstractEntity returnedEntity = (AbstractEntity) entity;
if (returnedEntity.isReadAllowedFor(getLoginUser())) { if (returnedEntity.isReadAllowedFor(getLoginUser())) {
ret.add(returnedEntity); ret.add(returnedEntity);
} }
@ -196,11 +196,11 @@ public abstract class AbstractModuleImpl implements ModuleInterface {
// return clean result // return clean result
return ret; return ret;
} catch (Exception ex) { } catch (Exception ex) {
return null; throw new HSAdminException(ex);
} }
} }
public Entity update(Entity existingEntity) throws HSAdminException { public AbstractEntity update(AbstractEntity existingEntity) throws HSAdminException {
// get the user who is logged in // get the user who is logged in
UnixUser loginUser = getLoginUser(); UnixUser loginUser = getLoginUser();
@ -236,7 +236,7 @@ public abstract class AbstractModuleImpl implements ModuleInterface {
return existingEntity; return existingEntity;
} }
public void delete(Entity existingEntity) throws HSAdminException { public void delete(AbstractEntity existingEntity) throws HSAdminException {
// get the user who is logged in // get the user who is logged in
UnixUser user = getLoginUser(); UnixUser user = getLoginUser();
@ -280,7 +280,7 @@ public abstract class AbstractModuleImpl implements ModuleInterface {
queueProcessor(proc, user, existingEntity, "geloescht"); queueProcessor(proc, user, existingEntity, "geloescht");
} }
public EntityProcessorFactory createProcessorFactory(Class<? extends Entity> entityClass) { public EntityProcessorFactory createProcessorFactory(Class<? extends AbstractEntity> entityClass) {
try { try {
String procFactName = entityClass.getCanonicalName() String procFactName = entityClass.getCanonicalName()
+ "ProcessorFactory"; + "ProcessorFactory";
@ -310,7 +310,7 @@ public abstract class AbstractModuleImpl implements ModuleInterface {
return loginUser; return loginUser;
} }
public void queueProcessor(Processor proc, UnixUser user, Entity entity, String action) { public void queueProcessor(Processor proc, UnixUser user, AbstractEntity entity, String action) {
log.debug("queueing processor for user " + user.getId() + "/" log.debug("queueing processor for user " + user.getId() + "/"
+ user.getUserId() + "/" + user.getName()); + user.getUserId() + "/" + user.getName());
EntityInfo entityInfo = EntityInfo entityInfo =

View File

@ -8,7 +8,7 @@ public class AuthorisationException extends HSAdminException {
private UnixUser user; private UnixUser user;
private String method; private String method;
private Entity entity; private AbstractEntity entity;
private String field; private String field;
public UnixUser getUser() { public UnixUser getUser() {
@ -19,7 +19,7 @@ public class AuthorisationException extends HSAdminException {
return method; return method;
} }
public Entity getEntity() { public AbstractEntity getEntity() {
return entity; return entity;
} }
@ -34,7 +34,7 @@ public class AuthorisationException extends HSAdminException {
this.method = method; this.method = method;
} }
public AuthorisationException(UnixUser user, String method, Entity entity) { public AuthorisationException(UnixUser user, String method, AbstractEntity entity) {
super("nicht authorisiert fuer " + method + "(" super("nicht authorisiert fuer " + method + "("
+ entity.createStringKey() + ")"); + entity.createStringKey() + ")");
@ -43,7 +43,7 @@ public class AuthorisationException extends HSAdminException {
this.entity = entity; this.entity = entity;
} }
public AuthorisationException(UnixUser user, String method, Entity entity, public AuthorisationException(UnixUser user, String method, AbstractEntity entity,
String field) { String field) {
super("nicht authorisiert fuer " + method + "(" super("nicht authorisiert fuer " + method + "("
+ entity.createStringKey() + "." + field + ")"); + entity.createStringKey() + "." + field + ")");

View File

@ -13,7 +13,7 @@ public class EntitySessionHelper {
* @param entityClass * @param entityClass
* @return * @return
*/ */
public static AbstractModuleImpl createEntitySessionWrapper(Class<? extends Entity> entityClass) { public static AbstractModuleImpl createEntitySessionWrapper(Class<? extends AbstractEntity> entityClass) {
// get in instance // get in instance
AbstractModuleImpl impl = null; AbstractModuleImpl impl = null;
try { try {

View File

@ -20,7 +20,7 @@ public class GenericModuleImpl implements ModuleInterface {
} }
@Override @Override
public Entity initialize(Entity newEntity) throws HSAdminException { public AbstractEntity initialize(AbstractEntity newEntity) throws HSAdminException {
log.trace("initialize(" + newEntity + ")"); log.trace("initialize(" + newEntity + ")");
AbstractModuleImpl wrapper = AbstractModuleImpl wrapper =
EntitySessionHelper.createEntitySessionWrapper(newEntity.getClass()); EntitySessionHelper.createEntitySessionWrapper(newEntity.getClass());
@ -29,14 +29,14 @@ public class GenericModuleImpl implements ModuleInterface {
} }
@Override @Override
public Entity add(Entity newEntity) throws HSAdminException { public AbstractEntity add(AbstractEntity newEntity) throws HSAdminException {
if (!newEntity.isNew()) if (!newEntity.isNew())
throw new HSAdminException("cannot add an already persistent entity"); throw new HSAdminException("cannot add an already persistent entity");
log.trace("add(" + newEntity + ")"); log.trace("add(" + newEntity + ")");
AbstractModuleImpl wrapper = AbstractModuleImpl wrapper =
EntitySessionHelper.createEntitySessionWrapper(newEntity.getClass()); EntitySessionHelper.createEntitySessionWrapper(newEntity.getClass());
wrapper.construct(tx); wrapper.construct(tx);
Entity result = null; AbstractEntity result = null;
try { try {
result = wrapper.add(newEntity); result = wrapper.add(newEntity);
return result; return result;
@ -46,7 +46,7 @@ public class GenericModuleImpl implements ModuleInterface {
} }
@Override @Override
public Entity find(Class<? extends Entity> entityClass, Object key) throws HSAdminException { public AbstractEntity find(Class<? extends AbstractEntity> entityClass, Object key) throws HSAdminException {
log.trace("find(" + entityClass + ", " + key + ")"); log.trace("find(" + entityClass + ", " + key + ")");
AbstractModuleImpl wrapper = EntitySessionHelper.createEntitySessionWrapper(entityClass); AbstractModuleImpl wrapper = EntitySessionHelper.createEntitySessionWrapper(entityClass);
wrapper.construct(tx); wrapper.construct(tx);
@ -54,7 +54,7 @@ public class GenericModuleImpl implements ModuleInterface {
} }
@Override @Override
public Entity findByString(Class<? extends Entity> entityClass, String key) throws HSAdminException { public AbstractEntity findByString(Class<? extends AbstractEntity> entityClass, String key) throws HSAdminException {
log.trace("find(" + entityClass + ", " + key + ")"); log.trace("find(" + entityClass + ", " + key + ")");
AbstractModuleImpl wrapper = EntitySessionHelper.createEntitySessionWrapper(entityClass); AbstractModuleImpl wrapper = EntitySessionHelper.createEntitySessionWrapper(entityClass);
wrapper.construct(tx); wrapper.construct(tx);
@ -62,7 +62,7 @@ public class GenericModuleImpl implements ModuleInterface {
} }
@Override @Override
public List<Entity> search(Class<? extends Entity> entityClass, String condition, String orderBy) throws HSAdminException { public List<AbstractEntity> search(Class<? extends AbstractEntity> entityClass, String condition, String orderBy) throws HSAdminException {
log.trace("search(" + entityClass + ", " + condition + ")"); log.trace("search(" + entityClass + ", " + condition + ")");
AbstractModuleImpl wrapper = EntitySessionHelper.createEntitySessionWrapper(entityClass); AbstractModuleImpl wrapper = EntitySessionHelper.createEntitySessionWrapper(entityClass);
wrapper.construct(tx); wrapper.construct(tx);
@ -70,7 +70,7 @@ public class GenericModuleImpl implements ModuleInterface {
} }
@Override @Override
public Entity update(Entity existingEntity) throws HSAdminException { public AbstractEntity update(AbstractEntity existingEntity) throws HSAdminException {
if (existingEntity.isNew()) if (existingEntity.isNew())
return add(existingEntity); return add(existingEntity);
log.debug("update(" + existingEntity + ")"); log.debug("update(" + existingEntity + ")");
@ -84,7 +84,7 @@ public class GenericModuleImpl implements ModuleInterface {
} }
@Override @Override
public void delete(Entity existingEntity) throws HSAdminException { public void delete(AbstractEntity existingEntity) throws HSAdminException {
log.trace("delete(" + existingEntity + ")"); log.trace("delete(" + existingEntity + ")");
AbstractModuleImpl wrapper = AbstractModuleImpl wrapper =
EntitySessionHelper.createEntitySessionWrapper(existingEntity.getClass()); EntitySessionHelper.createEntitySessionWrapper(existingEntity.getClass());

View File

@ -14,37 +14,37 @@ public interface ModuleInterface {
/** /**
* initializes a newly created entity. * initializes a newly created entity.
*/ */
public Entity initialize(Entity newEntity) throws HSAdminException; public AbstractEntity initialize(AbstractEntity newEntity) throws HSAdminException;
/** /**
* Adds a new entity instance to the model. * Adds a new entity instance to the model.
*/ */
public Entity add(Entity newEntity) throws HSAdminException; public AbstractEntity add(AbstractEntity newEntity) throws HSAdminException;
/** /**
* Finds an entity instance in the model, using its primary key. * Finds an entity instance in the model, using its primary key.
*/ */
public Entity find(Class<? extends Entity> entityClass, Object key) throws HSAdminException; public AbstractEntity find(Class<? extends AbstractEntity> entityClass, Object key) throws HSAdminException;
/** /**
* Finds an entity instance in the model, using its primary key in a String * Finds an entity instance in the model, using its primary key in a String
* representation. * representation.
*/ */
public Entity findByString(Class<? extends Entity> entityClass, String key) throws HSAdminException; public AbstractEntity findByString(Class<? extends AbstractEntity> entityClass, String key) throws HSAdminException;
/** /**
* Searches entity instances in the model, using a simplified JPA-QL query. * Searches entity instances in the model, using a simplified JPA-QL query.
*/ */
public List<Entity> search(Class<? extends Entity> entityClass, String query, String orderBy) throws HSAdminException; public List<AbstractEntity> search(Class<? extends AbstractEntity> entityClass, String query, String orderBy) throws HSAdminException;
/** /**
* Updates an existing entity in the model. * Updates an existing entity in the model.
*/ */
public Entity update(Entity existingEntity) throws HSAdminException; public AbstractEntity update(AbstractEntity existingEntity) throws HSAdminException;
/** /**
* Deletes an existing entity from the model. * Deletes an existing entity from the model.
*/ */
public void delete(Entity existingEntity) throws HSAdminException; public void delete(AbstractEntity existingEntity) throws HSAdminException;
} }

View File

@ -11,28 +11,28 @@ public class SecureDefaultModuleImpl extends AbstractModuleImpl {
private static final long serialVersionUID = 4567381515459292565L; private static final long serialVersionUID = 4567381515459292565L;
@Override @Override
public Entity initialize(Entity newEntity) throws AuthorisationException { public AbstractEntity initialize(AbstractEntity newEntity) throws AuthorisationException {
return super.initialize(newEntity); return super.initialize(newEntity);
} }
@Override @Override
public Entity find(Class<? extends Entity> entityClass, Object key) throws HSAdminException { public AbstractEntity find(Class<? extends AbstractEntity> entityClass, Object key) throws HSAdminException {
Entity entity = super.find(entityClass, key); AbstractEntity entity = super.find(entityClass, key);
if (entity != null && !entity.isReadAllowedFor(getLoginUser())) if (entity != null && !entity.isReadAllowedFor(getLoginUser()))
throw new AuthorisationException(getLoginUser(), "find"); throw new AuthorisationException(getLoginUser(), "find");
return entity; return entity;
} }
@Override @Override
public Entity findByString(Class<? extends Entity> entityClass, String key) throws HSAdminException { public AbstractEntity findByString(Class<? extends AbstractEntity> entityClass, String key) throws HSAdminException {
Entity entity = super.findByString(entityClass, key); AbstractEntity entity = super.findByString(entityClass, key);
if (entity != null && !entity.isReadAllowedFor(getLoginUser())) if (entity != null && !entity.isReadAllowedFor(getLoginUser()))
throw new AuthorisationException(getLoginUser(), "findByString"); throw new AuthorisationException(getLoginUser(), "findByString");
return entity; return entity;
} }
@Override @Override
public List<Entity> search(Class<? extends Entity> entityClass, String condition, String orderBy) public List<AbstractEntity> search(Class<? extends AbstractEntity> entityClass, String condition, String orderBy)
throws HSAdminException { throws HSAdminException {
// restrict query to entities where the loginUser could have rights on // restrict query to entities where the loginUser could have rights on
SearchFilter filterAnnot; SearchFilter filterAnnot;
@ -47,13 +47,13 @@ public class SecureDefaultModuleImpl extends AbstractModuleImpl {
} }
// do query // do query
List<Entity> res = super.search(entityClass, condition, orderBy); List<AbstractEntity> res = super.search(entityClass, condition, orderBy);
List<Entity> ret = new LinkedList<Entity>(); List<AbstractEntity> ret = new LinkedList<AbstractEntity>();
// remove entities where login user has no access rights // remove entities where login user has no access rights
if (res != null) { if (res != null) {
for (Entity entity : res) { for (AbstractEntity entity : res) {
Entity returnedEntity = entity; AbstractEntity returnedEntity = entity;
if (returnedEntity.isReadAllowedFor(getLoginUser())) if (returnedEntity.isReadAllowedFor(getLoginUser()))
ret.add(returnedEntity); ret.add(returnedEntity);
} }
@ -77,21 +77,21 @@ public class SecureDefaultModuleImpl extends AbstractModuleImpl {
} }
@Override @Override
public Entity add(Entity newEntity) throws HSAdminException { public AbstractEntity add(AbstractEntity newEntity) throws HSAdminException {
// access rights checking is done by base class // access rights checking is done by base class
return super.add(newEntity); return super.add(newEntity);
} }
@Override @Override
public Entity update(Entity existingEntity) throws HSAdminException { public AbstractEntity update(AbstractEntity existingEntity) throws HSAdminException {
// access rights checking is done by base class // access rights checking is done by base class
return super.update(existingEntity); return super.update(existingEntity);
} }
@Override @Override
public void delete(Entity detachedEntity) throws HSAdminException { public void delete(AbstractEntity detachedEntity) throws HSAdminException {
// get the entity from the database // get the entity from the database
Entity attachedEntity = getTransaction().getEntityManager().find(detachedEntity.getClass(), AbstractEntity attachedEntity = getTransaction().getEntityManager().find(detachedEntity.getClass(),
detachedEntity.id()); detachedEntity.id());
// does the login user have the right to delete? // does the login user have the right to delete?

View File

@ -150,7 +150,7 @@ public class Transaction {
* Used to detach entities before update. Makes it possible to compare * Used to detach entities before update. Makes it possible to compare
* old and new attribute values. * old and new attribute values.
*/ */
public void detach(Entity entity) { public void detach(AbstractEntity entity) {
// TODO: replace hibernate specific implmentation // TODO: replace hibernate specific implmentation
// org.hibernate.Session hSession = (Session) entityManager.getDelegate(); // org.hibernate.Session hSession = (Session) entityManager.getDelegate();
// hSession.evict(entity); // hSession.evict(entity);

View File

@ -13,6 +13,15 @@ public class PersistenceManager {
private Map<String, EntityManagerFactory> persistenceUnits; private Map<String, EntityManagerFactory> persistenceUnits;
public static EntityManager getEntityManager(String persistUnitName) {
EntityManagerFactory emf = PersistenceManager.getInstance().getEMF(persistUnitName);
return emf.createEntityManager();
}
public static void close() {
getInstance().closeFactories();
}
private PersistenceManager() { private PersistenceManager() {
persistenceUnits = new HashMap<String, EntityManagerFactory>(); persistenceUnits = new HashMap<String, EntityManagerFactory>();
} }
@ -26,12 +35,6 @@ public class PersistenceManager {
return emf; return emf;
} }
public static EntityManager getEntityManager(String persistUnitName) {
PersistenceManager pm = PersistenceManager.getInstance();
EntityManagerFactory emf = pm.getEMF(persistUnitName);
return emf.createEntityManager();
}
private static PersistenceManager getInstance() { private static PersistenceManager getInstance() {
if (instance == null) { if (instance == null) {
instance = new PersistenceManager(); instance = new PersistenceManager();
@ -39,5 +42,12 @@ public class PersistenceManager {
return instance; return instance;
} }
private void closeFactories() {
for (String puName : persistenceUnits.keySet()) {
System.out.println("Persistence Unit: " + puName);
EntityManagerFactory emf = persistenceUnits.get(puName);
emf.close();
persistenceUnits.remove(puName);
}
}
} }

View File

@ -0,0 +1,23 @@
package de.hsadmin.core.model.onetier;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
public class PersistenceManagerContextListener implements ServletContextListener {
public PersistenceManagerContextListener() {
}
@Override
public void contextDestroyed(ServletContextEvent contextEvent) {
System.out.println("PersistenceManager.contextDestroyed()");
PersistenceManager.close();
}
@Override
public void contextInitialized(ServletContextEvent contextEvent) {
// do nothing
}
}

View File

@ -2,7 +2,7 @@ package de.hsadmin.core.qserv;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import de.hsadmin.core.model.Entity; import de.hsadmin.core.model.AbstractEntity;
/** /**
* Most processor factories need only these methods. * Most processor factories need only these methods.
@ -10,13 +10,13 @@ import de.hsadmin.core.model.Entity;
* @author peter * @author peter
*/ */
public interface EntityProcessorFactory { public interface EntityProcessorFactory {
public <T extends Entity> Processor createCreateProcessor(EntityManager em, public <T extends AbstractEntity> Processor createCreateProcessor(EntityManager em,
T entity) throws ProcessorException; T entity) throws ProcessorException;
public <T extends Entity> Processor createUpdateProcessor(EntityManager em, public <T extends AbstractEntity> Processor createUpdateProcessor(EntityManager em,
T newEntity) throws ProcessorException; T newEntity) throws ProcessorException;
public <T extends Entity> Processor createDeleteProcessor(EntityManager em, public <T extends AbstractEntity> Processor createDeleteProcessor(EntityManager em,
T entity) throws ProcessorException; T entity) throws ProcessorException;
} }

View File

@ -7,7 +7,7 @@ import javax.persistence.EntityManager;
import javax.persistence.FetchType; import javax.persistence.FetchType;
import javax.persistence.GenerationType; import javax.persistence.GenerationType;
import de.hsadmin.core.model.Entity; import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.EntityInfo; import de.hsadmin.core.model.EntityInfo;
import de.hsadmin.core.model.ModuleImpl; import de.hsadmin.core.model.ModuleImpl;
import de.hsadmin.mods.qstat.QTaskModuleImpl; import de.hsadmin.mods.qstat.QTaskModuleImpl;
@ -18,7 +18,7 @@ import de.hsadmin.mods.user.UnixUser;
@javax.persistence.SequenceGenerator(name = "QueueTaskSeqGen", sequenceName = "queue_task_id_seq") @javax.persistence.SequenceGenerator(name = "QueueTaskSeqGen", sequenceName = "queue_task_id_seq")
@EntityInfo(name = "Systemauftrag") @EntityInfo(name = "Systemauftrag")
@ModuleImpl(QTaskModuleImpl.class) @ModuleImpl(QTaskModuleImpl.class)
public class QueueTask extends Entity implements Serializable { public class QueueTask extends AbstractEntity implements Serializable {
private static final long serialVersionUID = 2171870783383767875L; private static final long serialVersionUID = 2171870783383767875L;

View File

@ -2,16 +2,57 @@ package de.hsadmin.mods.cust;
import static javax.persistence.FetchType.EAGER; import static javax.persistence.FetchType.EAGER;
import javax.persistence.EntityManager; import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.mods.user.UnixUser; import de.hsadmin.mods.user.UnixUser;
@javax.persistence.Entity(name = "BankAccounts") @Entity(name = "BankAccounts")
@javax.persistence.Table(name = "bank_account") @Table(name = "bank_account")
public class BankAccount extends de.hsadmin.core.model.Entity implements public class BankAccount extends AbstractEntity implements Serializable {
java.io.Serializable {
private static final long serialVersionUID = 2965368183976686458L; private static final long serialVersionUID = 2965368183976686458L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "bank_account_id", columnDefinition = "integer")
private long id;
@JoinColumn(name = "bp_id", columnDefinition = "integer")
@OneToOne(fetch = EAGER)
private Customer customer;
@Column(name = "autodebit_ga", columnDefinition = "boolean", nullable = true)
private Boolean autoDebitGA;
@Column(name = "autodebit_ar", columnDefinition = "boolean", nullable = true)
private Boolean autoDebitAR;
@Column(name = "autodebit_op", columnDefinition = "boolean", nullable = true)
private Boolean autoDebitOP;
@Column(name = "bank_customer", columnDefinition = "character varying(50)", nullable = true)
private String bankCustomer;
@Column(name = "bank_account", columnDefinition = "character varying(10)", nullable = true)
private String bankAccount;
@Column(name = "bank_code", columnDefinition = "character varying(8)", nullable = true)
private String bankCode;
@Column(name = "bank_name", columnDefinition = "character varying(50)", nullable = true)
private String bankName;
public static String createQueryFromStringKey(String humanKey) { public static String createQueryFromStringKey(String humanKey) {
return "customer.name = " + humanKey; return "customer.name = " + humanKey;
} }
@ -26,13 +67,6 @@ public class BankAccount extends de.hsadmin.core.model.Entity implements
return id; return id;
} }
// attribute id
@javax.persistence.Id
@javax.persistence.GeneratedValue(strategy = javax.persistence.GenerationType.SEQUENCE)
@javax.persistence.SequenceGenerator(name = "bank_account_id_seq_gen", sequenceName = "bank_account_bank_account_i_seq", allocationSize = 20)
@javax.persistence.Column(name = "bank_account_id", columnDefinition = "integer")
private long id;
public long getId() { public long getId() {
return id; return id;
} }
@ -41,11 +75,6 @@ public class BankAccount extends de.hsadmin.core.model.Entity implements
this.id = id; this.id = id;
} }
// attribute customer
@javax.persistence.JoinColumn(name = "bp_id", columnDefinition = "integer")
@javax.persistence.OneToOne(fetch = EAGER)
private Customer customer;
public Customer getCustomer() { public Customer getCustomer() {
return customer; return customer;
} }
@ -54,10 +83,6 @@ public class BankAccount extends de.hsadmin.core.model.Entity implements
this.customer = customer; this.customer = customer;
} }
// attribute autoDebitGA
@javax.persistence.Column(name = "autodebit_ga", columnDefinition = "boolean", nullable = true)
private Boolean autoDebitGA;
public Boolean isAutoDebitGA() { public Boolean isAutoDebitGA() {
return autoDebitGA; return autoDebitGA;
} }
@ -70,10 +95,6 @@ public class BankAccount extends de.hsadmin.core.model.Entity implements
this.autoDebitGA = autoDebitGA; this.autoDebitGA = autoDebitGA;
} }
// attribute autoDebitAR
@javax.persistence.Column(name = "autodebit_ar", columnDefinition = "boolean", nullable = true)
private Boolean autoDebitAR;
public Boolean isAutoDebitAR() { public Boolean isAutoDebitAR() {
return autoDebitAR; return autoDebitAR;
} }
@ -86,10 +107,6 @@ public class BankAccount extends de.hsadmin.core.model.Entity implements
this.autoDebitAR = autoDebitAR; this.autoDebitAR = autoDebitAR;
} }
// attribute autoDebitOP
@javax.persistence.Column(name = "autodebit_op", columnDefinition = "boolean", nullable = true)
private Boolean autoDebitOP;
public Boolean isAutoDebitOP() { public Boolean isAutoDebitOP() {
return autoDebitOP; return autoDebitOP;
} }
@ -102,10 +119,6 @@ public class BankAccount extends de.hsadmin.core.model.Entity implements
this.autoDebitOP = autoDebitOP; this.autoDebitOP = autoDebitOP;
} }
// attribute bankCustomer
@javax.persistence.Column(name = "bank_customer", columnDefinition = "character varying(50)", nullable = true)
private String bankCustomer;
public String getBankCustomer() { public String getBankCustomer() {
return bankCustomer; return bankCustomer;
} }
@ -114,10 +127,6 @@ public class BankAccount extends de.hsadmin.core.model.Entity implements
this.bankCustomer = bankCustomer; this.bankCustomer = bankCustomer;
} }
// attribute bankAccount
@javax.persistence.Column(name = "bank_account", columnDefinition = "character varying(10)", nullable = true)
private String bankAccount;
public String getBankAccount() { public String getBankAccount() {
return bankAccount; return bankAccount;
} }
@ -126,10 +135,6 @@ public class BankAccount extends de.hsadmin.core.model.Entity implements
this.bankAccount = bankAccount; this.bankAccount = bankAccount;
} }
// attribute bankCode
@javax.persistence.Column(name = "bank_code", columnDefinition = "character varying(8)", nullable = true)
private String bankCode;
public String getBankCode() { public String getBankCode() {
return bankCode; return bankCode;
} }
@ -138,10 +143,6 @@ public class BankAccount extends de.hsadmin.core.model.Entity implements
this.bankCode = bankCode; this.bankCode = bankCode;
} }
// attribute bankName
@javax.persistence.Column(name = "bank_name", columnDefinition = "character varying(50)", nullable = true)
private String bankName;
public String getBankName() { public String getBankName() {
return bankName; return bankName;
} }
@ -150,13 +151,11 @@ public class BankAccount extends de.hsadmin.core.model.Entity implements
this.bankName = bankName; this.bankName = bankName;
} }
// / {$inheritDoc}
@Override @Override
public boolean isNew() { public boolean isNew() {
return id == 0; return id == 0;
} }
// / {@inheritDoc}
@Override @Override
public UnixUser owningUser(EntityManager em) { public UnixUser owningUser(EntityManager em) {
return customer.owningUser(em); return customer.owningUser(em);

View File

@ -1,88 +1,72 @@
package de.hsadmin.mods.cust; package de.hsadmin.mods.cust;
import static javax.persistence.FetchType.EAGER; import static javax.persistence.FetchType.EAGER;
import static javax.persistence.GenerationType.SEQUENCE;
import java.io.Serializable;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.GenerationType;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.mods.user.UnixUser; import de.hsadmin.mods.user.UnixUser;
@javax.persistence.Entity(name = "Contacts") @javax.persistence.Entity(name = "Contacts")
@javax.persistence.Table(name = "contact") @javax.persistence.Table(name = "contact")
@javax.persistence.SequenceGenerator(name = "ContactsSeqGen", sequenceName = "contact_contact_id_seq") public class Contact extends AbstractEntity implements Serializable {
public class Contact extends de.hsadmin.core.model.Entity implements
java.io.Serializable {
private static final long serialVersionUID = 9119607911598098558L; private static final long serialVersionUID = 9119607911598098558L;
// attribute id
@javax.persistence.Id @javax.persistence.Id
@javax.persistence.GeneratedValue(strategy = SEQUENCE, generator = "ContactsSeqGen") @javax.persistence.GeneratedValue(strategy = GenerationType.IDENTITY)
@javax.persistence.Column(name = "contact_id", columnDefinition = "integer") @javax.persistence.Column(name = "contact_id", columnDefinition = "integer")
private long id; private long id;
// attribute customer
@javax.persistence.JoinColumn(name = "bp_id", columnDefinition = "integer") @javax.persistence.JoinColumn(name = "bp_id", columnDefinition = "integer")
@javax.persistence.ManyToOne(fetch = EAGER) @javax.persistence.ManyToOne(fetch = EAGER)
private Customer customer; private Customer customer;
// attribute salut
@javax.persistence.Column(name = "salut", columnDefinition = "character varying(30)") @javax.persistence.Column(name = "salut", columnDefinition = "character varying(30)")
private String salut; private String salut;
// attribute firstName
@javax.persistence.Column(name = "first_name", columnDefinition = "character varying(40)") @javax.persistence.Column(name = "first_name", columnDefinition = "character varying(40)")
private String firstName; private String firstName;
// attribute lastName
@javax.persistence.Column(name = "last_name", columnDefinition = "character varying(40)") @javax.persistence.Column(name = "last_name", columnDefinition = "character varying(40)")
private String lastName; private String lastName;
// attribute title
@javax.persistence.Column(name = "title", columnDefinition = "character varying(20)") @javax.persistence.Column(name = "title", columnDefinition = "character varying(20)")
private String title; private String title;
// attribute firma
@javax.persistence.Column(name = "firma", columnDefinition = "character varying(120)") @javax.persistence.Column(name = "firma", columnDefinition = "character varying(120)")
private String firma; private String firma;
// attribute co
@javax.persistence.Column(name = "co", columnDefinition = "character varying(50)") @javax.persistence.Column(name = "co", columnDefinition = "character varying(50)")
private String co; private String co;
// attribute street
@javax.persistence.Column(name = "street", columnDefinition = "character varying(50)") @javax.persistence.Column(name = "street", columnDefinition = "character varying(50)")
private String street; private String street;
// attribute zipCode
@javax.persistence.Column(name = "zipcode", columnDefinition = "character varying(10)") @javax.persistence.Column(name = "zipcode", columnDefinition = "character varying(10)")
private String zipCode; private String zipCode;
// attribute city
@javax.persistence.Column(name = "city", columnDefinition = "character varying(40)") @javax.persistence.Column(name = "city", columnDefinition = "character varying(40)")
private String city; private String city;
// attribute country
@javax.persistence.Column(name = "country", columnDefinition = "character varying(30)") @javax.persistence.Column(name = "country", columnDefinition = "character varying(30)")
private String country; private String country;
// attribute phonePrivate
@javax.persistence.Column(name = "phone_private", columnDefinition = "character varying(30)") @javax.persistence.Column(name = "phone_private", columnDefinition = "character varying(30)")
private String phonePrivate; private String phonePrivate;
// attribute phoneOffice
@javax.persistence.Column(name = "phone_office", columnDefinition = "character varying(30)") @javax.persistence.Column(name = "phone_office", columnDefinition = "character varying(30)")
private String phoneOffice; private String phoneOffice;
// attribute phoneMobile
@javax.persistence.Column(name = "phone_mobile", columnDefinition = "character varying(30)") @javax.persistence.Column(name = "phone_mobile", columnDefinition = "character varying(30)")
private String phoneMobile; private String phoneMobile;
// attribute fax
@javax.persistence.Column(name = "fax", columnDefinition = "character varying(30)") @javax.persistence.Column(name = "fax", columnDefinition = "character varying(30)")
private String fax; private String fax;
// attribute email
@javax.persistence.Column(name = "email", columnDefinition = "character varying(50)") @javax.persistence.Column(name = "email", columnDefinition = "character varying(50)")
private String email; private String email;
@ -115,18 +99,15 @@ public class Contact extends de.hsadmin.core.model.Entity implements
this.email = email; this.email = email;
} }
// / {@inheritDoc}
public static String createQueryFromStringKey(String humanKey) { public static String createQueryFromStringKey(String humanKey) {
return "name='" + humanKey + "'"; return "name='" + humanKey + "'";
} }
// / {@inheritDoc}
@Override @Override
public String createStringKey() { public String createStringKey() {
return getCustomer().getName(); return getCustomer().getName();
} }
// / {@inheritDoc}
@Override @Override
public long id() { public long id() {
return id; return id;
@ -268,13 +249,11 @@ public class Contact extends de.hsadmin.core.model.Entity implements
this.email = email; this.email = email;
} }
// / {$inheritDoc}
@Override @Override
public boolean isNew() { public boolean isNew() {
return id == 0; return id == 0;
} }
// / {@inheritDoc}
@Override @Override
public UnixUser owningUser(EntityManager em) { public UnixUser owningUser(EntityManager em) {
return null; // TODO: no access yet return null; // TODO: no access yet

View File

@ -3,78 +3,83 @@ package de.hsadmin.mods.cust;
import static javax.persistence.CascadeType.ALL; import static javax.persistence.CascadeType.ALL;
import static javax.persistence.FetchType.EAGER; import static javax.persistence.FetchType.EAGER;
import static javax.persistence.FetchType.LAZY; import static javax.persistence.FetchType.LAZY;
import static javax.persistence.GenerationType.SEQUENCE;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Temporal;
import de.hsadmin.mods.pac.Pac; import de.hsadmin.mods.pac.Pac;
import de.hsadmin.mods.user.UnixUser; import de.hsadmin.mods.user.UnixUser;
@javax.persistence.Entity(name = "Customers") @Entity(name = "Customers")
@javax.persistence.Table(name = "business_partner") @Table(name = "business_partner")
@javax.persistence.SequenceGenerator(name = "CustomersSeqGen", sequenceName = "business_partner_bp_id_seq") public class Customer extends de.hsadmin.core.model.AbstractEntity implements Serializable {
public class Customer extends de.hsadmin.core.model.Entity implements Serializable {
private static final long serialVersionUID = -7450594652238392616L; private static final long serialVersionUID = -7450594652238392616L;
@javax.persistence.Id @Id
@javax.persistence.GeneratedValue(strategy = SEQUENCE, generator = "CustomersSeqGen") @GeneratedValue(strategy = GenerationType.IDENTITY)
@javax.persistence.Column(name = "bp_id", columnDefinition = "integer") @Column(name = "bp_id", columnDefinition = "integer")
private long id; private long id;
@javax.persistence.Column(name = "member_id", columnDefinition = "integer") @Column(name = "member_id", columnDefinition = "integer")
private int memberNo; private int memberNo;
@javax.persistence.Column(name = "member_code", columnDefinition = "character varying(20)") @Column(name = "member_code", columnDefinition = "character varying(20)")
private String name; private String name;
@javax.persistence.Column(name = "member_since", columnDefinition = "date", nullable = true) @Column(name = "member_since", columnDefinition = "date", nullable = true)
private Date memberSince; private Date memberSince;
@javax.persistence.Column(name = "member_until", columnDefinition = "date", nullable = true) @Column(name = "member_until", columnDefinition = "date", nullable = true)
@javax.persistence.Temporal(javax.persistence.TemporalType.DATE) @Temporal(javax.persistence.TemporalType.DATE)
private Date memberUntil; private Date memberUntil;
@javax.persistence.Column(name = "member_role", columnDefinition = "character varying(100)", nullable = true) @Column(name = "member_role", columnDefinition = "character varying(100)", nullable = true)
private String memberRole; private String memberRole;
@javax.persistence.Column(name = "author_contract", columnDefinition = "date", nullable = true) @Column(name = "author_contract", columnDefinition = "date", nullable = true)
@javax.persistence.Temporal(javax.persistence.TemporalType.DATE) @Temporal(javax.persistence.TemporalType.DATE)
private Date authorContract; private Date authorContract;
@javax.persistence.Column(name = "nondisc_contract", columnDefinition = "date", nullable = true) @Column(name = "nondisc_contract", columnDefinition = "date", nullable = true)
@javax.persistence.Temporal(javax.persistence.TemporalType.DATE) @Temporal(javax.persistence.TemporalType.DATE)
private Date nonDiscContract; private Date nonDiscContract;
@javax.persistence.Column(name = "shares_updated", columnDefinition = "date", nullable = true) @Column(name = "shares_updated", columnDefinition = "date", nullable = true)
@javax.persistence.Temporal(javax.persistence.TemporalType.DATE) @Temporal(javax.persistence.TemporalType.DATE)
private Date sharesUpdated; private Date sharesUpdated;
@javax.persistence.Column(name = "shares_signed", columnDefinition = "integer") @Column(name = "shares_signed", columnDefinition = "integer")
private int sharesSigned; private int sharesSigned;
@javax.persistence.Column(name = "uid_vat", columnDefinition = "character varying(20)", nullable = true) @Column(name = "uid_vat", columnDefinition = "character varying(20)", nullable = true)
private String uidVAT; private String uidVAT;
@javax.persistence.OneToMany(fetch = EAGER, cascade = ALL, mappedBy = "customer") @OneToMany(fetch = EAGER, cascade = ALL, mappedBy = "customer")
private Set<Contact> contacts; private Set<Contact> contacts;
// virtual attribute bankAccount @OneToOne(fetch = EAGER, cascade = ALL, mappedBy = "customer")
@javax.persistence.OneToOne(fetch = EAGER, cascade = ALL, mappedBy = "customer")
private BankAccount bankAccount; private BankAccount bankAccount;
// virtual attribute billData @OneToOne(fetch = EAGER, cascade = ALL, mappedBy = "customer")
@javax.persistence.OneToOne(fetch = EAGER, cascade = ALL, mappedBy = "customer")
private CustomersTariff billData; private CustomersTariff billData;
// virtual attribute pacs @OneToMany(fetch = LAZY, cascade = ALL, mappedBy = "customer")
@javax.persistence.OneToMany(fetch = LAZY, cascade = ALL, mappedBy = "customer") @OrderBy("name")
@javax.persistence.OrderBy("name")
private Set<Pac> pacs; private Set<Pac> pacs;
public Customer() { public Customer() {
@ -262,6 +267,6 @@ public class Customer extends de.hsadmin.core.model.Entity implements Serializab
} }
public static String restriction() { public static String restriction() {
return "name=:loginUserName"; return "obj.name=:loginUserName";
} }
} }

View File

@ -0,0 +1,7 @@
package de.hsadmin.mods.cust;
import de.hsadmin.core.model.AbstractModuleImpl;
public class CustomerModuleImpl extends AbstractModuleImpl {
}

View File

@ -1,23 +1,63 @@
package de.hsadmin.mods.cust; package de.hsadmin.mods.cust;
import static javax.persistence.FetchType.EAGER; import static javax.persistence.FetchType.EAGER;
import static javax.persistence.GenerationType.SEQUENCE;
import java.io.Serializable;
import java.util.Date; import java.util.Date;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.GenerationType;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.mods.user.UnixUser; import de.hsadmin.mods.user.UnixUser;
@javax.persistence.Entity(name = "CustomersTariffs") @javax.persistence.Entity(name = "CustomersTariffs")
@javax.persistence.Table(name = "billdata") @javax.persistence.Table(name = "billdata")
@javax.persistence.SequenceGenerator(name = "CustomersTariffsSeqGen", sequenceName = "billdata_billdata_id_seq") public class CustomersTariff extends AbstractEntity implements Serializable {
public class CustomersTariff extends de.hsadmin.core.model.Entity implements
java.io.Serializable {
private static final long serialVersionUID = -3628577459027111705L; private static final long serialVersionUID = -3628577459027111705L;
// / bean ctor @javax.persistence.Id
@javax.persistence.GeneratedValue(strategy = GenerationType.IDENTITY)
@javax.persistence.Column(name = "billdata_id", columnDefinition = "integer")
private long id;
@javax.persistence.JoinColumn(name = "bp_id", columnDefinition = "integer")
@javax.persistence.OneToOne(fetch = EAGER)
private Customer customer;
@javax.persistence.Column(name = "tariff_domain_discount_since", columnDefinition = "date")
@javax.persistence.Temporal(javax.persistence.TemporalType.DATE)
private Date domainDiscountSince;
@javax.persistence.Column(name = "tariff_domain_discount_until", columnDefinition = "date")
@javax.persistence.Temporal(javax.persistence.TemporalType.DATE)
private Date domainDiscountUntil;
@javax.persistence.Column(name = "tariff_traffic_discount_since", columnDefinition = "date")
@javax.persistence.Temporal(javax.persistence.TemporalType.DATE)
private Date trafficDiscountSince;
@javax.persistence.Column(name = "tariff_traffic_discount_until", columnDefinition = "date")
@javax.persistence.Temporal(javax.persistence.TemporalType.DATE)
private Date trafficDiscountUntil;
@javax.persistence.Column(name = "tariff_quota_discount_since", columnDefinition = "date")
@javax.persistence.Temporal(javax.persistence.TemporalType.DATE)
private Date quotaDiscountSince;
@javax.persistence.Column(name = "tariff_quota_discount_until", columnDefinition = "date")
@javax.persistence.Temporal(javax.persistence.TemporalType.DATE)
private Date quotaDiscountUntil;
@javax.persistence.Column(name = "tariff_discount_since", columnDefinition = "date")
@javax.persistence.Temporal(javax.persistence.TemporalType.DATE)
private Date discountSince;
@javax.persistence.Column(name = "tariff_discount_until", columnDefinition = "date")
@javax.persistence.Temporal(javax.persistence.TemporalType.DATE)
private Date discountUntil;
public CustomersTariff() { public CustomersTariff() {
} }
@ -25,29 +65,20 @@ public class CustomersTariff extends de.hsadmin.core.model.Entity implements
this.customer = cust; this.customer = cust;
} }
// / {@inheritDoc}
public static String createQueryFromStringKey(String humanKey) { public static String createQueryFromStringKey(String humanKey) {
return "customer.name = '" + humanKey + "'"; return "customer.name = '" + humanKey + "'";
} }
// / {@inheritDoc}
@Override @Override
public String createStringKey() { public String createStringKey() {
return getCustomer().getName(); return getCustomer().getName();
} }
// / {@inheritDoc}
@Override @Override
public long id() { public long id() {
return id; return id;
} }
// attribute id
@javax.persistence.Id
@javax.persistence.GeneratedValue(strategy = SEQUENCE, generator = "CustomersTariffsSeqGen")
@javax.persistence.Column(name = "billdata_id", columnDefinition = "integer")
private long id;
public long getId() { public long getId() {
return id; return id;
} }
@ -56,12 +87,6 @@ public class CustomersTariff extends de.hsadmin.core.model.Entity implements
this.id = id; this.id = id;
} }
// attribute customer
@javax.persistence.JoinColumn(name = "bp_id", columnDefinition = "integer")
@javax.persistence.OneToOne(fetch = EAGER)
// TODO: das will ich gar nicht, geht aber nicht ohne?!?
private Customer customer;
public Customer getCustomer() { public Customer getCustomer() {
return customer; return customer;
} }
@ -70,11 +95,6 @@ public class CustomersTariff extends de.hsadmin.core.model.Entity implements
this.customer = customer; this.customer = customer;
} }
// attribute domainDiscountSince
@javax.persistence.Column(name = "tariff_domain_discount_since", columnDefinition = "date")
@javax.persistence.Temporal(javax.persistence.TemporalType.DATE)
private Date domainDiscountSince;
public Date getDomainDiscountSince() { public Date getDomainDiscountSince() {
return domainDiscountSince; return domainDiscountSince;
} }
@ -83,11 +103,6 @@ public class CustomersTariff extends de.hsadmin.core.model.Entity implements
this.domainDiscountSince = domainDiscountSince; this.domainDiscountSince = domainDiscountSince;
} }
// attribute domainDiscountUntil
@javax.persistence.Column(name = "tariff_domain_discount_until", columnDefinition = "date")
@javax.persistence.Temporal(javax.persistence.TemporalType.DATE)
private Date domainDiscountUntil;
public Date getDomainDiscountUntil() { public Date getDomainDiscountUntil() {
return domainDiscountUntil; return domainDiscountUntil;
} }
@ -96,11 +111,6 @@ public class CustomersTariff extends de.hsadmin.core.model.Entity implements
this.domainDiscountUntil = domainDiscountUntil; this.domainDiscountUntil = domainDiscountUntil;
} }
// attribute trafficDiscountSince
@javax.persistence.Column(name = "tariff_traffic_discount_since", columnDefinition = "date")
@javax.persistence.Temporal(javax.persistence.TemporalType.DATE)
private Date trafficDiscountSince;
public Date getTrafficDiscountSince() { public Date getTrafficDiscountSince() {
return trafficDiscountSince; return trafficDiscountSince;
} }
@ -109,11 +119,6 @@ public class CustomersTariff extends de.hsadmin.core.model.Entity implements
this.trafficDiscountSince = trafficDiscountSince; this.trafficDiscountSince = trafficDiscountSince;
} }
// attribute trafficDiscountUntil
@javax.persistence.Column(name = "tariff_traffic_discount_until", columnDefinition = "date")
@javax.persistence.Temporal(javax.persistence.TemporalType.DATE)
private Date trafficDiscountUntil;
public Date getTrafficDiscountUntil() { public Date getTrafficDiscountUntil() {
return trafficDiscountUntil; return trafficDiscountUntil;
} }
@ -122,11 +127,6 @@ public class CustomersTariff extends de.hsadmin.core.model.Entity implements
this.trafficDiscountUntil = trafficDiscountUntil; this.trafficDiscountUntil = trafficDiscountUntil;
} }
// attribute quotaDiscountSince
@javax.persistence.Column(name = "tariff_quota_discount_since", columnDefinition = "date")
@javax.persistence.Temporal(javax.persistence.TemporalType.DATE)
private Date quotaDiscountSince;
public Date getQuotaDiscountSince() { public Date getQuotaDiscountSince() {
return quotaDiscountSince; return quotaDiscountSince;
} }
@ -135,11 +135,6 @@ public class CustomersTariff extends de.hsadmin.core.model.Entity implements
this.quotaDiscountSince = quotaDiscountSince; this.quotaDiscountSince = quotaDiscountSince;
} }
// attribute quotaDiscountUntil
@javax.persistence.Column(name = "tariff_quota_discount_until", columnDefinition = "date")
@javax.persistence.Temporal(javax.persistence.TemporalType.DATE)
private Date quotaDiscountUntil;
public Date getQuotaDiscountUntil() { public Date getQuotaDiscountUntil() {
return quotaDiscountUntil; return quotaDiscountUntil;
} }
@ -148,11 +143,6 @@ public class CustomersTariff extends de.hsadmin.core.model.Entity implements
this.quotaDiscountUntil = quotaDiscountUntil; this.quotaDiscountUntil = quotaDiscountUntil;
} }
// attribute discountSince
@javax.persistence.Column(name = "tariff_discount_since", columnDefinition = "date")
@javax.persistence.Temporal(javax.persistence.TemporalType.DATE)
private Date discountSince;
public Date getDiscountSince() { public Date getDiscountSince() {
return discountSince; return discountSince;
} }
@ -161,11 +151,6 @@ public class CustomersTariff extends de.hsadmin.core.model.Entity implements
this.discountSince = discountSince; this.discountSince = discountSince;
} }
// attribute discountUntil
@javax.persistence.Column(name = "tariff_discount_until", columnDefinition = "date")
@javax.persistence.Temporal(javax.persistence.TemporalType.DATE)
private Date discountUntil;
public Date getDiscountUntil() { public Date getDiscountUntil() {
return discountUntil; return discountUntil;
} }
@ -174,13 +159,11 @@ public class CustomersTariff extends de.hsadmin.core.model.Entity implements
this.discountUntil = discountUntil; this.discountUntil = discountUntil;
} }
// / {$inheritDoc}
@Override @Override
public boolean isNew() { public boolean isNew() {
return id == 0; return id == 0;
} }
// / {@inheritDoc}
@Override @Override
public UnixUser owningUser(EntityManager em) { public UnixUser owningUser(EntityManager em) {
return customer.owningUser(em); return customer.owningUser(em);

View File

@ -11,7 +11,7 @@ import de.hsadmin.mods.user.UnixUser;
@javax.persistence.Entity(name = "BaseComponents") @javax.persistence.Entity(name = "BaseComponents")
@javax.persistence.Table(name = " basecomponent") @javax.persistence.Table(name = " basecomponent")
@javax.persistence.SequenceGenerator(name = "BaseComponentsSeqGen", sequenceName = "basecomponent_basecomponent_seq") @javax.persistence.SequenceGenerator(name = "BaseComponentsSeqGen", sequenceName = "basecomponent_basecomponent_seq")
public class BaseComponent extends de.hsadmin.core.model.Entity implements Serializable { public class BaseComponent extends de.hsadmin.core.model.AbstractEntity implements Serializable {
private static final long serialVersionUID = -8161827018235142603L; private static final long serialVersionUID = -8161827018235142603L;

View File

@ -15,7 +15,7 @@ import de.hsadmin.mods.user.UnixUser;
@javax.persistence.Table(name="hive") @javax.persistence.Table(name="hive")
@javax.persistence.SequenceGenerator(name="HivesSeqGen", sequenceName="hive_hive_id_seq") @javax.persistence.SequenceGenerator(name="HivesSeqGen", sequenceName="hive_hive_id_seq")
public class Hive public class Hive
extends de.hsadmin.core.model.Entity extends de.hsadmin.core.model.AbstractEntity
implements java.io.Serializable implements java.io.Serializable
{ {
private static final long serialVersionUID = -2270234313165009590L; private static final long serialVersionUID = -2270234313165009590L;

View File

@ -10,7 +10,7 @@ import de.hsadmin.mods.user.UnixUser;
@javax.persistence.Table(name="inet_addr") @javax.persistence.Table(name="inet_addr")
@javax.persistence.SequenceGenerator(name="INetAddressesSeqGen", sequenceName="inet_addr_inet_addr_id_seq") @javax.persistence.SequenceGenerator(name="INetAddressesSeqGen", sequenceName="inet_addr_inet_addr_id_seq")
public class INetAddress public class INetAddress
extends de.hsadmin.core.model.Entity extends de.hsadmin.core.model.AbstractEntity
implements java.io.Serializable implements java.io.Serializable
{ {
private static final long serialVersionUID = -5792279453911426607L; private static final long serialVersionUID = -5792279453911426607L;

View File

@ -17,7 +17,7 @@ import de.hsadmin.mods.user.UnixUser;
@javax.persistence.Table(name = "packet") @javax.persistence.Table(name = "packet")
@javax.persistence.SequenceGenerator(name = "PacsSeqGen", sequenceName = "packet_packet_id_seq") @javax.persistence.SequenceGenerator(name = "PacsSeqGen", sequenceName = "packet_packet_id_seq")
@de.hsadmin.core.model.EntityInfo(name = "Paket") @de.hsadmin.core.model.EntityInfo(name = "Paket")
public class Pac extends de.hsadmin.core.model.Entity implements Serializable { public class Pac extends de.hsadmin.core.model.AbstractEntity implements Serializable {
private static final long serialVersionUID = 1201899873300190132L; private static final long serialVersionUID = 1201899873300190132L;

View File

@ -3,7 +3,7 @@ package de.hsadmin.mods.qstat;
import java.util.List; import java.util.List;
import de.hsadmin.core.model.AbstractModuleImpl; import de.hsadmin.core.model.AbstractModuleImpl;
import de.hsadmin.core.model.Entity; import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.HSAdminException; import de.hsadmin.core.model.HSAdminException;
import de.hsadmin.mods.user.UnixUser; import de.hsadmin.mods.user.UnixUser;
@ -15,7 +15,7 @@ public class QTaskModuleImpl extends AbstractModuleImpl {
} }
@Override @Override
public List<Entity> search(Class<? extends Entity> entityClass, String condition, String orderBy) throws HSAdminException { public List<AbstractEntity> search(Class<? extends AbstractEntity> entityClass, String condition, String orderBy) throws HSAdminException {
// do query and return result // do query and return result
if (orderBy == null || orderBy.length() == 0) { if (orderBy == null || orderBy.length() == 0) {
orderBy = "ORDER BY obj.started DESC"; orderBy = "ORDER BY obj.started DESC";

View File

@ -23,7 +23,7 @@ import de.hsadmin.mods.pac.Pac;
@Table(name = "unixuser") @Table(name = "unixuser")
@SequenceGenerator(name = "UnixUsersSeqGen", sequenceName = "unixuser_unixuser_id_seq") @SequenceGenerator(name = "UnixUsersSeqGen", sequenceName = "unixuser_unixuser_id_seq")
@EntityInfo(name = "UNIX-Zugang/Mailbox") @EntityInfo(name = "UNIX-Zugang/Mailbox")
public class UnixUser extends de.hsadmin.core.model.Entity implements Serializable { public class UnixUser extends de.hsadmin.core.model.AbstractEntity implements Serializable {
private static final long serialVersionUID = 7823071611805642906L; private static final long serialVersionUID = 7823071611805642906L;

View File

@ -7,7 +7,7 @@ import javax.persistence.EntityManager;
import javax.persistence.Query; import javax.persistence.Query;
import de.hsadmin.core.model.AuthorisationException; import de.hsadmin.core.model.AuthorisationException;
import de.hsadmin.core.model.Entity; import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.AbstractModuleImpl; import de.hsadmin.core.model.AbstractModuleImpl;
import de.hsadmin.core.model.HSAdminException; import de.hsadmin.core.model.HSAdminException;
import de.hsadmin.mods.pac.Pac; import de.hsadmin.mods.pac.Pac;
@ -20,14 +20,14 @@ public class UnixUserModuleImpl extends AbstractModuleImpl {
} }
@Override @Override
public Entity initialize(Entity newEntity) throws AuthorisationException { public AbstractEntity initialize(AbstractEntity newEntity) throws AuthorisationException {
UnixUser newUnixUser = (UnixUser) super.initialize(newEntity); UnixUser newUnixUser = (UnixUser) super.initialize(newEntity);
newUnixUser.setName(getLoginUser().getPac().getName() + '-'); newUnixUser.setName(getLoginUser().getPac().getName() + '-');
return newUnixUser; return newUnixUser;
} }
@Override @Override
public Entity find(Class<? extends Entity> entityClass, Object key) throws HSAdminException { public AbstractEntity find(Class<? extends AbstractEntity> entityClass, Object key) throws HSAdminException {
// do query // do query
UnixUser res = (UnixUser) super.find(entityClass, key); UnixUser res = (UnixUser) super.find(entityClass, key);
@ -39,7 +39,7 @@ public class UnixUserModuleImpl extends AbstractModuleImpl {
} }
@Override @Override
public Entity findByString(Class<? extends Entity> entityClass, String key) throws HSAdminException { public AbstractEntity findByString(Class<? extends AbstractEntity> entityClass, String key) throws HSAdminException {
// do query // do query
UnixUser res = (UnixUser) super.findByString(entityClass, key); UnixUser res = (UnixUser) super.findByString(entityClass, key);
@ -49,17 +49,17 @@ public class UnixUserModuleImpl extends AbstractModuleImpl {
} }
@Override @Override
public List<Entity> search(Class<? extends Entity> entityClass, String condition, String orderBy) throws HSAdminException { public List<AbstractEntity> search(Class<? extends AbstractEntity> entityClass, String condition, String orderBy) throws HSAdminException {
// do query // do query
if (orderBy == null || orderBy.length() == 0) { if (orderBy == null || orderBy.length() == 0) {
orderBy = "ORDER BY obj.name ASC"; orderBy = "ORDER BY obj.name ASC";
} }
List<Entity> res = super.search(entityClass, condition, orderBy); List<AbstractEntity> res = super.search(entityClass, condition, orderBy);
List<Entity> ret = new LinkedList<Entity>(); List<AbstractEntity> ret = new LinkedList<AbstractEntity>();
// remove entities where login user has no access rights // remove entities where login user has no access rights
if (res != null) { if (res != null) {
for (Entity entity : res) { for (AbstractEntity entity : res) {
try { try {
UnixUser returnedUnixUser = (UnixUser) entity; UnixUser returnedUnixUser = (UnixUser) entity;
needsPartialAccessOnPacOf(returnedUnixUser, "search"); needsPartialAccessOnPacOf(returnedUnixUser, "search");
@ -74,7 +74,7 @@ public class UnixUserModuleImpl extends AbstractModuleImpl {
} }
@Override @Override
public Entity add(Entity newEntity) throws HSAdminException { public AbstractEntity add(AbstractEntity newEntity) throws HSAdminException {
EntityManager em = getEntityManager(); EntityManager em = getEntityManager();
// only allow pac which matches the username (TODO: hard coded // only allow pac which matches the username (TODO: hard coded
// Hostsharing convention) // Hostsharing convention)
@ -143,7 +143,7 @@ public class UnixUserModuleImpl extends AbstractModuleImpl {
} }
@Override @Override
public Entity update(Entity existingEntity) throws HSAdminException { public AbstractEntity update(AbstractEntity existingEntity) throws HSAdminException {
// get the entity from the database // get the entity from the database
UnixUser detachedUnixUser = (UnixUser) existingEntity; UnixUser detachedUnixUser = (UnixUser) existingEntity;
UnixUser attachedUnixUser = getEntityManager().find(detachedUnixUser.getClass(), UnixUser attachedUnixUser = getEntityManager().find(detachedUnixUser.getClass(),
@ -202,7 +202,7 @@ public class UnixUserModuleImpl extends AbstractModuleImpl {
} }
@Override @Override
public void delete(Entity existingEntity) throws HSAdminException { public void delete(AbstractEntity existingEntity) throws HSAdminException {
// get the entity from the database // get the entity from the database
UnixUser detachedUnixUser = (UnixUser) existingEntity; UnixUser detachedUnixUser = (UnixUser) existingEntity;
UnixUser attachedUnixUser = getEntityManager().find(detachedUnixUser.getClass(), UnixUser attachedUnixUser = getEntityManager().find(detachedUnixUser.getClass(),

View File

@ -5,7 +5,7 @@ import java.util.Date;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import de.hsadmin.core.model.Entity; import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.qserv.CompoundProcessor; import de.hsadmin.core.qserv.CompoundProcessor;
import de.hsadmin.core.qserv.EntityProcessorFactory; import de.hsadmin.core.qserv.EntityProcessorFactory;
import de.hsadmin.core.qserv.Processor; import de.hsadmin.core.qserv.Processor;
@ -22,7 +22,7 @@ public class UnixUserProcessorFactory implements EntityProcessorFactory {
/** /**
* @return a Processor which creates a new UNIX user account * @return a Processor which creates a new UNIX user account
*/ */
public <T extends Entity> Processor createCreateProcessor(EntityManager em, public <T extends AbstractEntity> Processor createCreateProcessor(EntityManager em,
T entity) { T entity) {
UnixUser user = (UnixUser) entity; UnixUser user = (UnixUser) entity;
CompoundProcessor aCP = new CompoundProcessor(new ShellProcessor( CompoundProcessor aCP = new CompoundProcessor(new ShellProcessor(
@ -38,7 +38,7 @@ public class UnixUserProcessorFactory implements EntityProcessorFactory {
/** /**
* @return a Processor which updates an existing UNIX user account * @return a Processor which updates an existing UNIX user account
*/ */
public <T extends Entity> Processor createUpdateProcessor(EntityManager em, public <T extends AbstractEntity> Processor createUpdateProcessor(EntityManager em,
T entity) { T entity) {
UnixUser user = (UnixUser) entity; UnixUser user = (UnixUser) entity;
CompoundProcessor aCP = new CompoundProcessor(new ShellProcessor( CompoundProcessor aCP = new CompoundProcessor(new ShellProcessor(
@ -55,7 +55,7 @@ public class UnixUserProcessorFactory implements EntityProcessorFactory {
/** /**
* @return a Processor which deletes an existing UNIX user account * @return a Processor which deletes an existing UNIX user account
*/ */
public <T extends Entity> Processor createDeleteProcessor(EntityManager em, public <T extends AbstractEntity> Processor createDeleteProcessor(EntityManager em,
T entity) { T entity) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyMMdd-HHmm-"); SimpleDateFormat sdf = new SimpleDateFormat("yyyMMdd-HHmm-");
String trashPrefix = "/home/trash/" + sdf.format(new Date()); String trashPrefix = "/home/trash/" + sdf.format(new Date());

View File

@ -10,7 +10,7 @@ import java.util.Map;
import de.hsadmin.core.model.AuthenticationException; import de.hsadmin.core.model.AuthenticationException;
import de.hsadmin.core.model.AuthorisationException; import de.hsadmin.core.model.AuthorisationException;
import de.hsadmin.core.model.Entity; import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.GenericModuleImpl; import de.hsadmin.core.model.GenericModuleImpl;
import de.hsadmin.core.model.HSAdminException; import de.hsadmin.core.model.HSAdminException;
import de.hsadmin.core.model.ModuleInterface; import de.hsadmin.core.model.ModuleInterface;
@ -26,17 +26,14 @@ public abstract class AbstractRemote implements IRemote {
authentication = new TicketAuthentication(); authentication = new TicketAuthentication();
} }
protected abstract Class<? extends Entity> getEntityClass(); protected abstract Class<? extends AbstractEntity> getEntityClass();
protected abstract void entity2map(Entity entity, Map<String, String> resultMap); protected abstract void entity2map(AbstractEntity entity, Map<String, String> resultMap);
protected abstract void map2entity(Map<String, String> setParams, Entity entity); protected abstract void map2entity(Map<String, String> setParams, AbstractEntity entity);
protected abstract void regularizeKeys(Map<String, String> whereParams); protected abstract void regularizeKeys(Map<String, String> whereParams);
/* (non-Javadoc)
* @see de.hsadmin.remote.IRemote#search(java.lang.String, java.lang.String, java.util.Map)
*/
public List<Map<String, String>> search(String runAsUser, String ticket, public List<Map<String, String>> search(String runAsUser, String ticket,
Map<String, String> whereParams) throws HSAdminException { Map<String, String> whereParams) throws HSAdminException {
String user = runAsUser; String user = runAsUser;
@ -46,10 +43,13 @@ public abstract class AbstractRemote implements IRemote {
ModuleInterface module = new GenericModuleImpl(transaction); ModuleInterface module = new GenericModuleImpl(transaction);
UnixUser unixUser = null; UnixUser unixUser = null;
unixUser = (UnixUser) module.findByString(UnixUser.class, user); unixUser = (UnixUser) module.findByString(UnixUser.class, user);
List<Entity> list = module.search(getEntityClass(), List<AbstractEntity> list = module.search(getEntityClass(),
buildQueryCondition(whereParams), null); buildQueryCondition(whereParams), null);
if (list == null) {
throw new HSAdminException("result list is null, runtime-error?");
}
ArrayList<Map<String, String>> result = new ArrayList<Map<String, String>>(); ArrayList<Map<String, String>> result = new ArrayList<Map<String, String>>();
for (Entity e : list) { for (AbstractEntity e : list) {
HashMap<String, String> entry = new HashMap<String, String>(); HashMap<String, String> entry = new HashMap<String, String>();
entity2map(e, entry); entity2map(e, entry);
if (e.isReadAllowedFor(unixUser)) { if (e.isReadAllowedFor(unixUser)) {
@ -69,9 +69,6 @@ public abstract class AbstractRemote implements IRemote {
} }
} }
/* (non-Javadoc)
* @see de.hsadmin.remote.IRemote#add(java.lang.String, java.lang.String, java.util.Map)
*/
public Map<String, String> add(String runAsUser, String ticket, public Map<String, String> add(String runAsUser, String ticket,
Map<String, String> setParams) throws HSAdminException { Map<String, String> setParams) throws HSAdminException {
String user = runAsUser; String user = runAsUser;
@ -79,12 +76,12 @@ public abstract class AbstractRemote implements IRemote {
try { try {
if (authentication.login(user, ticket)) { if (authentication.login(user, ticket)) {
ModuleInterface module = new GenericModuleImpl(transaction); ModuleInterface module = new GenericModuleImpl(transaction);
Constructor<? extends Entity> constructor = Constructor<? extends AbstractEntity> constructor =
getEntityClass().getConstructor(); getEntityClass().getConstructor();
Entity entity = constructor.newInstance(); AbstractEntity entity = constructor.newInstance();
map2entity(setParams, entity); map2entity(setParams, entity);
transaction.beginTransaction(); transaction.beginTransaction();
Entity insertedEntity = module.add(entity); AbstractEntity insertedEntity = module.add(entity);
transaction.commitTransaction(); transaction.commitTransaction();
HashMap<String, String> entry = new HashMap<String, String>(); HashMap<String, String> entry = new HashMap<String, String>();
entity2map(insertedEntity, entry); entity2map(insertedEntity, entry);
@ -99,9 +96,6 @@ public abstract class AbstractRemote implements IRemote {
} }
} }
/* (non-Javadoc)
* @see de.hsadmin.remote.IRemote#delete(java.lang.String, java.lang.String, java.util.Map)
*/
public void delete(String runAsUser, String ticket, public void delete(String runAsUser, String ticket,
Map<String, String> whereParams) throws HSAdminException { Map<String, String> whereParams) throws HSAdminException {
String user = runAsUser; String user = runAsUser;
@ -116,10 +110,10 @@ public abstract class AbstractRemote implements IRemote {
throw new HSAdminException( throw new HSAdminException(
"better safe than sorry: no where parameter found"); "better safe than sorry: no where parameter found");
} }
List<Entity> list = module.search(getEntityClass(), List<AbstractEntity> list = module.search(getEntityClass(),
queryCondition, null); queryCondition, null);
transaction.beginTransaction(); transaction.beginTransaction();
for (Entity e : list) { for (AbstractEntity e : list) {
if (e.isWriteAllowedFor(unixUser)) { if (e.isWriteAllowedFor(unixUser)) {
module.delete(e); module.delete(e);
} else { } else {
@ -139,9 +133,6 @@ public abstract class AbstractRemote implements IRemote {
} }
} }
/* (non-Javadoc)
* @see de.hsadmin.remote.IRemote#update(java.lang.String, java.lang.String, java.util.Map, java.util.Map)
*/
public List<Map<String, String>> update(String runAsUser, String ticket, public List<Map<String, String>> update(String runAsUser, String ticket,
Map<String, String> setParams, Map<String, String> whereParams) Map<String, String> setParams, Map<String, String> whereParams)
throws HSAdminException { throws HSAdminException {
@ -158,10 +149,10 @@ public abstract class AbstractRemote implements IRemote {
throw new HSAdminException( throw new HSAdminException(
"better safe than sorry: no where parameter found"); "better safe than sorry: no where parameter found");
} }
List<Entity> list = module.search(getEntityClass(), List<AbstractEntity> list = module.search(getEntityClass(),
queryCondition, "ORDER BY name ASC"); queryCondition, "ORDER BY obj.name ASC");
transaction.beginTransaction(); transaction.beginTransaction();
for (Entity update : list) { for (AbstractEntity update : list) {
if (update.isWriteAllowedFor(unixUser)) { if (update.isWriteAllowedFor(unixUser)) {
transaction.detach(update); transaction.detach(update);
map2entity(setParams, update); map2entity(setParams, update);

View File

@ -0,0 +1,269 @@
package de.hsadmin.remote;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.Set;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.mods.cust.BankAccount;
import de.hsadmin.mods.cust.Contact;
import de.hsadmin.mods.cust.Customer;
public class CustomerRemote extends AbstractRemote {
private static final DateFormat df = SimpleDateFormat.getDateInstance(DateFormat.SHORT);
@Override
protected Class<? extends AbstractEntity> getEntityClass() {
return Customer.class;
}
@Override
protected void entity2map(AbstractEntity entity,
Map<String, String> resultMap) {
Customer cust = (Customer) entity;
resultMap.put("id", Long.toString(cust.getId()));
resultMap.put("membercode", cust.getName());
resultMap.put("memberno", Integer.toString(cust.getMemberNo()));
Date memberSince = cust.getMemberSince();
if (assertNotNull(memberSince)) {
resultMap.put("membersince", df.format(memberSince));
}
Date memberUntil = cust.getMemberUntil();
if (assertNotNull(memberUntil)) {
resultMap.put("memberuntil", df.format(memberUntil));
}
resultMap.put("memberrole", cust.getMemberRole());
Date authorContract = cust.getAuthorContract();
if (assertNotNull(authorContract)) {
resultMap.put("authorcontract", df.format(authorContract));
}
Date nonDiscContract = cust.getNonDiscContract();
if (assertNotNull(nonDiscContract)) {
resultMap.put("nondisccontract", df.format(nonDiscContract));
}
Date sharesUpdated = cust.getSharesUpdated();
if (assertNotNull(sharesUpdated)) {
resultMap.put("sharesupdated", df.format(sharesUpdated));
}
resultMap.put("sharessigned", Integer.toString(cust.getSharesSigned()));
resultMap.put("uidvat", cust.getUidVAT());
BankAccount bank = cust.getBankAccount();
if (bank != null) {
resultMap.put("autodebit_ga", bank.getAutoDebitGA() != null && bank.getAutoDebitGA() ? "Yes" : "No");
resultMap.put("autodebit_ar", bank.getAutoDebitAR() != null && bank.getAutoDebitAR() ? "Yes" : "No");
resultMap.put("autodebit_op", bank.getAutoDebitOP() != null && bank.getAutoDebitOP() ? "Yes" : "No");
resultMap.put("bank_customer", bank.getBankCustomer());
resultMap.put("bank_account", bank.getBankAccount());
resultMap.put("bank_code", bank.getBankCode());
resultMap.put("bank_name", bank.getBankName());
}
Set<Contact> contacts = cust.getContacts();
if (contacts != null && !contacts.isEmpty()) {
Contact c = contacts.iterator().next();
resultMap.put("contact_salut", c.getSalut());
resultMap.put("contact_title", c.getTitle());
resultMap.put("contact_firstname", c.getFirstName());
resultMap.put("contact_lastname", c.getLastName());
resultMap.put("contact_firma", c.getFirma());
resultMap.put("contact_co", c.getCo());
resultMap.put("contact_street", c.getStreet());
resultMap.put("contact_zipcode", c.getZipCode());
resultMap.put("contact_city", c.getCity());
resultMap.put("contact_country", c.getCountry());
resultMap.put("contact_phone_private", c.getPhonePrivate());
resultMap.put("contact_phone_office", c.getPhoneOffice());
resultMap.put("contact_phone_mobile", c.getPhoneMobile());
resultMap.put("contact_fax", c.getFax());
resultMap.put("contact_email", c.getEmail());
}
}
@Override
protected void map2entity(Map<String, String> setParams,
AbstractEntity entity) {
Customer cust = (Customer) entity;
String idStr = setParams.get("id");
if (assertNotNull(idStr)) {
cust.setId(Long.parseLong(idStr));
}
String memberCode = setParams.get("membercode");
if (assertNotNull(memberCode)) {
cust.setName(memberCode);
}
String memberNo = setParams.get("memberno");
if (assertNotNull(memberNo)) {
cust.setMemberNo(Integer.parseInt(memberNo));
}
String memberSince = setParams.get("membersince");
if (assertNotNull(memberSince)) {
try {
cust.setMemberSince(df.parse(memberSince));
} catch (ParseException e) {
// don't care
}
}
String memberUntil = setParams.get("memberuntil");
if (assertNotNull(memberUntil)) {
try {
cust.setMemberUntil(df.parse(memberUntil));
} catch (ParseException e) {
// don't care
}
}
String memberRole = setParams.get("memberrole");
if (assertNotNull(memberRole)) {
cust.setMemberRole(memberRole);
}
String authorContract = setParams.get("authorcontract");
if (assertNotNull(authorContract)) {
try {
cust.setAuthorContract(df.parse(authorContract));
} catch (ParseException e) {
// don't care
}
}
String nonDiscContract = setParams.get("nondisccontract");
if (assertNotNull(nonDiscContract)) {
try {
cust.setNonDiscContract(df.parse(nonDiscContract));
} catch (ParseException e) {
// don't care
}
}
String sharesUpdated = setParams.get("sharesupdated");
if (assertNotNull(sharesUpdated)) {
try {
cust.setSharesUpdated(df.parse(sharesUpdated));
} catch (ParseException e) {
// don't care
}
}
String sharesSigned = setParams.get("sharessigned");
if (assertNotNull(sharesSigned)) {
cust.setId(Integer.parseInt(sharesSigned));
}
String uidVat = setParams.get("uidvat");
if (assertNotNull(uidVat)) {
cust.setUidVAT(uidVat);
}
BankAccount bank = cust.getBankAccount();
if (bank == null) {
bank = new BankAccount();
bank.setCustomer(cust);
cust.setBankAccount(bank);
}
String autoDebitGA = setParams.get("autodebit_ga");
if (assertNotNull(autoDebitGA)) {
autoDebitGA = autoDebitGA.toUpperCase();
bank.setAutoDebitGA(new Boolean(autoDebitGA.startsWith("T") || autoDebitGA.startsWith("Y")));
}
String autoDebitAR = setParams.get("autodebit_ar");
if (assertNotNull(autoDebitAR)) {
autoDebitAR = autoDebitAR.toUpperCase();
bank.setAutoDebitAR(new Boolean(autoDebitAR.startsWith("T") || autoDebitAR.startsWith("Y")));
}
String autoDebitOP = setParams.get("autodebit_op");
if (assertNotNull(autoDebitOP)) {
autoDebitOP = autoDebitOP.toUpperCase();
bank.setAutoDebitOP(new Boolean(autoDebitOP.startsWith("T") || autoDebitOP.startsWith("Y")));
}
String bankCustomer = setParams.get("bank_customer");
if (assertNotNull(bankCustomer)) {
bank.setBankCustomer(bankCustomer);
}
String bankAccount = setParams.get("bank_account");
if (assertNotNull(bankAccount)) {
bank.setBankAccount(bankAccount);
}
String bankCode = setParams.get("bank_code");
if (assertNotNull(bankCode)) {
bank.setBankCode(bankCode);
}
String bankName = setParams.get("bank_name");
if (assertNotNull(bankName)) {
bank.setBankName(bankName);
}
Set<Contact> contacts = cust.getContacts();
Contact c = null;
if (contacts == null || contacts.isEmpty()) {
c = new Contact(cust);
contacts.add(c);
} else {
c = contacts.iterator().next();
}
String salut = setParams.get("contact_salut");
if (assertNotNull(salut)) {
c.setSalut(salut);
}
String title = setParams.get("contact_title");
if (assertNotNull(title)) {
c.setTitle(title);
}
String firstName = setParams.get("contact_firstname");
if (assertNotNull(firstName)) {
c.setFirstName(firstName);
}
String lastName = setParams.get("contact_lastname");
if (assertNotNull(lastName)) {
c.setLastName(lastName);
}
String firma = setParams.get("contact_firma");
if (assertNotNull(firma)) {
c.setLastName(firma);
}
String co = setParams.get("contact_co");
if (assertNotNull(co)) {
c.setCo(co);
}
String street = setParams.get("contact_street");
if (assertNotNull(street)) {
c.setStreet(street);
}
String zipCode = setParams.get("contact_zipcode");
if (assertNotNull(zipCode)) {
c.setZipCode(zipCode);
}
String city = setParams.get("contact_city");
if (assertNotNull(city)) {
c.setCity(city);
}
String country = setParams.get("contact_country");
if (assertNotNull(country)) {
c.setCountry(country);
}
String phonePrivate = setParams.get("contact_phone_private");
if (assertNotNull(phonePrivate)) {
c.setPhonePrivate(phonePrivate);
}
String phoneOffice = setParams.get("contact_phone_office");
if (assertNotNull(phoneOffice)) {
c.setPhoneOffice(phoneOffice);
}
String phoneMobile = setParams.get("contact_phone_mobile");
if (assertNotNull(phoneMobile)) {
c.setPhoneMobile(phoneMobile);
}
String fax = setParams.get("contact_fax");
if (assertNotNull(fax)) {
c.setFax(fax);
}
String eMail = setParams.get("contact_email");
if (assertNotNull(eMail)) {
c.setEmail(eMail);
}
}
@Override
protected void regularizeKeys(Map<String, String> whereParams) {
// nothing to do
replaceKey(whereParams, "membercode", "name");
replaceKey(whereParams, "memberno", "memberNo");
replaceKey(whereParams, "membersince", "memberSince");
replaceKey(whereParams, "memberuntil", "memberUntil");
}
}

View File

@ -5,7 +5,7 @@ import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
import de.hsadmin.core.model.Entity; import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.qserv.QueueTask; import de.hsadmin.core.qserv.QueueTask;
public class QueueTaskRemote extends AbstractRemote { public class QueueTaskRemote extends AbstractRemote {
@ -13,12 +13,12 @@ public class QueueTaskRemote extends AbstractRemote {
private static final DateFormat df = SimpleDateFormat.getDateInstance(DateFormat.SHORT); private static final DateFormat df = SimpleDateFormat.getDateInstance(DateFormat.SHORT);
@Override @Override
protected Class<? extends Entity> getEntityClass() { protected Class<? extends AbstractEntity> getEntityClass() {
return QueueTask.class; return QueueTask.class;
} }
@Override @Override
protected void entity2map(Entity entity, Map<String, String> resultMap) { protected void entity2map(AbstractEntity entity, Map<String, String> resultMap) {
QueueTask task = (QueueTask) entity; QueueTask task = (QueueTask) entity;
resultMap.put("id", Long.toString(task.getId())); resultMap.put("id", Long.toString(task.getId()));
resultMap.put("status", task.getStatus().toString()); resultMap.put("status", task.getStatus().toString());
@ -37,7 +37,7 @@ public class QueueTaskRemote extends AbstractRemote {
} }
@Override @Override
protected void map2entity(Map<String, String> setParams, Entity entity) { protected void map2entity(Map<String, String> setParams, AbstractEntity entity) {
// never used // never used
} }

View File

@ -2,18 +2,18 @@ package de.hsadmin.remote;
import java.util.Map; import java.util.Map;
import de.hsadmin.core.model.Entity; import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.mods.user.UnixUser; import de.hsadmin.mods.user.UnixUser;
public class UnixUserRemote extends AbstractRemote { public class UnixUserRemote extends AbstractRemote {
@Override @Override
protected Class<? extends Entity> getEntityClass() { protected Class<? extends AbstractEntity> getEntityClass() {
return UnixUser.class; return UnixUser.class;
} }
@Override @Override
protected void entity2map(Entity entity, Map<String, String> map) { protected void entity2map(AbstractEntity entity, Map<String, String> map) {
UnixUser user = (UnixUser) entity; UnixUser user = (UnixUser) entity;
map.put("id", Long.toString(user.getId())); map.put("id", Long.toString(user.getId()));
map.put("name", user.getName()); map.put("name", user.getName());
@ -33,7 +33,7 @@ public class UnixUserRemote extends AbstractRemote {
} }
@Override @Override
protected void map2entity(Map<String, String> map, Entity entity) { protected void map2entity(Map<String, String> map, AbstractEntity entity) {
UnixUser user = (UnixUser) entity; UnixUser user = (UnixUser) entity;
String id = map.get("id"); String id = map.get("id");
if (assertNotNull(id)) { if (assertNotNull(id)) {

View File

@ -1,2 +1,3 @@
member=de.hsadmin.remote.CustomerRemote
user=de.hsadmin.remote.UnixUserRemote user=de.hsadmin.remote.UnixUserRemote
q=de.hsadmin.remote.QueueTaskRemote q=de.hsadmin.remote.QueueTaskRemote

View File

@ -0,0 +1,198 @@
package de.hsadmin.remote;
import static org.junit.Assert.assertEquals;
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;
public class CustomerTest {
private static final String MODULE = "member";
private XmlRpcClient client;
private RemoteCASHelper cas;
@Before
public void setUp() throws Exception {
client = RemoteTestHelper.getClient();
cas = new RemoteCASHelper();
}
@After
public void tearDown() throws Exception {
client = null;
cas = null;
}
@Test
public void testAddAsHostmaster() {
String user = "pe";
int membersCount = -9999;
try {
membersCount = getMembersCount(user);
} catch (XmlRpcException e) {
fail(e.getMessage());
}
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> setParams = new HashMap<String, String>();
setParams.put("membercode", "hsh00-aaa");
setParams.put("memberno", "20001");
setParams.put("membersince", "01.10.2010");
setParams.put("contact_salut", "Herr");
setParams.put("contact_title", "Dr.");
setParams.put("contact_firstname", "Rainer");
setParams.put("contact_lastname", "Mustermann");
setParams.put("contact_salut", "Herr");
setParams.put("contact_street", "Hauptstr. 1");
setParams.put("contact_zipcode", "99998");
setParams.put("contact_city", "Musterstadt");
setParams.put("contact_country", "D");
setParams.put("contact_phone_private", "+49 9999 123456");
setParams.put("contact_email", "rainer.mustermann@example.org");
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.BACKEND_URL),
setParams };
try {
client.execute(MODULE + ".add", params);
// Object execute = client.execute(MODULE + ".add", params);
// Map<?, ?> result = (Map<?, ?>) execute;
// System.out.println(result);
assertEquals(membersCount + 1, getMembersCount(user));
} catch (XmlRpcException e) {
fail(e.getMessage());
}
}
@Test
public void testSearchAsHostmaster() {
String user = "pe";
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>();
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.BACKEND_URL),
whereParams };
try {
Object execute = client.execute(MODULE + ".search", params);
Object[] result = (Object[]) execute;
assertTrue(result.length > 100);
} catch (XmlRpcException e) {
fail(e.getMessage());
}
}
@Test
public void testSearchAsPacAdmin() {
String user = "peh00";
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>();
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.BACKEND_URL),
whereParams };
try {
Object execute = client.execute(MODULE + ".search", params);
Object[] result = (Object[]) execute;
assertTrue(result.length == 0);
} catch (XmlRpcException e) {
fail(e.getMessage());
}
}
@Test
public void testSearchAsPacUser() {
String user = "peh00-phor";
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>();
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.BACKEND_URL),
whereParams };
try {
Object execute = client.execute(MODULE + ".search", params);
Object[] result = (Object[]) execute;
assertTrue(result.length == 0);
} catch (XmlRpcException e) {
fail(e.getMessage());
}
}
@Test
public void testSearchAsMember() {
String user = "hsh00-peh";
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>();
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.BACKEND_URL),
whereParams };
try {
Object execute = client.execute(MODULE + ".search", params);
Object[] result = (Object[]) execute;
assertTrue(result.length == 1);
} catch (XmlRpcException e) {
fail(e.getMessage());
}
}
@Test
public void testDeleteAsMember() {
String user = "hsh00-aaa";
int membersCount = -9999;
try {
membersCount = getMembersCount(user);
} catch (XmlRpcException e) {
fail(e.getMessage());
}
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>();
whereParams.put("membercode", "hsh00-aaa");
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.BACKEND_URL),
whereParams };
try {
client.execute(MODULE + ".delete", params);
assertEquals(membersCount - 1, getMembersCount(user));
} catch (XmlRpcException e) {
fail(e.getMessage());
}
}
@Test
public void testDeleteAsHostmaster() {
String user = "pe";
int membersCount = -9999;
try {
membersCount = getMembersCount(user);
} catch (XmlRpcException e) {
fail(e.getMessage());
}
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>();
whereParams.put("membercode", "hsh00-aaa");
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.BACKEND_URL),
whereParams };
try {
client.execute(MODULE + ".delete", params);
assertEquals(membersCount - 1, getMembersCount(user));
} catch (XmlRpcException e) {
fail(e.getMessage());
}
}
private int getMembersCount(String user) throws XmlRpcException {
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>();
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.BACKEND_URL),
whereParams };
Object execute = client.execute(MODULE + ".search", params);
Object[] result = (Object[]) execute;
return result.length;
}
}

View File

@ -36,7 +36,7 @@ public class QueueTaskTest {
@Test @Test
public void testSearchAllAsPacAdmin() { public void testSearchAllAsPacAdmin() {
String user = "peh00"; String user = "peh00";
String grantingTicketURL = cas.getGrantingTicketURL(user, user); String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>(); Map<String, String> whereParams = new HashMap<String, String>();
Object[] params = new Object[] { user, Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.BACKEND_URL), cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.BACKEND_URL),
@ -44,7 +44,7 @@ public class QueueTaskTest {
try { try {
Object execute = client.execute(MODULE + ".search", params); Object execute = client.execute(MODULE + ".search", params);
Object[] result = (Object[]) execute; Object[] result = (Object[]) execute;
assertTrue(result.length > 100); assertTrue(result.length > 20);
for (Object o : result) { for (Object o : result) {
if (o instanceof Map<?, ?>) { if (o instanceof Map<?, ?>) {
Map<?, ?> row = (Map<?, ?>) o; Map<?, ?> row = (Map<?, ?>) o;
@ -61,7 +61,7 @@ public class QueueTaskTest {
@Test @Test
public void testUpdate() { public void testUpdate() {
String user = "peh00"; String user = "peh00";
String grantingTicketURL = cas.getGrantingTicketURL(user, user); String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> setParams = new HashMap<String, String>(); Map<String, String> setParams = new HashMap<String, String>();
Map<String, String> whereParams = new HashMap<String, String>(); Map<String, String> whereParams = new HashMap<String, String>();
setParams.put("details", "Test"); setParams.put("details", "Test");
@ -82,7 +82,7 @@ public class QueueTaskTest {
@Test @Test
public void testCreateFails() { public void testCreateFails() {
String user = "peh00"; String user = "peh00";
String grantingTicketURL = cas.getGrantingTicketURL(user, user); String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> setParams = new HashMap<String, String>(); Map<String, String> setParams = new HashMap<String, String>();
setParams.put("status", "done"); setParams.put("status", "done");
setParams.put("title", "Test"); setParams.put("title", "Test");
@ -107,7 +107,7 @@ public class QueueTaskTest {
@Test @Test
public void testDeleteAsPacAdminFails() { public void testDeleteAsPacAdminFails() {
String user = "peh00"; String user = "peh00";
String grantingTicketURL = cas.getGrantingTicketURL(user, user); String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>(); Map<String, String> whereParams = new HashMap<String, String>();
whereParams.put("user", "peh00"); whereParams.put("user", "peh00");
Object[] params = new Object[] { user, Object[] params = new Object[] { user,

View File

@ -34,20 +34,8 @@ public class RemoteCASHelper {
loginURL = config.getProperty("loginURL", LOGIN_URL); loginURL = config.getProperty("loginURL", LOGIN_URL);
} }
public String getGrantingTicketURL(String user, String pw) { public String getGrantingTicketURL(String user) {
if ("peh00".equals(pw)) { String pw = config.getProperty(user + ".passWord", "-");
pw = config.getProperty("peh00.passWord", "-");
}
if ("peh01".equals(pw)) {
pw = config.getProperty("peh01.passWord", "-");
}
if ("pe".equals(pw)) {
pw = config.getProperty("pe.passWord", "-");
}
if (user.equals(pw)) {
System.err.println("Unknown Password for: " + pw);
return null;
}
try { try {
String encodedParams = URLEncoder.encode("username", "UTF-8") String encodedParams = URLEncoder.encode("username", "UTF-8")
+ "=" + URLEncoder.encode(user, "UTF-8") + "=" + URLEncoder.encode(user, "UTF-8")

View File

@ -5,6 +5,7 @@ import org.junit.runners.Suite;
@RunWith(Suite.class) @RunWith(Suite.class)
@Suite.SuiteClasses({ @Suite.SuiteClasses({
CustomerTest.class,
UnixUserTest.class, UnixUserTest.class,
// MySqlDatabaseTest.class, // MySqlDatabaseTest.class,
// MySqlUserTest.class, // MySqlUserTest.class,

View File

@ -35,7 +35,7 @@ public class UnixUserTest {
@Test @Test
public void testSearchAsPacAdmin() { public void testSearchAsPacAdmin() {
String user = "peh00"; String user = "peh00";
String grantingTicketURL = cas.getGrantingTicketURL(user, user); String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>(); Map<String, String> whereParams = new HashMap<String, String>();
Object[] params = new Object[] { user, Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.BACKEND_URL), cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.BACKEND_URL),
@ -62,7 +62,7 @@ public class UnixUserTest {
int count = getObjectCount(); int count = getObjectCount();
try { try {
String user = "peh00"; String user = "peh00";
String grantingTicketURL = cas.getGrantingTicketURL(user, user); String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> setParams = new HashMap<String, String>(); Map<String, String> setParams = new HashMap<String, String>();
setParams.put("name", "peh00-test2"); setParams.put("name", "peh00-test2");
setParams.put("password", "test123"); setParams.put("password", "test123");
@ -91,7 +91,7 @@ public class UnixUserTest {
int count = getObjectCount(); int count = getObjectCount();
try { try {
String user = "peh00"; String user = "peh00";
String grantingTicketURL = cas.getGrantingTicketURL(user, user); String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> setParams = new HashMap<String, String>(); Map<String, String> setParams = new HashMap<String, String>();
setParams.put("name", "peh01-testfail"); setParams.put("name", "peh01-testfail");
setParams.put("password", "test123"); setParams.put("password", "test123");
@ -112,7 +112,7 @@ public class UnixUserTest {
int count = getObjectCount(); int count = getObjectCount();
try { try {
String user = "peh00"; String user = "peh00";
String grantingTicketURL = cas.getGrantingTicketURL(user, user); String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> setParams = new HashMap<String, String>(); Map<String, String> setParams = new HashMap<String, String>();
setParams.put("name", "peh00-langer-name"); setParams.put("name", "peh00-langer-name");
setParams.put("password", "test123"); setParams.put("password", "test123");
@ -133,7 +133,7 @@ public class UnixUserTest {
int count = getObjectCount(); int count = getObjectCount();
try { try {
String user = "peh00"; String user = "peh00";
String grantingTicketURL = cas.getGrantingTicketURL(user, user); String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>(); Map<String, String> whereParams = new HashMap<String, String>();
Map<String, String> setParams = new HashMap<String, String>(); Map<String, String> setParams = new HashMap<String, String>();
whereParams.put("name", "peh00-test2"); whereParams.put("name", "peh00-test2");
@ -167,7 +167,7 @@ public class UnixUserTest {
int count = getObjectCount(); int count = getObjectCount();
try { try {
String user = "peh00"; String user = "peh00";
String grantingTicketURL = cas.getGrantingTicketURL(user, user); String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>(); Map<String, String> whereParams = new HashMap<String, String>();
whereParams.put("name", "peh00-langer-name"); whereParams.put("name", "peh00-langer-name");
Object[] params = new Object[] { user, Object[] params = new Object[] { user,
@ -186,7 +186,7 @@ public class UnixUserTest {
int count = getObjectCount(); int count = getObjectCount();
try { try {
String user = "peh01"; String user = "peh01";
String grantingTicketURL = cas.getGrantingTicketURL(user, user); String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>(); Map<String, String> whereParams = new HashMap<String, String>();
whereParams.put("name", "peh00-test2"); whereParams.put("name", "peh00-test2");
Object[] params = new Object[] { user, Object[] params = new Object[] { user,
@ -205,7 +205,7 @@ public class UnixUserTest {
int count = getObjectCount(); int count = getObjectCount();
try { try {
String user = "peh00"; String user = "peh00";
String grantingTicketURL = cas.getGrantingTicketURL(user, user); String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>(); Map<String, String> whereParams = new HashMap<String, String>();
whereParams.put("name", "peh00-test2"); whereParams.put("name", "peh00-test2");
Object[] params = new Object[] { user, Object[] params = new Object[] { user,
@ -223,7 +223,7 @@ public class UnixUserTest {
int count = -1; int count = -1;
try { try {
String user = "peh00"; String user = "peh00";
String grantingTicketURL = cas.getGrantingTicketURL(user, user); String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>(); Map<String, String> whereParams = new HashMap<String, String>();
Object[] params = new Object[] { user, Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.BACKEND_URL), cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.BACKEND_URL),

View File

@ -4,6 +4,10 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5"> version="2.5">
<listener>
<listener-class>de.hsadmin.core.model.onetier.PersistenceManagerContextListener</listener-class>
</listener>
<servlet> <servlet>
<servlet-name>Queue Status Servlet</servlet-name> <servlet-name>Queue Status Servlet</servlet-name>
<servlet-class>de.hsadmin.core.qserv.QueueStatusReceiverServlet</servlet-class> <servlet-class>de.hsadmin.core.qserv.QueueStatusReceiverServlet</servlet-class>