Refactored mapping of RegattaMetadataDTO to LeaderboardContext

This commit is contained in:
Steffen Schaefer committed 2015-07-20 15:44:29 +02:00
1 parent c02caa3878
commit e9abde48e7
4 files changed
+39 -20

No files matched your search

@@ -105,6 +105,11 @@ public final class EventActionUtil {
public static void forLeaderboardsOfEvent(DispatchContext context, UUID eventId, LeaderboardCallback callback) {
RacingEventService service = context.getRacingEventService();
Event event = service.getEvent(eventId);
forLeaderboardsOfEvent(context, event, callback);
}
public static void forLeaderboardsOfEvent(DispatchContext context, Event event, LeaderboardCallback callback) {
RacingEventService service = context.getRacingEventService();
for (LeaderboardGroup leaderboardGroup : event.getLeaderboardGroups()) {
for (Leaderboard leaderboard : leaderboardGroup.getLeaderboards()) {
callback.doForLeaderboard(new LeaderboardContext(service, event, leaderboardGroup, leaderboard));
@@ -11,11 +11,11 @@ import java.util.logging.Logger;
import com.google.gwt.core.shared.GwtIncompatible;
import com.sap.sailing.domain.base.Event;
import com.sap.sailing.domain.leaderboard.Leaderboard;
import com.sap.sailing.domain.leaderboard.LeaderboardGroup;
import com.sap.sailing.gwt.server.HomeServiceUtil;
import com.sap.sailing.gwt.ui.shared.dispatch.Action;
import com.sap.sailing.gwt.ui.shared.dispatch.DispatchContext;
import com.sap.sailing.gwt.ui.shared.dispatch.event.EventActionUtil.LeaderboardCallback;
import com.sap.sailing.gwt.ui.shared.eventview.EventViewDTO;
import com.sap.sailing.gwt.ui.shared.eventview.EventViewDTO.EventType;
import com.sap.sailing.gwt.ui.shared.eventview.RegattaMetadataDTO;
@@ -38,12 +38,12 @@ public class GetEventViewAction implements Action<EventViewDTO> {
@GwtIncompatible
public EventViewDTO execute(DispatchContext context) {
Event event = context.getRacingEventService().getEvent(eventId);
final Event event = context.getRacingEventService().getEvent(eventId);
if (event == null) {
throw new RuntimeException("Event not found");
}
EventViewDTO dto = new EventViewDTO();
final EventViewDTO dto = new EventViewDTO();
HomeServiceUtil.mapToMetadataDTO(event, dto, context.getRacingEventService());
ImageDescriptor logoImage = event.findImageWithTag(MediaTagConstants.LOGO);
@@ -56,21 +56,22 @@ public class GetEventViewAction implements Action<EventViewDTO> {
// bug2982: always show leaderboard and competitor analytics
dto.setHasAnalytics(true);
boolean isFakeSeries = HomeServiceUtil.isFakeSeries(event);
final boolean isFakeSeries = HomeServiceUtil.isFakeSeries(event);
for (LeaderboardGroup leaderboardGroup : event.getLeaderboardGroups()) {
for (Leaderboard leaderboard : leaderboardGroup.getLeaderboards()) {
EventActionUtil.forLeaderboardsOfEvent(context, event, new LeaderboardCallback() {
@Override
public void doForLeaderboard(LeaderboardContext context) {
try {
if(isFakeSeries && !HomeServiceUtil.isPartOfEvent(event, leaderboard)) {
continue;
if(isFakeSeries && !context.isPartOfEvent()) {
return;
}
RegattaMetadataDTO regattaDTO = HomeServiceUtil.toRegattaMetadataDTO(event, leaderboardGroup, leaderboard);
RegattaMetadataDTO regattaDTO = context.asRegattaMetadataDTO();
dto.getRegattas().add(regattaDTO);
} catch (Exception e) {
logger.log(Level.SEVERE, "Catched exception while reading data for leaderboard " + leaderboard.getName(), e);
logger.log(Level.SEVERE, "Catched exception while reading data for leaderboard " + context.getLeaderboardName(), e);
}
}
}
});
if (isFakeSeries) {
dto.setType(EventType.SERIES_EVENT);
@@ -9,12 +9,11 @@ import java.util.UUID;
import com.google.gwt.core.shared.GwtIncompatible;
import com.sap.sailing.domain.base.Event;
import com.sap.sailing.domain.leaderboard.Leaderboard;
import com.sap.sailing.domain.leaderboard.LeaderboardGroup;
import com.sap.sailing.gwt.server.HomeServiceUtil;
import com.sap.sailing.gwt.ui.shared.dispatch.Action;
import com.sap.sailing.gwt.ui.shared.dispatch.DispatchContext;
import com.sap.sailing.gwt.ui.shared.dispatch.ResultWithTTL;
import com.sap.sailing.gwt.ui.shared.dispatch.event.EventActionUtil.LeaderboardCallback;
import com.sap.sailing.gwt.ui.shared.dispatch.event.EventActionUtil.RaceCallback;
import com.sap.sailing.gwt.ui.shared.eventview.RegattaMetadataDTO;
import com.sap.sailing.gwt.ui.shared.general.EventState;
@@ -34,7 +33,7 @@ public class GetRegattasAndLiveRacesForEventAction implements Action<ResultWithT
@GwtIncompatible
public ResultWithTTL<RegattasAndLiveRacesDTO> execute(DispatchContext context) {
Event event = context.getRacingEventService().getEvent(eventId);
final Map<String, RegattaMetadataDTO> regattas = mapRegattas(event);
final Map<String, RegattaMetadataDTO> regattas = mapRegattas(context, event);
final TreeMap<RegattaMetadataDTO, TreeSet<LiveRaceDTO>> regattasWithRaces = new TreeMap<>();
EventState eventState = HomeServiceUtil.calculateEventState(event);
@@ -65,13 +64,14 @@ public class GetRegattasAndLiveRacesForEventAction implements Action<ResultWithT
}
@GwtIncompatible
private Map<String, RegattaMetadataDTO> mapRegattas(Event event) {
Map<String, RegattaMetadataDTO> result = new HashMap<>();
for (LeaderboardGroup lg : event.getLeaderboardGroups()) {
for (Leaderboard lb : lg.getLeaderboards()) {
result.put(lb.getName(), HomeServiceUtil.toRegattaMetadataDTO(event, lg, lb));
private Map<String, RegattaMetadataDTO> mapRegattas(DispatchContext context, Event event) {
final Map<String, RegattaMetadataDTO> result = new HashMap<>();
EventActionUtil.forLeaderboardsOfEvent(context, event, new LeaderboardCallback() {
@Override
public void doForLeaderboard(LeaderboardContext context) {
result.put(context.getLeaderboardName(), context.asRegattaMetadataDTO());
}
}
});
return result;
}
@@ -19,6 +19,7 @@ import com.sap.sailing.gwt.ui.shared.dispatch.DispatchException;
import com.sap.sailing.gwt.ui.shared.dispatch.ResultWithTTL;
import com.sap.sailing.gwt.ui.shared.dispatch.event.EventActionUtil.RaceCallback;
import com.sap.sailing.gwt.ui.shared.dispatch.regatta.RegattaWithProgressDTO;
import com.sap.sailing.gwt.ui.shared.eventview.RegattaMetadataDTO;
import com.sap.sailing.server.RacingEventService;
public class LeaderboardContext {
@@ -87,4 +88,16 @@ public class LeaderboardContext {
throw new DispatchException("Error loading leaderboard");
}
}
public String getLeaderboardName() {
return leaderboard.getName();
}
public RegattaMetadataDTO asRegattaMetadataDTO() {
return HomeServiceUtil.toRegattaMetadataDTO(event, leaderboardGroup, leaderboard);
}
public boolean isPartOfEvent() {
return HomeServiceUtil.isPartOfEvent(event, leaderboard);
}
}