Search in sources :

Example 51 with Event

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));
}
Also used : alfio.repository(alfio.repository) java.util(java.util) BeforeClass(org.junit.BeforeClass) ZonedDateTime(java.time.ZonedDateTime) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) RepositoryConfiguration(alfio.config.RepositoryConfiguration) BigDecimal(java.math.BigDecimal) ErrorCode(alfio.model.result.ErrorCode) SpringJUnit4ClassRunner(org.springframework.test.context.junit4.SpringJUnit4ClassRunner) Pair(org.apache.commons.lang3.tuple.Pair) LocalTime(java.time.LocalTime) OrganizationRepository(alfio.repository.user.OrganizationRepository) Test(org.junit.Test) IntegrationTestUtil(alfio.test.util.IntegrationTestUtil) ZoneId(java.time.ZoneId) ConfigurationRepository(alfio.repository.system.ConfigurationRepository) DateUtils(org.apache.commons.lang3.time.DateUtils) Result(alfio.model.result.Result) TicketCategory(alfio.model.TicketCategory) Initializer(alfio.config.Initializer) Ticket(alfio.model.Ticket) UserManager(alfio.manager.user.UserManager) ContextConfiguration(org.springframework.test.context.ContextConfiguration) LocalDate(java.time.LocalDate) DataSourceConfiguration(alfio.config.DataSourceConfiguration) Event(alfio.model.Event) TestConfiguration(alfio.TestConfiguration) Assert(org.junit.Assert) alfio.model.modification(alfio.model.modification) Transactional(org.springframework.transaction.annotation.Transactional) Ticket(alfio.model.Ticket) Event(alfio.model.Event) Test(org.junit.Test)

Example 52 with Event

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));
}
Also used : TextTemplateGenerator(alfio.manager.support.TextTemplateGenerator) Event(alfio.model.Event) SendCodeModification(alfio.model.modification.SendCodeModification) Test(org.junit.Test)

Example 53 with Event

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);
}
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) ValidationResult(alfio.model.result.ValidationResult) Transactional(org.springframework.transaction.annotation.Transactional)

Example 54 with Event

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());
}
Also used : ZoneId(java.time.ZoneId) Event(alfio.model.Event) List(java.util.List) PageAndContent(alfio.controller.api.support.PageAndContent) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 55 with Event

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);
}
Also used : Organization(alfio.model.user.Organization) Event(alfio.model.Event)

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