Search in sources :

Example 16 with Organization

use of alfio.model.user.Organization in project alf.io by alfio-event.

the class ExtensionApiController method deleteOrganizationSettingValue.

@DeleteMapping("/setting/organization/{orgShortName}/{id}")
public void deleteOrganizationSettingValue(@PathVariable("orgShortName") String orgShortName, @PathVariable("id") int id, Principal principal) {
    Organization org = organizationRepository.findByName(orgShortName).orElseThrow(IllegalStateException::new);
    ensureOrganization(principal, org);
    extensionService.deleteSettingValue(id, "-" + org.getId());
}
Also used : Organization(alfio.model.user.Organization)

Example 17 with Organization

use of alfio.model.user.Organization in project alf.io by alfio-event.

the class TicketController method internalShowTicket.

private String internalShowTicket(String eventName, String ticketIdentifier, boolean ticketEmailSent, Model model, String backSuffix, Locale locale) {
    Optional<Triple<Event, TicketReservation, Ticket>> oData = ticketReservationManager.fetchCompleteAndAssigned(eventName, ticketIdentifier);
    if (!oData.isPresent()) {
        return "redirect:/event/" + eventName;
    }
    Triple<Event, TicketReservation, Ticket> data = oData.get();
    TicketCategory ticketCategory = ticketCategoryRepository.getByIdAndActive(data.getRight().getCategoryId(), data.getLeft().getId());
    Organization organization = organizationRepository.getById(data.getLeft().getOrganizationId());
    Event event = data.getLeft();
    TicketReservation reservation = data.getMiddle();
    // 
    model.addAttribute("ticket", data.getRight()).addAttribute("reservation", // 
    reservation).addAttribute("event", // 
    event).addAttribute("ticketCategory", // 
    ticketCategory).addAttribute("organization", // 
    organization).addAttribute("ticketEmailSent", ticketEmailSent).addAttribute("reservationId", ticketReservationManager.getShortReservationID(event, reservation.getId())).addAttribute("deskPaymentRequired", Optional.ofNullable(reservation.getPaymentMethod()).orElse(PaymentProxy.STRIPE).isDeskPaymentRequired()).addAttribute("backSuffix", backSuffix).addAttribute("userLanguage", locale.getLanguage()).addAttribute("pageTitle", "show-ticket.header.title").addAttribute("useFirstAndLastName", event.mustUseFirstAndLastName()).addAttribute("validityStart", Optional.ofNullable(ticketCategory.getTicketValidityStart(event.getZoneId())).orElse(event.getBegin())).addAttribute("validityEnd", Optional.ofNullable(ticketCategory.getTicketValidityEnd(event.getZoneId())).orElse(event.getEnd())).addAttribute("ticketIdParam", "ticketId=" + ticketIdentifier);
    return "/event/show-ticket";
}
Also used : Triple(org.apache.commons.lang3.tuple.Triple) Ticket(alfio.model.Ticket) Organization(alfio.model.user.Organization) Event(alfio.model.Event) TicketCategory(alfio.model.TicketCategory) TicketReservation(alfio.model.TicketReservation)

Example 18 with Organization

use of alfio.model.user.Organization in project alf.io by alfio-event.

the class TicketController method showTicketForUpdate.

