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