hs.hsadmin/hsarback/src/de/hsadmin/remote/UnixUserRemote.java
2013-04-29 20:01:09 +02:00

83 lines
2.3 KiB
Java

package de.hsadmin.remote;
import java.util.Map;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.Transaction;
import de.hsadmin.mods.user.UnixUser;
public class UnixUserRemote extends AbstractRemote {
@Override
protected Class<? extends AbstractEntity> getEntityClass() {
return UnixUser.class;
}
@Override
protected void entity2map(Transaction tx, AbstractEntity entity, Map<String, Object> map) {
UnixUser user = (UnixUser) entity;
map.put("id", Long.toString(user.getId()));
map.put("name", user.getName());
map.put("comment", user.getComment());
map.put("userid", Long.toString(user.getUserId()));
map.put("pac", user.getPac().getName());
map.put("shell", user.getShell());
map.put("homedir", user.getHomedir());
Integer quotaSoft = user.getQuotaSoftlimit();
if (assertNotNull(quotaSoft)) {
map.put("quota_softlimit", quotaSoft.toString());
}
Integer quotaHard = user.getQuotaHardlimit();
if (assertNotNull(quotaHard)) {
map.put("quota_hardlimit", quotaHard.toString());
}
}
@Override
protected void map2entity(Transaction tx, Map<String, Object> map, AbstractEntity entity) {
UnixUser user = (UnixUser) entity;
String id = (String) map.get("id");
if (assertNotNull(id)) {
user.setId(Long.parseLong(id));
}
String name = (String) map.get("name");
if (assertNotNull(name)) {
user.setName(name);
}
String password = (String) map.get("password");
if (assertNotNull(password)) {
user.setPassword(password);
}
String comment = (String) map.get("comment");
if (assertNotNull(comment)) {
user.setComment(comment);
}
String userid = (String) map.get("userid");
if (assertNotNull(userid)) {
user.setUserId(Long.parseLong(userid));
}
String shell = (String) map.get("shell");
if (assertNotNull(shell)) {
user.setShell(shell);
}
String homedir = (String) map.get("homedir");
if (assertNotNull(homedir)) {
user.setHomedir(homedir);
}
String quota = (String) map.get("quota_softlimit");
if (assertNotNull(quota)) {
user.setQuotaSoftlimit(Integer.parseInt(quota));
}
String quotaLimit = (String) map.get("quota_hardlimit");
if (assertNotNull(quotaLimit)) {
user.setQuotaHardlimit(Integer.parseInt(quotaLimit));
}
}
@Override
protected void regularizeKeys(Map<String, String> whereParams) {
replaceKey(whereParams, "pac", "pac.name");
}
}