Skip to content
Snippets Groups Projects
Commit 4b4323f1 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-1513 add createdBy link to postfachNachricht if nachricht was triggered by client

parent 297cbcef
Branches
Tags
No related merge requests found
...@@ -10,11 +10,9 @@ import javax.validation.constraints.Size; ...@@ -10,11 +10,9 @@ import javax.validation.constraints.Size;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import de.itvsh.goofy.common.LinkedResource;
import de.itvsh.goofy.common.binaryfile.FileId; import de.itvsh.goofy.common.binaryfile.FileId;
import de.itvsh.goofy.common.command.CommandBody; import de.itvsh.goofy.common.command.CommandBody;
import de.itvsh.goofy.common.user.UserId; import de.itvsh.goofy.common.user.UserId;
import de.itvsh.goofy.common.user.UserProfileController;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
...@@ -42,7 +40,7 @@ public class PostfachMail implements CommandBody { ...@@ -42,7 +40,7 @@ public class PostfachMail implements CommandBody {
private String vorgangId; private String vorgangId;
private ZonedDateTime createdAt; private ZonedDateTime createdAt;
@LinkedResource(controllerClass = UserProfileController.class) @JsonIgnore
private UserId createdBy; private UserId createdBy;
private ZonedDateTime sentAt; private ZonedDateTime sentAt;
......
...@@ -15,6 +15,7 @@ import org.springframework.stereotype.Component; ...@@ -15,6 +15,7 @@ import org.springframework.stereotype.Component;
import de.itvsh.goofy.common.ModelBuilder; import de.itvsh.goofy.common.ModelBuilder;
import de.itvsh.goofy.common.binaryfile.BinaryFileController; import de.itvsh.goofy.common.binaryfile.BinaryFileController;
import de.itvsh.goofy.common.command.CommandController.CommandByRelationController; import de.itvsh.goofy.common.command.CommandController.CommandByRelationController;
import de.itvsh.goofy.common.user.UserProfileController;
import de.itvsh.goofy.postfach.PostfachMailController.PostfachMailCommandController; import de.itvsh.goofy.postfach.PostfachMailController.PostfachMailCommandController;
@Component @Component
...@@ -24,10 +25,15 @@ class PostfachMailModelAssembler implements RepresentationModelAssembler<Postfac ...@@ -24,10 +25,15 @@ class PostfachMailModelAssembler implements RepresentationModelAssembler<Postfac
public static final String REL_RESEND_POSTFACH_MAIL = "resendPostfachMail"; public static final String REL_RESEND_POSTFACH_MAIL = "resendPostfachMail";
public static final String REL_ATTACHMENTS = "attachments"; public static final String REL_ATTACHMENTS = "attachments";
static final String REL_UPLOAD_ATTACHMENT = "uploadAttachment"; static final String REL_UPLOAD_ATTACHMENT = "uploadAttachment";
static final String REL_CREATED_BY = "createdBy";
private static final Predicate<PostfachMail> SENT_FAILED = postfachMail -> BooleanUtils.isFalse(postfachMail.getSentSuccessful()); private static final Predicate<PostfachMail> SENT_FAILED = postfachMail -> BooleanUtils.isFalse(postfachMail.getSentSuccessful());
private static final Predicate<PostfachMail> HAS_ATTACHMENTS = nachricht -> !nachricht.getAttachments().isEmpty(); 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);
public CollectionModel<EntityModel<PostfachMail>> toCollectionModel(Stream<PostfachMail> entities, String vorgangId, long vorgangVersion, public CollectionModel<EntityModel<PostfachMail>> toCollectionModel(Stream<PostfachMail> entities, String vorgangId, long vorgangVersion,
Optional<String> postfachId) { Optional<String> postfachId) {
CollectionModel<EntityModel<PostfachMail>> model = CollectionModel.of(entities.map(this::toModel).toList(), CollectionModel<EntityModel<PostfachMail>> model = CollectionModel.of(entities.map(this::toModel).toList(),
...@@ -49,6 +55,8 @@ class PostfachMailModelAssembler implements RepresentationModelAssembler<Postfac ...@@ -49,6 +55,8 @@ class PostfachMailModelAssembler implements RepresentationModelAssembler<Postfac
.ifMatch(HAS_ATTACHMENTS) .ifMatch(HAS_ATTACHMENTS)
.addLink(linkTo(methodOn(PostfachMailController.class).findAttachments(PostfachNachrichtId.from(postfachMail.getId()))) .addLink(linkTo(methodOn(PostfachMailController.class).findAttachments(PostfachNachrichtId.from(postfachMail.getId())))
.withRel(REL_ATTACHMENTS)) .withRel(REL_ATTACHMENTS))
.ifMatch(SENT_BY_CLIENT_USER)
.addLink(linkTo(UserProfileController.class).slash(postfachMail.getCreatedBy()).withRel(REL_CREATED_BY))
.buildModel(); .buildModel();
} }
......
package de.itvsh.goofy.postfach; package de.itvsh.goofy.postfach;
import static org.assertj.core.api.Assertions.*;
import java.util.Optional; import java.util.Optional;
import java.util.UUID;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
...@@ -14,6 +13,9 @@ import org.springframework.hateoas.EntityModel; ...@@ -14,6 +13,9 @@ import org.springframework.hateoas.EntityModel;
import org.springframework.hateoas.IanaLinkRelations; import org.springframework.hateoas.IanaLinkRelations;
import org.springframework.hateoas.Link; import org.springframework.hateoas.Link;
import static org.assertj.core.api.Assertions.*;
import de.itvsh.goofy.common.user.UserId;
import de.itvsh.goofy.vorgang.VorgangHeaderTestFactory; import de.itvsh.goofy.vorgang.VorgangHeaderTestFactory;
class PostfachMailModelAssemblerTest { class PostfachMailModelAssemblerTest {
...@@ -78,6 +80,30 @@ class PostfachMailModelAssemblerTest { ...@@ -78,6 +80,30 @@ class PostfachMailModelAssemblerTest {
} }
} }
@DisplayName("created by link")
@Nested
class TestCreatedByLink {
@Test
void shouldBePresent() {
var link = modelAssembler.toModel(PostfachMailTestFactory.create()).getLink(PostfachMailModelAssembler.REL_CREATED_BY);
assertThat(link).isPresent().get().extracting(Link::getHref)
.isEqualTo("/api/userProfiles/" + PostfachMailTestFactory.CREATED_BY);
}
@DisplayName("should not be present if the value of createdBy starts with 'system'")
@Test
void shouldNOTBePresentOnSystemUser() {
var link = modelAssembler
.toModel(PostfachMailTestFactory.createBuilder()
.createdBy(UserId.from(PostfachMailModelAssembler.SYSTEM_USER_IDENTIFIER + UUID.randomUUID().toString())).build())
.getLink(PostfachMailModelAssembler.REL_CREATED_BY);
assertThat(link).isNotPresent();
}
}
} }
@Nested @Nested
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment