use of alfio.model.user.User in project alf.io by alfio-event.
the class ConfigurationManager method saveCategoryConfiguration.
public void saveCategoryConfiguration(int categoryId, int eventId, List<ConfigurationModification> list, String username) {
User user = userManager.findUserByUsername(username);
EventAndOrganizationId event = eventRepository.findEventAndOrganizationIdById(eventId);
Validate.notNull(event, "event does not exist");
Validate.isTrue(userManager.isOwnerOfOrganization(user, event.getOrganizationId()), "Cannot update settings, user is not owner of event");
list.stream().filter(ConfigurationManager::toBeSaved).forEach(c -> {
Optional<Configuration> existing = configurationRepository.findByKeyAtCategoryLevel(eventId, event.getOrganizationId(), categoryId, c.getKey());
Optional<String> value = evaluateValue(c.getKey(), c.getValue());
if (value.isEmpty()) {
configurationRepository.deleteCategoryLevelByKey(c.getKey(), eventId, categoryId);
} else if (existing.isPresent()) {
configurationRepository.updateCategoryLevel(eventId, event.getOrganizationId(), categoryId, c.getKey(), value.get());
} else {
configurationRepository.insertTicketCategoryLevel(event.getOrganizationId(), eventId, categoryId, c.getKey(), value.get(), ConfigurationKeys.fromString(c.getKey()).getDescription());
}
});
}
use of alfio.model.user.User in project alf.io by alfio-event.
the class ConfigurationManager method saveAllEventConfiguration.
public void saveAllEventConfiguration(int eventId, int organizationId, List<ConfigurationModification> list, String username) {
User user = userManager.findUserByUsername(username);
Validate.isTrue(userManager.isOwnerOfOrganization(user, organizationId), "Cannot update settings, user is not owner");
EventAndOrganizationId event = eventRepository.findEventAndOrganizationIdById(eventId);
Validate.notNull(event, "event does not exist");
if (organizationId != event.getOrganizationId()) {
Validate.isTrue(userManager.isOwnerOfOrganization(user, event.getOrganizationId()), "Cannot update settings, user is not owner of event");
}
list.stream().filter(ConfigurationManager::toBeSaved).forEach(c -> saveEventConfiguration(eventId, organizationId, c.getKey(), c.getValue()));
}
Aggregations