Search in sources :

Example 1 with User

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

the class EventApiController method downloadSponsorScanExport.

@GetMapping("/events/{eventName}/sponsor-scan/export")
public void downloadSponsorScanExport(@PathVariable("eventName") String eventName, @RequestParam(name = "format", defaultValue = "excel") String format, HttpServletResponse response, Principal principal) throws IOException {
    var event = eventManager.getSingleEvent(eventName, principal.getName());
    List<TicketFieldConfiguration> fields = ticketFieldRepository.findAdditionalFieldsForEvent(event.getId());
    List<String> header = new ArrayList<>();
    header.add("Username/Api Key");
    header.add("Description");
    header.add("Timestamp");
    header.add("Full name");
    header.add("Email");
    header.addAll(fields.stream().map(TicketFieldConfiguration::getName).collect(toList()));
    header.add("Sponsor notes");
    header.add("Lead Status");
    Stream<String[]> sponsorScans = userManager.findAllEnabledUsers(principal.getName()).stream().map(u -> Pair.of(u, userManager.getUserRole(u))).filter(p -> p.getRight() == Role.SPONSOR).flatMap(p -> sponsorScanRepository.loadSponsorData(event.getId(), p.getKey().getId(), SponsorScanRepository.DEFAULT_TIMESTAMP).stream().map(v -> Pair.of(v, ticketFieldRepository.findAllValuesForTicketId(v.getTicket().getId())))).map(p -> {
        DetailedScanData data = p.getLeft();
        Map<String, String> descriptions = p.getRight();
        return Pair.of(data, fields.stream().map(x -> descriptions.getOrDefault(x.getName(), "")).collect(toList()));
    }).map(p -> {
        List<String> line = new ArrayList<>();
        Ticket ticket = p.getLeft().getTicket();
        SponsorScan sponsorScan = p.getLeft().getSponsorScan();
        User user = userManager.findUser(sponsorScan.getUserId());
        line.add(user.getUsername());
        line.add(user.getDescription());
        line.add(sponsorScan.getTimestamp().toString());
        line.add(ticket.getFullName());
        line.add(ticket.getEmail());
        line.addAll(p.getRight());
        line.add(sponsorScan.getNotes());
        line.add(sponsorScan.getLeadStatus().name());
        return line.toArray(new String[0]);
    });
    if ("excel".equals(format)) {
        exportSponsorScanExcel(event.getShortName(), header, sponsorScans, response);
    } else {
        exportSponsorScanCSV(event.getShortName(), header, sponsorScans, response);
    }
}
Also used : EventDescriptionRepository(alfio.repository.EventDescriptionRepository) alfio.manager(alfio.manager) PaymentProxy(alfio.model.transaction.PaymentProxy) TemplateProcessor(alfio.controller.support.TemplateProcessor) SneakyThrows(lombok.SneakyThrows) ZonedDateTime(java.time.ZonedDateTime) AlfioMetadata(alfio.model.metadata.AlfioMetadata) StringUtils(org.apache.commons.lang3.StringUtils) BigDecimal(java.math.BigDecimal) Pair(org.apache.commons.lang3.tuple.Pair) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SponsorScanRepository(alfio.repository.SponsorScanRepository) Triple(org.apache.commons.lang3.tuple.Triple) ZipEntry(java.util.zip.ZipEntry) PageAndContent(alfio.controller.api.support.PageAndContent) Organization(alfio.model.user.Organization) Predicate(java.util.function.Predicate) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) DynamicFieldTemplateRepository(alfio.repository.DynamicFieldTemplateRepository) Role(alfio.model.user.Role) Principal(java.security.Principal) Stream(java.util.stream.Stream) alfio.model(alfio.model) StringUtils.defaultString(org.apache.commons.lang3.StringUtils.defaultString) LocalDate(java.time.LocalDate) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) alfio.model.modification(alfio.model.modification) ValidationResult(alfio.model.result.ValidationResult) ZipOutputStream(java.util.zip.ZipOutputStream) Transaction(alfio.model.transaction.Transaction) DataAccessException(org.springframework.dao.DataAccessException) Errors(org.springframework.validation.Errors) java.util(java.util) TicketHelper(alfio.controller.api.support.TicketHelper) ConfigurationLevel(alfio.manager.system.ConfigurationLevel) CsvException(com.opencsv.exceptions.CsvException) Getter(lombok.Getter) EventListItem(alfio.controller.api.support.EventListItem) CSVReader(com.opencsv.CSVReader) ConfigurationManager(alfio.manager.system.ConfigurationManager) AlfioScriptingException(alfio.extension.exception.AlfioScriptingException) Function(java.util.function.Function) Supplier(java.util.function.Supplier) alfio.util(alfio.util) CollectionUtils(org.apache.commons.collections4.CollectionUtils) TicketFieldRepository(alfio.repository.TicketFieldRepository) HttpServletRequest(javax.servlet.http.HttpServletRequest) StreamUtils(org.springframework.util.StreamUtils) OutputStream(java.io.OutputStream) ItalianEInvoicing(alfio.model.TicketReservationInvoicingAdditionalInfo.ItalianEInvoicing) UTF_8(java.nio.charset.StandardCharsets.UTF_8) HttpServletResponse(javax.servlet.http.HttpServletResponse) User(alfio.model.user.User) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) Validator(alfio.util.Validator) HttpStatus(org.springframework.http.HttpStatus) Collectors.toList(java.util.stream.Collectors.toList) Validate(org.apache.commons.lang3.Validate) ChronoUnit(java.time.temporal.ChronoUnit) ExtensionCapability(alfio.manager.support.extension.ExtensionCapability) UserManager(alfio.manager.user.UserManager) DateTimeFormatter(java.time.format.DateTimeFormatter) Data(lombok.Data) Log4j2(lombok.extern.log4j.Log4j2) ResponseEntity(org.springframework.http.ResponseEntity) Wrappers.optionally(alfio.util.Wrappers.optionally) I18nManager(alfio.manager.i18n.I18nManager) AllArgsConstructor(lombok.AllArgsConstructor) ConfigurationKeys(alfio.model.system.ConfigurationKeys) User(alfio.model.user.User) StringUtils.defaultString(org.apache.commons.lang3.StringUtils.defaultString)

