From 2cd335c7d4326340cabead401ec6b306df779b75 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Mon, 15 Aug 2016 19:14:19 +0200 Subject: [PATCH] possible to update pacOptions now --- .../DefaultListPersistentObjectMapper.java | 13 ++++------ .../java/de/hsadmin/service/pac/PacVO.java | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/framework/src/main/java/de/hsadmin/module/property/mapping/DefaultListPersistentObjectMapper.java b/framework/src/main/java/de/hsadmin/module/property/mapping/DefaultListPersistentObjectMapper.java index 60d1c08..e660c96 100644 --- a/framework/src/main/java/de/hsadmin/module/property/mapping/DefaultListPersistentObjectMapper.java +++ b/framework/src/main/java/de/hsadmin/module/property/mapping/DefaultListPersistentObjectMapper.java @@ -18,18 +18,13 @@ public class DefaultListPersistentObjectMapper implement } @Override - public void writeValueToPersistentObject(Object persistentObject, String propertyName, List value) throws TechnicalException, UserException { - final List valueFromPersistentObject = readValueFromPersistentObject(persistentObject, propertyName); - valueFromPersistentObject.clear(); -// for (final VO elem : value) { -// valueFromPersistentObject.add(elem); -// elem. -// } -// ReflectionUtil.invokeSetter(persistentObject, propertyName, ???; + public void writeValueToPersistentObject(final Object persistentObject, final String propertyName, final List value) + throws TechnicalException, UserException { + throw new TechnicalException("writeValueToPersistentObject not implemented"); } @Override - public List readValueFromPersistentObject(Object persistentObject, String propertyName) throws TechnicalException, UserException { + public List readValueFromPersistentObject(final Object persistentObject, final String propertyName) throws TechnicalException, UserException { final Object object = ReflectionUtil.invokeGetter(persistentObject, propertyName); if (object instanceof Collection) { final List valueList = new ArrayList<>(); diff --git a/services/src/main/java/de/hsadmin/service/pac/PacVO.java b/services/src/main/java/de/hsadmin/service/pac/PacVO.java index ed270b6..f1929e7 100644 --- a/services/src/main/java/de/hsadmin/service/pac/PacVO.java +++ b/services/src/main/java/de/hsadmin/service/pac/PacVO.java @@ -3,10 +3,13 @@ package de.hsadmin.service.pac; import java.util.Date; import java.util.List; +import de.hsadmin.bo.pac.Pac; import de.hsadmin.common.error.TechnicalException; +import de.hsadmin.common.error.UserException; import de.hsadmin.module.ValueObject; import de.hsadmin.module.impl.AbstractVO; import de.hsadmin.module.property.ElementsType; +import de.hsadmin.module.property.Property; import de.hsadmin.module.property.ReadWrite; import de.hsadmin.module.property.ReadWritePolicy; import de.hsadmin.module.property.Required; @@ -146,4 +149,25 @@ public class PacVO extends AbstractVO implements ValueObject { public void setPacComponents(List pacComponents) { this.pacComponents = pacComponents; } + + @Override + public void copyPropertiesToPersistentObject(final Object persistentObject) throws UserException, TechnicalException + { + assert persistentObject != null; + final List> properties = properties(); + for (Property p : properties) { + if ("pacComponents".equals(p.getName())) { + if (persistentObject instanceof Pac) { + final Pac persistentPac = (Pac) persistentObject; + for (final PacComponentVO componentVO : getPacComponents()) { + final String feature = componentVO.getFeature(); + final Integer quantity = componentVO.getQuantity(); + persistentPac.getPacComponent(feature).setQuantity(quantity); + } + } + } else { + p.copyValueToPersistentObject(persistentObject); + } + } + } }