refactoring for implicit creation of dependend hosting-assets #108

Merged
hsh-michaelhoennig merged 22 commits from refactoring-for-implicit-creation-of-dependend-hosting-assets into master 2024-09-26 10:51:30 +02:00
2 changed files with 15 additions and 4 deletions
Showing only changes of commit 087d59b238 - Show all commits

View File

@ -23,6 +23,7 @@ import java.util.UUID;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import static net.hostsharing.hsadminng.mapper.PostgresDateRange.toPostgresDateRange; import static net.hostsharing.hsadminng.mapper.PostgresDateRange.toPostgresDateRange;
import static org.modelmapper.convention.MatchingStrategies.STRICT;
@RestController @RestController
public class HsBookingItemController implements HsBookingItemsApi { public class HsBookingItemController implements HsBookingItemsApi {
@ -62,7 +63,8 @@ public class HsBookingItemController implements HsBookingItemsApi {
context.define(currentSubject, assumedRoles); context.define(currentSubject, assumedRoles);
final var entityToSave = mapper.map(body, HsBookingItemRbacEntity.class, RESOURCE_TO_ENTITY_POSTMAPPER); final var entityToSave = mapper.withMatchingStrategy(STRICT)
.map(body, HsBookingItemRbacEntity.class, RESOURCE_TO_ENTITY_POSTMAPPER);
final var mapped = new BookingItemEntitySaveProcessor(em, entityToSave) final var mapped = new BookingItemEntitySaveProcessor(em, entityToSave)
.preprocessEntity() .preprocessEntity()
.validateEntity() .validateEntity()

View File

@ -1,6 +1,7 @@
package net.hostsharing.hsadminng.mapper; package net.hostsharing.hsadminng.mapper;
import org.modelmapper.ModelMapper; import org.modelmapper.ModelMapper;
import org.modelmapper.spi.MatchingStrategy;
import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils;
import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManager;
@ -15,7 +16,6 @@ import java.util.stream.Stream;
import static java.util.Arrays.stream; import static java.util.Arrays.stream;
import static net.hostsharing.hsadminng.errors.DisplayAs.DisplayName; import static net.hostsharing.hsadminng.errors.DisplayAs.DisplayName;
import static org.modelmapper.convention.MatchingStrategies.STRICT;
/** /**
* A nicer API for ModelMapper. * A nicer API for ModelMapper.
@ -26,8 +26,17 @@ public class Mapper extends ModelMapper {
EntityManager em; EntityManager em;
public Mapper() { public Mapper() {
// make sure that resource.whateverUuid does not get mapped to entity.uuid, if resource.uuid does not exist getConfiguration().setAmbiguityIgnored(true);
getConfiguration().setMatchingStrategy(STRICT); }
/** Use STRICT to make sure that resource.whateverUuid does not accidentally get mapped to entity.uuid,
* if resource.uuid does not exist
*
* @return this
*/
public Mapper withMatchingStrategy(final MatchingStrategy matchingStrategy) {
getConfiguration().setMatchingStrategy(matchingStrategy);
return this;
} }
public <S, T> List<T> mapList(final List<S> source, final Class<T> targetClass) { public <S, T> List<T> mapList(final List<S> source, final Class<T> targetClass) {