Example 2 with User

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

the class ConfigurationManager method getSingleConfigForOrganization.

public String getSingleConfigForOrganization(int organizationId, String keyAsString, String username) {
    User user = userManager.findUserByUsername(username);
    if (!userManager.isOwnerOfOrganization(user, organizationId)) {
        return null;
    }
    var key = safeValueOf(keyAsString);
    return getFirstConfigurationResult(configurationRepository.findByOrganizationAndKey(organizationId, key.name()), keyAsString);
}
Also used : User(alfio.model.user.User)

Example 3 with User

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

the class ConfigurationManager method loadCategoryConfig.

public Map<ConfigurationKeys.SettingCategory, List<Configuration>> loadCategoryConfig(int eventId, int categoryId, String username) {
    User user = userManager.findUserByUsername(username);
    EventAndOrganizationId event = eventRepository.findEventAndOrganizationIdById(eventId);
    int organizationId = event.getOrganizationId();
    if (!userManager.isOwnerOfOrganization(user, organizationId)) {
        return Collections.emptyMap();
    }
    Map<ConfigurationKeys.SettingCategory, List<Configuration>> existing = configurationRepository.findCategoryConfiguration(organizationId, eventId, categoryId).stream().sorted().collect(groupByCategory());
    return groupByCategory(CATEGORY_CONFIGURATION, existing);
}
Also used : User(alfio.model.user.User) EventAndOrganizationId(alfio.model.EventAndOrganizationId) Collectors.toList(java.util.stream.Collectors.toList)

Example 4 with User

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

the class ConfigurationManager method loadOrganizationConfig.

