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

99 lines
3.1 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;
import de.hsadmin.mods.dom.Domain;
import de.hsadmin.mods.email.EMailAddress;
public class EMailAddressRemote extends AbstractRemote {
@Override
2011-10-28 16:08:18 +02:00
protected void entity2map(AbstractEntity entity, Map<String, Object> map) {
2010-10-05 21:42:07 +02:00
EMailAddress adr = (EMailAddress) entity;
long id = adr.getId();
String domain = adr.getDomain().getName();
String admin = adr.getDomain().getUser().getName();
String pac = adr.getDomain().getUser().getPac().getName();
String target = adr.getTarget();
2011-03-22 23:02:06 +01:00
String localpart = adr.getLocalpart();
2010-10-05 21:42:07 +02:00
String subdomain = adr.getSubdomain();
String emailaddress = adr.getEMailAddress();
String fulldomain = adr.getFullDomain();
map.put("id", Long.toString(id));
2010-12-16 18:24:21 +01:00
if (assertNotNull(domain)) map.put("domain", domain);
if (assertNotNull(admin)) map.put("admin", admin);
if (assertNotNull(pac)) map.put("pac", pac);
2011-10-28 16:51:11 +02:00
if (assertNotNull(target)) {
StringTokenizer tokenizer = new StringTokenizer(target, ",");
List<String> tokenList = new ArrayList<String>();
while (tokenizer.hasMoreTokens()) {
tokenList.add(tokenizer.nextToken().trim());
}
map.put("target", tokenList);
}
2010-12-16 18:24:21 +01:00
if (assertNotNull(localpart)) map.put("localpart", localpart);
if (assertNotNull(subdomain)) map.put("subdomain", subdomain);
if (assertNotNull(emailaddress)) map.put("emailaddress", emailaddress);
if (assertNotNull(fulldomain)) map.put("fulldomain", fulldomain);
2010-10-05 21:42:07 +02:00
}
@Override
2011-10-28 16:08:18 +02:00
protected void map2entity(Map<String, Object> map, AbstractEntity entity) {
2010-10-05 21:42:07 +02:00
EMailAddress adr = (EMailAddress) entity;
2011-10-28 16:08:18 +02:00
String localpart = (String) map.get("localpart");
2011-03-22 23:02:06 +01:00
if (assertNotNull(localpart)) {
adr.setLocalpart(localpart);
2010-10-05 21:42:07 +02:00
}
2011-10-28 16:08:18 +02:00
String subdomain = (String) map.get("subdomain");
2010-10-05 21:42:07 +02:00
if (assertNotNull(subdomain)) {
adr.setSubdomain(subdomain);
}
2011-10-28 16:08:18 +02:00
Object l = map.get("target");
if (l != null && 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++) {
if (targetObjArray[idx] instanceof String) {
2011-10-28 16:08:18 +02:00
if (tBuff.length() > 0) {
tBuff.append(',');
}
tBuff.append((String) targetObjArray[idx]);
2011-10-28 16:08:18 +02:00
}
}
adr.setTarget(tBuff.toString());
2012-10-18 13:08:35 +02:00
} else {
if (l != null && l instanceof String) {
adr.setTarget((String) l);
}
2011-10-28 16:08:18 +02:00
}
String domain = (String) map.get("domain");
2010-10-05 21:42:07 +02:00
if (assertNotNull(domain)) {
Domain dom = new Domain();
dom.setName(domain);
adr.setDomain(dom);
}
}
@Override
protected Class<? extends AbstractEntity> getEntityClass() {
return EMailAddress.class;
}
@Override
protected void regularizeKeys(Map<String, String> whereParams) {
replaceKey(whereParams, "domain", "domain.name");
replaceKey(whereParams, "pac", "domain.user.pac.name");
replaceKey(whereParams, "admin", "domain.user.name");
}
@Override
protected String getOrderBy() {
2010-10-05 21:42:07 +02:00
return "ORDER BY obj.domain.name ASC, obj.subdomain ASC, obj.localpart ASC";
}
}