Search in sources :

Example 1 with LinkedGroup

use of alfio.model.group.LinkedGroup in project alf.io by alfio-event.

the class GroupManager method updateLink.

@Transactional
public LinkedGroup updateLink(int id, LinkedGroupModification modification) {
    LinkedGroup original = groupRepository.getConfigurationForUpdate(id);
    if (requiresCleanState(modification, original)) {
        Validate.isTrue(groupRepository.countWhitelistedTicketsForConfiguration(original.getId()) == 0, "Cannot update as there are already confirmed tickets.");
    }
    groupRepository.updateConfiguration(id, modification.getGroupId(), original.getEventId(), modification.getTicketCategoryId(), modification.getType(), modification.getMatchType(), modification.getMaxAllocation());
    return groupRepository.getConfiguration(id);
}
Also used : LinkedGroup(alfio.model.group.LinkedGroup) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with LinkedGroup

use of alfio.model.group.LinkedGroup in project alf.io by alfio-event.

the class GroupManager method acquireMemberForTicket.

@Transactional
public boolean acquireMemberForTicket(Ticket ticket) {
    List<LinkedGroup> configurations = findLinks(ticket.getEventId(), ticket.getCategoryId());
    if (CollectionUtils.isEmpty(configurations)) {
        return true;
    }
    LinkedGroup configuration = configurations.get(0);
    Optional<GroupMember> optionalItem = getMatchingMember(configuration, ticket.getEmail());
    if (optionalItem.isEmpty()) {
        return false;
    }
    GroupMember item = optionalItem.get();
    boolean preventDuplication = configuration.getType() == ONCE_PER_VALUE;
    boolean limitAssignments = preventDuplication || configuration.getType() == LIMITED_QUANTITY;
    if (limitAssignments) {
        // reload and lock configuration
        configuration = groupRepository.getConfigurationForUpdate(configuration.getId());
        int existing = groupRepository.countExistingWhitelistedTickets(item.getId(), configuration.getId());
        int expected = preventDuplication ? 1 : Optional.ofNullable(configuration.getMaxAllocation()).orElse(0);
        if (existing >= expected) {
            return false;
        }
    }
    groupRepository.insertWhitelistedTicket(item.getId(), configuration.getId(), ticket.getId(), preventDuplication ? Boolean.TRUE : null);
    Map<String, Object> modifications = new HashMap<>();
    modifications.put("itemId", item.getId());
    modifications.put("configurationId", configuration.getId());
    modifications.put("ticketId", ticket.getId());
    auditingRepository.insert(ticket.getTicketsReservationId(), null, ticket.getEventId(), Audit.EventType.GROUP_MEMBER_ACQUIRED, new Date(), Audit.EntityType.TICKET, String.valueOf(ticket.getId()), singletonList(modifications));
    return true;
}
Also used : GroupMember(alfio.model.group.GroupMember) LinkedGroup(alfio.model.group.LinkedGroup) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with LinkedGroup

use of alfio.model.group.LinkedGroup in project alf.io by alfio-event.

the class GroupManagerIntegrationTest method testDuplicates.

