limit = Util.ensureRange(limit, 0, 100);
GetEnrollmentsTransaction transaction = new GetEnrollmentsTransaction(userId, offset, limit);
transaction.execute();
ArrayNode statuses = new ArrayNode(JsonNodeFactory.instance);
for (TicketAndStatus ticketAndStatus : transaction.getStatuses()) {
// TODO: We should consider how to join EventEntities and EnrollmentEntities.
// If the event is private (or draft), its information does not be fed.
// However, we show the existence of the event now.
if (ticketAndStatus.event == null || !ticketAndStatus.event.isSearchable())
continue;
ObjectNode obj = new ObjectNode(JsonNodeFactory.instance);
obj.put("ticket", ticketAndStatus.ticket.toSafeJSON());
obj.put("event", ticketAndStatus.event.toSafeJSON());
obj.put("status", ticketAndStatus.status.toString());
statuses.add(obj);
}
ObjectNode obj = new ObjectNode(JsonNodeFactory.instance);
obj.put("totalTicketCount", transaction.getTotalTicketCount());
obj.put("ticketStatuses", statuses);