public Map<ConfigurationKeys.SettingCategory, List<Configuration>> loadOrganizationConfig(int organizationId, String username) {
    User user = userManager.findUserByUsername(username);
    if (!userManager.isOwnerOfOrganization(user, organizationId)) {
        return Collections.emptyMap();
    }
    boolean isAdmin = userManager.isAdmin(user);
    Map<ConfigurationKeys.SettingCategory, List<Configuration>> existing = configurationRepository.findOrganizationConfiguration(organizationId).stream().filter(checkActualConfigurationLevel(isAdmin, ORGANIZATION)).sorted().collect(groupByCategory());
    String paymentMethodsBlacklist = getFor(ConfigurationKeys.PAYMENT_METHODS_BLACKLIST, new OrganizationLevel(organizationId)).getValueOrDefault("");
    Map<SettingCategory, List<Configuration>> result = groupByCategory(isAdmin ? union(SYSTEM, ORGANIZATION) : ORGANIZATION_CONFIGURATION, existing);
    List<SettingCategory> toBeRemoved = PaymentProxy.availableProxies().stream().filter(pp -> paymentMethodsBlacklist.contains(pp.getKey())).flatMap(pp -> pp.getSettingCategories().stream()).collect(toList());
    if (toBeRemoved.isEmpty()) {
        return result;
    } else {
        return result.entrySet().stream().filter(entry -> !toBeRemoved.contains(entry.getKey())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    }
}
Also used : OrganizationLevel(alfio.manager.system.ConfigurationLevels.OrganizationLevel) AnalyticsConfiguration(alfio.controller.api.v2.model.AnalyticsConfiguration) java.util(java.util) ConfigurationKeyValuePathLevel(alfio.model.system.ConfigurationKeyValuePathLevel) PaymentProxy(alfio.model.transaction.PaymentProxy) RequiredArgsConstructor(lombok.RequiredArgsConstructor) CategoryLevel(alfio.manager.system.ConfigurationLevels.CategoryLevel) PurchaseContext(alfio.model.PurchaseContext) Cache(com.github.benmanes.caffeine.cache.Cache) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) IterableUtils(org.apache.commons.collections4.IterableUtils) Pair(org.apache.commons.lang3.tuple.Pair) Profiles(org.springframework.core.env.Profiles) OrganizationLevel(alfio.manager.system.ConfigurationLevels.OrganizationLevel) EventAndOrganizationId(alfio.model.EventAndOrganizationId) Configurable(alfio.model.Configurable) Collector(java.util.stream.Collector) HttpSession(javax.servlet.http.HttpSession) EventLevel(alfio.manager.system.ConfigurationLevels.EventLevel) Predicate(java.util.function.Predicate) PaymentMethod(alfio.model.transaction.PaymentMethod) User(alfio.model.user.User) AlfioInfo(alfio.controller.api.v2.model.AlfioInfo) PurchaseContextInfoBuilder(alfio.controller.api.v2.user.support.PurchaseContextInfoBuilder) EventRepository(alfio.repository.EventRepository) CompareToBuilder(org.apache.commons.lang3.builder.CompareToBuilder) Collectors(java.util.stream.Collectors) ConfigurationRepository(alfio.repository.system.ConfigurationRepository) Consumer(java.util.function.Consumer) Collectors.toList(java.util.stream.Collectors.toList) Initializer(alfio.config.Initializer) Validate(org.apache.commons.lang3.Validate) ConfigurationModification(alfio.model.modification.ConfigurationModification) Environment(org.springframework.core.env.Environment) UserManager(alfio.manager.user.UserManager) TicketReservation(alfio.model.TicketReservation) Configuration(alfio.model.system.Configuration) Log4j2(lombok.extern.log4j.Log4j2) ConfigurationPathLevel(alfio.model.system.ConfigurationPathLevel) ConfigurationKeys(alfio.model.system.ConfigurationKeys) Transactional(org.springframework.transaction.annotation.Transactional) User(alfio.model.user.User) Collectors.toList(java.util.stream.Collectors.toList)

Example 5 with User

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

the class ConfigurationManager method getSingleConfigForEvent.

public String getSingleConfigForEvent(int eventId, String keyAsString, String username) {
    User user = userManager.findUserByUsername(username);
    EventAndOrganizationId event = eventRepository.findEventAndOrganizationIdById(eventId);
    int organizationId = event.getOrganizationId();
    if (!userManager.isOwnerOfOrganization(user, organizationId)) {
        return null;
    }
    var key = safeValueOf(keyAsString);
    return getFirstConfigurationResult(configurationRepository.findByEventAndKey(organizationId, eventId, key.name()), keyAsString);
}
Also used : User(alfio.model.user.User) EventAndOrganizationId(alfio.model.EventAndOrganizationId)

Aggregations

User (alfio.model.user.User)12 EventAndOrganizationId (alfio.model.EventAndOrganizationId)6 Collectors (java.util.stream.Collectors)4 Collectors.toList (java.util.stream.Collectors.toList)4 Log4j2 (lombok.extern.log4j.Log4j2)4 StringUtils (org.apache.commons.lang3.StringUtils)4 UserManager (alfio.manager.user.UserManager)3 java.util (java.util)3 Pair (org.apache.commons.lang3.tuple.Pair)3 AnalyticsConfiguration (alfio.controller.api.v2.model.AnalyticsConfiguration)2 alfio.model (alfio.model)2 ConfigurationKeys (alfio.model.system.ConfigurationKeys)2 PaymentProxy (alfio.model.transaction.PaymentProxy)2 Organization (alfio.model.user.Organization)2 Role (alfio.model.user.Role)2 EventRepository (alfio.repository.EventRepository)2 UserRepository (alfio.repository.user.UserRepository)2 Function (java.util.function.Function)2 Predicate (java.util.function.Predicate)2 Stream (java.util.stream.Stream)2