@Test
void testDuplicates() {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", TicketCategory.TicketAccessType.INHERIT, 10, new DateTimeModification(LocalDate.now(ClockProvider.clock()).plusDays(1), LocalTime.now(ClockProvider.clock())), new DateTimeModification(LocalDate.now(ClockProvider.clock()).plusDays(2), LocalTime.now(ClockProvider.clock())), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null, 0, null, null, AlfioMetadata.empty()));
    Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);
    Event event = pair.getKey();
    Group group = groupManager.createNew("test", "This is a test", event.getOrganizationId());
    assertNotNull(group);
    LinkedGroupModification modification = new LinkedGroupModification(null, group.getId(), event.getId(), null, LinkedGroup.Type.ONCE_PER_VALUE, LinkedGroup.MatchType.FULL, null);
    LinkedGroup configuration = groupManager.createLink(group.getId(), event.getId(), modification);
    assertNotNull(configuration);
    Result<Integer> items = groupManager.insertMembers(group.getId(), Arrays.asList(new GroupMemberModification(null, "test@test.ch", "description"), new GroupMemberModification(null, "test@test.ch", "description")));
    Assertions.assertFalse(items.isSuccess());
    assertEquals("value.duplicate", items.getFirstErrorOrNull().getCode());
    assertEquals("test@test.ch", items.getFirstErrorOrNull().getDescription());
}
Also used : Group(alfio.model.group.Group) LinkedGroup(alfio.model.group.LinkedGroup) LinkedGroup(alfio.model.group.LinkedGroup) Event(alfio.model.Event) BaseIntegrationTest(alfio.util.BaseIntegrationTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with LinkedGroup

use of alfio.model.group.LinkedGroup in project alf.io by alfio-event.

the class GroupManagerIntegrationTest method testLinkToEvent.

@Test
void testLinkToEvent() {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", TicketCategory.TicketAccessType.INHERIT, 10, new DateTimeModification(LocalDate.now(ClockProvider.clock()).plusDays(1), LocalTime.now(ClockProvider.clock())), new DateTimeModification(LocalDate.now(ClockProvider.clock()).plusDays(2), LocalTime.now(ClockProvider.clock())), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null, 0, null, null, AlfioMetadata.empty()));
    Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);
    Event event = pair.getKey();
    Group group = groupManager.createNew("test", "This is a test", event.getOrganizationId());
    assertNotNull(group);
    LinkedGroupModification modification = new LinkedGroupModification(null, group.getId(), event.getId(), null, LinkedGroup.Type.ONCE_PER_VALUE, LinkedGroup.MatchType.FULL, null);
    LinkedGroup configuration = groupManager.createLink(group.getId(), event.getId(), modification);
    assertNotNull(configuration);
    List<TicketCategory> ticketCategories = eventManager.loadTicketCategories(event);
    int categoryId = ticketCategories.get(0).getId();
    assertTrue(groupManager.isGroupLinked(event.getId(), categoryId));
    List<LinkedGroup> activeConfigurations = groupRepository.findActiveConfigurationsFor(event.getId(), categoryId);
    assertFalse(activeConfigurations.isEmpty(), "ActiveConfigurations should be empty");
    assertEquals(1, activeConfigurations.size());
    assertEquals(configuration.getId(), activeConfigurations.get(0).getId());
    assertFalse(groupManager.isAllowed("test@test.ch", event.getId(), categoryId), "Group is empty, therefore no value is allowed");
    Result<Integer> items = groupManager.insertMembers(group.getId(), Collections.singletonList(new GroupMemberModification(null, "test@test.ch", "description")));
    assertTrue(items.isSuccess());
    assertEquals(Integer.valueOf(1), items.getData());
    assertTrue(groupManager.isAllowed("test@test.ch", event.getId(), categoryId));
    TicketReservationModification ticketReservation = new TicketReservationModification();
    ticketReservation.setQuantity(1);
    ticketReservation.setTicketCategoryId(categoryId);
    String reservationId = ticketReservationManager.createTicketReservation(event, Collections.singletonList(new TicketReservationWithOptionalCodeModification(ticketReservation, Optional.empty())), Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.empty(), Locale.ENGLISH, false, null);
    Ticket ticket = ticketRepository.findFirstTicketInReservation(reservationId).orElseThrow(NullPointerException::new);
    ticketRepository.updateTicketOwnerById(ticket.getId(), "test@test.ch", "This is a Test", "This is", "a Test");
    ticket = ticketRepository.findFirstTicketInReservation(reservationId).orElseThrow(NullPointerException::new);
    assertTrue(groupManager.acquireMemberForTicket(ticket));
    reservationId = ticketReservationManager.createTicketReservation(event, Collections.singletonList(new TicketReservationWithOptionalCodeModification(ticketReservation, Optional.empty())), Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.empty(), Locale.ENGLISH, false, null);
    ticket = ticketRepository.findFirstTicketInReservation(reservationId).orElseThrow(NullPointerException::new);
    assertFalse(groupManager.acquireMemberForTicket(ticket), "shouldn't be allowed");
}
Also used : Group(alfio.model.group.Group) LinkedGroup(alfio.model.group.LinkedGroup) Ticket(alfio.model.Ticket) LinkedGroup(alfio.model.group.LinkedGroup) TicketCategory(alfio.model.TicketCategory) LocalDate(java.time.LocalDate) Event(alfio.model.Event) BaseIntegrationTest(alfio.util.BaseIntegrationTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with LinkedGroup

use of alfio.model.group.LinkedGroup in project alf.io by alfio-event.

the class GroupManager method isAllowed.

@Transactional
public boolean isAllowed(String value, int eventId, int categoryId) {
    List<LinkedGroup> configurations = findLinks(eventId, categoryId);
    if (CollectionUtils.isEmpty(configurations)) {
        return true;
    }
    LinkedGroup configuration = configurations.get(0);
    return getMatchingMember(configuration, value).isPresent();
}
Also used : LinkedGroup(alfio.model.group.LinkedGroup) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

LinkedGroup (alfio.model.group.LinkedGroup)5 Transactional (org.springframework.transaction.annotation.Transactional)3 Event (alfio.model.Event)2 Group (alfio.model.group.Group)2 BaseIntegrationTest (alfio.util.BaseIntegrationTest)2 Test (org.junit.jupiter.api.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 Ticket (alfio.model.Ticket)1 TicketCategory (alfio.model.TicketCategory)1 GroupMember (alfio.model.group.GroupMember)1 LocalDate (java.time.LocalDate)1