Example #1
10
  public void createRandomIndividuals(int numIndividuals, KTH kth) {
    Map<Integer, Room> rooms = kth.getRooms();
    int numRooms = kth.getRooms().size();

    for (int i = 0; i < numIndividuals; i++) {
      // register all available timeslots
      ArrayList<TimeSlot> availableTimeSlots = new ArrayList<TimeSlot>();
      for (int roomId : rooms.keySet()) {
        for (int d = 0; d < RoomTimeTable.NUM_DAYS; d++) {
          for (int t = 0; t < RoomTimeTable.NUM_TIMESLOTS; t++) {
            availableTimeSlots.add(new TimeSlot(roomId, d, t));
          }
        }
      }

      TimeTable tt = new TimeTable(numRooms);
      for (int roomId : rooms.keySet()) {
        Room room = rooms.get(roomId);
        RoomTimeTable rtt = new RoomTimeTable(room);
        tt.putRoomTimeTable(roomId, rtt);
      }

      // index variables
      int rttId = 0;
      int day = 0;
      int timeSlot = 0;

      // assign all event to any randomly selected available timeslot
      Random rand = new Random(System.currentTimeMillis());
      for (Event e : kth.getEvents().values()) {
        TimeSlot availableTimeSlot =
            availableTimeSlots.get(rand.nextInt(availableTimeSlots.size()));
        RoomTimeTable rtt = tt.getRoomTimeTables()[availableTimeSlot.roomId];
        rtt.setEvent(availableTimeSlot.day, availableTimeSlot.timeSlot, e.getId());
        availableTimeSlots.remove(availableTimeSlot);
        /* DEBUG
        System.out.println("==============");
        System.out.println("ROOM TIME TABLE ID: " + rtt.getRoom().getName());
        System.out.println("Day: " + availableTimeSlot.day + " Timeslot: " + availableTimeSlot.timeSlot + " Event ID: " + e.getId());
        */
      }
      individuals.add(tt);
      availableTimeSlots.clear();
    }
  }
Example #2
0
  private void populateTrainingSessions() {
    if (null == sessions) {
      sessions = new HashSet<TrainingSession>();
    }

    Set<Event> events = getSubscribedEvents();
    for (Event ev : events) {
      TrainingSession ts1 =
          new TrainingSession(
              ev.getId(),
              this,
              new java.util.Date(1227817411),
              "a workout desc",
              true,
              "something for now",
              "something");
      TrainingSession ts2 =
          new TrainingSession(
              ev.getId(),
              this,
              new java.util.Date(1229459011),
              "a workout desc",
              true,
              "something for now",
              "something");

      UserRegistry.getCurrentInstance().userEJB.addTrainingSession(ts1);
      UserRegistry.getCurrentInstance().userEJB.addTrainingSession(ts2);

      sessions.add(ts1);
      sessions.add(ts2);
    }

    UserRegistry.getCurrentInstance().updateUser(this);
  }
  public void fireEvent(Event event) {
    if (event == null) throw new IllegalArgumentException("event == null");
    Set<Listener> set = listeners.get(event.getId());

    if (set != null) {
      for (Listener l : set.toArray(new Listener[set.size()])) {
        l.eventOccured(event);
      }
    }
  }
Example #4
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);
 }
  private Long createAndStoreEvent(String title, Date theDate) {

    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();

    Event theEvent = new Event();
    theEvent.setTitle(title);
    theEvent.setDate(theDate);

    session.save(theEvent);

    session.getTransaction().commit();

    return theEvent.getId();
  }
Example #6
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();
    }
  }