changes to placeholder identifier and (de)serialization

This commit is contained in:
Fredrik Teschke committed 2014-03-10 15:00:35 +01:00
1 parent 10f0b01576
commit 1ebed6373e
62 files changed
+812 -350

No files matched your search

@@ -11,18 +11,18 @@ import com.sap.sailing.mongodb.MongoDBService;
public class Activator implements BundleActivator {
private Set<ServiceRegistration<?>> registrations = new HashSet<>();
@Override
public void start(BundleContext context) throws Exception {
for (CollectionNames name : CollectionNames.values())
MongoDBService.INSTANCE.registerExclusively(CollectionNames.class, name.name());
}
@Override
public void start(BundleContext context) throws Exception {
for (CollectionNames name : CollectionNames.values())
MongoDBService.INSTANCE.registerExclusively(CollectionNames.class, name.name());
}
@Override
public void stop(BundleContext context) throws Exception {
for (ServiceRegistration<?> reg : registrations) {
reg.unregister();
}
registrations.clear();
}
@Override
public void stop(BundleContext context) throws Exception {
for (ServiceRegistration<?> reg : registrations) {
reg.unregister();
}
registrations.clear();
}
}
@@ -104,6 +104,7 @@ import com.sap.sailing.domain.leaderboard.meta.LeaderboardGroupMetaLeaderboard;
import com.sap.sailing.domain.persistence.DomainObjectFactory;
import com.sap.sailing.domain.persistence.MongoRaceLogStoreFactory;
import com.sap.sailing.domain.persistence.racelog.tracking.DeviceIdentifierMongoHandler;
import com.sap.sailing.domain.persistence.racelog.tracking.impl.PlaceHolderDeviceIdentifierMongoHandler;
import com.sap.sailing.domain.racelog.CompetitorResults;
import com.sap.sailing.domain.racelog.RaceLog;
import com.sap.sailing.domain.racelog.RaceLogCourseAreaChangedEvent;
@@ -171,6 +172,7 @@ public class DomainObjectFactoryImpl implements DomainObjectFactory {
this.serviceFinderFactory = serviceFinderFactory;
if (serviceFinderFactory != null) {
this.deviceIdentifierServiceFinder = serviceFinderFactory.createServiceFinder(DeviceIdentifierMongoHandler.class);
this.deviceIdentifierServiceFinder.setFallbackService(new PlaceHolderDeviceIdentifierMongoHandler());
} else {
this.deviceIdentifierServiceFinder = null;
}
@@ -1568,6 +1570,7 @@ public class DomainObjectFactoryImpl implements DomainObjectFactory {
throws TransformationException, NoCorrespondingServiceRegisteredException {
String deviceType = (String) deviceId.get(FieldNames.DEVICE_TYPE.name());
Object deviceTypeId = deviceId.get(FieldNames.DEVICE_TYPE_ID.name());
return deviceIdentifierServiceFinder.findService(deviceType).transformBack(deviceTypeId);
String stringRepresentation = (String) deviceId.get(FieldNames.DEVICE_STRING_REPRESENTATION.name());
return deviceIdentifierServiceFinder.findService(deviceType).deserialize(deviceTypeId, deviceType, stringRepresentation);
}
}
@@ -90,5 +90,5 @@ public enum FieldNames {
CONFIGURATION_CONFIG_PROCEDURES,
// GPSFixes
DEVICE_TYPE_ID, DEVICE_ID, DEVICE_TYPE, GPSFIX_TYPE, GPSFIX,
DEVICE_TYPE_ID, DEVICE_ID, DEVICE_TYPE, GPSFIX_TYPE, GPSFIX, DEVICE_STRING_REPRESENTATION,
}
@@ -48,6 +48,7 @@ import com.sap.sailing.domain.common.TimePoint;
import com.sap.sailing.domain.common.WindSource;
import com.sap.sailing.domain.common.impl.MillisecondsTimePoint;
import com.sap.sailing.domain.common.impl.Util;
import com.sap.sailing.domain.common.impl.Util.Pair;
import com.sap.sailing.domain.common.impl.Util.Triple;
import com.sap.sailing.domain.common.racelog.tracking.NoCorrespondingServiceRegisteredException;
import com.sap.sailing.domain.common.racelog.tracking.TransformationException;
@@ -62,6 +63,7 @@ import com.sap.sailing.domain.leaderboard.SettableScoreCorrection;
import com.sap.sailing.domain.leaderboard.ThresholdBasedResultDiscardingRule;
import com.sap.sailing.domain.persistence.MongoObjectFactory;
import com.sap.sailing.domain.persistence.racelog.tracking.DeviceIdentifierMongoHandler;
import com.sap.sailing.domain.persistence.racelog.tracking.impl.PlaceHolderDeviceIdentifierMongoHandler;
import com.sap.sailing.domain.racelog.RaceLogCourseAreaChangedEvent;
import com.sap.sailing.domain.racelog.RaceLogCourseDesignChangedEvent;
import com.sap.sailing.domain.racelog.RaceLogEvent;
@@ -115,6 +117,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
this.database = database;
if (serviceFinderFactory != null) {
this.deviceIdentifierServiceFinder = serviceFinderFactory.createServiceFinder(DeviceIdentifierMongoHandler.class);
this.deviceIdentifierServiceFinder.setFallbackService(new PlaceHolderDeviceIdentifierMongoHandler());
} else {
this.deviceIdentifierServiceFinder = null;
}
@@ -1146,9 +1149,12 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
throws TransformationException, NoCorrespondingServiceRegisteredException {
String type = device.getIdentifierType();
DeviceIdentifierMongoHandler handler = deviceIdentifierServiceFinder.findService(type);
Object deviceTypeId = handler.transformForth(device);
Pair<? extends Object, String> pair = handler.serialize(device);
type = pair.getB();
Object deviceTypeId = pair.getA();
return new BasicDBObjectBuilder()
.add(FieldNames.DEVICE_TYPE.name(), device.getIdentifierType())
.add(FieldNames.DEVICE_TYPE_ID.name(), deviceTypeId).get();
.add(FieldNames.DEVICE_TYPE.name(), type)
.add(FieldNames.DEVICE_TYPE_ID.name(), deviceTypeId)
.add(FieldNames.DEVICE_STRING_REPRESENTATION.name(), device.getStringRepresentation()).get();
}
}
@@ -1,29 +1,6 @@
package com.sap.sailing.domain.persistence.racelog.tracking;
import com.mongodb.DBObject;
import com.sap.sailing.domain.common.racelog.tracking.TransformationHandler;
import com.sap.sailing.domain.common.racelog.tracking.TypeBasedServiceFinder;
import com.sap.sailing.domain.racelog.RaceLog;
import com.sap.sailing.domain.racelog.tracking.DeviceCompetitorMappingEvent;
import com.sap.sailing.domain.racelog.tracking.DeviceIdentifier;
import com.sap.sailing.domain.racelog.tracking.DeviceIdentifierSerializationHandler;
/**
* {@link DeviceIdentifier} objects need to be stored in the database, e.g., for
* {@link RaceLog} persistence, when writing an object of type
* {@link DeviceCompetitorMappingEvent}. In conjunction with a
* {@link TypeBasedServiceFinder} it is possible to extend the set of device
* types whose device identifiers can be stored to and loaded from the database
* by providing specific implementations of this handler interface. In an OSGi
* context, bundles can register implementations of this handler interface with
* the OSGi service registry to extend the set of supported device types without
* modifications to the existing code base.
*
* The resulting {@link Object} is expected to be either a simple {@link Object}
* that can serialized, or a structured {@link DBObject}.
*
* @author Fredrik Teschke
*
*/
public interface DeviceIdentifierMongoHandler extends
TransformationHandler<DeviceIdentifier, Object> {
public interface DeviceIdentifierMongoHandler extends DeviceIdentifierSerializationHandler<Object> {
}
@@ -0,0 +1,9 @@
package com.sap.sailing.domain.persistence.racelog.tracking.impl;
import com.sap.sailing.domain.persistence.racelog.tracking.DeviceIdentifierMongoHandler;
import com.sap.sailing.domain.racelog.tracking.impl.PlaceHolderDeviceIdentifierSerializationHandler;
public class PlaceHolderDeviceIdentifierMongoHandler extends PlaceHolderDeviceIdentifierSerializationHandler
implements DeviceIdentifierMongoHandler {
}