Skip to content
Snippets Groups Projects

OZG-7872 OZG-8039 add related resource link on postfach

Merged Martin Küster requested to merge OZG-7872-ErneutVersenden into main
3 unresolved threads
6 files
+ 369
22
Compare changes
  • Side-by-side
  • Inline
Files
6
@@ -25,6 +25,7 @@ package de.ozgcloud.alfa.common.command;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Stream;
@@ -41,10 +42,11 @@ import de.ozgcloud.alfa.bescheid.DocumentController;
import de.ozgcloud.alfa.collaboration.CollaborationController.CollaborationByVorgangController;
import de.ozgcloud.alfa.forwarding.ForwardingController;
import de.ozgcloud.alfa.kommentar.KommentarController;
import de.ozgcloud.alfa.postfach.PostfachMailController;
import de.ozgcloud.alfa.vorgang.VorgangController;
import de.ozgcloud.alfa.wiedervorlage.WiedervorlageController;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
@Component
class CommandModelAssembler implements RepresentationModelAssembler<Command, EntityModel<Command>> {
@@ -57,14 +59,29 @@ class CommandModelAssembler implements RepresentationModelAssembler<Command, Ent
static final Predicate<Command> HAS_KNOWN_COMMAND_ORDER = command -> command.getCommandOrder() != CommandOrder.UNBEKANNT;
private static final List<CommandOrder> ORDER_PROCESSED_SEPERATELY = List.of(
CommandOrder.RECEIVE_POSTFACH_NACHRICHT,
CommandOrder.RESEND_POSTFACH_MAIL,
CommandOrder.SEND_POSTFACH_MAIL,
CommandOrder.SEND_POSTFACH_NACHRICHT);
static final Predicate<Command> IS_PROCESSABLE_ORDER = command -> !ORDER_PROCESSED_SEPERATELY.contains(command.getCommandOrder());
private final List<CommandProcessor> processors;
@Override
public EntityModel<Command> toModel(Command command) {
return EntityModel.of(command)
var entityModel = EntityModel.of(command)
.add(linkTo(CommandController.class).slash(command.getId()).withSelfRel())
.addIf(CommandHelper.IS_DONE.and(HAS_KNOWN_COMMAND_ORDER).test(command), () -> effectedResourceLinkByOrderType(command))
.addIf(CommandHelper.IS_DONE.and(HAS_KNOWN_COMMAND_ORDER).and(IS_PROCESSABLE_ORDER).test(command),
() -> effectedResourceLinkByOrderType(command))
.addIf(CommandHelper.IS_PENDING.test(command), () -> linkTo(CommandController.class).slash(command.getId()).withRel(REL_UPDATE))
.addIf(IS_NOT_LOESCH_ANFORDERUNG_AND_REVOKEABLE.test(command),
() -> linkTo(methodOn(CommandController.class).revoke(command.getId(), null)).withRel(REL_REVOKE));
processors.forEach(processor -> processor.process(entityModel));
    • Gibt es einen Grund warum das hier manuell aufgerufen wird und nicht von Spring gemacht wird? Wenn die jeweiligen Processoren RepresentationModelProcessor<EntityModel<Command>> implementieren, kümmert sich Spring darum.

      • Author Maintainer

        Ja, das hat mehrere Gründe. Dadurch das es explizit aufgerufen wird kann man es einfacher verstehen und nachvollziehen und zum anderen brauchen wir dann nicht immer die null Abfrage auf den Content der ja aktuell auch immer wieder dupliziert wird in den Processoren.

      • In CommandProcessor gibt es doch trotzdem die Nullabfrage. Ich finde es überraschend in einer Spring Boot Anwendung nicht die Spring Boot Features zu benutzen die es gibt. Ich bin aber auch nicht dagegen es explizit zu machen, weil es hier nicht viel Arbeit ist

        Edited by Felix Reichenbach
      • Author Maintainer

        Die gibt es jetzt aber nur einmal zentral im CommandProcessor, nicht in jedem fachlichen Prozessor. Es kann in die ein oder andere Richtung überraschen, das ist denke ich Geschmackssache. (hab da auch schon etwas länger mit Tobias drüber philosophiert)

      • Please register or sign in to reply
Please register or sign in to reply
return entityModel;
}
Link effectedResourceLinkByOrderType(Command entity) {
@@ -73,14 +90,13 @@ class CommandModelAssembler implements RepresentationModelAssembler<Command, Ent
WebMvcLinkBuilder linkBuilder = switch (type) {
case FORWARDING -> linkTo(methodOn(ForwardingController.class).findByVorgangId(entity.getVorgangId()));
case KOMMENTAR -> linkTo(KommentarController.class).slash(entity.getRelationId());
case POSTFACH -> linkTo(methodOn(PostfachMailController.class).getAll(entity.getVorgangId()));
case VORGANG -> linkTo(VorgangController.class).slash(entity.getRelationId());
case VORGANG_LIST -> linkTo(VorgangController.class);
case WIEDERVORLAGE -> linkTo(WiedervorlageController.class).slash(entity.getRelationId());
case BESCHEID -> linkTo(methodOn(BescheidController.class).getDraft(entity.getVorgangId()));
case DOCUMENT -> linkTo(DocumentController.class).slash(entity.getCreatedResource());
case COLLABORATION -> linkTo(methodOn(CollaborationByVorgangController.class).getAllByVorgangId(entity.getVorgangId()));
case NONE -> throw new IllegalArgumentException("Unknown CommandOrder: " + entity.getOrder());
default -> throw new IllegalArgumentException("Unknown CommandOrder: " + entity.getOrder());
};
return linkBuilder.withRel(REL_EFFECTED_RESOURCE);
Loading