@RequestMapping(value = "/event/{eventName}/ticket/{ticketIdentifier}/update", method = RequestMethod.GET)
public String showTicketForUpdate(@PathVariable("eventName") String eventName, @PathVariable("ticketIdentifier") String ticketIdentifier, Model model, Locale locale) {
    Optional<Triple<Event, TicketReservation, Ticket>> oData = ticketReservationManager.fetchCompleteAndAssigned(eventName, ticketIdentifier);
    if (!oData.isPresent()) {
        return "redirect:/event/" + eventName;
    }
    Triple<Event, TicketReservation, Ticket> data = oData.get();
    Event event = data.getLeft();
    TicketCategory ticketCategory = ticketCategoryRepository.getByIdAndActive(data.getRight().getCategoryId(), event.getId());
    Organization organization = organizationRepository.getById(event.getOrganizationId());
    boolean enableFreeCancellation = configurationManager.getBooleanConfigValue(Configuration.from(event.getOrganizationId(), event.getId(), ticketCategory.getId(), ALLOW_FREE_TICKETS_CANCELLATION), false);
    Ticket ticket = data.getRight();
    // 
    model.addAttribute("ticketAndCategory", Pair.of(eventManager.getTicketCategoryById(ticket.getCategoryId(), event.getId()), new TicketDecorator(ticket, enableFreeCancellation, eventManager.checkTicketCancellationPrerequisites().apply(ticket), "ticket/" + ticket.getUuid() + "/view", ticketHelper.findTicketFieldConfigurationAndValue(event.getId(), ticket, locale), true, ""))).addAttribute("reservation", // 
    data.getMiddle()).addAttribute("reservationId", ticketReservationManager.getShortReservationID(event, data.getMiddle().getId())).addAttribute("event", // 
    event).addAttribute("ticketCategory", // 
    ticketCategory).addAttribute("countries", TicketHelper.getLocalizedCountries(locale)).addAttribute("organization", // 
    organization).addAttribute("pageTitle", "show-ticket.header.title").addAttribute("useFirstAndLastName", event.mustUseFirstAndLastName());
    return "/event/update-ticket";
}
Also used : Triple(org.apache.commons.lang3.tuple.Triple) TicketDecorator(alfio.controller.support.TicketDecorator) Ticket(alfio.model.Ticket) Organization(alfio.model.user.Organization) Event(alfio.model.Event) TicketCategory(alfio.model.TicketCategory) TicketReservation(alfio.model.TicketReservation)

Example 19 with Organization

use of alfio.model.user.Organization in project alf.io by alfio-event.

the class SpecialPriceManager method sendCodeToAssignee.

public boolean sendCodeToAssignee(List<SendCodeModification> input, String eventName, int categoryId, String username) {
    final Event event = eventManager.getSingleEvent(eventName, username);
    final Organization organization = eventManager.loadOrganizer(event, username);
    Set<SendCodeModification> set = new LinkedHashSet<>(input);
    checkCodeAssignment(set, categoryId, event, username);
    Validate.isTrue(set.stream().allMatch(IS_CODE_PRESENT), "There are missing codes. Please check input file.");
    List<ContentLanguage> eventLanguages = i18nManager.getEventLanguages(event.getLocales());
    Validate.isTrue(!eventLanguages.isEmpty(), "No locales have been defined for the event. Please check the configuration");
    ContentLanguage defaultLocale = eventLanguages.contains(ContentLanguage.ENGLISH) ? ContentLanguage.ENGLISH : eventLanguages.get(0);
    set.forEach(m -> {
        Locale locale = Locale.forLanguageTag(StringUtils.defaultString(StringUtils.trimToNull(m.getLanguage()), defaultLocale.getLanguage()));
        Map<String, Object> model = TemplateResource.prepareModelForSendReservedCode(organization, event, m, eventManager.getEventUrl(event));
        notificationManager.sendSimpleEmail(event, m.getEmail(), messageSource.getMessage("email-code.subject", new Object[] { event.getDisplayName() }, locale), () -> templateManager.renderTemplate(event, TemplateResource.SEND_RESERVED_CODE, model, locale));
        int marked = specialPriceRepository.markAsSent(ZonedDateTime.now(event.getZoneId()), m.getAssignee().trim(), m.getEmail().trim(), m.getCode().trim());
        Validate.isTrue(marked == 1, "Expected exactly one row updated, got " + marked);
    });
    return true;
}
Also used : Organization(alfio.model.user.Organization) Event(alfio.model.Event) ContentLanguage(alfio.model.ContentLanguage) SendCodeModification(alfio.model.modification.SendCodeModification)

Example 20 with Organization

use of alfio.model.user.Organization in project alf.io by alfio-event.

the class TicketReservationManager method updateTicketOwner.

