Skip to content

Commit

Permalink
[SELC-5299] Fix count notification (#400)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-putzu authored Jul 17, 2024
1 parent 7c9169a commit a406b9d
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -276,12 +277,15 @@ public NotificationCountResult countNotificationsByFilters(String productId, Str
return new NotificationCountResult(productId, total);
}

private Document createQuery(String productId, List<OnboardingStatus> status, String from, String to, String dateField) {
private Document createQuery(String productId, List<OnboardingStatus> status, String from, String to, String dateField, boolean workflowTypeExist) {
Document query = new Document();
query.append("productId", productId);
query.append("status", new Document("$in", status.stream().map(OnboardingStatus::name).toList()));
query.append("workflowType", new Document("$in", ALLOWED_WORKFLOWS_FOR_INSTITUTION_NOTIFICATIONS.stream().map(Enum::name).toList()));

if (workflowTypeExist) {
query.append("workflowType", new Document("$in", ALLOWED_WORKFLOWS_FOR_INSTITUTION_NOTIFICATIONS.stream().map(Enum::name).toList()));
} else {
query.append("workflowType", new Document("$exists", false));
}
Document dateQuery = new Document();
Optional.ofNullable(from).ifPresent(value -> query.append(dateField, dateQuery.append("$gte", LocalDate.parse(from, DateTimeFormatter.ISO_LOCAL_DATE))));
Optional.ofNullable(to).ifPresent(value -> query.append(dateField, dateQuery.append("$lte", LocalDate.parse(to, DateTimeFormatter.ISO_LOCAL_DATE))));
Expand All @@ -291,6 +295,15 @@ private Document createQuery(String productId, List<OnboardingStatus> status, St
return query;
}

private Document createQuery(String productId, List<OnboardingStatus> status, String from, String to, String dateField) {
Document query = new Document();
List<Document> workflowCriteria = new ArrayList<>();
workflowCriteria.add(createQuery(productId, status, from, to, dateField, true));
workflowCriteria.add(createQuery(productId, status, from, to, dateField, false));
query.append("$or", workflowCriteria);
return query;
}

public List<Onboarding> getOnboardingsToResend(ResendNotificationsFilters filters, int page, int pageSize) {
return repository.find(createQueryByFilters(filters)).page(page, pageSize).list();
}
Expand Down

0 comments on commit a406b9d

Please sign in to comment.