Skip to content

Commit

Permalink
#110 - fix wrong check
Browse files Browse the repository at this point in the history
  • Loading branch information
cbellone committed Jul 5, 2016
1 parent 0490581 commit e5cd913
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/main/java/alfio/controller/form/ReservationForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,19 @@ public Optional<Pair<List<TicketReservationWithOptionalCodeModification>, List<A
final List<TicketReservationModification> categories = selected();
final List<AdditionalServiceReservationModification> additionalServices = selectedAdditionalServices();

final boolean wrongCategorySelected = categories.stream().filter(c -> {
final boolean validCategorySelection = categories.stream().allMatch(c -> {
TicketCategory tc = eventManager.getTicketCategoryById(c.getTicketCategoryId(), event.getId());
return OptionalWrapper.optionally(() -> eventManager.findEventByTicketCategory(tc)).isPresent();
}).count() != selectionCount;
});

final boolean wrongAdditionalServiceSelected = additionalServices.stream().filter(asm -> {
final boolean validAdditionalServiceSelected = additionalServices.stream().allMatch(asm -> {
AdditionalService as = eventManager.getAdditionalServiceById(asm.getAdditionalServiceId(), event.getId());
ZonedDateTime now = ZonedDateTime.now(event.getZoneId());
return as.getInception(event.getZoneId()).isBefore(now) && as.getExpiration(event.getZoneId()).isAfter(now) &&
OptionalWrapper.optionally(() -> eventManager.findEventByAdditionalService(as)).isPresent();
}).count() != additionalServicesCount;
});

if(wrongCategorySelected || wrongAdditionalServiceSelected) {
if(!validCategorySelection || !validAdditionalServiceSelected) {
bindingResult.reject(ErrorsCode.STEP_1_TICKET_CATEGORY_MUST_BE_SALEABLE);
return Optional.empty();
}
Expand Down

0 comments on commit e5cd913

Please sign in to comment.