diff --git a/goofy-client/libs/tech-shared/src/lib/date.util.spec.ts b/goofy-client/libs/tech-shared/src/lib/date.util.spec.ts index 1a49e7774a47c2342012ba8f90e6de5efbabd8cc..335679bd7a39a840dbf2a9bd28487ed80844b4ed 100644 --- a/goofy-client/libs/tech-shared/src/lib/date.util.spec.ts +++ b/goofy-client/libs/tech-shared/src/lib/date.util.spec.ts @@ -1,5 +1,7 @@ import { registerLocaleData } from '@angular/common'; import localeDe from '@angular/common/locales/de'; +import { format } from 'date-fns'; +import { de } from 'date-fns/locale'; import { formatForDatabase, formatFullDate, formatFullDateWithTimeAndDay, formatFullDateWithTimeWithoutSeconds, formatToPrettyDate, formatWithoutYear } from './date.util'; registerLocaleData(localeDe); @@ -43,8 +45,8 @@ describe('Date Util', () => { describe('formatToPrettyDate()', () => { it('should format date without year', () => { const today: Date = new Date(); - const day: number = today.getDate(); - const month: string = today.toLocaleString('de', { month: 'short' }); + const day: string = format(today, 'dd'); + const month: string = format(today, 'MMMM', {locale: de}); const result: string = formatToPrettyDate(today); diff --git a/goofy-server/src/main/java/de/itvsh/goofy/common/binaryfile/BinaryFileMaxSizeConstraint.java b/goofy-server/src/main/java/de/itvsh/goofy/common/binaryfile/BinaryFileMaxSizeConstraint.java index 422f1d3598c8acf9a6d831ecb5278334d9483fc8..58995022a3d3db74f05252a7cc4f703dfa030e4b 100644 --- a/goofy-server/src/main/java/de/itvsh/goofy/common/binaryfile/BinaryFileMaxSizeConstraint.java +++ b/goofy-server/src/main/java/de/itvsh/goofy/common/binaryfile/BinaryFileMaxSizeConstraint.java @@ -25,5 +25,5 @@ public @interface BinaryFileMaxSizeConstraint { int max() default UploadBinaryFileSizeValidator.DEFAULT_MAX_SIZE; - String unit() default UploadBinaryFileSizeValidator.DEFAULT_UNIT; + String unit() default UploadBinaryFileSizeValidator.DEFAULT_UNIT_STRING; } \ No newline at end of file diff --git a/goofy-server/src/main/java/de/itvsh/goofy/common/binaryfile/BinaryFileUnit.java b/goofy-server/src/main/java/de/itvsh/goofy/common/binaryfile/BinaryFileUnit.java deleted file mode 100644 index f485e7eec2471b82ae6c6354d27216f5ca400345..0000000000000000000000000000000000000000 --- a/goofy-server/src/main/java/de/itvsh/goofy/common/binaryfile/BinaryFileUnit.java +++ /dev/null @@ -1,6 +0,0 @@ -package de.itvsh.goofy.common.binaryfile; - -class BinaryFileUnit {// NOSONAR - - static final String MB = "MB"; -} \ No newline at end of file diff --git a/goofy-server/src/main/java/de/itvsh/goofy/common/binaryfile/UploadBinaryFileSizeValidator.java b/goofy-server/src/main/java/de/itvsh/goofy/common/binaryfile/UploadBinaryFileSizeValidator.java index 017fedfbfdcf3eaad9ffd0f585e7fb903592f857..71bbb5d8ec3d8972fac2e05cec56d21ba987b620 100644 --- a/goofy-server/src/main/java/de/itvsh/goofy/common/binaryfile/UploadBinaryFileSizeValidator.java +++ b/goofy-server/src/main/java/de/itvsh/goofy/common/binaryfile/UploadBinaryFileSizeValidator.java @@ -13,10 +13,12 @@ import org.springframework.util.unit.DataUnit; class UploadBinaryFileSizeValidator implements ConstraintValidator<BinaryFileMaxSizeConstraint, UploadBinaryFileRequest> { - static final String DEFAULT_UNIT = BinaryFileUnit.MB; + static final String DEFAULT_UNIT_STRING = "MB"; + static final DataUnit DEFAULT_UNIT = DataUnit.fromSuffix(DEFAULT_UNIT_STRING); + static final int DEFAULT_MAX_SIZE = 40; - private final DataSize defaultDataSize = DataSize.of(DEFAULT_MAX_SIZE, DataUnit.fromSuffix(DEFAULT_UNIT)); + private final DataSize defaultDataSize = DataSize.of(DEFAULT_MAX_SIZE, DEFAULT_UNIT); @Autowired private BinaryFileProperties binaryFileProperties; diff --git a/goofy-server/src/main/java/de/itvsh/goofy/vorgang/Eingang.java b/goofy-server/src/main/java/de/itvsh/goofy/vorgang/Eingang.java index 69fd514e917e48ed7930c8358c600175e5b8904d..480a0fb12c48426c219dcd53b36f5b8413bbf9b6 100644 --- a/goofy-server/src/main/java/de/itvsh/goofy/vorgang/Eingang.java +++ b/goofy-server/src/main/java/de/itvsh/goofy/vorgang/Eingang.java @@ -4,9 +4,11 @@ import java.util.Map; import lombok.Builder; import lombok.Getter; +import lombok.ToString; @Getter @Builder +@ToString public class Eingang { private String id; @@ -18,6 +20,6 @@ public class Eingang { private Antragsteller antragsteller; private EingangHeader header; - + @ToString.Exclude private Map<String, Object> formData; } diff --git a/goofy-server/src/main/java/de/itvsh/goofy/vorgang/VorgangHeader.java b/goofy-server/src/main/java/de/itvsh/goofy/vorgang/VorgangHeader.java index 3d7bb25cedebb72e3c97b438326f6a7355b2e2ef..da48d2c4e99e8fa0687ea626c43573904018acbc 100644 --- a/goofy-server/src/main/java/de/itvsh/goofy/vorgang/VorgangHeader.java +++ b/goofy-server/src/main/java/de/itvsh/goofy/vorgang/VorgangHeader.java @@ -42,6 +42,5 @@ class VorgangHeader implements Vorgang { @JsonProperty(access = Access.READ_ONLY) private LocalDate nextFrist; - @Builder.Default - private boolean hasPostfachNachricht = true; + private boolean hasPostfachNachricht; } diff --git a/goofy-server/src/main/java/de/itvsh/goofy/vorgang/VorgangHeaderMapper.java b/goofy-server/src/main/java/de/itvsh/goofy/vorgang/VorgangHeaderMapper.java index 65c2d8620eb64b50c3edb7fa7602b0b374e78a81..3b2e7405e2be384a32d988db34f0f9bd8a971628 100644 --- a/goofy-server/src/main/java/de/itvsh/goofy/vorgang/VorgangHeaderMapper.java +++ b/goofy-server/src/main/java/de/itvsh/goofy/vorgang/VorgangHeaderMapper.java @@ -2,6 +2,7 @@ package de.itvsh.goofy.vorgang; import java.time.LocalDate; import java.util.List; +import java.util.stream.Stream; import org.apache.commons.lang3.StringUtils; import org.mapstruct.CollectionMappingStrategy; @@ -18,19 +19,27 @@ import de.itvsh.ozg.pluto.vorgang.GrpcVorgangHeader; interface VorgangHeaderMapper { static final String WIEDERVORLAGE_NEXT_FRIST_ATTRIBUTE_NAME = "nextWiedervorlageFrist"; + static final String HAS_POSTFACH_NACHRICHT_ATTRIBUTE_NAME = "hasPostfachNachricht"; @Mapping(target = "nextFrist", source = "clientAttributesList") + @Mapping(target = "hasPostfachNachricht", source = "clientAttributesList") VorgangHeader toVorgangHeader(GrpcVorgangHeader vorgangHeader); default LocalDate mapNextFrist(List<GrpcClientAttribute> clientAttributes) { - var clientAttributeList = clientAttributes.stream() - .filter(attribute -> StringUtils.equals(attribute.getAttributeName(), WIEDERVORLAGE_NEXT_FRIST_ATTRIBUTE_NAME)) - .map(GrpcClientAttribute::getValue) + return findByName(WIEDERVORLAGE_NEXT_FRIST_ATTRIBUTE_NAME, clientAttributes) .map(GrpcClientAttributeValue::getStringValue) - .map(LocalDate::parse).toList(); - if (clientAttributeList.isEmpty()) { - return null; - } - return clientAttributeList.get(0); + .map(LocalDate::parse).findFirst().orElse(null); + } + + default boolean mapHasPostfachNachricht(List<GrpcClientAttribute> clientAttributes) { + return findByName(HAS_POSTFACH_NACHRICHT_ATTRIBUTE_NAME, clientAttributes) + .map(GrpcClientAttributeValue::getBoolValue) + .findFirst().orElse(false); + } + + default Stream<GrpcClientAttributeValue> findByName(String attributeName, List<GrpcClientAttribute> clientAttributes) { + return clientAttributes.stream() + .filter(attribute -> StringUtils.equals(attribute.getAttributeName(), attributeName)) + .map(GrpcClientAttribute::getValue); } } diff --git a/goofy-server/src/main/java/de/itvsh/goofy/wiedervorlage/WiedervorlageRemoteService.java b/goofy-server/src/main/java/de/itvsh/goofy/wiedervorlage/WiedervorlageRemoteService.java index e7acc36fec730a9cbb1478c1cc6db3bac5471696..90a4a74b0724a97bc5f5d6a725ab4a00b905defd 100644 --- a/goofy-server/src/main/java/de/itvsh/goofy/wiedervorlage/WiedervorlageRemoteService.java +++ b/goofy-server/src/main/java/de/itvsh/goofy/wiedervorlage/WiedervorlageRemoteService.java @@ -28,10 +28,12 @@ public class WiedervorlageRemoteService { static final String CLIENT_ATTRIBUTE_NEXT_WIEDERVORLAGE_FRIST = "nextWiedervorlageFrist"; static final String ITEM_NAME = "Wiedervorlage"; - @GrpcClient(GoofyServerApplication.GRPC_CLIENT) - private ClientAttributeServiceBlockingStub clientAttributeServiceStub; @GrpcClient(GoofyServerApplication.GRPC_CLIENT) private VorgangAttachedItemServiceBlockingStub vorgangAttachedItemServiceStub; + + @GrpcClient(GoofyServerApplication.GRPC_CLIENT) + private ClientAttributeServiceBlockingStub clientAttributeServiceStub; + @Autowired private WiedervorlageMapper mapper; @Autowired diff --git a/goofy-server/src/main/java/de/itvsh/goofy/wiedervorlage/WiedervorlageService.java b/goofy-server/src/main/java/de/itvsh/goofy/wiedervorlage/WiedervorlageService.java index 84e1333f4d711bfd26d89e4136ab08c429d499ec..4d6961375b53686657df8aa323f17c06f8eddd96 100644 --- a/goofy-server/src/main/java/de/itvsh/goofy/wiedervorlage/WiedervorlageService.java +++ b/goofy-server/src/main/java/de/itvsh/goofy/wiedervorlage/WiedervorlageService.java @@ -30,15 +30,11 @@ class WiedervorlageService { } Optional<LocalDate> calculateNextFrist(Stream<Wiedervorlage> wiedervorlagen) { - var sortedWiedervorlagen = wiedervorlagen + return wiedervorlagen .filter(IS_NOT_DONE) .sorted(Comparator.comparing(Wiedervorlage::getFrist)) - .toList(); - - if (sortedWiedervorlagen.isEmpty()) { - return Optional.empty(); - } - return Optional.of(sortedWiedervorlagen.get(0).getFrist()); + .map(Wiedervorlage::getFrist) + .findFirst(); } public Stream<Wiedervorlage> findByVorgangId(String vorgangId) { diff --git a/goofy-server/src/main/resources/application.yml b/goofy-server/src/main/resources/application.yml index 375e521387d7f60396e1b2d2c011930b0a033937..d8cb5523c319c31b2f3c4c1c4b724403f01ae7eb 100644 --- a/goofy-server/src/main/resources/application.yml +++ b/goofy-server/src/main/resources/application.yml @@ -10,7 +10,7 @@ spring: pathmatch: matching-strategy: ant-path-matcher application: - name: Goofy + name: goofy jackson: deserialization: 'ADJUST_DATES_TO_CONTEXT_TIME_ZONE': false diff --git a/goofy-server/src/test/java/de/itvsh/goofy/common/binaryfile/BinaryFileITCase.java b/goofy-server/src/test/java/de/itvsh/goofy/common/binaryfile/BinaryFileITCase.java index d9ef6713344a1ab20aa935ddf9b8d11301789800..314dd0914ee15335414c3a4e1d20b46b09f3c686 100644 --- a/goofy-server/src/test/java/de/itvsh/goofy/common/binaryfile/BinaryFileITCase.java +++ b/goofy-server/src/test/java/de/itvsh/goofy/common/binaryfile/BinaryFileITCase.java @@ -78,7 +78,7 @@ class BinaryFileITCase { .andExpect(jsonPath("issues[0].messageCode").value("validation_field_file_size_exceeded")) .andExpect(jsonPath("issues[0].message").value("validation_field_file_size_exceeded")) .andExpect(jsonPath("issues[0].parameters[0].name").value("unit")) - .andExpect(jsonPath("issues[0].parameters[0].value").value(BinaryFileUnit.MB)); + .andExpect(jsonPath("issues[0].parameters[0].value").value(UploadBinaryFileSizeValidator.DEFAULT_UNIT_STRING)); } @Test diff --git a/goofy-server/src/test/java/de/itvsh/goofy/common/callcontext/CallContextTestFactory.java b/goofy-server/src/test/java/de/itvsh/goofy/common/callcontext/CallContextTestFactory.java index f8cfa40b1ea13d0cae7a67078157804f300db230..c283db65e2663f66645cd4c3e1995e032c1e8095 100644 --- a/goofy-server/src/test/java/de/itvsh/goofy/common/callcontext/CallContextTestFactory.java +++ b/goofy-server/src/test/java/de/itvsh/goofy/common/callcontext/CallContextTestFactory.java @@ -1,7 +1,6 @@ package de.itvsh.goofy.common.callcontext; -import static de.itvsh.goofy.common.callcontext.ContextService.KEY_USER_ID; -import static de.itvsh.goofy.common.callcontext.ContextService.KEY_USER_NAME; +import static de.itvsh.goofy.common.callcontext.ContextService.*; import java.util.Map; @@ -9,6 +8,8 @@ import de.itvsh.goofy.common.user.UserTestFactory; public class CallContextTestFactory { + public static final String CLIENT_NAME = "TEST_CLIENT"; + static Map<String, String> createContextMap() { return Map.of( KEY_USER_ID, UserTestFactory.ID.toString(), diff --git a/goofy-server/src/test/java/de/itvsh/goofy/vorgang/GrpcClientAttributeTestFactory.java b/goofy-server/src/test/java/de/itvsh/goofy/vorgang/GrpcClientAttributeTestFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..aed0796d6ef350c15d113ac68b50db1a1e98cfc5 --- /dev/null +++ b/goofy-server/src/test/java/de/itvsh/goofy/vorgang/GrpcClientAttributeTestFactory.java @@ -0,0 +1,31 @@ + +package de.itvsh.goofy.vorgang; + +import de.itvsh.goofy.common.callcontext.CallContextTestFactory; +import de.itvsh.ozg.pluto.grpc.clientAttribute.GrpcAccessPermission; +import de.itvsh.ozg.pluto.grpc.clientAttribute.GrpcClientAttribute; +import de.itvsh.ozg.pluto.grpc.clientAttribute.GrpcClientAttribute.Builder; +import de.itvsh.ozg.pluto.grpc.clientAttribute.GrpcClientAttributeValue; + +class GrpcClientAttributeTestFactory { + + static final String CLIENT = CallContextTestFactory.CLIENT_NAME; + static final GrpcAccessPermission ACCESS = GrpcAccessPermission.READ_WRITE; + + static final GrpcClientAttribute create() { + return createBuilder().build(); + } + + static final Builder createBuilder() { + return GrpcClientAttribute.newBuilder() + .setClientName(CLIENT) + .setAccess(ACCESS); + } + + static final GrpcClientAttribute createWith(String attributeName, boolean value) { + return createBuilder().setAttributeName(attributeName) + .setValue(GrpcClientAttributeValue.newBuilder().setBoolValue(value).build()) + .build(); + } + +} diff --git a/goofy-server/src/test/java/de/itvsh/goofy/vorgang/VorgangHeaderMapperTest.java b/goofy-server/src/test/java/de/itvsh/goofy/vorgang/VorgangHeaderMapperTest.java index d547eefa8764cf3e61150c5eebe2d53a9a5621b3..7ef7bfd6a87831789f1d9fc6811d33a3b794263e 100644 --- a/goofy-server/src/test/java/de/itvsh/goofy/vorgang/VorgangHeaderMapperTest.java +++ b/goofy-server/src/test/java/de/itvsh/goofy/vorgang/VorgangHeaderMapperTest.java @@ -75,7 +75,6 @@ class VorgangHeaderMapperTest { var header = mapper.toVorgangHeader(vorgangHeaderWithEmptyClientAttributes); assertThat(header.getNextFrist()).isNull(); - ; } @Test @@ -94,6 +93,28 @@ class VorgangHeaderMapperTest { } } + @Nested + class HasPostfachNachricht { + @Test + void shouldSetFalseIfNotExists() { + var vorgangHeader = GrpcVorgangHeaderTestFactory.createBuilder().clearClientAttributes().build(); + + var mapped = mapper.toVorgangHeader(vorgangHeader); + + assertThat(mapped.isHasPostfachNachricht()).isFalse(); + } + + @Test + void shouldBeTrue() { + var clientAttribute = GrpcClientAttributeTestFactory.createWith("hasPostfachNachricht", true); + var vorgangHeader = GrpcVorgangHeaderTestFactory.createBuilder().addClientAttributes(clientAttribute).build(); + + var mapped = mapper.toVorgangHeader(vorgangHeader); + + assertThat(mapped.isHasPostfachNachricht()).isTrue(); + } + } + private VorgangHeader callMapper() { return mapper.toVorgangHeader(GrpcVorgangHeaderTestFactory.create()); } diff --git a/goofy-server/src/test/java/de/itvsh/goofy/wiedervorlage/WiedervorlageServiceTest.java b/goofy-server/src/test/java/de/itvsh/goofy/wiedervorlage/WiedervorlageServiceTest.java index db6195cb7217ed5905aa8072f3e47d6a402a30ea..1609042fd1f5e58458f8dffa0dd91f1970e9c338 100644 --- a/goofy-server/src/test/java/de/itvsh/goofy/wiedervorlage/WiedervorlageServiceTest.java +++ b/goofy-server/src/test/java/de/itvsh/goofy/wiedervorlage/WiedervorlageServiceTest.java @@ -113,7 +113,7 @@ class WiedervorlageServiceTest { var nextFrist = calculateNextFrist(Stream.of(fristPast2Days, fristPast1Day, fristFuture1Day, fristFuture2Days)); - assertThat(nextFrist.get()).isEqualTo(LocalDate.now().minus(2, ChronoUnit.DAYS)); + assertThat(nextFrist).contains(LocalDate.now().minus(2, ChronoUnit.DAYS)); } @Test @@ -125,7 +125,7 @@ class WiedervorlageServiceTest { var nextFrist = calculateNextFrist(Stream.of(fristPast1DayNotDone, fristPast1DayDone)); - assertThat(nextFrist.get()).isEqualTo(LocalDate.now().plus(1, ChronoUnit.DAYS)); + assertThat(nextFrist).contains(LocalDate.now().plus(1, ChronoUnit.DAYS)); } private Optional<LocalDate> calculateNextFrist(Stream<Wiedervorlage> wiedervorlagen) {