From 718bd74e228dc2aa66b35f34036d8534e8105dc8 Mon Sep 17 00:00:00 2001 From: anhefti Date: Tue, 12 Mar 2019 08:11:36 +0100 Subject: [PATCH] fixed compile error for Java 8 --- .../seb/SebClientConfigServiceImpl.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/seb/SebClientConfigServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/seb/SebClientConfigServiceImpl.java index 149687b9..9ae4e7fb 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/seb/SebClientConfigServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/seb/SebClientConfigServiceImpl.java @@ -11,8 +11,10 @@ package ch.ethz.seb.sebserver.webservice.servicelayer.seb; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.UnsupportedEncodingException; +import java.util.ArrayList; import java.util.Collection; -import java.util.Optional; +import java.util.Collections; +import java.util.List; import java.util.UUID; import org.springframework.beans.factory.annotation.Value; @@ -85,14 +87,19 @@ public class SebClientConfigServiceImpl implements SebClientConfigService { @Override public Result exportSebClientConfigurationOfInstitution(final Long institutionId) { - return this.sebClientConfigDAO.all(institutionId, true) - .flatMap(l -> l.stream() - .sorted((sc1, sc2) -> sc1.date.compareTo(sc2.date)) - .findFirst() - .or(() -> Optional.of( - autoCreateSebClientConfigurationForIntitution(institutionId).getOrThrow())) - .map(this::createExport) - .get()); + return Result.tryCatchOf(() -> { + final List sebConfigs = new ArrayList<>(this.sebClientConfigDAO + .all(institutionId, true) + .getOrThrow()); + + if (sebConfigs.isEmpty()) { + return autoCreateSebClientConfigurationForIntitution(institutionId) + .flatMap(this::createExport); + } + + Collections.sort(sebConfigs, (sc1, sc2) -> sc1.date.compareTo(sc2.date)); + return this.createExport(sebConfigs.get(0)); + }); } private final static String SEB_CLIENT_CONFIG_EXAMPLE_XML =