This commit is contained in:
Michael Hoennig 2024-06-26 15:20:17 +02:00
parent c2cd6c2f23
commit 79c7469fef
3 changed files with 7 additions and 5 deletions

View File

@ -127,12 +127,14 @@ public class HsHostingAssetController implements HsHostingAssetsApi {
new HsHostingAssetEntityPatcher(em, current).apply(body);
// 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);

View File

@ -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);
}

View File

@ -89,7 +89,7 @@ public abstract class HsEntityValidator<E extends PropertiesProvider> {
throw new IllegalArgumentException("Integer value (or null) expected, but got " + value);
}
public Map<String, Object> postprocess(final E entity, final Map<String, Object> config) {
public Map<String, Object> postProcess(final E entity, final Map<String, Object> config) {
final var copy = new HashMap<>(config);
stream(propertyValidators).forEach(p -> {
if ( p.writeOnly) {