hs.hsadmin/hsarback/src/de/hsadmin/remote/EMailAliasRemote.java

73 lines
1.9 KiB
Java
Raw Normal View History

2010-10-05 21:42:07 +02:00
package de.hsadmin.remote;
2011-10-28 16:51:11 +02:00
import java.util.ArrayList;
2011-10-28 16:08:18 +02:00
import java.util.List;
2010-10-05 21:42:07 +02:00
import java.util.Map;
2011-10-28 16:51:11 +02:00
import java.util.StringTokenizer;
2010-10-05 21:42:07 +02:00
import de.hsadmin.core.model.AbstractEntity;
2013-04-29 20:01:09 +02:00
import de.hsadmin.core.model.Transaction;
2010-10-05 21:42:07 +02:00
import de.hsadmin.mods.email.EMailAlias;
public class EMailAliasRemote extends AbstractRemote {
@Override
2013-04-29 20:01:09 +02:00
protected void entity2map(Transaction tx, AbstractEntity entity, Map<String, Object> map) {
2010-10-05 21:42:07 +02:00
EMailAlias alias = (EMailAlias) entity;
String id = Long.toString(alias.getId());
String name = alias.getName();
String pac = alias.getPac().getName();
String target = alias.getTarget();
map.put("id", id);
map.put("name", name);
map.put("pac", pac);
2011-10-28 16:51:11 +02:00
StringTokenizer tokenizer = new StringTokenizer(target, ",");
List<String> tokenList = new ArrayList<String>();
while (tokenizer.hasMoreTokens()) {
tokenList.add(tokenizer.nextToken().trim());
}
map.put("target", tokenList);
2010-10-05 21:42:07 +02:00
}
@Override
protected Class<? extends AbstractEntity> getEntityClass() {
return EMailAlias.class;
}
@Override
2013-04-29 20:01:09 +02:00
protected void map2entity(Transaction tx, Map<String, Object> map, AbstractEntity entity) {
2010-10-05 21:42:07 +02:00
EMailAlias alias = (EMailAlias) entity;
2011-10-28 16:08:18 +02:00
String name = (String) map.get("name");
2010-10-05 21:42:07 +02:00
if (assertNotNull(name)) {
alias.setName(name);
}
2011-10-28 16:08:18 +02:00
Object l = map.get("target");
2012-07-18 16:56:08 +02:00
if (l instanceof String) {
String target = (String) l;
if (assertNotNull(target)) {
alias.setTarget(target);
}
}
if (l instanceof Object[]) {
2011-10-28 16:08:18 +02:00
StringBuffer tBuff = new StringBuffer();
Object[] targetObjArray = (Object[]) l;
for (int idx=0; idx<targetObjArray.length; idx++) {
Object targetObj = targetObjArray[idx];
if (targetObj instanceof String) {
2011-10-28 16:08:18 +02:00
if (tBuff.length() > 0) {
tBuff.append(',');
}
tBuff.append((String) targetObj);
2011-10-28 16:08:18 +02:00
}
}
alias.setTarget(tBuff.toString());
2010-10-05 21:42:07 +02:00
}
}
@Override
protected void regularizeKeys(Map<String, String> whereParams) {
replaceKey(whereParams, "pac", "pac.name");
}
}