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.");
}
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);
}
}
}
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())));
}
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);
}
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);
}
Aggregations