null values, hive ip is pac default now

This commit is contained in:
Peter Hormanns 2016-08-17 18:31:17 +02:00
parent a744393240
commit a6ee788d67
6 changed files with 41 additions and 31 deletions

View File

@ -2,6 +2,9 @@ importClass(java.util.ArrayList);
importClass(java.util.HashMap); importClass(java.util.HashMap);
function hsaParseParam(val) { function hsaParseParam(val) {
if (val === null) {
return val;
}
if (val instanceof java.util.List) { if (val instanceof java.util.List) {
return val; return val;
} }
@ -36,12 +39,14 @@ function hsaParseParamObject(o) {
var hsh = new HashMap(); var hsh = new HashMap();
for (var key in o) { for (var key in o) {
var val = o[key]; var val = o[key];
if (!val === null) {
if (typeof val === 'object' && val.constructor === Array) { if (typeof val === 'object' && val.constructor === Array) {
val = hsaParseParamArray(val); val = hsaParseParamArray(val);
} }
else if (typeof val === 'object') { else if (typeof val === 'object') {
val = hsaParseParamObject(val); val = hsaParseParamObject(val);
}; };
}
hsh.put(key, val); hsh.put(key, val);
}; };
return hsh; return hsh;

View File

@ -22,6 +22,7 @@ public abstract class AbstractProperty<T> implements Property<T> {
private PersistentObjectMapper<T> persistentObjectMapper; private PersistentObjectMapper<T> persistentObjectMapper;
private ParameterMapMapper<T> parameterMapMapper; private ParameterMapMapper<T> parameterMapMapper;
private boolean undefinedValue;
public AbstractProperty( public AbstractProperty(
final ValueObject owner, final ValueObject owner,
@ -34,6 +35,7 @@ public abstract class AbstractProperty<T> implements Property<T> {
this.policy = readWritePolicy; this.policy = readWritePolicy;
this.search = searchPolicy; this.search = searchPolicy;
this.required = required; this.required = required;
this.undefinedValue = true;
} }
protected PersistentObjectMapper<T> getPersistentObjectMapper() { protected PersistentObjectMapper<T> getPersistentObjectMapper() {
@ -50,7 +52,7 @@ public abstract class AbstractProperty<T> implements Property<T> {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected void setParameterMapMapper(ParameterMapMapper<?> mapper) { protected void setParameterMapMapper(final ParameterMapMapper<?> mapper) {
parameterMapMapper = (ParameterMapMapper<T>) mapper; parameterMapMapper = (ParameterMapMapper<T>) mapper;
} }
@ -74,6 +76,11 @@ public abstract class AbstractProperty<T> implements Property<T> {
return required; return required;
} }
@Override
public boolean isUndefined() {
return undefinedValue;
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Class<? extends Property<T>> getPropertyType() { public Class<? extends Property<T>> getPropertyType() {
return (Class<? extends Property<T>>) getClass(); return (Class<? extends Property<T>>) getClass();
@ -82,11 +89,15 @@ public abstract class AbstractProperty<T> implements Property<T> {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public T getValue() throws TechnicalException { public T getValue() throws TechnicalException {
if (undefinedValue) {
throw new TechnicalException("undefined value");
}
return (T) ReflectionUtil.invokeGetter(owningVO, getName()); return (T) ReflectionUtil.invokeGetter(owningVO, getName());
} }
@Override @Override
public void setValue(T value) throws TechnicalException { public void setValue(T value) throws TechnicalException {
undefinedValue = false;
ReflectionUtil.invokeSetter(owningVO, getName(), value); ReflectionUtil.invokeSetter(owningVO, getName(), value);
} }
@ -115,9 +126,8 @@ public abstract class AbstractProperty<T> implements Property<T> {
@Override @Override
public void copyValueToPersistentObject(Object persistentObject) throws TechnicalException, UserException { public void copyValueToPersistentObject(Object persistentObject) throws TechnicalException, UserException {
T newValue = getValue(); if (!undefinedValue) {
if (newValue != null) { getPersistentObjectMapper().writeValueToPersistentObject(persistentObject, getName(), getValue());
getPersistentObjectMapper().writeValueToPersistentObject(persistentObject, getName(), newValue);
} }
} }

View File

@ -25,6 +25,8 @@ public interface Property<T> {
public boolean valueIsNullOrEmpty(); public boolean valueIsNullOrEmpty();
public boolean isUndefined();
public void copyValueFromPersistentObject(final Object persistentObject) throws TechnicalException, UserException; public void copyValueFromPersistentObject(final Object persistentObject) throws TechnicalException, UserException;
public void copyValueToPersistentObject(final Object persistentObject) throws TechnicalException, UserException; public void copyValueToPersistentObject(final Object persistentObject) throws TechnicalException, UserException;

View File

@ -1,7 +1,6 @@
package de.hsadmin.module.property; package de.hsadmin.module.property;
import de.hsadmin.common.error.TechnicalException; import de.hsadmin.common.error.TechnicalException;
import de.hsadmin.common.error.UserException;
import de.hsadmin.common.util.ReflectionUtil; import de.hsadmin.common.util.ReflectionUtil;
import de.hsadmin.module.ValueObject; import de.hsadmin.module.ValueObject;
import de.hsadmin.module.impl.AbstractProperty; import de.hsadmin.module.impl.AbstractProperty;
@ -67,18 +66,4 @@ public class StringSetProperty extends AbstractProperty<StringSet> {
} }
} }
@Override
public void copyValueFromPersistentObject(Object persistentObject)
throws TechnicalException, UserException {
// TODO Auto-generated method stub
super.copyValueFromPersistentObject(persistentObject);
}
@Override
public void copyValueToPersistentObject(Object persistentObject)
throws TechnicalException, UserException {
// TODO Auto-generated method stub
super.copyValueToPersistentObject(persistentObject);
}
} }

View File

@ -44,12 +44,16 @@ public class PacService extends AbstractModule<PacVO> implements PacServiceLocal
throws UserException, TechnicalException { throws UserException, TechnicalException {
final PacVO vo = super.create(requestContext, prototype); final PacVO vo = super.create(requestContext, prototype);
final Pac bo = new Pac(); final Pac bo = new Pac();
final String inetAddressProperty = prototype.getInetAddress();
assert inetAddressProperty != null;
bo.setCurINetAddr(findInetAddress(inetAddressProperty));
final String hiveProperty = prototype.getHive(); final String hiveProperty = prototype.getHive();
assert hiveProperty != null; assert hiveProperty != null;
bo.setHive(findHiveByName(hiveProperty)); final Hive hive = findHiveByName(hiveProperty);
bo.setHive(hive);
final String inetAddressProperty = prototype.getInetAddress();
if (inetAddressProperty != null) {
bo.setCurINetAddr(findInetAddress(inetAddressProperty));
} else {
bo.setCurINetAddr(hive.getInetAddr());
}
final String basePacProperty = prototype.getBasePac(); final String basePacProperty = prototype.getBasePac();
assert basePacProperty != null; assert basePacProperty != null;
bo.setBasePac(findBasePacByName(basePacProperty)); bo.setBasePac(findBasePacByName(basePacProperty));

View File

@ -164,8 +164,12 @@ public class PacVO extends AbstractVO implements ValueObject {
{ {
assert persistentObject != null; assert persistentObject != null;
final List<Property<?>> properties = properties(); final List<Property<?>> properties = properties();
for (Property<?> p : properties) { for (Property<?> prop : properties) {
if ("pacComponents".equals(p.getName())) { final String propName = prop.getName();
if ("customer".equals(propName) || "basePac".equals(propName) || "hive".equals(propName) || "inetAddress".equals(propName)) {
continue;
}
if ("pacComponents".equals(propName)) {
if (persistentObject instanceof Pac) { if (persistentObject instanceof Pac) {
final Pac persistentPac = (Pac) persistentObject; final Pac persistentPac = (Pac) persistentObject;
final List<PacComponentVO> pacComps = getPacComponents(); final List<PacComponentVO> pacComps = getPacComponents();
@ -178,7 +182,7 @@ public class PacVO extends AbstractVO implements ValueObject {
} }
} }
} else { } else {
p.copyValueToPersistentObject(persistentObject); prop.copyValueToPersistentObject(persistentObject);
} }
} }
} }