From c5915cdfa854c9781f25961fb44d8b5bf052a62b Mon Sep 17 00:00:00 2001 From: y72wvh Date: Thu, 28 Sep 2023 15:21:02 +0200 Subject: [PATCH] [fix] get moog campaigns bug --- pom.xml | 2 +- .../service/impl/CampaignServiceImpl.java | 21 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 5a346d60..178b671b 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ fr.insee.survey platine-management - 1.0.22 + 1.0.23 platine-management REST API for communication between DB and Platine-Management UI and Platine-My-Surveys UI diff --git a/src/main/java/fr/insee/survey/datacollectionmanagement/metadata/service/impl/CampaignServiceImpl.java b/src/main/java/fr/insee/survey/datacollectionmanagement/metadata/service/impl/CampaignServiceImpl.java index 994a9f8b..f2b217ee 100644 --- a/src/main/java/fr/insee/survey/datacollectionmanagement/metadata/service/impl/CampaignServiceImpl.java +++ b/src/main/java/fr/insee/survey/datacollectionmanagement/metadata/service/impl/CampaignServiceImpl.java @@ -41,24 +41,25 @@ public class CampaignServiceImpl implements CampaignService { public Collection getCampaigns() { List moogCampaigns = new ArrayList<>(); - List campaigns = campaignRepository.findAll(); + List campaigns = campaignRepository.findAll().stream().filter(c -> !c.getPartitionings().isEmpty()).toList(); for (Campaign campaign : campaigns) { CampaignMoogDto campaignMoogDto = new CampaignMoogDto(); campaignMoogDto.setId(campaign.getId()); campaignMoogDto.setLabel(campaign.getCampaignWording()); - Optional dateMin = campaign.getPartitionings().stream().map(Partitioning::getOpeningDate) - .collect(Collectors.toList()).stream() + Optional dateMin = campaign.getPartitionings().stream().map(Partitioning::getOpeningDate).toList().stream() .min(Comparator.comparing(Date::getTime)); - Optional dateMax = campaign.getPartitionings().stream().map(Partitioning::getClosingDate) - .collect(Collectors.toList()).stream() + Optional dateMax = campaign.getPartitionings().stream().map(Partitioning::getClosingDate).toList().stream() .max(Comparator.comparing(Date::getTime)); - campaignMoogDto.setCollectionStartDate(dateMin.get().getTime()); - campaignMoogDto.setCollectionEndDate(dateMax.get().getTime()); - - moogCampaigns.add(campaignMoogDto); + if (dateMin.isPresent() && dateMax.isPresent()) { + campaignMoogDto.setCollectionStartDate(dateMin.get().getTime()); + campaignMoogDto.setCollectionEndDate(dateMax.get().getTime()); + moogCampaigns.add(campaignMoogDto); + } else { + log.warn("No start date or end date found for campaign {}", campaign.getId()); + } } return moogCampaigns; } @@ -146,7 +147,7 @@ public boolean isCampaignOngoing(String idCampaign) throws NotFoundException { LOGGER.info("Partitiong {} of campaign {} is closed", part.getId(), idCampaign); } } - return camp.get().getPartitionings().size() != 0 && nbOnGoingParts == camp.get().getPartitionings().size(); + return !camp.get().getPartitionings().isEmpty() && nbOnGoingParts == camp.get().getPartitionings().size(); } }