Skip to content
Snippets Groups Projects
Commit 2f2b597b authored by OZGCloud's avatar OZGCloud
Browse files

Merge branch 'master' of git.ozg-sh.de:mgm/goofy

parents 146db991 f2cf1997
No related branches found
No related tags found
No related merge requests found
...@@ -25,7 +25,6 @@ package de.ozgcloud.alfa.common.binaryfile; ...@@ -25,7 +25,6 @@ package de.ozgcloud.alfa.common.binaryfile;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*; import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.springframework.hateoas.CollectionModel; import org.springframework.hateoas.CollectionModel;
...@@ -51,7 +50,6 @@ public class BinaryFileModelAssembler implements RepresentationModelAssembler<Oz ...@@ -51,7 +50,6 @@ public class BinaryFileModelAssembler implements RepresentationModelAssembler<Oz
} }
public CollectionModel<EntityModel<OzgFile>> toCollectionModel(Stream<OzgFile> entities) { public CollectionModel<EntityModel<OzgFile>> toCollectionModel(Stream<OzgFile> entities) {
return CollectionModel.of(entities.map(this::toModel).collect(Collectors.toList()), return CollectionModel.of(entities.map(this::toModel).toList(), linkTo(BinaryFileController.class).withSelfRel());
linkTo(BinaryFileController.class).withSelfRel());
} }
} }
\ No newline at end of file
...@@ -11,15 +11,12 @@ public class CommandHelper { ...@@ -11,15 +11,12 @@ public class CommandHelper {
static final Predicate<Command> IS_DONE = command -> command.getStatus() == CommandStatus.FINISHED static final Predicate<Command> IS_DONE = command -> command.getStatus() == CommandStatus.FINISHED
|| command.getStatus() == CommandStatus.REVOKED || command.getStatus() == CommandStatus.ERROR; || command.getStatus() == CommandStatus.REVOKED || command.getStatus() == CommandStatus.ERROR;
static final Predicate<Command> IS_PENDING = command -> { static final Predicate<Command> IS_PENDING = command -> command.getStatus() == CommandStatus.PENDING
return command.getStatus() == CommandStatus.PENDING
|| command.getStatus() == CommandStatus.REVOKE_PENDING; || command.getStatus() == CommandStatus.REVOKE_PENDING;
};
public static final Predicate<Command> IS_REVOKEABLE = command -> command.getOrder().isRevokeable() public static final Predicate<Command> IS_REVOKEABLE = command -> command.getOrder().isRevokeable()
&& command.getStatus() == CommandStatus.FINISHED; && command.getStatus() == CommandStatus.FINISHED;
public static final Predicate<Command> IS_LOESCHANFORDERUNG = command -> command.getOrder() == CommandOrder.VORGANG_ZUM_LOESCHEN_MARKIEREN public static final Predicate<Command> IS_LOESCHANFORDERUNG = command -> command.getOrder() == CommandOrder.VORGANG_ZUM_LOESCHEN_MARKIEREN
|| command.getOrder() == CommandOrder.LOESCH_ANFORDERUNG_ZURUECKNEHMEN; || command.getOrder() == CommandOrder.LOESCH_ANFORDERUNG_ZURUECKNEHMEN;
} }
\ No newline at end of file
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
package de.ozgcloud.alfa.vorgang.forwarding; package de.ozgcloud.alfa.vorgang.forwarding;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.function.Predicate;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -45,6 +45,9 @@ public class ForwardingController { ...@@ -45,6 +45,9 @@ public class ForwardingController {
static final String PARAM_VORGANG_ID = "vorgangId"; static final String PARAM_VORGANG_ID = "vorgangId";
static final Predicate<Forwarding> IS_FAILED_FORWARDING = forwarding -> forwarding.getStatus() == Status.FAILED
|| forwarding.getStatus() == Status.SEND_ERROR;
@Autowired @Autowired
private ForwardingService service; private ForwardingService service;
@Autowired @Autowired
...@@ -56,9 +59,7 @@ public class ForwardingController { ...@@ -56,9 +59,7 @@ public class ForwardingController {
} }
public List<Forwarding> findFailedForwardings(String vorgangId) { public List<Forwarding> findFailedForwardings(String vorgangId) {
return findByVorgang(vorgangId) return findByVorgang(vorgangId).filter(IS_FAILED_FORWARDING).toList();
.filter(forwarding -> forwarding.getStatus() == Status.FAILED || forwarding.getStatus() == Status.SEND_ERROR)
.collect(Collectors.toList());
} }
public Stream<Forwarding> findByVorgang(String vorgangId) { public Stream<Forwarding> findByVorgang(String vorgangId) {
......
...@@ -25,7 +25,7 @@ package de.ozgcloud.alfa.vorgang.forwarding; ...@@ -25,7 +25,7 @@ package de.ozgcloud.alfa.vorgang.forwarding;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*; import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*;
import java.util.stream.Collectors; import java.util.function.Predicate;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.springframework.hateoas.CollectionModel; import org.springframework.hateoas.CollectionModel;
...@@ -50,28 +50,34 @@ class ForwardingModelAssembler implements RepresentationModelAssembler<Forwardin ...@@ -50,28 +50,34 @@ class ForwardingModelAssembler implements RepresentationModelAssembler<Forwardin
static final LinkRelation REL_ERROR = LinkRelation.of("error"); static final LinkRelation REL_ERROR = LinkRelation.of("error");
static final Predicate<Forwarding> IS_SENT = forwarding -> forwarding.getStatus() == Status.SENT;
static final Predicate<Forwarding> IS_SUCCESSFULL = forwarding -> forwarding.getStatus() == Status.SUCCESSFULL;
static final Predicate<Forwarding> IS_SENT_OR_SUCCESSFULL = forwarding -> forwarding.getStatus() == Status.SENT
|| forwarding.getStatus() == Status.SUCCESSFULL;
static final Predicate<Forwarding> IS_FAILED = forwarding -> forwarding.getStatus() == Status.FAILED;
static final Predicate<Forwarding> IS_SEND_ERROR = forwarding -> forwarding.getStatus() == Status.SEND_ERROR;
@Override @Override
public EntityModel<Forwarding> toModel(Forwarding entity) { public EntityModel<Forwarding> toModel(Forwarding entity) {
var selfLink = linkTo(ForwardingController.class).slash(entity.getId()); var selfLink = linkTo(ForwardingController.class).slash(entity.getId());
return ModelBuilder.fromEntity(entity) return ModelBuilder.fromEntity(entity)
.addLink(linkTo(ForwardingController.class).slash(entity.getId()).withSelfRel()) .addLink(linkTo(ForwardingController.class).slash(entity.getId()).withSelfRel())
.ifMatch(forwarding -> forwarding.getStatus() == Status.SENT) .ifMatch(IS_SENT)
.addLinks(buildMarkAsSuccessLink(entity)) .addLinks(buildMarkAsSuccessLink(entity))
.ifMatch(forwarding -> forwarding.getStatus() == Status.SENT || forwarding.getStatus() == Status.SUCCESSFULL) .ifMatch(IS_SENT_OR_SUCCESSFULL)
.addLinks(buildMarkAsFailLink(entity)) .addLinks(buildMarkAsFailLink(entity))
.ifMatch(forwarding -> forwarding.getStatus() == Status.FAILED) .ifMatch(IS_FAILED)
.addLink(selfLink.withRel(REL_FAILED)) .addLink(selfLink.withRel(REL_FAILED))
.ifMatch(forwarding -> forwarding.getStatus() == Status.SUCCESSFULL) .ifMatch(IS_SUCCESSFULL)
.addLink(selfLink.withRel(REL_SUCCESSFULL)) .addLink(selfLink.withRel(REL_SUCCESSFULL))
.ifMatch(forwarding -> forwarding.getStatus() == Status.SEND_ERROR) .ifMatch(IS_SEND_ERROR)
.addLink(selfLink.withRel(REL_ERROR)) .addLink(selfLink.withRel(REL_ERROR))
.buildModel(); .buildModel();
} }
public CollectionModel<EntityModel<Forwarding>> toCollectionModel(Stream<Forwarding> entities) { public CollectionModel<EntityModel<Forwarding>> toCollectionModel(Stream<Forwarding> entities) {
return CollectionModel.of(entities.map(this::toModel).collect(Collectors.toList()), return CollectionModel.of(entities.map(this::toModel).toList(), linkTo(ForwardingController.class).withSelfRel());
linkTo(ForwardingController.class).withSelfRel());
} }
public Link buildMarkAsSuccessLink(Forwarding forwarding) { public Link buildMarkAsSuccessLink(Forwarding forwarding) {
......
package de.ozgcloud.alfa.attachment; package de.ozgcloud.alfa.attachment;
import org.assertj.core.api.Assertions; import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import de.ozgcloud.alfa.common.binaryfile.FileId; import de.ozgcloud.alfa.common.binaryfile.FileId;
public class AttachmentMapperTest { class AttachmentMapperTest {
@Test @Test
void shouldMapAttachmentsToEmptyList() { void shouldMapAttachmentsToEmptyList() {
Assertions.assertThat(AttachmentMapper.mapAttachments(null)).isEmpty(); var attachments = AttachmentMapper.mapAttachments(null);
assertThat(attachments).isEmpty();
} }
@Test @Test
void shouldMapAttachmentsToList() { void shouldMapAttachmentsToList() {
Assertions.assertThat(AttachmentMapper.mapAttachments(Lists.newArrayList("a1", "a2"))).containsExactly(FileId.from("a1"), FileId.from("a2")); var attachments = AttachmentMapper.mapAttachments(Lists.newArrayList("a1", "a2"));
assertThat(attachments).containsExactly(FileId.from("a1"), FileId.from("a2"));
} }
@Test @Test
void shouldMapOneElementToList() { void shouldMapOneElementToList() {
Assertions.assertThat(AttachmentMapper.mapAttachments("a1")).containsExactly(FileId.from("a1")); var attachments = AttachmentMapper.mapAttachments("a1");
assertThat(attachments).containsExactly(FileId.from("a1"));
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment