Skip to content
Snippets Groups Projects
Commit 9c4ec14b authored by OZGCloud's avatar OZGCloud
Browse files

OZG-2859 Fall entity.getCreatedBy() == null wird abgefangen

parent 015d6990
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ package de.itvsh.goofy.historie; ...@@ -2,6 +2,7 @@ package de.itvsh.goofy.historie;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*; import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*;
import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Stream; import java.util.stream.Stream;
...@@ -17,6 +18,8 @@ import de.itvsh.goofy.common.user.UserProfileController; ...@@ -17,6 +18,8 @@ import de.itvsh.goofy.common.user.UserProfileController;
@Component @Component
class HistorieModelAssembler implements RepresentationModelAssembler<Command, EntityModel<Command>> { class HistorieModelAssembler implements RepresentationModelAssembler<Command, EntityModel<Command>> {
private static final String SYSTEM_NOTIFICATION_MANAGER_PREFIX = "system-notification_manager";
static final String REL_ASSIGNED_TO = "assignedTo"; static final String REL_ASSIGNED_TO = "assignedTo";
static final String ASSIGNED_TO_BODY_FIELD = "assignedTo"; static final String ASSIGNED_TO_BODY_FIELD = "assignedTo";
...@@ -32,7 +35,7 @@ class HistorieModelAssembler implements RepresentationModelAssembler<Command, En ...@@ -32,7 +35,7 @@ class HistorieModelAssembler implements RepresentationModelAssembler<Command, En
} }
Command unsetSystemUser(Command entity) { Command unsetSystemUser(Command entity) {
if (entity.getCreatedBy().toString().startsWith("system-notification_manager")) { if (Objects.nonNull(entity.getCreatedBy()) && entity.getCreatedBy().toString().startsWith(SYSTEM_NOTIFICATION_MANAGER_PREFIX)) {
return entity.toBuilder().createdBy(null).build(); return entity.toBuilder().createdBy(null).build();
} }
......
...@@ -76,5 +76,12 @@ class HistorieModelAssemblerTest { ...@@ -76,5 +76,12 @@ class HistorieModelAssemblerTest {
assertThat(model.getLink("createdBy")).isNotPresent(); assertThat(model.getLink("createdBy")).isNotPresent();
} }
@Test
void shouldNotBePresentOnNullValue() {
var model = modelAssembler.toModel(CommandTestFactory.createBuilder().createdBy(null).build());
assertThat(model.getLink("createdBy")).isNotPresent();
}
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment