use of alfio.model.Event in project alf.io by alfio-event.
the class EventRepositoryTest method testJavaInsertedDatesRespectTheirTimeZone.
@Test
public void testJavaInsertedDatesRespectTheirTimeZone() throws Exception {
// these are the values of what we have inserted in the SQL insert script
ZonedDateTime beginEventDate = ZonedDateTime.of(2015, 4, 18, 0, 0, 0, 0, ZoneId.of("America/New_York"));
ZonedDateTime endEventDate = ZonedDateTime.of(2015, 4, 19, 23, 59, 59, 0, ZoneId.of("America/New_York"));
int orgId = organizationRepository.getIdByName(ORG_NAME);
AffectedRowCountAndKey<Integer> pair = eventRepository.insert("unittest", Event.EventType.INTERNAL, "display Name", "http://localhost:8080/", "http://localhost:8080", "http://localhost:8080", null, null, "Lugano", "9", "8", beginEventDate, endEventDate, NEW_YORK_TZ, "CHF", 4, true, new BigDecimal(1), "", "", orgId, 7, PriceContainer.VatStatus.INCLUDED, 0, null, Event.Status.PUBLIC);
Event e = eventRepository.findById(pair.getKey());
assertNotNull("Event not found in DB", e);
assertEquals("Begin date is not correct", beginEventDate, e.getBegin());
assertEquals("End date is not correct", endEventDate, e.getEnd());
// since when debugging the toString method is used .... and it rely on the system TimeZone, we test it too
System.out.println(e.getBegin().toString());
System.out.println(e.getEnd().toString());
}
use of alfio.model.Event in project alf.io by alfio-event.
the class IntegrationTestUtil method initEvent.
public static Pair<Event, String> initEvent(List<TicketCategoryModification> categories, OrganizationRepository organizationRepository, UserManager userManager, EventManager eventManager, EventRepository eventRepository, List<EventModification.AdditionalService> additionalServices) {
String organizationName = UUID.randomUUID().toString();
String username = UUID.randomUUID().toString();
String eventName = UUID.randomUUID().toString();
userManager.createOrganization(organizationName, "org", "email@example.com");
Organization organization = organizationRepository.findByName(organizationName).get();
userManager.insertUser(organization.getId(), username, "test", "test", "test@example.com", Role.OPERATOR, User.Type.INTERNAL);
userManager.insertUser(organization.getId(), username + "_owner", "test", "test", "test@example.com", Role.OWNER, User.Type.INTERNAL);
LocalDateTime expiration = LocalDateTime.now().plusDays(5).plusHours(1);
Map<String, String> desc = new HashMap<>();
desc.put("en", "muh description");
desc.put("it", "muh description");
desc.put("de", "muh description");
EventModification em = new EventModification(null, Event.EventType.INTERNAL, "url", "url", "url", "url", null, eventName, "event display name", organization.getId(), "muh location", "0.0", "0.0", ZoneId.systemDefault().getId(), desc, new DateTimeModification(LocalDate.now().plusDays(5), LocalTime.now()), new DateTimeModification(expiration.toLocalDate(), expiration.toLocalTime()), BigDecimal.TEN, "CHF", AVAILABLE_SEATS, BigDecimal.ONE, true, Collections.singletonList(PaymentProxy.OFFLINE), categories, false, new LocationDescriptor("", "", "", ""), 7, null, additionalServices);
eventManager.createEvent(em);
Event event = eventManager.getSingleEvent(eventName, username);
Assert.assertEquals(AVAILABLE_SEATS, eventRepository.countExistingTickets(event.getId()).intValue());
return Pair.of(event, username);
}
use of alfio.model.Event in project alf.io by alfio-event.
the class WaitingQueueApiController method subscribe.
@RequestMapping(value = "/event/{eventName}/waiting-queue/subscribe", method = RequestMethod.POST, headers = "X-Requested-With=XMLHttpRequest")
public Map<String, Object> subscribe(WaitingQueueSubscriptionForm subscription, BindingResult bindingResult, Model model, @PathVariable("eventName") String eventName, HttpServletRequest request) {
Optional<Event> optional = eventRepository.findOptionalByShortName(eventName);
Map<String, Object> result = new HashMap<>();
if (!optional.isPresent()) {
bindingResult.reject("");
result.put("validationResult", ValidationResult.failed(new ValidationResult.ErrorDescriptor("shortName", "error.shortName")));
return result;
}
Event event = optional.get();
ValidationResult validationResult = Validator.validateWaitingQueueSubscription(subscription, bindingResult, event);
if (validationResult.isSuccess()) {
model.addAttribute("error", !waitingQueueManager.subscribe(event, subscription.toCustomerName(event), subscription.getEmail(), subscription.getSelectedCategory(), subscription.getUserLanguage()));
result.put("partial", templateManager.renderServletContextResource("/WEB-INF/templates/event/waiting-queue-subscription-result.ms", model.asMap(), request, HTML));
}
result.put("validationResult", validationResult);
return result;
}
use of alfio.model.Event in project alf.io by alfio-event.
the class AdditionalServiceApiController method insert.
@RequestMapping(value = "/event/{eventId}/additional-services", method = RequestMethod.POST)
@Transactional
public ResponseEntity<EventModification.AdditionalService> insert(@PathVariable("eventId") int eventId, @RequestBody EventModification.AdditionalService additionalService, BindingResult bindingResult) {
ValidationResult validationResult = Validator.validateAdditionalService(additionalService, bindingResult);
Validate.isTrue(validationResult.isSuccess(), "validation failed");
return eventRepository.findOptionalById(eventId).map(event -> {
AffectedRowCountAndKey<Integer> result = additionalServiceRepository.insert(eventId, Optional.ofNullable(additionalService.getPrice()).map(MonetaryUtil::unitToCents).orElse(0), additionalService.isFixPrice(), additionalService.getOrdinal(), additionalService.getAvailableQuantity(), additionalService.getMaxQtyPerOrder(), additionalService.getInception().toZonedDateTime(event.getZoneId()), additionalService.getExpiration().toZonedDateTime(event.getZoneId()), additionalService.getVat(), additionalService.getVatType(), additionalService.getType(), additionalService.getSupplementPolicy());
Validate.isTrue(result.getAffectedRowCount() == 1, "too many records updated");
int id = result.getKey();
Stream.concat(additionalService.getTitle().stream(), additionalService.getDescription().stream()).forEach(t -> additionalServiceTextRepository.insert(id, t.getLocale(), t.getType(), t.getValue()));
return ResponseEntity.ok(EventModification.AdditionalService.from(additionalServiceRepository.getById(result.getKey(), eventId)).withText(additionalServiceTextRepository.findAllByAdditionalServiceId(result.getKey())).withZoneId(event.getZoneId()).build());
}).orElseThrow(IllegalArgumentException::new);
}
use of alfio.model.Event in project alf.io by alfio-event.
the class AdminWaitingQueueApiController method loadStatus.
private Map<String, Boolean> loadStatus(Event event) {
ZonedDateTime now = ZonedDateTime.now(event.getZoneId());
List<SaleableTicketCategory> stcList = eventManager.loadTicketCategories(event).stream().filter(tc -> !tc.isAccessRestricted()).map(tc -> new SaleableTicketCategory(tc, "", now, event, ticketReservationManager.countAvailableTickets(event, tc), tc.getMaxTickets(), null)).collect(Collectors.toList());
boolean active = EventUtil.checkWaitingQueuePreconditions(event, stcList, configurationManager, eventStatisticsManager.noSeatsAvailable());
boolean paused = active && configurationManager.getBooleanConfigValue(Configuration.from(event.getOrganizationId(), event.getId(), STOP_WAITING_QUEUE_SUBSCRIPTIONS), false);
Map<String, Boolean> result = new HashMap<>();
result.put("active", active);
result.put("paused", paused);
return result;
}
Aggregations