Search in sources :

Example 26 with Event

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());
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Event(alfio.model.Event) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 27 with Event

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);
}
Also used : LocalDateTime(java.time.LocalDateTime) Organization(alfio.model.user.Organization) DateTimeModification(alfio.model.modification.DateTimeModification) LocationDescriptor(alfio.model.modification.support.LocationDescriptor) EventModification(alfio.model.modification.EventModification) Event(alfio.model.Event)

Example 28 with Event

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;
}
Also used : HashMap(java.util.HashMap) Event(alfio.model.Event) ValidationResult(alfio.model.result.ValidationResult) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 29 with Event

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);
}
Also used : PriceContainer(alfio.model.PriceContainer) ValidationResult(alfio.model.result.ValidationResult) AffectedRowCountAndKey(ch.digitalfondue.npjt.AffectedRowCountAndKey) Autowired(org.springframework.beans.factory.annotation.Autowired) BindingResult(org.springframework.validation.BindingResult) EventModification(alfio.model.modification.EventModification) BigDecimal(java.math.BigDecimal) AdditionalServiceRepository(alfio.repository.AdditionalServiceRepository) AdditionalServiceTextRepository(alfio.repository.AdditionalServiceTextRepository) EventRepository(alfio.repository.EventRepository) Validator(alfio.util.Validator) Collectors(java.util.stream.Collectors) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) AdditionalService(alfio.model.AdditionalService) Validate(org.apache.commons.lang3.Validate) Principal(java.security.Principal) Stream(java.util.stream.Stream) MonetaryUtil(alfio.util.MonetaryUtil) Log4j2(lombok.extern.log4j.Log4j2) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) Optional(java.util.Optional) ResponseEntity(org.springframework.http.ResponseEntity) Event(alfio.model.Event) Collections(java.util.Collections) OptionalWrapper.optionally(alfio.util.OptionalWrapper.optionally) Transactional(org.springframework.transaction.annotation.Transactional) AffectedRowCountAndKey(ch.digitalfondue.npjt.AffectedRowCountAndKey) ValidationResult(alfio.model.result.ValidationResult) Transactional(org.springframework.transaction.annotation.Transactional)

Example 30 with Event

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;
}
Also used : java.util(java.util) ZonedDateTime(java.time.ZonedDateTime) SaleableTicketCategory(alfio.controller.decorator.SaleableTicketCategory) ConfigurationManager(alfio.manager.system.ConfigurationManager) Collections.singletonList(java.util.Collections.singletonList) Pair(org.apache.commons.lang3.tuple.Pair) HttpServletResponse(javax.servlet.http.HttpServletResponse) STOP_WAITING_QUEUE_SUBSCRIPTIONS(alfio.model.system.ConfigurationKeys.STOP_WAITING_QUEUE_SUBSCRIPTIONS) Collectors(java.util.stream.Collectors) HttpStatus(org.springframework.http.HttpStatus) TicketReservationManager(alfio.manager.TicketReservationManager) WaitingQueueSubscription(alfio.model.WaitingQueueSubscription) EventManager(alfio.manager.EventManager) Principal(java.security.Principal) ConfigurationModification(alfio.model.modification.ConfigurationModification) EventStatisticsManager(alfio.manager.EventStatisticsManager) Configuration(alfio.model.system.Configuration) Data(lombok.Data) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) EventUtil(alfio.util.EventUtil) ResponseEntity(org.springframework.http.ResponseEntity) Event(alfio.model.Event) AllArgsConstructor(lombok.AllArgsConstructor) ConfigurationKeys(alfio.model.system.ConfigurationKeys) WaitingQueueManager(alfio.manager.WaitingQueueManager) OptionalWrapper.optionally(alfio.util.OptionalWrapper.optionally) ZonedDateTime(java.time.ZonedDateTime) SaleableTicketCategory(alfio.controller.decorator.SaleableTicketCategory)

Aggregations

Event (alfio.model.Event)71 Test (org.junit.Test)28 Ticket (alfio.model.Ticket)24 TicketCategory (alfio.model.TicketCategory)21 Organization (alfio.model.user.Organization)13 java.util (java.util)11 ZonedDateTime (java.time.ZonedDateTime)10 Autowired (org.springframework.beans.factory.annotation.Autowired)10 BigDecimal (java.math.BigDecimal)9 TicketReservation (alfio.model.TicketReservation)7 ConfigurationKeys (alfio.model.system.ConfigurationKeys)7 Collectors (java.util.stream.Collectors)7 Log4j2 (lombok.extern.log4j.Log4j2)7 StringUtils (org.apache.commons.lang3.StringUtils)7 ConfigurationManager (alfio.manager.system.ConfigurationManager)6 Configuration (alfio.model.system.Configuration)5 TicketRepository (alfio.repository.TicketRepository)5 Pair (org.apache.commons.lang3.tuple.Pair)5 Triple (org.apache.commons.lang3.tuple.Triple)5 UserManager (alfio.manager.user.UserManager)4