mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-28 14:57:12 +00:00
Refactored mapping of RegattaMetadataDTO to LeaderboardContext
This commit is contained in:
1 parent
c02caa3878
commit
e9abde48e7
4 files changed
+40
-21
No files matched your search
+6
-1
@@ -101,10 +101,15 @@ public final class EventActionUtil {
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void forLeaderboardsOfEvent(DispatchContext context, UUID eventId, LeaderboardCallback callback) {
|
public static void forLeaderboardsOfEvent(DispatchContext context, UUID eventId, LeaderboardCallback callback) {
|
||||||
RacingEventService service = context.getRacingEventService();
|
RacingEventService service = context.getRacingEventService();
|
||||||
Event event = service.getEvent(eventId);
|
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 (LeaderboardGroup leaderboardGroup : event.getLeaderboardGroups()) {
|
||||||
for (Leaderboard leaderboard : leaderboardGroup.getLeaderboards()) {
|
for (Leaderboard leaderboard : leaderboardGroup.getLeaderboards()) {
|
||||||
callback.doForLeaderboard(new LeaderboardContext(service, event, leaderboardGroup, leaderboard));
|
callback.doForLeaderboard(new LeaderboardContext(service, event, leaderboardGroup, leaderboard));
|
||||||
|
|||||||
+12
-11
@@ -11,11 +11,11 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import com.google.gwt.core.shared.GwtIncompatible;
|
import com.google.gwt.core.shared.GwtIncompatible;
|
||||||
import com.sap.sailing.domain.base.Event;
|
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.domain.leaderboard.LeaderboardGroup;
|
||||||
import com.sap.sailing.gwt.server.HomeServiceUtil;
|
import com.sap.sailing.gwt.server.HomeServiceUtil;
|
||||||
import com.sap.sailing.gwt.ui.shared.dispatch.Action;
|
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.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;
|
||||||
import com.sap.sailing.gwt.ui.shared.eventview.EventViewDTO.EventType;
|
import com.sap.sailing.gwt.ui.shared.eventview.EventViewDTO.EventType;
|
||||||
import com.sap.sailing.gwt.ui.shared.eventview.RegattaMetadataDTO;
|
import com.sap.sailing.gwt.ui.shared.eventview.RegattaMetadataDTO;
|
||||||
@@ -38,12 +38,12 @@ public class GetEventViewAction implements Action<EventViewDTO> {
|
|||||||
|
|
||||||
@GwtIncompatible
|
@GwtIncompatible
|
||||||
public EventViewDTO execute(DispatchContext context) {
|
public EventViewDTO execute(DispatchContext context) {
|
||||||
Event event = context.getRacingEventService().getEvent(eventId);
|
final Event event = context.getRacingEventService().getEvent(eventId);
|
||||||
if (event == null) {
|
if (event == null) {
|
||||||
throw new RuntimeException("Event not found");
|
throw new RuntimeException("Event not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
EventViewDTO dto = new EventViewDTO();
|
final EventViewDTO dto = new EventViewDTO();
|
||||||
HomeServiceUtil.mapToMetadataDTO(event, dto, context.getRacingEventService());
|
HomeServiceUtil.mapToMetadataDTO(event, dto, context.getRacingEventService());
|
||||||
|
|
||||||
ImageDescriptor logoImage = event.findImageWithTag(MediaTagConstants.LOGO);
|
ImageDescriptor logoImage = event.findImageWithTag(MediaTagConstants.LOGO);
|
||||||
@@ -56,21 +56,22 @@ public class GetEventViewAction implements Action<EventViewDTO> {
|
|||||||
// bug2982: always show leaderboard and competitor analytics
|
// bug2982: always show leaderboard and competitor analytics
|
||||||
dto.setHasAnalytics(true);
|
dto.setHasAnalytics(true);
|
||||||
|
|
||||||
boolean isFakeSeries = HomeServiceUtil.isFakeSeries(event);
|
final boolean isFakeSeries = HomeServiceUtil.isFakeSeries(event);
|
||||||
|
|
||||||
for (LeaderboardGroup leaderboardGroup : event.getLeaderboardGroups()) {
|
EventActionUtil.forLeaderboardsOfEvent(context, event, new LeaderboardCallback() {
|
||||||
for (Leaderboard leaderboard : leaderboardGroup.getLeaderboards()) {
|
@Override
|
||||||
|
public void doForLeaderboard(LeaderboardContext context) {
|
||||||
try {
|
try {
|
||||||
if(isFakeSeries && !HomeServiceUtil.isPartOfEvent(event, leaderboard)) {
|
if(isFakeSeries && !context.isPartOfEvent()) {
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
RegattaMetadataDTO regattaDTO = HomeServiceUtil.toRegattaMetadataDTO(event, leaderboardGroup, leaderboard);
|
RegattaMetadataDTO regattaDTO = context.asRegattaMetadataDTO();
|
||||||
dto.getRegattas().add(regattaDTO);
|
dto.getRegattas().add(regattaDTO);
|
||||||
} catch (Exception e) {
|
} 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) {
|
if (isFakeSeries) {
|
||||||
dto.setType(EventType.SERIES_EVENT);
|
dto.setType(EventType.SERIES_EVENT);
|
||||||
|
|||||||
+9
-9
@@ -9,12 +9,11 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import com.google.gwt.core.shared.GwtIncompatible;
|
import com.google.gwt.core.shared.GwtIncompatible;
|
||||||
import com.sap.sailing.domain.base.Event;
|
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.server.HomeServiceUtil;
|
||||||
import com.sap.sailing.gwt.ui.shared.dispatch.Action;
|
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.DispatchContext;
|
||||||
import com.sap.sailing.gwt.ui.shared.dispatch.ResultWithTTL;
|
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.dispatch.event.EventActionUtil.RaceCallback;
|
||||||
import com.sap.sailing.gwt.ui.shared.eventview.RegattaMetadataDTO;
|
import com.sap.sailing.gwt.ui.shared.eventview.RegattaMetadataDTO;
|
||||||
import com.sap.sailing.gwt.ui.shared.general.EventState;
|
import com.sap.sailing.gwt.ui.shared.general.EventState;
|
||||||
@@ -34,7 +33,7 @@ public class GetRegattasAndLiveRacesForEventAction implements Action<ResultWithT
|
|||||||
@GwtIncompatible
|
@GwtIncompatible
|
||||||
public ResultWithTTL<RegattasAndLiveRacesDTO> execute(DispatchContext context) {
|
public ResultWithTTL<RegattasAndLiveRacesDTO> execute(DispatchContext context) {
|
||||||
Event event = context.getRacingEventService().getEvent(eventId);
|
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<>();
|
final TreeMap<RegattaMetadataDTO, TreeSet<LiveRaceDTO>> regattasWithRaces = new TreeMap<>();
|
||||||
EventState eventState = HomeServiceUtil.calculateEventState(event);
|
EventState eventState = HomeServiceUtil.calculateEventState(event);
|
||||||
|
|
||||||
@@ -65,13 +64,14 @@ public class GetRegattasAndLiveRacesForEventAction implements Action<ResultWithT
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GwtIncompatible
|
@GwtIncompatible
|
||||||
private Map<String, RegattaMetadataDTO> mapRegattas(Event event) {
|
private Map<String, RegattaMetadataDTO> mapRegattas(DispatchContext context, Event event) {
|
||||||
Map<String, RegattaMetadataDTO> result = new HashMap<>();
|
final Map<String, RegattaMetadataDTO> result = new HashMap<>();
|
||||||
for (LeaderboardGroup lg : event.getLeaderboardGroups()) {
|
EventActionUtil.forLeaderboardsOfEvent(context, event, new LeaderboardCallback() {
|
||||||
for (Leaderboard lb : lg.getLeaderboards()) {
|
@Override
|
||||||
result.put(lb.getName(), HomeServiceUtil.toRegattaMetadataDTO(event, lg, lb));
|
public void doForLeaderboard(LeaderboardContext context) {
|
||||||
|
result.put(context.getLeaderboardName(), context.asRegattaMetadataDTO());
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
@@ -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.ResultWithTTL;
|
||||||
import com.sap.sailing.gwt.ui.shared.dispatch.event.EventActionUtil.RaceCallback;
|
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.dispatch.regatta.RegattaWithProgressDTO;
|
||||||
|
import com.sap.sailing.gwt.ui.shared.eventview.RegattaMetadataDTO;
|
||||||
import com.sap.sailing.server.RacingEventService;
|
import com.sap.sailing.server.RacingEventService;
|
||||||
|
|
||||||
public class LeaderboardContext {
|
public class LeaderboardContext {
|
||||||
@@ -87,4 +88,16 @@ public class LeaderboardContext {
|
|||||||
throw new DispatchException("Error loading leaderboard");
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user