add-unix-user-hosting-asset-validation #66

Merged
hsh-michaelhoennig merged 11 commits from add-unix-user-hosting-asset-validation into master 2024-06-27 12:39:45 +02:00
3 changed files with 7 additions and 5 deletions
Showing only changes of commit 79c7469fef - Show all commits

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) {
hsh-michaelhoennig marked this conversation as resolved Outdated

isWriteOnly()

isWriteOnly()