package de.hsadmin.remote; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeSet; import de.hsadmin.core.model.AbstractEntity; import de.hsadmin.mods.dom.Domain; import de.hsadmin.mods.dom.DomainOption; import de.hsadmin.mods.user.UnixUser; public class DomainRemote extends AbstractRemote { private static final DateFormat df = SimpleDateFormat.getDateInstance(DateFormat.SHORT); @Override protected Class getEntityClass() { return Domain.class; } @Override protected void entity2map(AbstractEntity entity, Map resultMap) { 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(); if (assertNotNull(sDate)) { String since = df.format(sDate); resultMap.put("since", since); } List domainOptionsList = new ArrayList(); resultMap.put("domainoptions", domainOptionsList); for (DomainOption opt : dom.getDomainOptions()) { domainOptionsList.add(opt.getName()); } } @Override protected void map2entity(Map setParams, AbstractEntity entity) { Domain dom = (Domain) entity; String name = (String) setParams.get("name"); String user = (String) setParams.get("user"); if (assertNotNull(name)) { dom.setName(name); } if (assertNotNull(user)) { UnixUser u = new UnixUser(); u.setName(user); dom.setUser(u); } Set domainOptionsSet = new TreeSet(); Object domOptsObj = setParams.get("domainoptions"); if (domOptsObj != null && domOptsObj instanceof List) { List domOptions = (List) domOptsObj; for (String optString : domOptions) { domOptions.add(optString); } } dom.setDomainOptions(domainOptionsSet); } @Override protected void regularizeKeys(Map whereParams) { replaceKey(whereParams, "user", "user.name"); replaceKey(whereParams, "pac", "user.pac.name"); replaceKey(whereParams, "hive", "hiveName"); } }