use of alfio.model.Event in project alf.io by alfio-event.
the class EventManagerIntegrationTest method testEventGenerationWithOverflow.
@Test(expected = IllegalArgumentException.class)
public void testEventGenerationWithOverflow() {
List<TicketCategoryModification> categories = Arrays.asList(new TicketCategoryModification(null, "default", 10, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", true, null, null, null, null, null), new TicketCategoryModification(null, "default", 10, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", true, null, null, null, null, null), new TicketCategoryModification(null, "default", 0, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null));
Event event = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository).getKey();
List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
assertNotNull(tickets);
assertFalse(tickets.isEmpty());
assertEquals(AVAILABLE_SEATS, tickets.size());
assertTrue(tickets.stream().noneMatch(t -> t.getCategoryId() == null));
}
use of alfio.model.Event in project alf.io by alfio-event.
the class SpecialPriceManagerTest method sendSuccessfulComplete.
@Test
public void sendSuccessfulComplete() throws Exception {
assertTrue(specialPriceManager.sendCodeToAssignee(singletonList(new SendCodeModification("123", "me", "me@domain.com", "it")), "", 0, ""));
ArgumentCaptor<TextTemplateGenerator> templateCaptor = ArgumentCaptor.forClass(TextTemplateGenerator.class);
verify(notificationManager).sendSimpleEmail(eq(event), eq("me@domain.com"), anyString(), templateCaptor.capture());
templateCaptor.getValue().generate();
ArgumentCaptor<Map> captor = ArgumentCaptor.forClass(Map.class);
verify(templateManager).renderTemplate(any(Event.class), eq(TemplateResource.SEND_RESERVED_CODE), captor.capture(), eq(Locale.ITALIAN));
Map<String, Object> model = captor.getValue();
assertEquals("123", model.get("code"));
assertEquals(event, model.get("event"));
assertEquals(organization, model.get("organization"));
assertEquals("http://my-event", model.get("eventPage"));
assertEquals("me", model.get("assignee"));
verify(messageSource).getMessage(eq("email-code.subject"), eq(new Object[] { "Event Name" }), eq(Locale.ITALIAN));
}
use of alfio.model.Event in project alf.io by alfio-event.
the class AdditionalServiceApiController method update.
@RequestMapping(value = "/event/{eventId}/additional-services/{additionalServiceId}", method = RequestMethod.PUT)
@Transactional
public ResponseEntity<EventModification.AdditionalService> update(@PathVariable("eventId") int eventId, @PathVariable("additionalServiceId") int additionalServiceId, @RequestBody EventModification.AdditionalService additionalService, BindingResult bindingResult) {
ValidationResult validationResult = Validator.validateAdditionalService(additionalService, bindingResult);
Validate.isTrue(validationResult.isSuccess(), "validation failed");
Validate.isTrue(additionalServiceId == additionalService.getId(), "wrong input");
return eventRepository.findOptionalById(eventId).map(event -> {
int result = additionalServiceRepository.update(additionalServiceId, additionalService.isFixPrice(), additionalService.getOrdinal(), additionalService.getAvailableQuantity(), additionalService.getMaxQtyPerOrder(), additionalService.getInception().toZonedDateTime(event.getZoneId()), additionalService.getExpiration().toZonedDateTime(event.getZoneId()), additionalService.getVat(), additionalService.getVatType(), Optional.ofNullable(additionalService.getPrice()).map(MonetaryUtil::unitToCents).orElse(0));
Validate.isTrue(result <= 1, "too many records updated");
Stream.concat(additionalService.getTitle().stream(), additionalService.getDescription().stream()).forEach(t -> {
if (t.getId() != null) {
additionalServiceTextRepository.update(t.getId(), t.getLocale(), t.getType(), t.getValue());
} else {
additionalServiceTextRepository.insert(additionalService.getId(), t.getLocale(), t.getType(), t.getValue());
}
});
return ResponseEntity.ok(additionalService);
}).orElseThrow(IllegalArgumentException::new);
}
use of alfio.model.Event in project alf.io by alfio-event.
the class EmailMessageApiController method loadEmailMessages.
@RequestMapping("/")
public PageAndContent<List<LightweightEmailMessage>> loadEmailMessages(@PathVariable("eventName") String eventName, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "search", required = false) String search, Principal principal) {
Event event = eventManager.getSingleEvent(eventName, principal.getName());
ZoneId zoneId = event.getZoneId();
Pair<Integer, List<LightweightMailMessage>> found = notificationManager.loadAllMessagesForEvent(event.getId(), page, search);
return new PageAndContent<>(found.getRight().stream().map(m -> new LightweightEmailMessage(m, zoneId, true)).collect(Collectors.toList()), found.getLeft());
}
use of alfio.model.Event in project alf.io by alfio-event.
the class ExtensionApiController method bulkUpdateEvent.
@PostMapping("/setting/organization/{orgShortName}/event/{shortName}/bulk-update")
public void bulkUpdateEvent(@PathVariable("orgShortName") String orgShortName, @PathVariable("shortName") String eventShortName, @RequestBody List<ExtensionMetadataValue> toUpdate, Principal principal) {
Organization org = organizationRepository.findByName(orgShortName).orElseThrow(IllegalStateException::new);
ensureOrganization(principal, org);
Event event = eventRepository.findByShortName(eventShortName);
ensureEventInOrganization(org, event);
String pattern = String.format("-%d-%d", org.getId(), event.getId());
ensureIdsArePresent(toUpdate, extensionService.getConfigurationParametersFor(pattern, pattern, "EVENT"));
extensionService.bulkUpdateEventSettings(org, event, toUpdate);
}
Aggregations