# added configuration options for each racing procedures (DeviceConfiguration)

This commit is contained in:
Lukas Niemeier committed 2013-11-16 11:49:47 +01:00
1 parent bca2fb06d7
commit ae6cc75b1c
40 files changed
+434 -173

No files matched your search

@@ -16,6 +16,7 @@ import java.util.logging.Logger;
import org.bson.types.ObjectId;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
@@ -123,7 +124,10 @@ import com.sap.sailing.domain.tracking.Wind;
import com.sap.sailing.domain.tracking.WindTrack;
import com.sap.sailing.domain.tracking.impl.WindImpl;
import com.sap.sailing.domain.tracking.impl.WindTrackImpl;
import com.sap.sailing.server.gateway.deserialization.JsonDeserializationException;
import com.sap.sailing.server.gateway.deserialization.JsonDeserializer;
import com.sap.sailing.server.gateway.deserialization.impl.CompetitorJsonDeserializer;
import com.sap.sailing.server.gateway.deserialization.impl.DeviceConfigurationJsonDeserializer;
import com.sap.sailing.server.gateway.deserialization.impl.Helpers;
public class DomainObjectFactoryImpl implements DomainObjectFactory {
@@ -1326,7 +1330,8 @@ public class DomainObjectFactoryImpl implements DomainObjectFactory {
private Pair<DeviceConfigurationMatcher, DeviceConfiguration> loadConfigurationEntry(DBObject dbObject) {
DBObject matcherObject = (DBObject) dbObject.get(FieldNames.CONFIGURATION_MATCHER.name());
DBObject configObject = (DBObject) dbObject.get(FieldNames.CONFIGURATION_CONFIG.name());
return new Pair<DeviceConfigurationMatcher, DeviceConfiguration>(loadConfigurationMatcher(matcherObject), loadConfiguration(configObject));
return new Pair<DeviceConfigurationMatcher, DeviceConfiguration>(loadConfigurationMatcher(matcherObject),
loadConfiguration(configObject));
}
private DeviceConfigurationMatcher loadConfigurationMatcher(DBObject matcherObject) {
@@ -1342,29 +1347,16 @@ public class DomainObjectFactoryImpl implements DomainObjectFactory {
}
private DeviceConfiguration loadConfiguration(DBObject configObject) {
DeviceConfigurationImpl configuration = new DeviceConfigurationImpl();
Object allowedCourseAreaObjects = configObject.get(FieldNames.CONFIGURATION_CONFIG_ALLOWED_COURSE_AREA_NAMES.name());
if (allowedCourseAreaObjects != null) {
List<String> allowedCourseAreas = new ArrayList<String>();
for (Object allowedCourseAreaObject : (BasicDBList)allowedCourseAreaObjects) {
allowedCourseAreas.add(allowedCourseAreaObject.toString());
}
configuration.setAllowedCourseAreaNames(allowedCourseAreas);
DeviceConfiguration configuration = null;
try {
JsonDeserializer<DeviceConfiguration> deserializer = DeviceConfigurationJsonDeserializer.create();
JSONObject json = Helpers.toJSONObjectSafe(new JSONParser().parse(JSON.serialize(configObject)));
configuration = deserializer.deserialize(json);
} catch (JsonDeserializationException | ParseException e) {
logger.log(Level.SEVERE, "Error parsing configuration object from MongoDB, falling back to empty configuration.");
logger.log(Level.SEVERE, "loadConfiguration", e);
configuration = new DeviceConfigurationImpl();
}
Object minRounds = configObject.get(FieldNames.CONFIGURATION_CONFIG_MIN_ROUNDS.name());
if (minRounds != null) {
configuration.setMinimumRoundsForCourse(((Number)minRounds).intValue());
}
Object maxRounds = configObject.get(FieldNames.CONFIGURATION_CONFIG_MAX_ROUNDS.name());
if (maxRounds != null) {
configuration.setMaximumRoundsForCourse(((Number)maxRounds).intValue());
}
Object mail = configObject.get(FieldNames.CONFIGURATION_CONFIG_RESULTS_MAIL.name());
if (mail != null) {
configuration.setResultsMailRecipient(mail.toString());
}
return configuration;
}
}
@@ -77,5 +77,7 @@ public enum FieldNames {
RACE_LOG_START_PROCEDURE_TYPE, RACE_LOG_PROTEST_START_TIME, RACE_LOG_COURSE_DESIGN_NAME,
// configurations
CONFIGURATION_MATCHER, CONFIGURATION_CONFIG, CONFIGURATION_MATCHER_ID, CONFIGURATION_MATCHER_TYPE, CONFIGURATION_MATCHER_CLIENTS, CONFIGURATION_CONFIG_ALLOWED_COURSE_AREA_NAMES, CONFIGURATION_CONFIG_MIN_ROUNDS, CONFIGURATION_CONFIG_MAX_ROUNDS, CONFIGURATION_CONFIG_RESULTS_MAIL;
CONFIGURATION_MATCHER, CONFIGURATION_CONFIG, CONFIGURATION_MATCHER_ID, CONFIGURATION_MATCHER_TYPE, CONFIGURATION_MATCHER_CLIENTS,
CONFIGURATION_CONFIG_ALLOWED_COURSE_AREA_NAMES, CONFIGURATION_CONFIG_MIN_ROUNDS, CONFIGURATION_CONFIG_MAX_ROUNDS, CONFIGURATION_CONFIG_RESULTS_MAIL,
CONFIGURATION_CONFIG_PROCEDURES;
}
@@ -42,8 +42,8 @@ import com.sap.sailing.domain.common.Speed;
import com.sap.sailing.domain.common.SpeedWithBearing;
import com.sap.sailing.domain.common.TimePoint;
import com.sap.sailing.domain.common.WindSource;
import com.sap.sailing.domain.common.impl.Util;
import com.sap.sailing.domain.common.impl.MillisecondsTimePoint;
import com.sap.sailing.domain.common.impl.Util;
import com.sap.sailing.domain.common.impl.Util.Triple;
import com.sap.sailing.domain.leaderboard.FlexibleLeaderboard;
import com.sap.sailing.domain.leaderboard.Leaderboard;
@@ -74,7 +74,9 @@ import com.sap.sailing.domain.tracking.TrackedRace;
import com.sap.sailing.domain.tracking.TrackedRegatta;
import com.sap.sailing.domain.tracking.Wind;
import com.sap.sailing.domain.tracking.WindTrack;
import com.sap.sailing.server.gateway.serialization.JsonSerializer;
import com.sap.sailing.server.gateway.serialization.impl.CompetitorJsonSerializer;
import com.sap.sailing.server.gateway.serialization.impl.DeviceConfigurationJsonSerializer;
public class MongoObjectFactoryImpl implements MongoObjectFactory {
private static Logger logger = Logger.getLogger(MongoObjectFactoryImpl.class.getName());
@@ -913,13 +915,13 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
DBObject entryObject = new BasicDBObject();
entryObject.put(FieldNames.CONFIGURATION_MATCHER_ID.name(), matcher.getMatcherIdentifier());
entryObject.put(FieldNames.CONFIGURATION_MATCHER.name(), storeDeviceConfigurationMatcher(matcher));
entryObject.put(FieldNames.CONFIGURATION_CONFIG.name(), storeDeviceConfigurationObject(configuration));
entryObject.put(FieldNames.CONFIGURATION_MATCHER.name(), createDeviceConfigurationMatcherObject(matcher));
entryObject.put(FieldNames.CONFIGURATION_CONFIG.name(), createDeviceConfigurationObject(configuration));
configurationsCollections.update(query, entryObject, /* upsrt */ true, /* multi */ false);
}
private DBObject storeDeviceConfigurationMatcher(DeviceConfigurationMatcher matcher) {
private DBObject createDeviceConfigurationMatcherObject(DeviceConfigurationMatcher matcher) {
DBObject matcherObject = new BasicDBObject();
matcherObject.put(FieldNames.CONFIGURATION_MATCHER_TYPE.name(), matcher.getMatcherType().name());
if (matcher instanceof DeviceConfigurationMatcherSingle) {
@@ -934,23 +936,11 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
return matcherObject;
}
private DBObject storeDeviceConfigurationObject(DeviceConfiguration configuration) {
DBObject configurationObject = new BasicDBObject();
if (configuration.getAllowedCourseAreaNames() != null) {
BasicDBList clients = new BasicDBList();
clients.addAll(configuration.getAllowedCourseAreaNames());
configurationObject.put(FieldNames.CONFIGURATION_CONFIG_ALLOWED_COURSE_AREA_NAMES.name(), clients);
}
if (configuration.getMinimumRoundsForCourse() != null) {
configurationObject.put(FieldNames.CONFIGURATION_CONFIG_MIN_ROUNDS.name(), configuration.getMinimumRoundsForCourse());
}
if (configuration.getMaximumRoundsForCourse() != null) {
configurationObject.put(FieldNames.CONFIGURATION_CONFIG_MAX_ROUNDS.name(), configuration.getMaximumRoundsForCourse());
}
if (configuration.getResultsMailRecipient() != null) {
configurationObject.put(FieldNames.CONFIGURATION_CONFIG_RESULTS_MAIL.name(), configuration.getResultsMailRecipient());
}
return configurationObject;
private DBObject createDeviceConfigurationObject(DeviceConfiguration configuration) {
JsonSerializer<DeviceConfiguration> serializer = DeviceConfigurationJsonSerializer.create();
JSONObject json = serializer.serialize(configuration);
DBObject entry = (DBObject) JSON.parse(json.toString());
return entry;
}
@Override