Skip to content

Commit

Permalink
[fix] get moog campaigns bug
Browse files Browse the repository at this point in the history
  • Loading branch information
BettyB979 committed Sep 28, 2023
1 parent 951d94f commit c5915cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</parent>
<groupId>fr.insee.survey</groupId>
<artifactId>platine-management</artifactId>
<version>1.0.22</version>
<version>1.0.23</version>
<name>platine-management</name>
<description>REST API for communication between DB and Platine-Management UI and Platine-My-Surveys UI</description>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,25 @@ public class CampaignServiceImpl implements CampaignService {
public Collection<CampaignMoogDto> getCampaigns() {

List<CampaignMoogDto> moogCampaigns = new ArrayList<>();
List<Campaign> campaigns = campaignRepository.findAll();
List<Campaign> 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<Date> dateMin = campaign.getPartitionings().stream().map(Partitioning::getOpeningDate)
.collect(Collectors.toList()).stream()
Optional<Date> dateMin = campaign.getPartitionings().stream().map(Partitioning::getOpeningDate).toList().stream()
.min(Comparator.comparing(Date::getTime));
Optional<Date> dateMax = campaign.getPartitionings().stream().map(Partitioning::getClosingDate)
.collect(Collectors.toList()).stream()
Optional<Date> 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;
}
Expand Down Expand Up @@ -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();
}

}

0 comments on commit c5915cd

Please sign in to comment.