started generic remote implementation
This commit is contained in:
parent
ba1d525cbe
commit
3611be9661
@ -8,6 +8,7 @@ import java.lang.annotation.Target;
|
|||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target(ElementType.FIELD)
|
@Target(ElementType.FIELD)
|
||||||
public @interface AnnFieldIO {
|
public @interface AnnFieldIO {
|
||||||
String validation() default "[A-Za-z0-9\\_\\-]";
|
String validation() default "[A-Za-z0-9\\_\\-]*";
|
||||||
ReadWriteAccess rw() default ReadWriteAccess.WRITEONCE;
|
ReadWriteAccess rw() default ReadWriteAccess.WRITEONCE;
|
||||||
|
Class<?> referTo() default Object.class;
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
package de.hsadmin.core.model;
|
package de.hsadmin.core.model;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import de.hsadmin.core.util.ReflectionUtil;
|
||||||
|
|
||||||
public class GenericModuleImpl implements ModuleInterface {
|
public class GenericModuleImpl implements ModuleInterface {
|
||||||
|
|
||||||
private Transaction tx;
|
private Transaction tx;
|
||||||
@ -84,8 +85,7 @@ public class GenericModuleImpl implements ModuleInterface {
|
|||||||
AnnFieldIO fieldValidation = f.getAnnotation(AnnFieldIO.class);
|
AnnFieldIO fieldValidation = f.getAnnotation(AnnFieldIO.class);
|
||||||
if (fieldValidation != null) {
|
if (fieldValidation != null) {
|
||||||
try {
|
try {
|
||||||
Method method = clasz.getMethod(getterName(f));
|
Object valueObject = ReflectionUtil.invokeGetter(anEntity, clasz, f);
|
||||||
Object valueObject = method.invoke(anEntity);
|
|
||||||
if (valueObject instanceof String) {
|
if (valueObject instanceof String) {
|
||||||
if (!Pattern.matches(fieldValidation.validation(), (String) valueObject)) {
|
if (!Pattern.matches(fieldValidation.validation(), (String) valueObject)) {
|
||||||
throw new HSAdminException("validation of field " + f.getName() + " failed, pattern: " + fieldValidation.validation());
|
throw new HSAdminException("validation of field " + f.getName() + " failed, pattern: " + fieldValidation.validation());
|
||||||
@ -98,14 +98,4 @@ public class GenericModuleImpl implements ModuleInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getterName(Field f) {
|
|
||||||
String name = f.getName();
|
|
||||||
char firstChar = Character.toUpperCase(name.charAt(0));
|
|
||||||
Class<?> type = f.getType();
|
|
||||||
if (type.getCanonicalName().startsWith("boolean")) {
|
|
||||||
return "is" + firstChar + name.substring(1);
|
|
||||||
}
|
|
||||||
return "get" + firstChar + name.substring(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
118
hsarback/src/de/hsadmin/core/util/ReflectionUtil.java
Normal file
118
hsarback/src/de/hsadmin/core/util/ReflectionUtil.java
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
package de.hsadmin.core.util;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
import de.hsadmin.cliClientConnector.TechnicalException;
|
||||||
|
import de.hsadmin.core.model.AbstractEntity;
|
||||||
|
import de.hsadmin.core.model.AnnFieldIO;
|
||||||
|
|
||||||
|
public class ReflectionUtil {
|
||||||
|
|
||||||
|
public static synchronized Object invokeGetter(AbstractEntity entity, Class<?> clasz, Field f) {
|
||||||
|
Object valueObject = null;
|
||||||
|
try {
|
||||||
|
Method method = clasz.getMethod(getterName(f));
|
||||||
|
valueObject = method.invoke(entity);
|
||||||
|
if (valueObject instanceof Boolean) {
|
||||||
|
valueObject = valueObject.toString();
|
||||||
|
} else
|
||||||
|
if (valueObject instanceof Number) {
|
||||||
|
valueObject = valueObject.toString();
|
||||||
|
} else
|
||||||
|
if (valueObject instanceof Date) {
|
||||||
|
valueObject = TextUtil.format((Date) valueObject);
|
||||||
|
} else
|
||||||
|
if (valueObject instanceof Set) {
|
||||||
|
Set<?> s = (Set<?>) valueObject;
|
||||||
|
List<String> nameList = new ArrayList<String>();
|
||||||
|
for (Object o : s) {
|
||||||
|
Class<?> t = o.getClass();
|
||||||
|
nameList.add((String) invokeGetter((AbstractEntity) o, t, t.getDeclaredField("name")));
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
if (valueObject instanceof List<?>) {
|
||||||
|
List<?> l = (List<?>) valueObject;
|
||||||
|
List<String> nameList = new ArrayList<String>();
|
||||||
|
for (Object o : l) {
|
||||||
|
Class<?> t = o.getClass();
|
||||||
|
nameList.add((String) invokeGetter((AbstractEntity) o, t, t.getDeclaredField("name")));
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
if (valueObject instanceof AbstractEntity) {
|
||||||
|
Class<?> t = f.getType();
|
||||||
|
valueObject = invokeGetter((AbstractEntity) valueObject, t, t.getDeclaredField("name"));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new TechnicalException(e);
|
||||||
|
}
|
||||||
|
return valueObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized void invokeSetter(AbstractEntity entity,
|
||||||
|
Class<?> clasz, Field f, Object valueObject) {
|
||||||
|
try {
|
||||||
|
Class<?> type = f.getType();
|
||||||
|
if (type.equals(String.class)) {
|
||||||
|
clasz.getMethod(setterName(f), String.class).invoke(entity, valueObject);
|
||||||
|
} else
|
||||||
|
if (type.equals(Date.class)) {
|
||||||
|
clasz.getMethod(setterName(f), Date.class).invoke(entity, TextUtil.parse((String) valueObject));
|
||||||
|
} else
|
||||||
|
if (type.getCanonicalName().equals("long")) {
|
||||||
|
clasz.getMethod(setterName(f), long.class).invoke(entity, Long.parseLong((String) valueObject));
|
||||||
|
} else
|
||||||
|
if (type.getCanonicalName().equals("int")) {
|
||||||
|
clasz.getMethod(setterName(f), int.class).invoke(entity, Integer.parseInt((String) valueObject));
|
||||||
|
} else
|
||||||
|
if (type.getCanonicalName().equals("boolean")) {
|
||||||
|
clasz.getMethod(setterName(f), boolean.class).invoke(entity, Boolean.valueOf((String) valueObject));
|
||||||
|
} else
|
||||||
|
if (type.equals(Set.class)) {
|
||||||
|
AnnFieldIO annotation = f.getAnnotation(AnnFieldIO.class);
|
||||||
|
Class<?> referTo = annotation.referTo();
|
||||||
|
Set<Object> newSet = new TreeSet<Object>();
|
||||||
|
clasz.getMethod(setterName(f), Set.class).invoke(entity, newSet);
|
||||||
|
if (valueObject != null && valueObject instanceof Object[]) {
|
||||||
|
for (Object item : ((Object[]) valueObject)) {
|
||||||
|
if (item instanceof String && referTo.getDeclaredField("name") != null) {
|
||||||
|
Object instance = referTo.newInstance();
|
||||||
|
if (instance instanceof AbstractEntity) {
|
||||||
|
invokeSetter((AbstractEntity) instance, referTo, referTo.getDeclaredField("name"), item);
|
||||||
|
newSet.add(instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Object newInstance = type.newInstance();
|
||||||
|
clasz.getMethod(setterName(f), type).invoke(entity, newInstance);
|
||||||
|
type.getMethod("setName", String.class).invoke(newInstance, valueObject);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new TechnicalException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getterName(Field f) {
|
||||||
|
String name = f.getName();
|
||||||
|
char firstChar = Character.toUpperCase(name.charAt(0));
|
||||||
|
Class<?> type = f.getType();
|
||||||
|
if (type.getCanonicalName().equals("boolean")) {
|
||||||
|
return "is" + firstChar + name.substring(1);
|
||||||
|
}
|
||||||
|
return "get" + firstChar + name.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String setterName(Field f) {
|
||||||
|
String name = f.getName();
|
||||||
|
char firstChar = Character.toUpperCase(name.charAt(0));
|
||||||
|
return "set" + firstChar + name.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,8 +1,15 @@
|
|||||||
package de.hsadmin.core.util;
|
package de.hsadmin.core.util;
|
||||||
|
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
public class TextUtil {
|
public class TextUtil {
|
||||||
|
|
||||||
public static String replaceUmlautCharacters(String umlautString) {
|
private static final DateFormat df = SimpleDateFormat.getDateInstance(DateFormat.SHORT);
|
||||||
|
|
||||||
|
public static synchronized String replaceUmlautCharacters(String umlautString) {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
for (char c : umlautString.toCharArray()) {
|
for (char c : umlautString.toCharArray()) {
|
||||||
if ( (c >= 'a' && c <= 'z') ||
|
if ( (c >= 'a' && c <= 'z') ||
|
||||||
@ -42,4 +49,21 @@ public class TextUtil {
|
|||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static synchronized String format(Date date) {
|
||||||
|
return df.format(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized Date parse(String dateString) {
|
||||||
|
try {
|
||||||
|
return df.parse(dateString);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
try {
|
||||||
|
return df.parse("01.01.1970");
|
||||||
|
} catch (ParseException e1) {
|
||||||
|
// don't care
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ public class Domain extends AbstractEntity {
|
|||||||
@Column(name = "domain_name", columnDefinition = "character varying(256)", nullable = false)
|
@Column(name = "domain_name", columnDefinition = "character varying(256)", nullable = false)
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@AnnFieldIO(rw=ReadWriteAccess.WRITEONCE)
|
@AnnFieldIO(validation="[a-z0-9\\_\\-\\.]*", rw=ReadWriteAccess.WRITEONCE)
|
||||||
@JoinColumn(name = "domain_owner", columnDefinition = "integer", nullable = false)
|
@JoinColumn(name = "domain_owner", columnDefinition = "integer", nullable = false)
|
||||||
@ManyToOne(fetch = EAGER)
|
@ManyToOne(fetch = EAGER)
|
||||||
private UnixUser user;
|
private UnixUser user;
|
||||||
@ -56,12 +56,12 @@ public class Domain extends AbstractEntity {
|
|||||||
@Column(name = "domain_dns_master", columnDefinition = "character varying(64)")
|
@Column(name = "domain_dns_master", columnDefinition = "character varying(64)")
|
||||||
private String dnsMaster;
|
private String dnsMaster;
|
||||||
|
|
||||||
@AnnFieldIO(validation="[a-zA-Z0-9\\-\\.]*", rw=ReadWriteAccess.READWRITE)
|
@AnnFieldIO(validation="[a-zA-Z0-9\\-\\.]*", rw=ReadWriteAccess.READWRITE, referTo=DomainOption.class)
|
||||||
@ManyToMany(cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
|
@ManyToMany(cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
|
||||||
@JoinTable(name="domain__domain_option",
|
@JoinTable(name="domain__domain_option",
|
||||||
joinColumns={@JoinColumn(name="domain_id", referencedColumnName="domain_id")},
|
joinColumns={@JoinColumn(name="domain_id", referencedColumnName="domain_id")},
|
||||||
inverseJoinColumns={@JoinColumn(name="domain_option_id", referencedColumnName="domain_option_id")})
|
inverseJoinColumns={@JoinColumn(name="domain_option_id", referencedColumnName="domain_option_id")})
|
||||||
private Set<DomainOption> domainOptions;
|
private Set<DomainOption> domainoptions;
|
||||||
|
|
||||||
public Domain() {
|
public Domain() {
|
||||||
}
|
}
|
||||||
@ -172,12 +172,12 @@ public class Domain extends AbstractEntity {
|
|||||||
"obj.user=:loginUser";
|
"obj.user=:loginUser";
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<DomainOption> getDomainOptions() {
|
public Set<DomainOption> getDomainoptions() {
|
||||||
return domainOptions;
|
return domainoptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDomainOptions(Set<DomainOption> domainOptions) {
|
public void setDomainoptions(Set<DomainOption> domainOptions) {
|
||||||
this.domainOptions = domainOptions;
|
this.domainoptions = domainOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,7 @@ public class DomainModuleImpl extends AbstractModuleImpl {
|
|||||||
Query q = em.createQuery("SELECT opt FROM " +
|
Query q = em.createQuery("SELECT opt FROM " +
|
||||||
DomainOption.class.getAnnotation(javax.persistence.Entity.class).name() +
|
DomainOption.class.getAnnotation(javax.persistence.Entity.class).name() +
|
||||||
" opt WHERE opt.name=:optName");
|
" opt WHERE opt.name=:optName");
|
||||||
Set<DomainOption> domainOptions = updatedDom.getDomainOptions();
|
Set<DomainOption> domainOptions = updatedDom.getDomainoptions();
|
||||||
for (DomainOption opt : domainOptions) {
|
for (DomainOption opt : domainOptions) {
|
||||||
q.setParameter("optName", opt.getName());
|
q.setParameter("optName", opt.getName());
|
||||||
List<?> list = q.getResultList();
|
List<?> list = q.getResultList();
|
||||||
|
@ -33,7 +33,7 @@ public class DomainOption extends AbstractEntity {
|
|||||||
@Column(name = "domain_option_name", columnDefinition = "character varying(256)", nullable = false)
|
@Column(name = "domain_option_name", columnDefinition = "character varying(256)", nullable = false)
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@ManyToMany(mappedBy="domainOptions", fetch=FetchType.LAZY)
|
@ManyToMany(mappedBy="domainoptions", fetch=FetchType.LAZY)
|
||||||
private List<Domain> domains;
|
private List<Domain> domains;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -23,7 +23,7 @@ public abstract class AbstractRemote implements IRemote {
|
|||||||
|
|
||||||
protected abstract void entity2map(AbstractEntity entity, Map<String, Object> resultMap);
|
protected abstract void entity2map(AbstractEntity entity, Map<String, Object> resultMap);
|
||||||
|
|
||||||
protected abstract void map2entity(Map<String, Object> setParams, AbstractEntity entity);
|
protected abstract void map2entity(Map<String, Object> setParams, AbstractEntity entity) throws HSAdminException;
|
||||||
|
|
||||||
protected abstract void regularizeKeys(Map<String, String> whereParams);
|
protected abstract void regularizeKeys(Map<String, String> whereParams);
|
||||||
|
|
||||||
|
@ -1,21 +1,17 @@
|
|||||||
package de.hsadmin.remote;
|
package de.hsadmin.remote;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.text.ParseException;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import de.hsadmin.core.model.AbstractEntity;
|
import de.hsadmin.core.model.AbstractEntity;
|
||||||
|
import de.hsadmin.core.util.TextUtil;
|
||||||
import de.hsadmin.mods.cust.BankAccount;
|
import de.hsadmin.mods.cust.BankAccount;
|
||||||
import de.hsadmin.mods.cust.Contact;
|
import de.hsadmin.mods.cust.Contact;
|
||||||
import de.hsadmin.mods.cust.Customer;
|
import de.hsadmin.mods.cust.Customer;
|
||||||
|
|
||||||
public class CustomerRemote extends AbstractRemote {
|
public class CustomerRemote extends AbstractRemote {
|
||||||
|
|
||||||
private static final DateFormat df = SimpleDateFormat.getDateInstance(DateFormat.SHORT);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class<? extends AbstractEntity> getEntityClass() {
|
protected Class<? extends AbstractEntity> getEntityClass() {
|
||||||
return Customer.class;
|
return Customer.class;
|
||||||
@ -30,24 +26,24 @@ public class CustomerRemote extends AbstractRemote {
|
|||||||
resultMap.put("memberno", Integer.toString(cust.getMemberNo()));
|
resultMap.put("memberno", Integer.toString(cust.getMemberNo()));
|
||||||
Date memberSince = cust.getMemberSince();
|
Date memberSince = cust.getMemberSince();
|
||||||
if (assertNotNull(memberSince)) {
|
if (assertNotNull(memberSince)) {
|
||||||
resultMap.put("membersince", df.format(memberSince));
|
resultMap.put("membersince", TextUtil.format(memberSince));
|
||||||
}
|
}
|
||||||
Date memberUntil = cust.getMemberUntil();
|
Date memberUntil = cust.getMemberUntil();
|
||||||
if (assertNotNull(memberUntil)) {
|
if (assertNotNull(memberUntil)) {
|
||||||
resultMap.put("memberuntil", df.format(memberUntil));
|
resultMap.put("memberuntil", TextUtil.format(memberUntil));
|
||||||
}
|
}
|
||||||
resultMap.put("memberrole", cust.getMemberRole());
|
resultMap.put("memberrole", cust.getMemberRole());
|
||||||
Date authorContract = cust.getAuthorContract();
|
Date authorContract = cust.getAuthorContract();
|
||||||
if (assertNotNull(authorContract)) {
|
if (assertNotNull(authorContract)) {
|
||||||
resultMap.put("authorcontract", df.format(authorContract));
|
resultMap.put("authorcontract", TextUtil.format(authorContract));
|
||||||
}
|
}
|
||||||
Date nonDiscContract = cust.getNonDiscContract();
|
Date nonDiscContract = cust.getNonDiscContract();
|
||||||
if (assertNotNull(nonDiscContract)) {
|
if (assertNotNull(nonDiscContract)) {
|
||||||
resultMap.put("nondisccontract", df.format(nonDiscContract));
|
resultMap.put("nondisccontract", TextUtil.format(nonDiscContract));
|
||||||
}
|
}
|
||||||
Date sharesUpdated = cust.getSharesUpdated();
|
Date sharesUpdated = cust.getSharesUpdated();
|
||||||
if (assertNotNull(sharesUpdated)) {
|
if (assertNotNull(sharesUpdated)) {
|
||||||
resultMap.put("sharesupdated", df.format(sharesUpdated));
|
resultMap.put("sharesupdated", TextUtil.format(sharesUpdated));
|
||||||
}
|
}
|
||||||
resultMap.put("sharessigned", Integer.toString(cust.getSharesSigned()));
|
resultMap.put("sharessigned", Integer.toString(cust.getSharesSigned()));
|
||||||
resultMap.put("uidvat", cust.getUidVAT());
|
resultMap.put("uidvat", cust.getUidVAT());
|
||||||
@ -104,19 +100,11 @@ public class CustomerRemote extends AbstractRemote {
|
|||||||
}
|
}
|
||||||
String memberSince = (String) setParams.get("membersince");
|
String memberSince = (String) setParams.get("membersince");
|
||||||
if (assertNotNull(memberSince)) {
|
if (assertNotNull(memberSince)) {
|
||||||
try {
|
cust.setMemberSince(TextUtil.parse(memberSince));
|
||||||
cust.setMemberSince(df.parse(memberSince));
|
|
||||||
} catch (ParseException e) {
|
|
||||||
// don't care
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
String memberUntil = (String) setParams.get("memberuntil");
|
String memberUntil = (String) setParams.get("memberuntil");
|
||||||
if (assertNotNull(memberUntil)) {
|
if (assertNotNull(memberUntil)) {
|
||||||
try {
|
cust.setMemberUntil(TextUtil.parse(memberUntil));
|
||||||
cust.setMemberUntil(df.parse(memberUntil));
|
|
||||||
} catch (ParseException e) {
|
|
||||||
// don't care
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
String memberRole = (String) setParams.get("memberrole");
|
String memberRole = (String) setParams.get("memberrole");
|
||||||
if (assertNotNull(memberRole)) {
|
if (assertNotNull(memberRole)) {
|
||||||
@ -124,27 +112,15 @@ public class CustomerRemote extends AbstractRemote {
|
|||||||
}
|
}
|
||||||
String authorContract = (String) setParams.get("authorcontract");
|
String authorContract = (String) setParams.get("authorcontract");
|
||||||
if (assertNotNull(authorContract)) {
|
if (assertNotNull(authorContract)) {
|
||||||
try {
|
cust.setAuthorContract(TextUtil.parse(authorContract));
|
||||||
cust.setAuthorContract(df.parse(authorContract));
|
|
||||||
} catch (ParseException e) {
|
|
||||||
// don't care
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
String nonDiscContract = (String) setParams.get("nondisccontract");
|
String nonDiscContract = (String) setParams.get("nondisccontract");
|
||||||
if (assertNotNull(nonDiscContract)) {
|
if (assertNotNull(nonDiscContract)) {
|
||||||
try {
|
cust.setNonDiscContract(TextUtil.parse(nonDiscContract));
|
||||||
cust.setNonDiscContract(df.parse(nonDiscContract));
|
|
||||||
} catch (ParseException e) {
|
|
||||||
// don't care
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
String sharesUpdated = (String) setParams.get("sharesupdated");
|
String sharesUpdated = (String) setParams.get("sharesupdated");
|
||||||
if (assertNotNull(sharesUpdated)) {
|
if (assertNotNull(sharesUpdated)) {
|
||||||
try {
|
cust.setSharesUpdated(TextUtil.parse(sharesUpdated));
|
||||||
cust.setSharesUpdated(df.parse(sharesUpdated));
|
|
||||||
} catch (ParseException e) {
|
|
||||||
// don't care
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
String sharesSigned = (String) setParams.get("sharessigned");
|
String sharesSigned = (String) setParams.get("sharessigned");
|
||||||
if (assertNotNull(sharesSigned)) {
|
if (assertNotNull(sharesSigned)) {
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package de.hsadmin.remote;
|
package de.hsadmin.remote;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -10,72 +8,71 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import de.hsadmin.core.model.AbstractEntity;
|
import de.hsadmin.core.model.AbstractEntity;
|
||||||
|
import de.hsadmin.core.util.TextUtil;
|
||||||
import de.hsadmin.mods.dom.Domain;
|
import de.hsadmin.mods.dom.Domain;
|
||||||
import de.hsadmin.mods.dom.DomainOption;
|
import de.hsadmin.mods.dom.DomainOption;
|
||||||
import de.hsadmin.mods.user.UnixUser;
|
import de.hsadmin.mods.user.UnixUser;
|
||||||
|
|
||||||
public class DomainRemote extends AbstractRemote {
|
public class DomainRemote extends GenericAbstractRemote {
|
||||||
|
|
||||||
private static final DateFormat df = SimpleDateFormat.getDateInstance(DateFormat.SHORT);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class<? extends AbstractEntity> getEntityClass() {
|
protected Class<? extends AbstractEntity> getEntityClass() {
|
||||||
return Domain.class;
|
return Domain.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
protected void entity2map(AbstractEntity entity, Map<String, Object> resultMap) {
|
// protected void entity2map(AbstractEntity entity, Map<String, Object> resultMap) {
|
||||||
Domain dom = (Domain) entity;
|
// Domain dom = (Domain) entity;
|
||||||
String id = Long.toString(dom.getId());
|
// String id = Long.toString(dom.getId());
|
||||||
resultMap.put("id", id);
|
// resultMap.put("id", id);
|
||||||
String name = dom.getName();
|
// String name = dom.getName();
|
||||||
resultMap.put("name", name);
|
// resultMap.put("name", name);
|
||||||
String user = dom.getUser().getName();
|
// String user = dom.getUser().getName();
|
||||||
resultMap.put("user", user);
|
// resultMap.put("user", user);
|
||||||
String hive = dom.getHiveName();
|
// String hive = dom.getHiveName();
|
||||||
resultMap.put("hive", hive);
|
// resultMap.put("hive", hive);
|
||||||
String pac = dom.getUser().getPac().getName();
|
// String pac = dom.getUser().getPac().getName();
|
||||||
resultMap.put("pac", pac);
|
// resultMap.put("pac", pac);
|
||||||
Date sDate = dom.getSince();
|
// Date sDate = dom.getSince();
|
||||||
if (assertNotNull(sDate)) {
|
// if (assertNotNull(sDate)) {
|
||||||
String since = df.format(sDate);
|
// String since = TextUtil.format(sDate);
|
||||||
resultMap.put("since", since);
|
// resultMap.put("since", since);
|
||||||
}
|
// }
|
||||||
List<String> domainOptionsList = new ArrayList<String>();
|
// List<String> domainOptionsList = new ArrayList<String>();
|
||||||
resultMap.put("domainoptions", domainOptionsList);
|
// resultMap.put("domainoptions", domainOptionsList);
|
||||||
Set<DomainOption> domainOptions = dom.getDomainOptions();
|
// Set<DomainOption> domainOptions = dom.getDomainOptions();
|
||||||
if (domainOptions != null) {
|
// if (domainOptions != null) {
|
||||||
for (DomainOption opt : domainOptions) {
|
// for (DomainOption opt : domainOptions) {
|
||||||
domainOptionsList.add(opt.getName());
|
// domainOptionsList.add(opt.getName());
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
protected void map2entity(Map<String, Object> setParams, AbstractEntity entity) {
|
// protected void map2entity(Map<String, Object> setParams, AbstractEntity entity) {
|
||||||
Domain dom = (Domain) entity;
|
// Domain dom = (Domain) entity;
|
||||||
String name = (String) setParams.get("name");
|
// String name = (String) setParams.get("name");
|
||||||
String user = (String) setParams.get("user");
|
// String user = (String) setParams.get("user");
|
||||||
if (assertNotNull(name)) {
|
// if (assertNotNull(name)) {
|
||||||
dom.setName(name);
|
// dom.setName(name);
|
||||||
}
|
// }
|
||||||
if (assertNotNull(user)) {
|
// if (assertNotNull(user)) {
|
||||||
UnixUser u = new UnixUser();
|
// UnixUser u = new UnixUser();
|
||||||
u.setName(user);
|
// u.setName(user);
|
||||||
dom.setUser(u);
|
// dom.setUser(u);
|
||||||
}
|
// }
|
||||||
Object domOptsObj = setParams.get("domainoptions");
|
// Object domOptsObj = setParams.get("domainoptions");
|
||||||
if (domOptsObj != null && domOptsObj instanceof Object[]) {
|
// if (domOptsObj != null && domOptsObj instanceof Object[]) {
|
||||||
Set<DomainOption> domainOptionsSet = new HashSet<DomainOption>();
|
// Set<DomainOption> domainOptionsSet = new HashSet<DomainOption>();
|
||||||
Object[] domOptions = (Object[]) domOptsObj;
|
// Object[] domOptions = (Object[]) domOptsObj;
|
||||||
for (int i=0; i<domOptions.length; i++) {
|
// for (int i=0; i<domOptions.length; i++) {
|
||||||
DomainOption domainOption = new DomainOption();
|
// DomainOption domainOption = new DomainOption();
|
||||||
domainOption.setName((String)domOptions[i]);
|
// domainOption.setName((String)domOptions[i]);
|
||||||
domainOptionsSet.add(domainOption);
|
// domainOptionsSet.add(domainOption);
|
||||||
}
|
// }
|
||||||
dom.setDomainOptions(domainOptionsSet);
|
// dom.setDomainOptions(domainOptionsSet);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void regularizeKeys(Map<String, String> whereParams) {
|
protected void regularizeKeys(Map<String, String> whereParams) {
|
||||||
|
64
hsarback/src/de/hsadmin/remote/GenericAbstractRemote.java
Normal file
64
hsarback/src/de/hsadmin/remote/GenericAbstractRemote.java
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
package de.hsadmin.remote;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import de.hsadmin.cliClientConnector.TechnicalException;
|
||||||
|
import de.hsadmin.core.model.AbstractEntity;
|
||||||
|
import de.hsadmin.core.model.AnnFieldIO;
|
||||||
|
import de.hsadmin.core.model.HSAdminException;
|
||||||
|
import de.hsadmin.core.model.ReadWriteAccess;
|
||||||
|
import de.hsadmin.core.util.ReflectionUtil;
|
||||||
|
|
||||||
|
public abstract class GenericAbstractRemote extends AbstractRemote {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected abstract Class<? extends AbstractEntity> getEntityClass();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected abstract void regularizeKeys(Map<String, String> whereParams);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void entity2map(AbstractEntity entity, Map<String, Object> resultMap) {
|
||||||
|
Class<? extends AbstractEntity> entityClass = getEntityClass();
|
||||||
|
Field[] fields = entityClass.getDeclaredFields();
|
||||||
|
for (Field f : fields) {
|
||||||
|
if (f.getName().equals("id") && f.getType().getCanonicalName().equals("long")) {
|
||||||
|
resultMap.put("id", (ReflectionUtil.invokeGetter(entity, entityClass, f)).toString());
|
||||||
|
} else {
|
||||||
|
AnnFieldIO fieldIO = f.getAnnotation(AnnFieldIO.class);
|
||||||
|
if (fieldIO != null && fieldIO.rw() != ReadWriteAccess.WRITEONLY) {
|
||||||
|
resultMap.put(f.getName(), ReflectionUtil.invokeGetter(entity, entityClass, f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void map2entity(Map<String, Object> paramsMap, AbstractEntity entity) throws HSAdminException {
|
||||||
|
Class<? extends AbstractEntity> entityClass = getEntityClass();
|
||||||
|
Set<String> keySet = paramsMap.keySet();
|
||||||
|
for (String key : keySet) {
|
||||||
|
Object valueObj = paramsMap.get(key);
|
||||||
|
try {
|
||||||
|
Field f = entityClass.getDeclaredField(key);
|
||||||
|
AnnFieldIO fieldIO = f.getAnnotation(AnnFieldIO.class);
|
||||||
|
if (valueObj != null && valueObj instanceof String && !Pattern.matches(fieldIO.validation(), (String) valueObj)) {
|
||||||
|
throw new HSAdminException("validation of field " + f.getName() + " failed, pattern: " + fieldIO.validation());
|
||||||
|
}
|
||||||
|
if (fieldIO.rw() != ReadWriteAccess.READONLY) {
|
||||||
|
ReflectionUtil.invokeSetter(entity, entityClass, f, valueObj);
|
||||||
|
} else {
|
||||||
|
throw new HSAdminException("field " + f.getName() + " is readonly");
|
||||||
|
}
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
throw new TechnicalException(e);
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
throw new HSAdminException("no such field: " + key, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,7 +1,5 @@
|
|||||||
package de.hsadmin.remote;
|
package de.hsadmin.remote;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -9,6 +7,7 @@ import java.util.SortedSet;
|
|||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import de.hsadmin.core.model.AbstractEntity;
|
import de.hsadmin.core.model.AbstractEntity;
|
||||||
|
import de.hsadmin.core.util.TextUtil;
|
||||||
import de.hsadmin.mods.cust.Customer;
|
import de.hsadmin.mods.cust.Customer;
|
||||||
import de.hsadmin.mods.pac.BasePac;
|
import de.hsadmin.mods.pac.BasePac;
|
||||||
import de.hsadmin.mods.pac.Hive;
|
import de.hsadmin.mods.pac.Hive;
|
||||||
@ -18,8 +17,6 @@ import de.hsadmin.mods.pac.PacComponent;
|
|||||||
|
|
||||||
public class PacRemote extends AbstractRemote {
|
public class PacRemote extends AbstractRemote {
|
||||||
|
|
||||||
private static final DateFormat df = SimpleDateFormat.getDateInstance(DateFormat.SHORT);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void entity2map(AbstractEntity entity, Map<String, Object> resultMap) {
|
protected void entity2map(AbstractEntity entity, Map<String, Object> resultMap) {
|
||||||
Pac pac = (Pac) entity;
|
Pac pac = (Pac) entity;
|
||||||
@ -28,7 +25,7 @@ public class PacRemote extends AbstractRemote {
|
|||||||
resultMap.put("hive", pac.getHiveName());
|
resultMap.put("hive", pac.getHiveName());
|
||||||
resultMap.put("customer", pac.getCustomer().getName());
|
resultMap.put("customer", pac.getCustomer().getName());
|
||||||
resultMap.put("curinetaddr", pac.getCurINetAddr().getInetAddr());
|
resultMap.put("curinetaddr", pac.getCurINetAddr().getInetAddr());
|
||||||
resultMap.put("created", df.format(pac.getCreated()));
|
resultMap.put("created", TextUtil.format(pac.getCreated()));
|
||||||
resultMap.put("basepac", pac.getBasepac().getName());
|
resultMap.put("basepac", pac.getBasepac().getName());
|
||||||
SortedSet<PacComponent> sortedComponents = new TreeSet<PacComponent>(new Comparator<PacComponent>() {
|
SortedSet<PacComponent> sortedComponents = new TreeSet<PacComponent>(new Comparator<PacComponent>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,19 +1,16 @@
|
|||||||
package de.hsadmin.remote;
|
package de.hsadmin.remote;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
|
||||||
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.AbstractEntity;
|
import de.hsadmin.core.model.AbstractEntity;
|
||||||
import de.hsadmin.core.qserv.QueueTask;
|
import de.hsadmin.core.qserv.QueueTask;
|
||||||
import de.hsadmin.core.qserv.QueueTask.QueueTaskStatus;
|
import de.hsadmin.core.qserv.QueueTask.QueueTaskStatus;
|
||||||
|
import de.hsadmin.core.util.TextUtil;
|
||||||
import de.hsadmin.mods.user.UnixUser;
|
import de.hsadmin.mods.user.UnixUser;
|
||||||
|
|
||||||
public class QueueTaskRemote extends AbstractRemote {
|
public class QueueTaskRemote extends AbstractRemote {
|
||||||
|
|
||||||
private static final DateFormat df = SimpleDateFormat.getDateInstance(DateFormat.SHORT);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class<? extends AbstractEntity> getEntityClass() {
|
protected Class<? extends AbstractEntity> getEntityClass() {
|
||||||
return QueueTask.class;
|
return QueueTask.class;
|
||||||
@ -32,11 +29,11 @@ public class QueueTaskRemote extends AbstractRemote {
|
|||||||
if (user != null) resultMap.put("user", user.getName());
|
if (user != null) resultMap.put("user", user.getName());
|
||||||
Date started = task.getStarted();
|
Date started = task.getStarted();
|
||||||
if (assertNotNull(started)) {
|
if (assertNotNull(started)) {
|
||||||
resultMap.put("started", df.format(started));
|
resultMap.put("started", TextUtil.format(started));
|
||||||
}
|
}
|
||||||
Date finished = task.getFinished();
|
Date finished = task.getFinished();
|
||||||
if (assertNotNull(finished)) {
|
if (assertNotNull(finished)) {
|
||||||
resultMap.put("finished", df.format(finished));
|
resultMap.put("finished", TextUtil.format(finished));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user