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

118 lines
3.9 KiB
Java
Raw Normal View History

2011-03-22 23:02:06 +01:00
package de.hsadmin.remote;
import java.util.Date;
2012-09-21 14:16:22 +02:00
import java.util.HashMap;
2011-03-22 23:02:06 +01:00
import java.util.Map;
2012-09-21 14:16:22 +02:00
import java.util.Set;
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());
2012-09-21 14:16:22 +02:00
Map<String, Object> components = new HashMap<String, Object>();
Set<PacComponent> pacComponents = pac.getPacComponents();
for (PacComponent comp : pacComponents) {
int quantity = comp.getQuantity();
if (quantity > 0) {
components.put(comp.getBaseComponent().getFeature(), Integer.toString(quantity));
2011-03-31 21:24:02 +02:00
}
}
2012-09-21 14:16:22 +02:00
resultMap.put("components", components);
// 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());
// StringBuffer bf = new StringBuffer();
// boolean empty = true;
// for (PacComponent comp : sortedComponents) {
// 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);
}
2012-09-21 14:16:22 +02:00
Object componentsObj = setParams.get("components");
if (componentsObj != null && componentsObj instanceof Map) {
Map<?, ?> componentsMap = (Map<?, ?>) componentsObj;
for (Object key : componentsMap.keySet()) {
pac.getPacComponent(key.toString()).setQuantity(Integer.parseInt(componentsMap.get(key).toString()));
}
}
Object nameParamObj = setParams.get("name");
if (nameParamObj != null && nameParamObj instanceof String) {
pac.setName((String) nameParamObj);
}
2011-03-22 23:02:06 +01:00
}
@Override
protected void regularizeKeys(Map<String, String> whereParams) {
replaceKey(whereParams, "customer", "customer.name");
}
}