public void updateTicketOwner(Ticket ticket, Locale locale, Event event, UpdateTicketOwnerForm updateTicketOwner, PartialTicketTextGenerator confirmationTextBuilder, PartialTicketTextGenerator ownerChangeTextBuilder, Optional<UserDetails> userDetails) {
    Ticket preUpdateTicket = ticketRepository.findByUUID(ticket.getUuid());
    Map<String, String> preUpdateTicketFields = ticketFieldRepository.findAllByTicketId(ticket.getId()).stream().collect(Collectors.toMap(TicketFieldValue::getName, TicketFieldValue::getValue));
    String newEmail = updateTicketOwner.getEmail().trim();
    CustomerName customerName = new CustomerName(updateTicketOwner.getFullName(), updateTicketOwner.getFirstName(), updateTicketOwner.getLastName(), event);
    ticketRepository.updateTicketOwner(ticket.getUuid(), newEmail, customerName.getFullName(), customerName.getFirstName(), customerName.getLastName());
    // 
    Locale userLocale = Optional.ofNullable(StringUtils.trimToNull(updateTicketOwner.getUserLanguage())).map(Locale::forLanguageTag).orElse(locale);
    ticketRepository.updateOptionalTicketInfo(ticket.getUuid(), userLocale.getLanguage());
    ticketFieldRepository.updateOrInsert(updateTicketOwner.getAdditional(), ticket.getId(), event.getId());
    Ticket newTicket = ticketRepository.findByUUID(ticket.getUuid());
    if (newTicket.getStatus() == TicketStatus.ACQUIRED && (!StringUtils.equalsIgnoreCase(newEmail, ticket.getEmail()) || !StringUtils.equalsIgnoreCase(customerName.getFullName(), ticket.getFullName()))) {
        sendTicketByEmail(newTicket, userLocale, event, confirmationTextBuilder);
    }
    boolean admin = isAdmin(userDetails);
    if (!admin && StringUtils.isNotBlank(ticket.getEmail()) && !StringUtils.equalsIgnoreCase(newEmail, ticket.getEmail()) && ticket.getStatus() == TicketStatus.ACQUIRED) {
        Locale oldUserLocale = Locale.forLanguageTag(ticket.getUserLanguage());
        String subject = messageSource.getMessage("ticket-has-changed-owner-subject", new Object[] { event.getDisplayName() }, oldUserLocale);
        notificationManager.sendSimpleEmail(event, ticket.getEmail(), subject, () -> ownerChangeTextBuilder.generate(newTicket));
        if (event.getBegin().isBefore(ZonedDateTime.now(event.getZoneId()))) {
            Organization organization = organizationRepository.getById(event.getOrganizationId());
            notificationManager.sendSimpleEmail(event, organization.getEmail(), "WARNING: Ticket has been reassigned after event start", () -> ownerChangeTextBuilder.generate(newTicket));
        }
    }
    if (admin) {
        TicketReservation reservation = findById(ticket.getTicketsReservationId()).orElseThrow(IllegalStateException::new);
        // if the current user is admin, then it would be good to update also the name of the Reservation Owner
        String username = userDetails.get().getUsername();
        log.warn("Reservation {}: forced assignee replacement old: {} new: {}", reservation.getId(), reservation.getFullName(), username);
        ticketReservationRepository.updateAssignee(reservation.getId(), username);
    }
    extensionManager.handleTicketAssignment(newTicket);
    Ticket postUpdateTicket = ticketRepository.findByUUID(ticket.getUuid());
    Map<String, String> postUpdateTicketFields = ticketFieldRepository.findAllByTicketId(ticket.getId()).stream().collect(Collectors.toMap(TicketFieldValue::getName, TicketFieldValue::getValue));
    auditUpdateTicket(preUpdateTicket, preUpdateTicketFields, postUpdateTicket, postUpdateTicketFields, event.getId());
}
Also used : Organization(alfio.model.user.Organization)

Aggregations

Organization (alfio.model.user.Organization)30 Event (alfio.model.Event)13 TicketCategory (alfio.model.TicketCategory)7 Ticket (alfio.model.Ticket)6 Triple (org.apache.commons.lang3.tuple.Triple)6 TicketReservation (alfio.model.TicketReservation)4 java.util (java.util)4 Collectors (java.util.stream.Collectors)4 Log4j2 (lombok.extern.log4j.Log4j2)4 Component (org.springframework.stereotype.Component)4 DateTimeModification (alfio.model.modification.DateTimeModification)3 LocationDescriptor (alfio.model.modification.support.LocationDescriptor)3 ZonedDateTime (java.time.ZonedDateTime)3 Collections.singletonList (java.util.Collections.singletonList)3 Transactional (org.springframework.transaction.annotation.Transactional)3 EventManager (alfio.manager.EventManager)2 NotificationManager (alfio.manager.NotificationManager)2 TicketReservationManager (alfio.manager.TicketReservationManager)2 Mailer (alfio.manager.system.Mailer)2 alfio.model (alfio.model)2