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

98 lines
3.1 KiB
Java
Raw Normal View History

2011-03-22 23:02:06 +01:00
package de.hsadmin.remote;
2011-08-30 15:41:19 +02:00
import java.util.Comparator;
2011-03-22 23:02:06 +01:00
import java.util.Date;
import java.util.Map;
2011-08-30 15:41:19 +02:00
import java.util.SortedSet;
import java.util.TreeSet;
2011-03-22 23:02:06 +01:00
import de.hsadmin.core.model.AbstractEntity;
2012-07-27 18:02:24 +02:00
import de.hsadmin.core.util.TextUtil;
2011-03-22 23:02:06 +01:00
import de.hsadmin.mods.cust.Customer;
import de.hsadmin.mods.pac.BasePac;
import de.hsadmin.mods.pac.Hive;
import de.hsadmin.mods.pac.INetAddress;
import de.hsadmin.mods.pac.Pac;
2011-03-31 21:24:02 +02:00
import de.hsadmin.mods.pac.PacComponent;
2011-03-22 23:02:06 +01:00
public class PacRemote extends AbstractRemote {
@Override
2011-10-28 16:08:18 +02:00
protected void entity2map(AbstractEntity entity, Map<String, Object> resultMap) {
2011-03-22 23:02:06 +01:00
Pac pac = (Pac) entity;
resultMap.put("name", pac.getName());
resultMap.put("id", Long.toString(pac.getId()));
resultMap.put("hive", pac.getHiveName());
resultMap.put("customer", pac.getCustomer().getName());
resultMap.put("curinetaddr", pac.getCurINetAddr().getInetAddr());
2012-07-27 18:02:24 +02:00
resultMap.put("created", TextUtil.format(pac.getCreated()));
2011-03-31 21:24:02 +02:00
resultMap.put("basepac", pac.getBasepac().getName());
2011-08-30 15:41:19 +02:00
SortedSet<PacComponent> sortedComponents = new TreeSet<PacComponent>(new Comparator<PacComponent>() {
@Override
public int compare(PacComponent o1, PacComponent o2) {
return o2.getBaseComponent().getSorting() - o1.getBaseComponent().getSorting();
}
});
sortedComponents.addAll(pac.getPacComponents());
2011-03-31 21:24:02 +02:00
StringBuffer bf = new StringBuffer();
boolean empty = true;
2011-08-30 15:41:19 +02:00
for (PacComponent comp : sortedComponents) {
2011-03-31 21:24:02 +02:00
if (comp.getQuantity() > 0) {
if (!empty) {
bf.append("; ");
}
bf.append(comp.getBaseComponent().getFeature());
bf.append("=");
bf.append(comp.getQuantity());
empty = false;
}
}
resultMap.put("components", bf.toString());
2011-03-22 23:02:06 +01:00
}
@Override
protected Class<? extends AbstractEntity> getEntityClass() {
return Pac.class;
}
@Override
2011-10-28 16:08:18 +02:00
protected void map2entity(Map<String, Object> setParams, AbstractEntity entity) {
2011-03-22 23:02:06 +01:00
Pac pac = (Pac) entity;
BasePac basePac = pac.getBasepac();
2011-10-28 16:08:18 +02:00
String basePacName = (String) setParams.get("basepac");
2011-05-19 18:51:59 +02:00
if ((basePac == null || basePac.getName() == null) && assertNotNull(basePacName)) {
2011-03-22 23:02:06 +01:00
basePac = new BasePac();
basePac.setName(basePacName);
pac.setBasepac(basePac);
}
pac.setCreated(new Date());
INetAddress curINetAddr = pac.getCurINetAddr();
2011-10-28 16:08:18 +02:00
String inetAddrString = (String) setParams.get("curinetaddr");
2011-05-19 20:16:11 +02:00
if ((curINetAddr == null || curINetAddr.getInetAddr() == null) && assertNotNull(inetAddrString)) {
2011-03-22 23:02:06 +01:00
curINetAddr = new INetAddress(inetAddrString);
pac.setCurINetAddr(curINetAddr);
}
Customer customer = pac.getCustomer();
2011-10-28 16:08:18 +02:00
String memberCode = (String) setParams.get("customer");
2011-03-22 23:02:06 +01:00
if (customer == null && assertNotNull(memberCode)) {
customer = new Customer();
customer.setName(memberCode);
pac.setCustomer(customer);
}
Hive hive = pac.getHive();
2011-10-28 16:08:18 +02:00
String hiveName = (String) setParams.get("hive");
2011-05-19 19:37:29 +02:00
if ((hive == null || hive.getName() == null) && assertNotNull(hiveName)) {
2011-03-22 23:02:06 +01:00
hive = new Hive();
hive.setName(hiveName);
pac.setHive(hive);
}
2011-10-28 16:08:18 +02:00
pac.setName((String) setParams.get("name"));
2011-03-22 23:02:06 +01:00
}
@Override
protected void regularizeKeys(Map<String, String> whereParams) {
replaceKey(whereParams, "customer", "customer.name");
}
}