MetaColumn factors are now imported with MasterDataImport

see bug #1605

also added an assert to the according OverallLeaderboard test case
This commit is contained in:
Frederik Petersen committed 2013-11-15 16:13:55 +01:00
1 parent b3c65ee93a
commit 967e3de29e
5 files changed
+68 -12

No files matched your search

@@ -1,5 +1,6 @@
package com.sap.sailing.domain.masterdataimport; package com.sap.sailing.domain.masterdataimport;
import java.util.Map;
import java.util.Set; import java.util.Set;
import com.sap.sailing.domain.base.LeaderboardMasterData; import com.sap.sailing.domain.base.LeaderboardMasterData;
@@ -23,19 +24,20 @@ public class LeaderboardGroupMasterData {
private final boolean displayGroupsRevese; private final boolean displayGroupsRevese;
private final Set<EventMasterData> events; private final Set<EventMasterData> events;
private final Set<RegattaMasterData> regattas; private final Set<RegattaMasterData> regattas;
private final Map<String, Double> metaColumnsWithFactors;
public LeaderboardGroupMasterData(String name, String description, boolean displayGroupsRevese, public LeaderboardGroupMasterData(String name, String description, boolean displayGroupsRevese,
boolean hasOverallLeaderboard, boolean hasOverallLeaderboard, ScoringScheme overallLeaderboardScoringScheme,
ScoringScheme overallLeaderboardScoringScheme, int[] overallLeaderboardDiscardingRule, Map<String, Double> metaColumnsWithFactors,
int[] overallLeaderboardDiscardingRule, Iterable<LeaderboardMasterData> leaderboards, Set<EventMasterData> events, Iterable<LeaderboardMasterData> leaderboards, Set<EventMasterData> events, Set<RegattaMasterData> regattas) {
Set<RegattaMasterData> regattas) {
super(); super();
this.name = name; this.name = name;
this.description = description; this.description = description;
this.hasOverallLeaderboard = hasOverallLeaderboard; this.hasOverallLeaderboard = hasOverallLeaderboard;
this.overallLeaderboardScoringScheme = overallLeaderboardScoringScheme; this.overallLeaderboardScoringScheme = overallLeaderboardScoringScheme;
this.overallLeaderboardDiscardingRule = overallLeaderboardDiscardingRule; this.overallLeaderboardDiscardingRule = overallLeaderboardDiscardingRule;
this.metaColumnsWithFactors = metaColumnsWithFactors;
this.leaderboards = leaderboards; this.leaderboards = leaderboards;
this.displayGroupsRevese = displayGroupsRevese; this.displayGroupsRevese = displayGroupsRevese;
this.events = events; this.events = events;
@@ -78,6 +80,10 @@ public class LeaderboardGroupMasterData {
public Set<RegattaMasterData> getRegattas() { public Set<RegattaMasterData> getRegattas() {
return regattas; return regattas;
} }
public Map<String, Double> getMetaColumnsWithFactors() {
return metaColumnsWithFactors;
}
} }
@@ -1,8 +1,10 @@
package com.sap.sailing.server.gateway.deserialization.masterdata.impl; package com.sap.sailing.server.gateway.deserialization.masterdata.impl;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
@@ -102,7 +104,19 @@ public class LeaderboardGroupMasterDataJsonDeserializer implements JsonDeseriali
} }
ScoringScheme overallLeaderboardScoringScheme = !hasOverallLeaderboard ? null : LeaderboardMasterDataJsonDeserializer.deserializeScoringScheme((JSONObject) object.get(LeaderboardGroupMasterDataJsonSerializer.FIELD_OVERALL_LEADERBOARD_SCORING_SCHEME), domainFactory); ScoringScheme overallLeaderboardScoringScheme = !hasOverallLeaderboard ? null : LeaderboardMasterDataJsonDeserializer.deserializeScoringScheme((JSONObject) object.get(LeaderboardGroupMasterDataJsonSerializer.FIELD_OVERALL_LEADERBOARD_SCORING_SCHEME), domainFactory);
int[] overallLeaderboardResultDiscardingThresholds = !hasOverallLeaderboard ? null : LeaderboardMasterDataJsonDeserializer.deserializeResultDesicardingRule((JSONObject) object.get(LeaderboardGroupMasterDataJsonSerializer.FIELD_OVERALL_LEADERBOARD_DISCARDING_THRESHOLDS)); int[] overallLeaderboardResultDiscardingThresholds = !hasOverallLeaderboard ? null : LeaderboardMasterDataJsonDeserializer.deserializeResultDesicardingRule((JSONObject) object.get(LeaderboardGroupMasterDataJsonSerializer.FIELD_OVERALL_LEADERBOARD_DISCARDING_THRESHOLDS));
return new LeaderboardGroupMasterData(name, description, displayGroupsReverse, hasOverallLeaderboard, overallLeaderboardScoringScheme, overallLeaderboardResultDiscardingThresholds, leaderboards, events, regattas); Map<String, Double> metaColumnsWithFactors = !hasOverallLeaderboard ? null : deserializeMetaColumnsWithFactor((JSONArray) object.get(LeaderboardGroupMasterDataJsonSerializer.FIELD_OVERALL_LEADERBOARD_META_COLUMNS));
return new LeaderboardGroupMasterData(name, description, displayGroupsReverse, hasOverallLeaderboard, overallLeaderboardScoringScheme, overallLeaderboardResultDiscardingThresholds, metaColumnsWithFactors, leaderboards, events, regattas);
}
private Map<String, Double> deserializeMetaColumnsWithFactor(JSONArray jsonArray) {
Map<String, Double> metaColumnsWithFactors = new HashMap<String, Double>();
for (Object obj : jsonArray) {
JSONObject jsonObj = (JSONObject) obj;
String name = (String) jsonObj.get(LeaderboardGroupMasterDataJsonSerializer.FIELD_NAME);
Double explicitFactor = (Double) jsonObj.get(LeaderboardGroupMasterDataJsonSerializer.FIELD_EXPLICIT_FACTOR);
metaColumnsWithFactors.put(name, explicitFactor);
}
return metaColumnsWithFactors;
} }
} }
@@ -15,6 +15,7 @@ import com.sap.sailing.domain.base.Regatta;
import com.sap.sailing.domain.common.Color; import com.sap.sailing.domain.common.Color;
import com.sap.sailing.domain.leaderboard.Leaderboard; 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.domain.leaderboard.meta.LeaderboardGroupMetaLeaderboard;
import com.sap.sailing.domain.racelog.RaceLogEvent; import com.sap.sailing.domain.racelog.RaceLogEvent;
import com.sap.sailing.server.gateway.serialization.JsonSerializer; import com.sap.sailing.server.gateway.serialization.JsonSerializer;
import com.sap.sailing.server.gateway.serialization.impl.BoatClassJsonSerializer; import com.sap.sailing.server.gateway.serialization.impl.BoatClassJsonSerializer;
@@ -36,6 +37,8 @@ public class LeaderboardGroupMasterDataJsonSerializer implements JsonSerializer<
public static final String FIELD_DISPLAY_GROUPS_REVERSE = "displayGroupsReverse"; public static final String FIELD_DISPLAY_GROUPS_REVERSE = "displayGroupsReverse";
public static final String FIELD_EVENTS = "events"; public static final String FIELD_EVENTS = "events";
public static final String FIELD_REGATTAS = "regattas"; public static final String FIELD_REGATTAS = "regattas";
public static final String FIELD_OVERALL_LEADERBOARD_META_COLUMNS = "overallLeaderboardMetaColumns";
public static final String FIELD_EXPLICIT_FACTOR = "explicitFactor";
private final LeaderboardMasterDataJsonSerializer leadboardSerializer; private final LeaderboardMasterDataJsonSerializer leadboardSerializer;
private final Iterable<Event> allEvents; private final Iterable<Event> allEvents;
private final JsonSerializer<Event> eventSerializer; private final JsonSerializer<Event> eventSerializer;
@@ -71,12 +74,14 @@ public class LeaderboardGroupMasterDataJsonSerializer implements JsonSerializer<
jsonLeaderboardGroup.put(FIELD_DESCRIPTION, leaderboardGroup.getDescription()); jsonLeaderboardGroup.put(FIELD_DESCRIPTION, leaderboardGroup.getDescription());
jsonLeaderboardGroup.put(FIELD_HAS_OVERALL_LEADERBOARD, leaderboardGroup.getOverallLeaderboard() != null); jsonLeaderboardGroup.put(FIELD_HAS_OVERALL_LEADERBOARD, leaderboardGroup.getOverallLeaderboard() != null);
if (leaderboardGroup.getOverallLeaderboard() != null) { if (leaderboardGroup.getOverallLeaderboard() != null) {
LeaderboardGroupMetaLeaderboard metaLeader = (LeaderboardGroupMetaLeaderboard) leaderboardGroup
.getOverallLeaderboard();
jsonLeaderboardGroup.put(FIELD_OVERALL_LEADERBOARD_DISCARDING_THRESHOLDS, jsonLeaderboardGroup.put(FIELD_OVERALL_LEADERBOARD_DISCARDING_THRESHOLDS,
LeaderboardMasterDataJsonSerializer.createJsonForResultDiscardingRule(leaderboardGroup LeaderboardMasterDataJsonSerializer.createJsonForResultDiscardingRule(metaLeader
.getOverallLeaderboard().getResultDiscardingRule())); .getResultDiscardingRule()));
jsonLeaderboardGroup.put(FIELD_OVERALL_LEADERBOARD_SCORING_SCHEME, jsonLeaderboardGroup.put(FIELD_OVERALL_LEADERBOARD_SCORING_SCHEME,
LeaderboardMasterDataJsonSerializer.createJsonForScoringScheme(leaderboardGroup LeaderboardMasterDataJsonSerializer.createJsonForScoringScheme(metaLeader.getScoringScheme()));
.getOverallLeaderboard().getScoringScheme())); jsonLeaderboardGroup.put(FIELD_OVERALL_LEADERBOARD_META_COLUMNS, createJsonArrayForMetaColumns(metaLeader));
} }
jsonLeaderboardGroup.put(FIELD_LEADERBOARDS, createJsonArrayForLeaderboards(leaderboardGroup.getLeaderboards())); jsonLeaderboardGroup.put(FIELD_LEADERBOARDS, createJsonArrayForLeaderboards(leaderboardGroup.getLeaderboards()));
jsonLeaderboardGroup.put(FIELD_DISPLAY_GROUPS_REVERSE, leaderboardGroup.isDisplayGroupsInReverseOrder()); jsonLeaderboardGroup.put(FIELD_DISPLAY_GROUPS_REVERSE, leaderboardGroup.isDisplayGroupsInReverseOrder());
@@ -88,6 +93,17 @@ public class LeaderboardGroupMasterDataJsonSerializer implements JsonSerializer<
return jsonLeaderboardGroup; return jsonLeaderboardGroup;
} }
private JSONArray createJsonArrayForMetaColumns(LeaderboardGroupMetaLeaderboard metaLeader) {
JSONArray array = new JSONArray();
for (RaceColumn column : metaLeader.getRaceColumns()) {
JSONObject metaColumn = new JSONObject();
metaColumn.put(FIELD_NAME, column.getName());
metaColumn.put(FIELD_EXPLICIT_FACTOR, column.getExplicitFactor());
array.add(metaColumn);
}
return array;
}
private JSONArray createJsonArrayForRegattas() { private JSONArray createJsonArrayForRegattas() {
JSONArray array = new JSONArray(); JSONArray array = new JSONArray();
Iterable<Regatta> regattas = leadboardSerializer.getRegattas(); Iterable<Regatta> regattas = leadboardSerializer.getRegattas();
@@ -51,11 +51,14 @@ import com.sap.sailing.domain.common.TimePoint;
import com.sap.sailing.domain.common.impl.MillisecondsTimePoint; import com.sap.sailing.domain.common.impl.MillisecondsTimePoint;
import com.sap.sailing.domain.common.impl.Util.Triple; import com.sap.sailing.domain.common.impl.Util.Triple;
import com.sap.sailing.domain.common.media.MediaTrack; import com.sap.sailing.domain.common.media.MediaTrack;
import com.sap.sailing.domain.leaderboard.FlexibleLeaderboard;
import com.sap.sailing.domain.leaderboard.Leaderboard; 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.domain.leaderboard.ScoringScheme; import com.sap.sailing.domain.leaderboard.ScoringScheme;
import com.sap.sailing.domain.leaderboard.ThresholdBasedResultDiscardingRule; import com.sap.sailing.domain.leaderboard.ThresholdBasedResultDiscardingRule;
import com.sap.sailing.domain.leaderboard.impl.FlexibleLeaderboardImpl;
import com.sap.sailing.domain.leaderboard.impl.LowPoint; import com.sap.sailing.domain.leaderboard.impl.LowPoint;
import com.sap.sailing.domain.leaderboard.meta.LeaderboardGroupMetaLeaderboard;
import com.sap.sailing.domain.persistence.PersistenceFactory; import com.sap.sailing.domain.persistence.PersistenceFactory;
import com.sap.sailing.domain.persistence.media.MediaDBFactory; import com.sap.sailing.domain.persistence.media.MediaDBFactory;
import com.sap.sailing.domain.racelog.RaceLogEventFactory; import com.sap.sailing.domain.racelog.RaceLogEventFactory;
@@ -1351,9 +1354,15 @@ public class MasterDataImportTest {
int[] discardRule = { 1, 2, 3, 4 }; int[] discardRule = { 1, 2, 3, 4 };
ScoringScheme scheme = new LowPoint(); ScoringScheme scheme = new LowPoint();
List<String> leaderboardNames = new ArrayList<String>(); List<String> leaderboardNames = new ArrayList<String>();
sourceService.addLeaderboardGroup(TEST_GROUP_NAME, "testGroupDesc", false, LeaderboardGroup sourceGroup = sourceService.addLeaderboardGroup(TEST_GROUP_NAME, "testGroupDesc", false,
leaderboardNames, discardRule, scheme.getType()); leaderboardNames, discardRule, scheme.getType());
FlexibleLeaderboard sourceLeaderboard1 = new FlexibleLeaderboardImpl("Leaderboard1", null, scheme, null);
sourceService.addLeaderboard(sourceLeaderboard1);
sourceGroup.addLeaderboard(sourceLeaderboard1);
LeaderboardGroupMetaLeaderboard metaLeaderboard = (LeaderboardGroupMetaLeaderboard) sourceGroup.getOverallLeaderboard();
double factor = 2.6;
metaLeaderboard.getRaceColumns().iterator().next().setFactor(factor);
// Serialize // Serialize
TopLevelMasterDataSerializer serializer = new TopLevelMasterDataSerializer( TopLevelMasterDataSerializer serializer = new TopLevelMasterDataSerializer(
@@ -1381,7 +1390,7 @@ public class MasterDataImportTest {
LeaderboardGroup leaderboardGroupOnTarget = destService.getLeaderboardGroupByName(TEST_GROUP_NAME); LeaderboardGroup leaderboardGroupOnTarget = destService.getLeaderboardGroupByName(TEST_GROUP_NAME);
Assert.assertNotNull(leaderboardGroupOnTarget); Assert.assertNotNull(leaderboardGroupOnTarget);
Leaderboard overallLeaderboard = leaderboardGroupOnTarget.getOverallLeaderboard(); LeaderboardGroupMetaLeaderboard overallLeaderboard = (LeaderboardGroupMetaLeaderboard) leaderboardGroupOnTarget.getOverallLeaderboard();
Assert.assertNotNull(overallLeaderboard); Assert.assertNotNull(overallLeaderboard);
Assert.assertNotNull(overallLeaderboard.getResultDiscardingRule()); Assert.assertNotNull(overallLeaderboard.getResultDiscardingRule());
@@ -1392,6 +1401,12 @@ public class MasterDataImportTest {
Assert.assertEquals(3, ((ThresholdBasedResultDiscardingRule) overallLeaderboard.getResultDiscardingRule()) Assert.assertEquals(3, ((ThresholdBasedResultDiscardingRule) overallLeaderboard.getResultDiscardingRule())
.getDiscardIndexResultsStartingWithHowManyRaces()[2]); .getDiscardIndexResultsStartingWithHowManyRaces()[2]);
Iterable<RaceColumn> metaColumns = overallLeaderboard.getRaceColumns();
RaceColumn metaColumn = metaColumns.iterator().next();
Assert.assertNotNull(metaColumn);
Assert.assertEquals(factor, metaColumn.getFactor());
} }
} }
@@ -158,6 +158,11 @@ public class ImportMasterDataOperation extends
leaderboardGroup, masterData.getOverallLeaderboardScoringScheme(), masterData.getOverallLeaderboardDiscardingRule()); leaderboardGroup, masterData.getOverallLeaderboardScoringScheme(), masterData.getOverallLeaderboardDiscardingRule());
leaderboardGroup.setOverallLeaderboard(overallLeaderboard); leaderboardGroup.setOverallLeaderboard(overallLeaderboard);
toState.addLeaderboard(overallLeaderboard); toState.addLeaderboard(overallLeaderboard);
Map<String, Double> factorsForMetaColumns = masterData.getMetaColumnsWithFactors();
for (RaceColumn column : overallLeaderboard.getRaceColumns()) {
Double explicitFactor = factorsForMetaColumns.get(column.getName());
column.setFactor(explicitFactor);
}
} }
} }