Skip to content

Commit

Permalink
alfio-event#549 - Retrieve WaitingQueueSubscription and apply lambda…
Browse files Browse the repository at this point in the history
…s for each requested fields
  • Loading branch information
Nassim Bounouas committed Dec 1, 2018
1 parent 262f3d1 commit 5edcd6b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,11 @@ private Event loadEvent(String eventName, Principal principal) {
public void downloadWaitingQueue(@PathVariable("eventName") String eventName, @RequestParam(name = "format", defaultValue = "excel") String format, HttpServletRequest request, HttpServletResponse response, Principal principal) throws IOException {
List<String> fields = Arrays.asList(Optional.ofNullable(request.getParameterValues("fields")).orElse(new String[]{}));
Event event = loadEvent(eventName, principal);
List<WaitingQueueSubscription> subscriptions = waitingQueueManager.loadAllSubscriptionsForEvent(event.getId());
System.out.println("*** CALL ***");
fields.stream().forEach(System.out::println);
System.out.println(event.getDisplayName());
new WaitingQueueDownloader().extractDataToExport(subscriptions, fields);
/*Map<Integer, TicketCategory> categoriesMap = eventManager.loadTicketCategories(event).stream().collect(Collectors.toMap(TicketCategory::getId, Function.identity()));
ZoneId eventZoneId = event.getZoneId();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package alfio.controller.api.admin;

import alfio.model.WaitingQueueSubscription;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

public class WaitingQueueDownloader {
private Map<String, String> map;
private Map<String, Consumer<WaitingQueueSubscription>> consumers;

public WaitingQueueDownloader() {
map = new HashMap<>();
Expand All @@ -20,9 +25,29 @@ public WaitingQueueDownloader() {
map.put("language", "Language");
map.put("selected_category", "Selected category");
map.put("subscription_type", "Subscription type");

consumers = new HashMap<>();
consumers.put("id", subscription -> System.out.println(subscription.getId()));
consumers.put("creation", subscription -> System.out.println(subscription.getCreation()));
consumers.put("event", subscription -> System.out.println(subscription.getEventId()));
consumers.put("status", subscription -> System.out.println(subscription.getStatus()));
consumers.put("fullname", subscription -> System.out.println(subscription.getFullName()));
consumers.put("firstname", subscription -> System.out.println(subscription.getFirstName()));
consumers.put("lastname", subscription -> System.out.println(subscription.getLastName()));
consumers.put("email", subscription -> System.out.println(subscription.getEmailAddress()));
consumers.put("ticket_reservation_id", subscription -> System.out.println(subscription.getReservationId()));
consumers.put("language", subscription -> System.out.println(subscription.getUserLanguage()));
consumers.put("selected_category", subscription -> System.out.println(subscription.getSelectedCategoryId()));
consumers.put("subscription_type", subscription -> System.out.println(subscription.getSubscriptionType()));
}

public Map<String, String> availableFields() {
return this.map;
}

public void extractDataToExport(List<WaitingQueueSubscription> subscriptions, List<String> fields) {
for (WaitingQueueSubscription t : subscriptions) {
fields.stream().filter(k -> this.consumers.containsKey(k)).forEach(k -> consumers.get(k).accept(t));
}
}
}

0 comments on commit 5edcd6b

Please sign in to comment.