consolidated obtaining wind finder spots for an Event into EventWindFinderUtil

Change-Id: Ia53fb1ca1c70f3311d08e04d74401fb0ce49419d
This commit is contained in:
Axel Uhl
2018-02-22 14:01:55 +01:00
parent bf3aa86e71
commit 63a676bf64
4 changed files with 54 additions and 47 deletions
@@ -0,0 +1,46 @@
package com.sap.sailing.gwt.common.client;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.logging.Logger;
import org.json.simple.parser.ParseException;
import com.sap.sailing.domain.base.Event;
import com.sap.sailing.domain.common.windfinder.SpotDTO;
import com.sap.sailing.domain.windfinder.Spot;
import com.sap.sailing.domain.windfinder.WindFinderTrackerFactory;
public class EventWindFinderUtil {
private static final Logger logger = Logger.getLogger(EventWindFinderUtil.class.getName());
/**
* Obtains wind finder spots for a given Event
*
* @param useCachedSpotsForTrackedRaces
* whether or not to use the cached set of wind finder spots for tracked races
*/
public Iterable<SpotDTO> getWindFinderSpotsToConsider(Event event, WindFinderTrackerFactory windFinderTrackerFactory, boolean useCachedSpotsForTrackedRaces) {
final List<SpotDTO> windFinderSpots = new ArrayList<>();
for (final String spotsCollectionId : event.getWindFinderReviewedSpotsCollectionIds()) {
try {
for (final Spot spot : windFinderTrackerFactory.getReviewedSpotsCollectionById(spotsCollectionId, /* lookupInCache */ true).
getSpots(/* cached */ true)) {
windFinderSpots.add(new SpotDTO(spot));
}
} catch (IOException | ParseException | InterruptedException | ExecutionException e) {
logger.warning("Unable to determine WindFinder spots for reviewed spot collection with ID "+spotsCollectionId);
}
}
for (final String spotIdFromTrackedRace : event.getAllFinderSpotIdsUsedByTrackedRacesInEvent()) {
try {
windFinderSpots.add(new SpotDTO(windFinderTrackerFactory.getSpotById(spotIdFromTrackedRace, /* cached */ true)));
} catch (IOException | ParseException | InterruptedException | ExecutionException e) {
logger.warning("Unable to determine WindFinder spot with ID "+spotIdFromTrackedRace);
}
}
return windFinderSpots;
}
}
@@ -1,22 +1,15 @@
package com.sap.sailing.gwt.home.communication.event;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.simple.parser.ParseException;
import com.google.gwt.core.shared.GwtIncompatible;
import com.sap.sailing.domain.base.Event;
import com.sap.sailing.domain.common.dto.EventType;
import com.sap.sailing.domain.common.windfinder.SpotDTO;
import com.sap.sailing.domain.leaderboard.LeaderboardGroup;
import com.sap.sailing.domain.windfinder.Spot;
import com.sap.sailing.gwt.common.client.EventWindFinderUtil;
import com.sap.sailing.gwt.home.communication.SailingAction;
import com.sap.sailing.gwt.home.communication.SailingDispatchContext;
import com.sap.sailing.gwt.home.communication.eventview.EventViewDTO;
@@ -70,26 +63,10 @@ public class GetEventViewAction implements SailingAction<EventViewDTO>, IsClient
dto.setOfficialWebsiteURL(event.getOfficialWebsiteURL() == null ? null : event.getOfficialWebsiteURL().toString());
URL sailorsInfoWebsiteURL = event.getSailorsInfoWebsiteURLOrFallback(context.getClientLocale());
dto.setSailorsInfoWebsiteURL(sailorsInfoWebsiteURL == null ? null : sailorsInfoWebsiteURL.toString());
final List<SpotDTO> windFinderSpots = new ArrayList<>();
for (final String spotsCollectionId : event.getWindFinderReviewedSpotsCollectionIds()) {
try {
for (final Spot spot : context.getWindFinderTrackerFactory().getReviewedSpotsCollectionById(spotsCollectionId, /* lookupInCache */ true).
getSpots(/* cached */ true)) {
windFinderSpots.add(new SpotDTO(spot));
}
} catch (IOException | ParseException | InterruptedException | ExecutionException e) {
logger.warning("Unable to determine WindFinder spots for reviewed spot collection with ID "+spotsCollectionId);
}
if (context.getWindFinderTrackerFactory() != null) {
dto.setAllWindFinderSpotsUsedByEvent(new EventWindFinderUtil().getWindFinderSpotsToConsider(event,
context.getWindFinderTrackerFactory(), /* useCachedSpotsForTrackedRaces */ true));
}
for (final String spotIdFromTrackedRace : event.getAllFinderSpotIdsUsedByTrackedRacesInEvent()) {
try {
windFinderSpots.add(new SpotDTO(context.getWindFinderTrackerFactory().getSpotById(spotIdFromTrackedRace, /* cached */ true)));
} catch (IOException | ParseException | InterruptedException | ExecutionException e) {
logger.warning("Unable to determine WindFinder spot with ID "+spotIdFromTrackedRace);
}
}
dto.setAllWindFinderSpotsUsedByEvent(windFinderSpots);
dto.setHasMedia(HomeServiceUtil.hasMedia(event));
dto.setState(HomeServiceUtil.calculateEventState(event));
// bug2982: always show leaderboard and competitor analytics
@@ -318,6 +318,7 @@ import com.sap.sailing.domain.windfinder.WindFinderTrackerFactory;
import com.sap.sailing.expeditionconnector.ExpeditionDeviceConfiguration;
import com.sap.sailing.expeditionconnector.ExpeditionSensorDeviceIdentifier;
import com.sap.sailing.expeditionconnector.ExpeditionTrackerFactory;
import com.sap.sailing.gwt.common.client.EventWindFinderUtil;
import com.sap.sailing.gwt.server.HomeServiceUtil;
import com.sap.sailing.gwt.ui.adminconsole.RaceLogSetTrackingTimesDTO;
import com.sap.sailing.gwt.ui.client.SailingService;
@@ -3925,26 +3926,9 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
}
eventDTO.setWindFinderReviewedSpotsCollection(event.getWindFinderReviewedSpotsCollectionIds());
final WindFinderTrackerFactory windFinderTrackerFactory = windFinderTrackerFactoryServiceTracker.getService();
final List<SpotDTO> windFinderSpots = new ArrayList<>();
if (windFinderTrackerFactory != null) {
for (final String spotsCollectionId : event.getWindFinderReviewedSpotsCollectionIds()) {
try {
for (final Spot spot : windFinderTrackerFactory.getReviewedSpotsCollectionById(spotsCollectionId, /* lookupInCache */ true).
getSpots(/* cached */ false)) {
windFinderSpots.add(new SpotDTO(spot));
}
} catch (IOException | org.json.simple.parser.ParseException | InterruptedException | ExecutionException e) {
logger.warning("Unable to determine WindFinder spots for reviewed spot collection with ID "+spotsCollectionId);
}
}
for (final String spotIdFromTrackedRace : event.getAllFinderSpotIdsUsedByTrackedRacesInEvent()) {
try {
windFinderSpots.add(new SpotDTO(windFinderTrackerFactory.getSpotById(spotIdFromTrackedRace, /* cached */ false)));
} catch (IOException | org.json.simple.parser.ParseException | InterruptedException | ExecutionException e) {
logger.warning("Unable to determine WindFinder spot with ID "+spotIdFromTrackedRace);
}
}
eventDTO.setAllWindFinderSpotsUsedByEvent(windFinderSpots);
eventDTO.setAllWindFinderSpotsUsedByEvent(new EventWindFinderUtil().getWindFinderSpotsToConsider(event,
windFinderTrackerFactory, /* useCachedSpotsForTrackedRaces */ false));
}
return eventDTO;
}
@@ -135,7 +135,7 @@ public class EventDTO extends EventBaseDTO {
return result;
}
public void setAllWindFinderSpotsUsedByEvent(List<SpotDTO> windFinderSpots) {
public void setAllWindFinderSpotsUsedByEvent(Iterable<SpotDTO> windFinderSpots) {
this.allWindFinderSpotIdsUsedByEvent = new ArrayList<>();
if (windFinderSpots != null) {
Util.addAll(windFinderSpots, this.allWindFinderSpotIdsUsedByEvent);