Exemplo n.º 1
0
 @RequestMapping(
     value = "/events/{eventName}/additional-field/swap-position/{id1}/{id2}",
     method = POST)
 public void swapAdditionalFieldPosition(
     @PathVariable("eventName") String eventName,
     @PathVariable("id1") int id1,
     @PathVariable("id2") int id2,
     Principal principal) {
   Event event = eventManager.getSingleEvent(eventName, principal.getName());
   eventManager.swapAdditionalFieldPosition(event.getId(), id1, id2);
 }
Exemplo n.º 2
0
  @RequestMapping("/events/{eventName}/sponsor-scan/export.csv")
  public void downloadSponsorScanExport(
      @PathVariable("eventName") String eventName,
      HttpServletResponse response,
      Principal principal)
      throws IOException {
    Event event = loadEvent(eventName, principal);
    List<TicketFieldConfiguration> fields =
        ticketFieldRepository.findAdditionalFieldsForEvent(event.getId());

    response.setContentType("text/csv;charset=UTF-8");
    response.setHeader(
        "Content-Disposition", "attachment; filename=" + eventName + "-sponsor-scan.csv");

    try (ServletOutputStream out = response.getOutputStream();
        CSVWriter writer = new CSVWriter(new OutputStreamWriter(out))) {
      for (int marker : BOM_MARKERS) {
        out.write(marker);
      }

      List<String> header = new ArrayList<>();
      header.add("Username");
      header.add("Timestamp");
      header.add("Full name");
      header.add("Email");
      header.addAll(
          fields.stream().map(TicketFieldConfiguration::getName).collect(Collectors.toList()));
      writer.writeNext(header.toArray(new String[header.size()]));
      userManager
          .findAllUsers(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(Collectors.toList()));
              })
          .map(
              p -> {
                List<String> line = new ArrayList<>();
                Ticket ticket = p.getLeft().getTicket();
                SponsorScan sponsorScan = p.getLeft().getSponsorScan();
                line.add(userManager.findUser(sponsorScan.getUserId()).getUsername());
                line.add(sponsorScan.getTimestamp().toString());
                line.add(ticket.getFullName());
                line.add(ticket.getEmail());
                line.addAll(p.getRight());
                return line.toArray(new String[line.size()]);
              })
          .forEachOrdered(writer::writeNext);
      writer.flush();
      out.flush();
    }
  }