cleanup
This commit is contained in:
parent
3a894ed72e
commit
1d0121f79d
@ -157,7 +157,6 @@ openapiProcessor {
|
||||
targetDir "$buildDir/generated/sources/openapi-javax"
|
||||
showWarnings true
|
||||
openApiNullable true
|
||||
// generateAliasAsModel true
|
||||
}
|
||||
}
|
||||
sourceSets.main.java.srcDir 'build/generated/sources/openapi'
|
||||
|
@ -3,14 +3,10 @@ package net.hostsharing.hsadminng.hs.booking.item;
|
||||
import net.hostsharing.hsadminng.hs.booking.generated.api.v1.model.HsBookingItemPatchResource;
|
||||
import net.hostsharing.hsadminng.mapper.EntityPatcher;
|
||||
import net.hostsharing.hsadminng.mapper.OptionalFromJson;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static java.util.Arrays.stream;
|
||||
|
||||
public class HsBookingItemEntityPatcher implements EntityPatcher<HsBookingItemPatchResource> {
|
||||
|
||||
private final HsBookingItemEntity entity;
|
||||
@ -24,40 +20,19 @@ public class HsBookingItemEntityPatcher implements EntityPatcher<HsBookingItemPa
|
||||
OptionalFromJson.of(resource.getCaption())
|
||||
.ifPresent(entity::setCaption);
|
||||
Optional.ofNullable(resource.getResources())
|
||||
.ifPresent(r -> entity.getResources().patch(objectToMap(resource.getResources())));
|
||||
.ifPresent(r -> entity.getResources().patch(castToKeyValueMap(resource.getResources())));
|
||||
OptionalFromJson.of(resource.getValidFrom())
|
||||
.ifPresent(entity::setValidFrom);
|
||||
OptionalFromJson.of(resource.getValidTo())
|
||||
.ifPresent(entity::setValidTo);
|
||||
}
|
||||
|
||||
static Map<String, Object> objectToMap(final Object obj) {
|
||||
if (obj instanceof Map<?, ?>) {
|
||||
return toKeyValueMap(obj);
|
||||
}
|
||||
return stream(obj.getClass().getDeclaredFields())
|
||||
.map(field -> {
|
||||
try {
|
||||
field.setAccessible(true);
|
||||
return new ImmutablePair<>(field.getName(), field.get(obj));
|
||||
} catch (final IllegalAccessException exc) {
|
||||
throw new RuntimeException(exc);
|
||||
}
|
||||
})
|
||||
.reduce(
|
||||
new HashMap<>(),
|
||||
(map, pair) -> {
|
||||
map.put(pair.getKey(), pair.getValue());
|
||||
return map;
|
||||
},
|
||||
(map1, map2) -> {
|
||||
map1.putAll(map2);
|
||||
return map1;
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Map<String, Object> toKeyValueMap(final Object obj) {
|
||||
static Map<String, Object> castToKeyValueMap(final Object obj) {
|
||||
if (obj instanceof Map<?, ?>) {
|
||||
return (Map<String, Object>) obj;
|
||||
}
|
||||
throw new ClassCastException("Map expected, but got: " + obj);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntityPatcher.objectToMap;
|
||||
import static net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntityPatcher.castToKeyValueMap;
|
||||
import static net.hostsharing.hsadminng.hs.office.debitor.TestHsOfficeDebitor.TEST_DEBITOR;
|
||||
import static net.hostsharing.hsadminng.mapper.PatchMap.entry;
|
||||
import static net.hostsharing.hsadminng.mapper.PatchMap.patchMap;
|
||||
@ -72,7 +72,7 @@ class HsBookingItemEntityPatcherUnitTest extends PatchUnitTestBase<
|
||||
final var entity = new HsBookingItemEntity();
|
||||
entity.setUuid(INITIAL_BOOKING_ITEM_UUID);
|
||||
entity.setDebitor(TEST_DEBITOR);
|
||||
entity.getResources().putAll(objectToMap(INITIAL_RESOURCES));
|
||||
entity.getResources().putAll(castToKeyValueMap(INITIAL_RESOURCES));
|
||||
entity.setCaption(INITIAL_CAPTION);
|
||||
entity.setValidity(Range.closedInfinite(GIVEN_VALID_FROM));
|
||||
return entity;
|
||||
|
Loading…
Reference in New Issue
Block a user