From 79c7469fef094b0bfb01a12b1ef12aadfd4ed895 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 26 Jun 2024 15:20:17 +0200 Subject: [PATCH] cleanup --- .../hs/hosting/asset/HsHostingAssetController.java | 8 +++++--- .../validators/HsHostingAssetEntityValidatorRegistry.java | 2 +- .../hsadminng/hs/validation/HsEntityValidator.java | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetController.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetController.java index 163aeae1..b0e5cd62 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetController.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetController.java @@ -127,12 +127,14 @@ public class HsHostingAssetController implements HsHostingAssetsApi { new HsHostingAssetEntityPatcher(em, current).apply(body); -// validate(current)/ / self-validation, hashing passwords etc. +// TODO.refa: draft for an alternative API +// validate(current) // self-validation, hashing passwords etc. // .then(HsHostingAssetEntityValidatorRegistry::prepareForSave) // hashing passwords etc. // .then(assetRepo::save) // .then(HsHostingAssetEntityValidatorRegistry::validateInContext) -// .then(this::mapToResource) using postprocessProperties to remove write-only + add read-only properties - +// // In this last step we need the entity and the mapped resource instance, +// // which is exactly what a postmapper takes as arguments. +// .then(this::mapToResource) using postProcessProperties to remove write-only + add read-only properties final var saved = validated(assetRepo.save(current)); final var mapped = mapper.map(saved, HsHostingAssetResource.class, ENTITY_TO_RESOURCE_POSTMAPPER); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsHostingAssetEntityValidatorRegistry.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsHostingAssetEntityValidatorRegistry.java index df00c710..a5331f81 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsHostingAssetEntityValidatorRegistry.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsHostingAssetEntityValidatorRegistry.java @@ -52,7 +52,7 @@ public class HsHostingAssetEntityValidatorRegistry { public static void postprocessProperties(final HsHostingAssetEntity entity, final HsHostingAssetResource resource) { final var validator = HsHostingAssetEntityValidatorRegistry.forType(entity.getType()); - final var config = validator.postprocess(entity, asMap(resource)); + final var config = validator.postProcess(entity, asMap(resource)); resource.setConfig(config); } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/validation/HsEntityValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/validation/HsEntityValidator.java index 9bc4b3cb..fb197cd7 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/validation/HsEntityValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/validation/HsEntityValidator.java @@ -89,7 +89,7 @@ public abstract class HsEntityValidator { throw new IllegalArgumentException("Integer value (or null) expected, but got " + value); } - public Map postprocess(final E entity, final Map config) { + public Map postProcess(final E entity, final Map config) { final var copy = new HashMap<>(config); stream(propertyValidators).forEach(p -> { if ( p.writeOnly) {