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

83 lines
2.4 KiB
Java
Raw Normal View History

2010-10-05 21:42:07 +02:00
package de.hsadmin.remote;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
2012-07-18 14:26:08 +02:00
import java.util.ArrayList;
2010-10-05 21:42:07 +02:00
import java.util.Date;
2012-07-18 14:26:08 +02:00
import java.util.List;
2010-10-05 21:42:07 +02:00
import java.util.Map;
2012-07-18 14:26:08 +02:00
import java.util.Set;
import java.util.TreeSet;
2010-10-05 21:42:07 +02:00
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.mods.dom.Domain;
2012-07-18 14:26:08 +02:00
import de.hsadmin.mods.dom.DomainOption;
2010-10-05 21:42:07 +02:00
import de.hsadmin.mods.user.UnixUser;
public class DomainRemote extends AbstractRemote {
private static final DateFormat df = SimpleDateFormat.getDateInstance(DateFormat.SHORT);
@Override
protected Class<? extends AbstractEntity> getEntityClass() {
return Domain.class;
}
@Override
2011-10-28 16:08:18 +02:00
protected void entity2map(AbstractEntity entity, Map<String, Object> resultMap) {
2010-10-05 21:42:07 +02:00
Domain dom = (Domain) entity;
String id = Long.toString(dom.getId());
resultMap.put("id", id);
String name = dom.getName();
resultMap.put("name", name);
String user = dom.getUser().getName();
resultMap.put("user", user);
String hive = dom.getHiveName();
resultMap.put("hive", hive);
String pac = dom.getUser().getPac().getName();
resultMap.put("pac", pac);
Date sDate = dom.getFiled();
2010-10-05 21:42:07 +02:00
if (assertNotNull(sDate)) {
String since = df.format(sDate);
resultMap.put("since", since);
}
2012-07-18 14:26:08 +02:00
List<String> domainOptionsList = new ArrayList<String>();
resultMap.put("domainoptions", domainOptionsList);
for (DomainOption opt : dom.getDomainOptions()) {
domainOptionsList.add(opt.getName());
}
2010-10-05 21:42:07 +02:00
}
@Override
2011-10-28 16:08:18 +02:00
protected void map2entity(Map<String, Object> setParams, AbstractEntity entity) {
2010-10-05 21:42:07 +02:00
Domain dom = (Domain) entity;
2011-10-28 16:08:18 +02:00
String name = (String) setParams.get("name");
String user = (String) setParams.get("user");
2010-10-05 21:42:07 +02:00
if (assertNotNull(name)) {
dom.setName(name);
}
if (assertNotNull(user)) {
UnixUser u = new UnixUser();
u.setName(user);
dom.setUser(u);
}
2012-07-18 14:26:08 +02:00
Set<DomainOption> domainOptionsSet = new TreeSet<DomainOption>();
Object domOptsObj = setParams.get("domainoptions");
if (domOptsObj != null && domOptsObj instanceof List<?>) {
List<String> domOptions = (List<String>) domOptsObj;
for (String optString : domOptions) {
domOptions.add(optString);
}
}
dom.setDomainOptions(domainOptionsSet);
2010-10-05 21:42:07 +02:00
}
@Override
protected void regularizeKeys(Map<String, String> whereParams) {
replaceKey(whereParams, "user", "user.name");
replaceKey(whereParams, "pac", "user.pac.name");
replaceKey(whereParams, "hive", "hiveName");
}
}