add-unix-user-hosting-asset-validation #66
@ -127,12 +127,14 @@ public class HsHostingAssetController implements HsHostingAssetsApi {
|
|||||||
|
|
||||||
new HsHostingAssetEntityPatcher(em, current).apply(body);
|
new HsHostingAssetEntityPatcher(em, current).apply(body);
|
||||||
|
|
||||||
|
// TODO.refa: draft for an alternative API
|
||||||
// validate(current) // self-validation, hashing passwords etc.
|
// validate(current) // self-validation, hashing passwords etc.
|
||||||
// .then(HsHostingAssetEntityValidatorRegistry::prepareForSave) // hashing passwords etc.
|
// .then(HsHostingAssetEntityValidatorRegistry::prepareForSave) // hashing passwords etc.
|
||||||
// .then(assetRepo::save)
|
// .then(assetRepo::save)
|
||||||
// .then(HsHostingAssetEntityValidatorRegistry::validateInContext)
|
// .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 saved = validated(assetRepo.save(current));
|
||||||
final var mapped = mapper.map(saved, HsHostingAssetResource.class, ENTITY_TO_RESOURCE_POSTMAPPER);
|
final var mapped = mapper.map(saved, HsHostingAssetResource.class, ENTITY_TO_RESOURCE_POSTMAPPER);
|
||||||
|
@ -52,7 +52,7 @@ public class HsHostingAssetEntityValidatorRegistry {
|
|||||||
|
|
||||||
public static void postprocessProperties(final HsHostingAssetEntity entity, final HsHostingAssetResource resource) {
|
public static void postprocessProperties(final HsHostingAssetEntity entity, final HsHostingAssetResource resource) {
|
||||||
final var validator = HsHostingAssetEntityValidatorRegistry.forType(entity.getType());
|
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);
|
resource.setConfig(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ public abstract class HsEntityValidator<E extends PropertiesProvider> {
|
|||||||
throw new IllegalArgumentException("Integer value (or null) expected, but got " + value);
|
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);
|
final var copy = new HashMap<>(config);
|
||||||
stream(propertyValidators).forEach(p -> {
|
stream(propertyValidators).forEach(p -> {
|
||||||
if ( p.writeOnly) {
|
if ( p.writeOnly) {
|
||||||
|
Loading…
Reference in New Issue
Block a user