clean code
This commit is contained in:
parent
85a7dd60bf
commit
a71fd7fe67
@ -21,7 +21,6 @@ import de.hsadmin.mods.user.UnixUser;
|
||||
*/
|
||||
public abstract class AbstractModuleImpl implements ModuleInterface {
|
||||
|
||||
private static final long serialVersionUID = 2693948730004920437L;
|
||||
private static Log log = LogFactory.getLog(AbstractModuleImpl.class);
|
||||
|
||||
private UnixUser loginUser;
|
||||
|
@ -1,7 +1,6 @@
|
||||
package de.hsadmin.core.model;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
@ -83,8 +82,17 @@ public class GenericModuleImpl implements ModuleInterface {
|
||||
|
||||
private void validateFields(AbstractEntity anEntity) throws HSAdminException {
|
||||
Class<? extends AbstractEntity> clasz = anEntity.getClass();
|
||||
Field[] fields = clasz.getDeclaredFields();
|
||||
for (Field f : fields) {
|
||||
validateAllFields(clasz, anEntity);
|
||||
// Bei Datenbanken und DB-Usern stehen die Attribute in der Oberklasse
|
||||
Class<?> superclass = clasz.getSuperclass();
|
||||
if (superclass != AbstractEntity.class) {
|
||||
validateAllFields(superclass, anEntity);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateAllFields(Class<?> clasz, AbstractEntity anEntity)
|
||||
throws HSAdminException {
|
||||
for (Field f : clasz.getDeclaredFields()) {
|
||||
FieldValidation fieldValidation = f.getAnnotation(FieldValidation.class);
|
||||
if (fieldValidation != null) {
|
||||
try {
|
||||
@ -95,45 +103,8 @@ public class GenericModuleImpl implements ModuleInterface {
|
||||
throw new HSAdminException("validation of field " + f.getName() + " failed");
|
||||
}
|
||||
}
|
||||
} catch (SecurityException e) {
|
||||
} catch (Exception e) {
|
||||
throw new HSAdminException(e);
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new HSAdminException(e);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new HSAdminException(e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new HSAdminException(e);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new HSAdminException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Bei Datenbanken und DB-Usern stehen die Attribute in der Oberklasse
|
||||
Class<?> superclass = clasz.getSuperclass();
|
||||
if (superclass != AbstractEntity.class) {
|
||||
fields = superclass.getDeclaredFields();
|
||||
for (Field f : fields) {
|
||||
FieldValidation fieldValidation = f.getAnnotation(FieldValidation.class);
|
||||
if (fieldValidation != null) {
|
||||
try {
|
||||
Method method = superclass.getMethod(getterName(f));
|
||||
Object valueObject = method.invoke(anEntity);
|
||||
if (valueObject instanceof String) {
|
||||
if (!Pattern.matches(fieldValidation.value(), (String) valueObject)) {
|
||||
throw new HSAdminException("validation of field " + f.getName() + " failed");
|
||||
}
|
||||
}
|
||||
} catch (SecurityException e) {
|
||||
throw new HSAdminException(e);
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new HSAdminException(e);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new HSAdminException(e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new HSAdminException(e);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new HSAdminException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,6 @@ import java.util.List;
|
||||
*/
|
||||
public class SecureDefaultModuleImpl extends AbstractModuleImpl {
|
||||
|
||||
private static final long serialVersionUID = 4567381515459292565L;
|
||||
|
||||
@Override
|
||||
public AbstractEntity initialize(AbstractEntity newEntity) throws AuthorisationException {
|
||||
return super.initialize(newEntity);
|
||||
|
@ -25,8 +25,6 @@ import de.hsadmin.mods.user.UnixUser;
|
||||
@SequenceGenerator(name = "DomainsSeqGen", sequenceName = "domain_domain_id_seq")
|
||||
public class Domain extends AbstractEntity {
|
||||
|
||||
private static final long serialVersionUID = -7496110900868795840L;
|
||||
|
||||
@Id
|
||||
@Column(name = "domain_id", columnDefinition = "integer")
|
||||
@GeneratedValue(strategy = SEQUENCE, generator = "DomainsSeqGen")
|
||||
|
@ -19,8 +19,6 @@ import de.hsadmin.mods.user.UnixUser;
|
||||
|
||||
public class DomainModuleImpl extends AbstractModuleImpl {
|
||||
|
||||
private static final long serialVersionUID = -3991273357778898175L;
|
||||
|
||||
@Override
|
||||
public AbstractEntity initialize(AbstractEntity newEntity) throws AuthorisationException {
|
||||
AbstractEntity newDom = super.initialize(newEntity);
|
||||
|
@ -2,37 +2,21 @@ package de.hsadmin.mods.qstat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import de.hsadmin.core.model.AbstractModuleImpl;
|
||||
import de.hsadmin.core.model.AbstractEntity;
|
||||
import de.hsadmin.core.model.AbstractModuleImpl;
|
||||
import de.hsadmin.core.model.HSAdminException;
|
||||
import de.hsadmin.mods.user.UnixUser;
|
||||
|
||||
public class QTaskModuleImpl extends AbstractModuleImpl {
|
||||
|
||||
private static final long serialVersionUID = 3942424688570077274L;
|
||||
|
||||
public QTaskModuleImpl() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AbstractEntity> search(Class<? extends AbstractEntity> entityClass, String condition, String orderBy) throws HSAdminException {
|
||||
// do query and return result
|
||||
if (orderBy == null || orderBy.length() == 0) {
|
||||
orderBy = "ORDER BY obj.started DESC";
|
||||
}
|
||||
return super.search(entityClass, condition, orderBy);
|
||||
}
|
||||
|
||||
// throws an AuthorisationException if the login user has no write acess
|
||||
// on the pac of the given UnixUser
|
||||
@SuppressWarnings("unused")
|
||||
private boolean hasAccessOnPacOf(UnixUser user) {
|
||||
// only pac admins (same name as pac) and the owner (customer) have
|
||||
// write access to the pac
|
||||
boolean isPacAdmin = getLoginUser().getName().equals(
|
||||
user.getPac().getName());
|
||||
boolean isCustomer = getLoginUser().getName().equals(
|
||||
user.getPac().getCustomer().getName());
|
||||
return isPacAdmin || isCustomer;
|
||||
}
|
||||
}
|
||||
|
@ -14,8 +14,6 @@ import de.hsadmin.mods.pac.Pac;
|
||||
|
||||
public class UnixUserModuleImpl extends AbstractModuleImpl {
|
||||
|
||||
private static final long serialVersionUID = 7480353553685400790L;
|
||||
|
||||
public UnixUserModuleImpl() {
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user