Target attributes update: Allow null values

Signed-off-by: Stefan Behl <stefan.behl@bosch-si.com>
This commit is contained in:
Stefan Behl
2018-08-01 09:10:03 +02:00
parent 7ae941e290
commit cd79b918b4

View File

@@ -672,12 +672,12 @@ public class JpaControllerManagement implements ControllerManagement {
case REPLACE:
// clear the attributes before adding the new attributes
controllerAttributes.clear();
controllerAttributes.putAll(data);
copyNonNull(data, controllerAttributes);
target.setRequestControllerAttributes(false);
break;
case MERGE:
// just merge the attributes in
controllerAttributes.putAll(data);
copyNonNull(data, controllerAttributes);
target.setRequestControllerAttributes(false);
break;
default:
@@ -689,6 +689,13 @@ public class JpaControllerManagement implements ControllerManagement {
return targetRepository.save(target);
}
private static void copyNonNull(final Map<String, String> src, final Map<String, String> trg) {
if (src == null || src.isEmpty()) {
return;
}
src.entrySet().stream().filter(e -> e.getValue() != null).forEach(e -> trg.put(e.getKey(), e.getValue()));
}
private void assertTargetAttributesQuota(final JpaTarget target) {
final int limit = quotaManagement.getMaxAttributeEntriesPerTarget();
QuotaHelper.assertAssignmentQuota(target.getId(), target.getControllerAttributes().size(), limit, "Attribute",