Search in sources :

Example 1 with EventAndOrganizationId

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

the class PollManager method updateOptions.

private void updateOptions(List<PollOptionModification> existingOptions, EventAndOrganizationId event, Long pollId) {
    var parameterSources = existingOptions.stream().map(option -> new MapSqlParameterSource("pollId", pollId).addValue("title", Json.toJson(requireNonNullElse(option.getTitle(), Map.of()))).addValue("description", Json.toJson(requireNonNullElse(option.getDescription(), Map.of()))).addValue("id", option.getId())).toArray(MapSqlParameterSource[]::new);
    int[] results = jdbcTemplate.batchUpdate(pollRepository.bulkUpdateOptions(), parameterSources);
    Validate.isTrue(IntStream.of(results).sum() == existingOptions.size(), "Unexpected result from update.");
}
Also used : PollOptionModification(alfio.model.modification.PollOptionModification) alfio.repository(alfio.repository) IntStream(java.util.stream.IntStream) java.util(java.util) alfio.model.poll(alfio.model.poll) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Objects.requireNonNullElse(java.util.Objects.requireNonNullElse) PollModification(alfio.model.modification.PollModification) Result(alfio.model.result.Result) Json(alfio.util.Json) Component(org.springframework.stereotype.Component) ErrorCode(alfio.model.result.ErrorCode) Validate(org.apache.commons.lang3.Validate) Ticket(alfio.model.Ticket) Pair(org.apache.commons.lang3.tuple.Pair) EventAndOrganizationId(alfio.model.EventAndOrganizationId) PinGenerator(alfio.util.PinGenerator) AllArgsConstructor(lombok.AllArgsConstructor) Transactional(org.springframework.transaction.annotation.Transactional) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource)

Example 2 with EventAndOrganizationId

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

the class SpecialPriceTokenGenerator method generateCode.

private void generateCode(SpecialPrice.SpecialPriceTicketCategoryId specialPrice) {
    TicketCategory ticketCategory = ticketCategoryRepository.getByIdAndActive(specialPrice.getTicketCategoryId()).orElseThrow(IllegalStateException::new);
    EventAndOrganizationId event = eventRepository.findEventAndOrganizationIdById(ticketCategory.getEventId());
    int maxLength = configurationManager.getFor(ConfigurationKeys.SPECIAL_PRICE_CODE_LENGTH, ConfigurationLevel.ticketCategory(event, ticketCategory.getId())).getValueAsIntOrDefault(6);
    while (true) {
        try {
            log.trace("generate code for special price with id {}", specialPrice.getId());
            specialPriceRepository.updateCode(nextValidCode(maxLength), specialPrice.getId());
            log.trace("done.");
            return;
        } catch (DataAccessException e) {
            log.warn("got a duplicate. Retrying...", e);
        }
    }
}
Also used : EventAndOrganizationId(alfio.model.EventAndOrganizationId) TicketCategory(alfio.model.TicketCategory) DataAccessException(org.springframework.dao.DataAccessException)

Example 3 with EventAndOrganizationId

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

the class ConfigurationApiController method generateTicketsForSubscriptions.

@PutMapping("/generate-tickets-for-subscriptions")
public ResponseEntity<Boolean> generateTicketsForSubscriptions(@RequestParam(value = "eventId", required = false) Integer eventId, @RequestParam(value = "organizationId", required = false) Integer organizationId, Principal principal) {
    boolean admin = RequestUtils.isAdmin(principal);
    Map<String, Object> jobMetadata = null;
    if (!admin && (organizationId == null || !userManager.isOwnerOfOrganization(principal.getName(), organizationId))) {
        return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
    }
    if (eventId != null && organizationId != null) {
        eventManager.checkOwnership(new EventAndOrganizationId(eventId, organizationId), principal.getName(), organizationId);
        jobMetadata = Map.of(AssignTicketToSubscriberJobExecutor.EVENT_ID, eventId, AssignTicketToSubscriberJobExecutor.ORGANIZATION_ID, organizationId);
    } else if (organizationId != null) {
        jobMetadata = Map.of(AssignTicketToSubscriberJobExecutor.ORGANIZATION_ID, organizationId);
    }
    return ResponseEntity.ok(adminJobManager.scheduleExecution(ASSIGN_TICKETS_TO_SUBSCRIBERS, requireNonNullElse(jobMetadata, Map.of())));
}
Also used : EventAndOrganizationId(alfio.model.EventAndOrganizationId)

Example 4 with EventAndOrganizationId

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

the class ConfigurationManager method deleteCategoryLevelByKey.

public void deleteCategoryLevelByKey(String key, int eventId, int categoryId, String username) {
    EventAndOrganizationId event = eventRepository.findEventAndOrganizationIdById(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 : EventAndOrganizationId(alfio.model.EventAndOrganizationId)

Example 5 with EventAndOrganizationId

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

the class ConfigurationManager method deleteEventLevelByKey.

public void deleteEventLevelByKey(String key, int eventId, String username) {
    EventAndOrganizationId event = eventRepository.findEventAndOrganizationIdById(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.deleteEventLevelByKey(key, eventId);
}
Also used : EventAndOrganizationId(alfio.model.EventAndOrganizationId)

Aggregations

EventAndOrganizationId (alfio.model.EventAndOrganizationId)16 User (alfio.model.user.User)5 Json (alfio.util.Json)3 Test (org.junit.jupiter.api.Test)3 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)3 NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)3 Ticket (alfio.model.Ticket)2 PollModification (alfio.model.modification.PollModification)2 PollOptionModification (alfio.model.modification.PollOptionModification)2 alfio.model.poll (alfio.model.poll)2 ErrorCode (alfio.model.result.ErrorCode)2 Result (alfio.model.result.Result)2 alfio.repository (alfio.repository)2 PinGenerator (alfio.util.PinGenerator)2 java.util (java.util)2 Objects.requireNonNullElse (java.util.Objects.requireNonNullElse)2 Collectors (java.util.stream.Collectors)2 Collectors.toList (java.util.stream.Collectors.toList)2 IntStream (java.util.stream.IntStream)2 AllArgsConstructor (lombok.AllArgsConstructor)2