From e00a6f745f7016b9263d260a54677056ac8d8b75 Mon Sep 17 00:00:00 2001 From: OZGCloud <ozgcloud@mgm-tp.com> Date: Mon, 27 Jun 2022 17:12:42 +0200 Subject: [PATCH] OZG-1513 adjust postfachModelAssembler to handle createdBy as null --- .../itvsh/goofy/postfach/PostfachMailModelAssembler.java | 4 ++-- .../goofy/postfach/PostfachMailModelAssemblerTest.java | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMailModelAssembler.java b/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMailModelAssembler.java index 74734a9518..0b49bcbc60 100644 --- a/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMailModelAssembler.java +++ b/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMailModelAssembler.java @@ -31,8 +31,8 @@ class PostfachMailModelAssembler implements RepresentationModelAssembler<Postfac private static final Predicate<PostfachMail> HAS_ATTACHMENTS = nachricht -> !nachricht.getAttachments().isEmpty(); static final String SYSTEM_USER_IDENTIFIER = "system"; - private static final Predicate<PostfachMail> SENT_BY_CLIENT_USER = postfachNachricht -> !postfachNachricht.getCreatedBy().toString() - .startsWith(SYSTEM_USER_IDENTIFIER); + private static final Predicate<PostfachMail> SENT_BY_CLIENT_USER = postfachNachricht -> Optional.ofNullable(postfachNachricht.getCreatedBy()) + .map(createdBy -> !createdBy.toString().startsWith(SYSTEM_USER_IDENTIFIER)).orElse(false); public CollectionModel<EntityModel<PostfachMail>> toCollectionModel(Stream<PostfachMail> entities, String vorgangId, long vorgangVersion, Optional<String> postfachId) { diff --git a/goofy-server/src/test/java/de/itvsh/goofy/postfach/PostfachMailModelAssemblerTest.java b/goofy-server/src/test/java/de/itvsh/goofy/postfach/PostfachMailModelAssemblerTest.java index 8faa7b4cf6..100b7a73b6 100644 --- a/goofy-server/src/test/java/de/itvsh/goofy/postfach/PostfachMailModelAssemblerTest.java +++ b/goofy-server/src/test/java/de/itvsh/goofy/postfach/PostfachMailModelAssemblerTest.java @@ -102,8 +102,15 @@ class PostfachMailModelAssemblerTest { assertThat(link).isNotPresent(); } - } + @Test + void shouldNotBePresentOnNull() { + var link = modelAssembler.toModel(PostfachMailTestFactory.createBuilder().createdBy(null).build()) + .getLink(PostfachMailModelAssembler.REL_CREATED_BY); + + assertThat(link).isNotPresent(); + } + } } @Nested -- GitLab