Skip to content
Snippets Groups Projects

Ozg 3936 refactor user profile url provider

Merged Felix Reichenbach requested to merge OZG-3936-refactor-UserProfileUrlProvider into main
2 unresolved threads
4 files
+ 84
4
Compare changes
  • Side-by-side
  • Inline
Files
4
@@ -39,7 +39,7 @@ import org.springframework.hateoas.mediatype.hal.HalModelBuilder;
import org.springframework.hateoas.server.RepresentationModelAssembler;
import org.springframework.stereotype.Component;
import de.ozgcloud.alfa.common.ModelBuilder;
import de.ozgcloud.alfa.common.LinkedResourceProcessor;
import de.ozgcloud.alfa.common.binaryfile.BinaryFileController;
import de.ozgcloud.alfa.common.user.UserManagerUrlProvider;
import de.ozgcloud.alfa.postfach.PostfachMail.Direction;
@@ -79,6 +79,7 @@ class PostfachMailModelAssembler implements RepresentationModelAssembler<Postfac
private final UserManagerUrlProvider userManagerUrlProvider;
private final VorgangController vorgangController;
private final LinkedResourceProcessor<PostfachMail> linkedResourceProcessor;
public RepresentationModel<EntityModel<PostfachSettings>> toCollectionModel(Stream<PostfachMail> postfachMails, VorgangWithEingang vorgang,
PostfachSettings postfachSettings) {
@@ -96,7 +97,7 @@ class PostfachMailModelAssembler implements RepresentationModelAssembler<Postfac
return HalModelBuilder
.halModelOf(postfachSettings)
.link(linkTo(methodOn(PostfachMailController.class).getAll(vorgang.getId())).withSelfRel())
.embed(postfachMails.map(this::toModel))
.embed(postfachMails.map(this::toModel).map(linkedResourceProcessor::process))
.build();
}
@@ -124,21 +125,20 @@ class PostfachMailModelAssembler implements RepresentationModelAssembler<Postfac
public EntityModel<PostfachMail> toModel(PostfachMail postfachMail) {
var selfLink = linkTo(PostfachMailController.class).slash(postfachMail.getId());
return ModelBuilder.fromEntity(postfachMail).addLink(selfLink.withSelfRel())
.ifMatch(IS_UNSEND).addLink(linkTo(PostfachMailCommandController.class, postfachMail.getId()).withRel(REL_SEND))
.ifMatch(SENT_FAILED)
.addLink(linkTo(methodOn(PostfachMailCommandController.class).createCommand(postfachMail.getId(), null))
.withRel(REL_RESEND_POSTFACH_MAIL))
.ifMatch(IS_UNSEND)
.addLink(linkTo(methodOn(PostfachMailCommandController.class).createCommand(postfachMail.getId(), null))
.withRel(REL_EDIT))
.ifMatch(HAS_ATTACHMENTS)
.addLink(linkTo(methodOn(PostfachMailController.class).findAttachments(PostfachNachrichtId.from(postfachMail.getId())))
.withRel(REL_ATTACHMENTS))
.ifMatch(() -> userManagerUrlProvider.isConfiguredForUserProfile() && SENT_BY_CLIENT_USER.test(postfachMail))
.addLink(() -> Link.of(String.format(userManagerUrlProvider.getUserProfileTemplate(), postfachMail.getCreatedBy()),
REL_CREATED_BY))
.buildModel();
return EntityModel.of(postfachMail)
.add(selfLink.withSelfRel())
.addIf(IS_UNSEND.test(postfachMail),
() -> linkTo(PostfachMailCommandController.class, postfachMail.getId()).withRel(REL_SEND))
.addIf(SENT_FAILED.test(postfachMail),
() -> linkTo(methodOn(PostfachMailCommandController.class).createCommand(postfachMail.getId(), null))
.withRel(REL_RESEND_POSTFACH_MAIL))
.addIf(IS_UNSEND.test(postfachMail),
() -> linkTo(methodOn(PostfachMailCommandController.class).createCommand(postfachMail.getId(), null)).withRel(REL_EDIT))
.addIf(HAS_ATTACHMENTS.test(postfachMail),
() -> linkTo(methodOn(PostfachMailController.class).findAttachments(PostfachNachrichtId.from(postfachMail.getId())))
.withRel(REL_ATTACHMENTS))
.addIf(userManagerUrlProvider.isConfiguredForUserProfile() && SENT_BY_CLIENT_USER.test(postfachMail),
() -> Link.of(String.format(userManagerUrlProvider.getUserProfileTemplate(), postfachMail.getCreatedBy()), REL_CREATED_BY));
}
}
\ No newline at end of file
Loading