Search in sources :

Example 1 with Event

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

the class DynamicResourcesController method getGoogleAnalyticsScript.

@RequestMapping("/resources/js/google-analytics")
public void getGoogleAnalyticsScript(HttpSession session, HttpServletResponse response, @RequestParam("e") Integer eventId) throws IOException {
    response.setContentType("application/javascript");
    Optional<Event> ev = Optional.ofNullable(eventId).flatMap(id -> Optional.ofNullable(eventRepository.findById(id)));
    ConfigurationPathKey pathKey = ev.map(e -> Configuration.from(e.getOrganizationId(), e.getId(), GOOGLE_ANALYTICS_KEY)).orElseGet(() -> Configuration.getSystemConfiguration(GOOGLE_ANALYTICS_KEY));
    final Optional<String> id = configurationManager.getStringConfigValue(pathKey);
    final String script;
    ConfigurationPathKey anonymousPathKey = ev.map(e -> Configuration.from(e.getOrganizationId(), e.getId(), GOOGLE_ANALYTICS_ANONYMOUS_MODE)).orElseGet(() -> Configuration.getSystemConfiguration(GOOGLE_ANALYTICS_ANONYMOUS_MODE));
    if (id.isPresent() && configurationManager.getBooleanConfigValue(anonymousPathKey, true)) {
        String trackingId = Optional.ofNullable(StringUtils.trimToNull((String) session.getAttribute("GA_TRACKING_ID"))).orElseGet(() -> UUID.randomUUID().toString());
        Map<String, Object> model = new HashMap<>();
        model.put("clientId", trackingId);
        model.put("account", id.get());
        script = templateManager.renderTemplate(TemplateResource.GOOGLE_ANALYTICS, model, Locale.ENGLISH);
    } else {
        script = id.map(x -> String.format(GOOGLE_ANALYTICS_SCRIPT, x)).orElse(EMPTY);
    }
    response.getWriter().write(script);
}
Also used : ConfigurationPathKey(alfio.model.system.Configuration.ConfigurationPathKey) HttpSession(javax.servlet.http.HttpSession) RequestParam(org.springframework.web.bind.annotation.RequestParam) java.util(java.util) ConfigurationPathKey(alfio.model.system.Configuration.ConfigurationPathKey) GOOGLE_ANALYTICS_KEY(alfio.model.system.ConfigurationKeys.GOOGLE_ANALYTICS_KEY) TemplateManager(alfio.util.TemplateManager) HttpServletResponse(javax.servlet.http.HttpServletResponse) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) IOException(java.io.IOException) ConfigurationManager(alfio.manager.system.ConfigurationManager) Controller(org.springframework.stereotype.Controller) EventRepository(alfio.repository.EventRepository) StringUtils(org.apache.commons.lang3.StringUtils) GOOGLE_ANALYTICS_ANONYMOUS_MODE(alfio.model.system.ConfigurationKeys.GOOGLE_ANALYTICS_ANONYMOUS_MODE) Configuration(alfio.model.system.Configuration) Event(alfio.model.Event) TemplateResource(alfio.util.TemplateResource) Event(alfio.model.Event) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Event

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

the class TicketController method generateTicketCode.

@RequestMapping(value = "/event/{eventName}/ticket/{ticketIdentifier}/code.png", method = RequestMethod.GET)
public void generateTicketCode(@PathVariable("eventName") String eventName, @PathVariable("ticketIdentifier") String ticketIdentifier, HttpServletResponse response) throws IOException, WriterException {
    Optional<Triple<Event, TicketReservation, Ticket>> oData = ticketReservationManager.fetchCompleteAndAssigned(eventName, ticketIdentifier);
    if (!oData.isPresent()) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return;
    }
    Triple<Event, TicketReservation, Ticket> data = oData.get();
    Event event = data.getLeft();
    Ticket ticket = data.getRight();
    String qrCodeText = ticket.ticketCode(event.getPrivateKey());
    response.setContentType("image/png");
    response.getOutputStream().write(ImageUtil.createQRCode(qrCodeText));
}
Also used : Triple(org.apache.commons.lang3.tuple.Triple) Ticket(alfio.model.Ticket) Event(alfio.model.Event) TicketReservation(alfio.model.TicketReservation)

Example 3 with Event

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

the class TicketController method internalSendTicketByEmail.

private Ticket internalSendTicketByEmail(HttpServletRequest request, Triple<Event, TicketReservation, Ticket> data) throws IOException {
    Ticket ticket = data.getRight();
    Event event = data.getLeft();
    Locale locale = LocaleUtil.getTicketLanguage(ticket, request);
    TicketReservation reservation = data.getMiddle();
    Organization organization = organizationRepository.getById(event.getOrganizationId());
    TicketCategory category = ticketCategoryRepository.getById(ticket.getCategoryId());
    notificationManager.sendTicketByEmail(ticket, event, locale, TemplateProcessor.buildPartialEmail(event, organization, reservation, category, templateManager, ticketReservationManager.ticketUpdateUrl(event, ticket.getUuid()), request), reservation, ticketCategoryRepository.getByIdAndActive(ticket.getCategoryId(), event.getId()));
    return ticket;
}
Also used : Locale(java.util.Locale) Ticket(alfio.model.Ticket) Organization(alfio.model.user.Organization) Event(alfio.model.Event) TicketCategory(alfio.model.TicketCategory) TicketReservation(alfio.model.TicketReservation)

Example 4 with Event

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

the class CustomMessageManager method generatePreview.

public Map<String, Object> generatePreview(String eventName, Optional<Integer> categoryId, List<MessageModification> input, String username) {
    Map<String, Object> result = new HashMap<>();
    Event event = eventManager.getSingleEvent(eventName, username);
    result.put("affectedUsers", categoryId.map(id -> ticketRepository.countAssignedTickets(event.getId(), id)).orElseGet(() -> ticketRepository.countAllAssigned(event.getId())));
    result.put("preview", preview(event, input, username));
    return result;
}
Also used : Event(alfio.model.Event)

Example 5 with Event

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

the class ConfigurationManager method deleteCategoryLevelByKey.

public void deleteCategoryLevelByKey(String key, int eventId, int categoryId, String username) {
    Event event = eventRepository.findById(eventId);
    Validate.notNull(event, "Wrong event id");
    Validate.isTrue(userManager.isOwnerOfOrganization(userManager.findUserByUsername(username), event.getOrganizationId()), "User is not owner of the organization. Therefore, delete is not allowed.");
    configurationRepository.deleteCategoryLevelByKey(key, eventId, categoryId);
}
Also used : 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