mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-20 12:45:35 +00:00
exchanged tabs with spaces
This commit is contained in:
+3
-3
@@ -9,9 +9,9 @@ package com.sap.sailing.domain.common.racelog.tracking;
|
||||
*/
|
||||
public enum RaceLogTrackingState {
|
||||
//can't determine whether tracking has ended from race log, therefore omitting TRACKING_ENDED state for now
|
||||
/**
|
||||
* no {@link DenoteForTrackingEvent} is present
|
||||
*/
|
||||
/**
|
||||
* no {@link DenoteForTrackingEvent} is present
|
||||
*/
|
||||
NOT_A_RACELOG_TRACKED_RACE,
|
||||
|
||||
/**
|
||||
|
||||
+13
-13
@@ -2,20 +2,20 @@ package com.sap.sailing.domain.common.racelog.tracking;
|
||||
|
||||
|
||||
public class SingleTypeBasedServiceFinderImpl<ServiceType> implements
|
||||
TypeBasedServiceFinder<ServiceType> {
|
||||
private final ServiceType service;
|
||||
private final String type;
|
||||
TypeBasedServiceFinder<ServiceType> {
|
||||
private final ServiceType service;
|
||||
private final String type;
|
||||
|
||||
public SingleTypeBasedServiceFinderImpl(ServiceType service, String type) {
|
||||
this.service = service;
|
||||
this.type = type;
|
||||
}
|
||||
public SingleTypeBasedServiceFinderImpl(ServiceType service, String type) {
|
||||
this.service = service;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServiceType findService(String type)
|
||||
throws NoCorrespondingServiceRegisteredException {
|
||||
if (type.equals(this.type)) return service;
|
||||
throw new NoCorrespondingServiceRegisteredException("Only one service registered", type, service.getClass());
|
||||
}
|
||||
@Override
|
||||
public ServiceType findService(String type)
|
||||
throws NoCorrespondingServiceRegisteredException {
|
||||
if (type.equals(this.type)) return service;
|
||||
throw new NoCorrespondingServiceRegisteredException("Only one service registered", type, service.getClass());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+23
-23
@@ -3,28 +3,28 @@ package com.sap.sailing.domain.common.racelog.tracking;
|
||||
import java.io.IOException;
|
||||
|
||||
public class TransformationException extends IOException {
|
||||
private static final long serialVersionUID = -7795777645371428971L;
|
||||
|
||||
public TransformationException() {
|
||||
}
|
||||
|
||||
public TransformationException(Class<?> from, Class<?> to, String at, Throwable e) {
|
||||
super(String.format("Couldn't transform %s into %s at %s", from.getName(), to.getName(), at), e);
|
||||
}
|
||||
|
||||
public TransformationException(Class<?> from, Class<?> to, String at) {
|
||||
this(from, to, at, null);
|
||||
}
|
||||
|
||||
public TransformationException(String message, Throwable e) {
|
||||
super(message, e);
|
||||
}
|
||||
private static final long serialVersionUID = -7795777645371428971L;
|
||||
|
||||
public TransformationException(Throwable e) {
|
||||
super(e);
|
||||
}
|
||||
|
||||
public TransformationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
public TransformationException() {
|
||||
}
|
||||
|
||||
public TransformationException(Class<?> from, Class<?> to, String at, Throwable e) {
|
||||
super(String.format("Couldn't transform %s into %s at %s", from.getName(), to.getName(), at), e);
|
||||
}
|
||||
|
||||
public TransformationException(Class<?> from, Class<?> to, String at) {
|
||||
this(from, to, at, null);
|
||||
}
|
||||
|
||||
public TransformationException(String message, Throwable e) {
|
||||
super(message, e);
|
||||
}
|
||||
|
||||
public TransformationException(Throwable e) {
|
||||
super(e);
|
||||
}
|
||||
|
||||
public TransformationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -7,6 +7,6 @@ package com.sap.sailing.domain.common.racelog.tracking;
|
||||
*
|
||||
*/
|
||||
public interface TransformationHandler<T1, T2> {
|
||||
T1 transformBack(T2 object) throws TransformationException;
|
||||
T2 transformForth(T1 object) throws TransformationException;
|
||||
T1 transformBack(T2 object) throws TransformationException;
|
||||
T2 transformForth(T1 object) throws TransformationException;
|
||||
}
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ package com.sap.sailing.domain.common.racelog.tracking;
|
||||
*/
|
||||
public interface TypeBasedServiceFinder<ServiceType> {
|
||||
public static final String TYPE = "type";
|
||||
|
||||
|
||||
/**
|
||||
* Find a service that implements the <ServiceType> interface for the specified {@code type}
|
||||
* of object (e.g. type of a {@link GPSFix}).
|
||||
|
||||
+30
-30
@@ -169,7 +169,7 @@ public class DomainObjectFactoryImpl implements DomainObjectFactory {
|
||||
if (serviceFinderFactory != null) {
|
||||
this.deviceIdentifierServiceFinder = serviceFinderFactory.createServiceFinder(DeviceIdentifierMongoHandler.class);
|
||||
} else {
|
||||
this.deviceIdentifierServiceFinder = null;
|
||||
this.deviceIdentifierServiceFinder = null;
|
||||
}
|
||||
this.baseDomainFactory = baseDomainFactory;
|
||||
this.competitorDeserializer = CompetitorJsonDeserializer.create(baseDomainFactory);
|
||||
@@ -1186,35 +1186,35 @@ public class DomainObjectFactoryImpl implements DomainObjectFactory {
|
||||
|
||||
private RaceLogEvent loadRaceLogDeviceCompetitorMappingEvent(TimePoint createdAt, RaceLogEventAuthor author, TimePoint logicalTimePoint,
|
||||
Serializable id, Integer passId, List<Competitor> competitors, DBObject dbObject) {
|
||||
DeviceIdentifier device = null;
|
||||
try {
|
||||
device = loadDeviceId(deviceIdentifierServiceFinder,
|
||||
(DBObject) dbObject.get(FieldNames.DEVICE_ID.name()));
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.WARNING, "Could not load deviceId for RaceLogEvent", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
Competitor mappedTo = baseDomainFactory.getExistingCompetitorById(
|
||||
(Serializable) dbObject.get(FieldNames.COMPETITOR_ID.name()));
|
||||
TimePoint from = loadTimePoint(dbObject, FieldNames.RACE_LOG_FROM);
|
||||
TimePoint to = loadTimePoint(dbObject, FieldNames.RACE_LOG_TO);
|
||||
DeviceIdentifier device = null;
|
||||
try {
|
||||
device = loadDeviceId(deviceIdentifierServiceFinder,
|
||||
(DBObject) dbObject.get(FieldNames.DEVICE_ID.name()));
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.WARNING, "Could not load deviceId for RaceLogEvent", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
Competitor mappedTo = baseDomainFactory.getExistingCompetitorById(
|
||||
(Serializable) dbObject.get(FieldNames.COMPETITOR_ID.name()));
|
||||
TimePoint from = loadTimePoint(dbObject, FieldNames.RACE_LOG_FROM);
|
||||
TimePoint to = loadTimePoint(dbObject, FieldNames.RACE_LOG_TO);
|
||||
return raceLogEventFactory.createDeviceCompetitorMappingEvent(createdAt, author, logicalTimePoint, id, device, mappedTo, passId, from, to);
|
||||
}
|
||||
|
||||
private RaceLogEvent loadRaceLogDeviceMarkMappingEvent(TimePoint createdAt, RaceLogEventAuthor author, TimePoint logicalTimePoint,
|
||||
Serializable id, Integer passId, List<Competitor> competitors, DBObject dbObject) {
|
||||
DeviceIdentifier device = null;
|
||||
try {
|
||||
device = loadDeviceId(deviceIdentifierServiceFinder,
|
||||
(DBObject) dbObject.get(FieldNames.DEVICE_ID.name()));
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.WARNING, "Could not load deviceId for RaceLogEvent", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
Mark mappedTo = baseDomainFactory.getOrCreateMark(
|
||||
(Serializable) dbObject.get(FieldNames.MARK_ID.name()), null);
|
||||
TimePoint from = loadTimePoint(dbObject, FieldNames.RACE_LOG_FROM);
|
||||
TimePoint to = loadTimePoint(dbObject, FieldNames.RACE_LOG_TO);
|
||||
DeviceIdentifier device = null;
|
||||
try {
|
||||
device = loadDeviceId(deviceIdentifierServiceFinder,
|
||||
(DBObject) dbObject.get(FieldNames.DEVICE_ID.name()));
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.WARNING, "Could not load deviceId for RaceLogEvent", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
Mark mappedTo = baseDomainFactory.getOrCreateMark(
|
||||
(Serializable) dbObject.get(FieldNames.MARK_ID.name()), null);
|
||||
TimePoint from = loadTimePoint(dbObject, FieldNames.RACE_LOG_FROM);
|
||||
TimePoint to = loadTimePoint(dbObject, FieldNames.RACE_LOG_TO);
|
||||
return raceLogEventFactory.createDeviceMarkMappingEvent(createdAt, author, logicalTimePoint, id, device, mappedTo, passId, from, to);
|
||||
}
|
||||
|
||||
@@ -1553,10 +1553,10 @@ public class DomainObjectFactoryImpl implements DomainObjectFactory {
|
||||
}
|
||||
|
||||
public static DeviceIdentifier loadDeviceId(
|
||||
TypeBasedServiceFinder<DeviceIdentifierMongoHandler> deviceIdentifierServiceFinder, DBObject deviceId)
|
||||
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);
|
||||
TypeBasedServiceFinder<DeviceIdentifierMongoHandler> deviceIdentifierServiceFinder, DBObject deviceId)
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
+13
-13
@@ -115,7 +115,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
|
||||
if (serviceFinderFactory != null) {
|
||||
this.deviceIdentifierServiceFinder = serviceFinderFactory.createServiceFinder(DeviceIdentifierMongoHandler.class);
|
||||
} else {
|
||||
this.deviceIdentifierServiceFinder = null;
|
||||
this.deviceIdentifierServiceFinder = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -794,12 +794,12 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
|
||||
|
||||
result.put(FieldNames.RACE_LOG_EVENT_CLASS.name(), DeviceCompetitorMappingEvent.class.getSimpleName());
|
||||
DBObject deviceId = null;
|
||||
try {
|
||||
deviceId = storeDeviceId(deviceIdentifierServiceFinder, event.getDevice());
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.WARNING, "Could not store deviceId for RaceLogEvent", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
deviceId = storeDeviceId(deviceIdentifierServiceFinder, event.getDevice());
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.WARNING, "Could not store deviceId for RaceLogEvent", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
result.put(FieldNames.DEVICE_ID.name(), deviceId);
|
||||
result.put(FieldNames.COMPETITOR_ID.name(), event.getMappedTo().getId());
|
||||
storeTimePoint(event.getFrom(), result, FieldNames.RACE_LOG_FROM);
|
||||
@@ -813,12 +813,12 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
|
||||
|
||||
result.put(FieldNames.RACE_LOG_EVENT_CLASS.name(), DeviceMarkMappingEvent.class.getSimpleName());
|
||||
DBObject deviceId = null;
|
||||
try {
|
||||
deviceId = storeDeviceId(deviceIdentifierServiceFinder, event.getDevice());
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.WARNING, "Could not store deviceId for RaceLogEvent", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
deviceId = storeDeviceId(deviceIdentifierServiceFinder, event.getDevice());
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.WARNING, "Could not store deviceId for RaceLogEvent", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
result.put(FieldNames.DEVICE_ID.name(), deviceId);
|
||||
result.put(FieldNames.MARK_ID.name(), event.getMappedTo().getId());
|
||||
storeTimePoint(event.getFrom(), result, FieldNames.RACE_LOG_FROM);
|
||||
|
||||
+1
-1
@@ -25,5 +25,5 @@ import com.sap.sailing.domain.racelog.tracking.DeviceIdentifier;
|
||||
*
|
||||
*/
|
||||
public interface DeviceIdentifierMongoHandler extends
|
||||
TransformationHandler<DeviceIdentifier, Object> {
|
||||
TransformationHandler<DeviceIdentifier, Object> {
|
||||
}
|
||||
|
||||
+3
-3
@@ -10,13 +10,13 @@ import com.sap.sailing.domain.persistence.racelog.tracking.impl.MongoGPSFixStore
|
||||
|
||||
public interface MongoGPSFixStoreFactory {
|
||||
MongoGPSFixStoreFactory INSTANCE = new MongoGPSFixStoreFactoryImpl();
|
||||
|
||||
|
||||
/**
|
||||
* Gets the default Mongo store based on the properties mongo.hostname[=localhost], mongo.port[=27017]
|
||||
* and mongo.dbName[=<contents of constant {@link #DEFAULT_DB_NAME}>] specified in the bundle context
|
||||
*/
|
||||
MongoGPSFixStore getMongoGPSFixStore(MongoObjectFactory mongoObjectFactory, DomainObjectFactory domainObjectFactory,
|
||||
TypeBasedServiceFinderFactory serviceFinderFactory)
|
||||
throws UnknownHostException, MongoException;
|
||||
TypeBasedServiceFinderFactory serviceFinderFactory)
|
||||
throws UnknownHostException, MongoException;
|
||||
|
||||
}
|
||||
+16
-16
@@ -11,28 +11,28 @@ import com.sap.sailing.domain.tracking.GPSFix;
|
||||
import com.sap.sailing.domain.tracking.impl.GPSFixImpl;
|
||||
|
||||
public class GPSFixMongoHandlerImpl implements GPSFixMongoHandler {
|
||||
MongoObjectFactoryImpl mof;
|
||||
DomainObjectFactoryImpl dof;
|
||||
MongoObjectFactoryImpl mof;
|
||||
DomainObjectFactoryImpl dof;
|
||||
|
||||
public GPSFixMongoHandlerImpl(MongoObjectFactoryImpl mof, DomainObjectFactoryImpl dof) {
|
||||
this.mof = mof;
|
||||
this.dof = dof;
|
||||
}
|
||||
public GPSFixMongoHandlerImpl(MongoObjectFactoryImpl mof, DomainObjectFactoryImpl dof) {
|
||||
this.mof = mof;
|
||||
this.dof = dof;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object transformForth(GPSFix fix) throws IllegalArgumentException {
|
||||
DBObject result = new BasicDBObject();
|
||||
mof.storeTimed(fix, result);
|
||||
mof.storePositioned(fix, result);
|
||||
@Override
|
||||
public Object transformForth(GPSFix fix) throws IllegalArgumentException {
|
||||
DBObject result = new BasicDBObject();
|
||||
mof.storeTimed(fix, result);
|
||||
mof.storePositioned(fix, result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GPSFix transformBack(Object object) {
|
||||
DBObject dbObject = (DBObject) object;
|
||||
@Override
|
||||
public GPSFix transformBack(Object object) {
|
||||
DBObject dbObject = (DBObject) object;
|
||||
TimePoint timePoint = dof.loadTimePoint(dbObject);
|
||||
Position position = dof.loadPosition(dbObject);
|
||||
return new GPSFixImpl(position, timePoint);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+17
-17
@@ -13,30 +13,30 @@ import com.sap.sailing.domain.tracking.GPSFixMoving;
|
||||
import com.sap.sailing.domain.tracking.impl.GPSFixMovingImpl;
|
||||
|
||||
public class GPSFixMovingMongoHandlerImpl implements GPSFixMongoHandler {
|
||||
MongoObjectFactoryImpl mof;
|
||||
DomainObjectFactoryImpl dof;
|
||||
MongoObjectFactoryImpl mof;
|
||||
DomainObjectFactoryImpl dof;
|
||||
|
||||
public GPSFixMovingMongoHandlerImpl(MongoObjectFactoryImpl mof, DomainObjectFactoryImpl dof) {
|
||||
this.mof = mof;
|
||||
this.dof = dof;
|
||||
}
|
||||
public GPSFixMovingMongoHandlerImpl(MongoObjectFactoryImpl mof, DomainObjectFactoryImpl dof) {
|
||||
this.mof = mof;
|
||||
this.dof = dof;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object transformForth(GPSFix fix) throws IllegalArgumentException {
|
||||
DBObject result = new BasicDBObject();
|
||||
mof.storeTimed(fix, result);
|
||||
mof.storePositioned(fix, result);
|
||||
mof.storeSpeedWithBearing(((GPSFixMoving) fix).getSpeed(), result);
|
||||
@Override
|
||||
public Object transformForth(GPSFix fix) throws IllegalArgumentException {
|
||||
DBObject result = new BasicDBObject();
|
||||
mof.storeTimed(fix, result);
|
||||
mof.storePositioned(fix, result);
|
||||
mof.storeSpeedWithBearing(((GPSFixMoving) fix).getSpeed(), result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GPSFix transformBack(Object object) {
|
||||
DBObject dbObject = (DBObject) object;
|
||||
@Override
|
||||
public GPSFix transformBack(Object object) {
|
||||
DBObject dbObject = (DBObject) object;
|
||||
TimePoint timePoint = dof.loadTimePoint(dbObject);
|
||||
Position position = dof.loadPosition(dbObject);
|
||||
SpeedWithBearing speed = dof.loadSpeedWithBearing(dbObject);
|
||||
return new GPSFixMovingImpl(position, timePoint, speed);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+6
-6
@@ -10,10 +10,10 @@ import com.sap.sailing.domain.persistence.racelog.tracking.MongoGPSFixStore;
|
||||
import com.sap.sailing.domain.persistence.racelog.tracking.MongoGPSFixStoreFactory;
|
||||
|
||||
public class MongoGPSFixStoreFactoryImpl implements MongoGPSFixStoreFactory {
|
||||
@Override
|
||||
public MongoGPSFixStore getMongoGPSFixStore(MongoObjectFactory mongoObjectFactory,
|
||||
DomainObjectFactory domainObjectFactory, TypeBasedServiceFinderFactory serviceFinderFactory)
|
||||
throws UnknownHostException, MongoException {
|
||||
return new MongoGPSFixStoreImpl(mongoObjectFactory, domainObjectFactory, serviceFinderFactory);
|
||||
}
|
||||
@Override
|
||||
public MongoGPSFixStore getMongoGPSFixStore(MongoObjectFactory mongoObjectFactory,
|
||||
DomainObjectFactory domainObjectFactory, TypeBasedServiceFinderFactory serviceFinderFactory)
|
||||
throws UnknownHostException, MongoException {
|
||||
return new MongoGPSFixStoreImpl(mongoObjectFactory, domainObjectFactory, serviceFinderFactory);
|
||||
}
|
||||
}
|
||||
|
||||
+106
-106
@@ -35,26 +35,26 @@ import com.sap.sailing.domain.tracking.GPSFix;
|
||||
import com.sap.sailing.domain.tracking.GPSFixMoving;
|
||||
|
||||
public class MongoGPSFixStoreImpl implements MongoGPSFixStore {
|
||||
private static final Logger logger = Logger.getLogger(MongoGPSFixStore.class.getName());
|
||||
private final TypeBasedServiceFinder<GPSFixMongoHandler> fixServiceFinder;
|
||||
private static final Logger logger = Logger.getLogger(MongoGPSFixStore.class.getName());
|
||||
private final TypeBasedServiceFinder<GPSFixMongoHandler> fixServiceFinder;
|
||||
private final TypeBasedServiceFinder<DeviceIdentifierMongoHandler> deviceServiceFinder;
|
||||
private final DBCollection collection;
|
||||
private final MongoObjectFactoryImpl mongoOF;
|
||||
private final ConcurrentHashMap<Object, GPSFixReceivedListener> listeners = new ConcurrentHashMap<>();
|
||||
|
||||
public MongoGPSFixStoreImpl(MongoObjectFactory mongoObjectFactory,
|
||||
DomainObjectFactory domainObjectFactory, TypeBasedServiceFinderFactory serviceFinderFactory) {
|
||||
mongoOF = (MongoObjectFactoryImpl) mongoObjectFactory;
|
||||
if (serviceFinderFactory != null) {
|
||||
fixServiceFinder = serviceFinderFactory.createServiceFinder(GPSFixMongoHandler.class);
|
||||
deviceServiceFinder = serviceFinderFactory.createServiceFinder(DeviceIdentifierMongoHandler.class);
|
||||
} else {
|
||||
fixServiceFinder = null;
|
||||
deviceServiceFinder = null;
|
||||
}
|
||||
collection = mongoOF.getGPSFixCollection();
|
||||
}
|
||||
|
||||
private final DBCollection collection;
|
||||
private final MongoObjectFactoryImpl mongoOF;
|
||||
private final ConcurrentHashMap<Object, GPSFixReceivedListener> listeners = new ConcurrentHashMap<>();
|
||||
|
||||
public MongoGPSFixStoreImpl(MongoObjectFactory mongoObjectFactory,
|
||||
DomainObjectFactory domainObjectFactory, TypeBasedServiceFinderFactory serviceFinderFactory) {
|
||||
mongoOF = (MongoObjectFactoryImpl) mongoObjectFactory;
|
||||
if (serviceFinderFactory != null) {
|
||||
fixServiceFinder = serviceFinderFactory.createServiceFinder(GPSFixMongoHandler.class);
|
||||
deviceServiceFinder = serviceFinderFactory.createServiceFinder(DeviceIdentifierMongoHandler.class);
|
||||
} else {
|
||||
fixServiceFinder = null;
|
||||
deviceServiceFinder = null;
|
||||
}
|
||||
collection = mongoOF.getGPSFixCollection();
|
||||
}
|
||||
|
||||
private GPSFix loadGPSFix(DBObject object) throws TransformationException, NoCorrespondingServiceRegisteredException {
|
||||
String type = (String) object.get(FieldNames.GPSFIX_TYPE.name());
|
||||
Object fixObject = object.get(FieldNames.GPSFIX.name());
|
||||
@@ -62,104 +62,104 @@ public class MongoGPSFixStoreImpl implements MongoGPSFixStore {
|
||||
}
|
||||
|
||||
private <FixT extends GPSFix> void loadTrack(DynamicGPSFixTrack<?, FixT> track, DeviceIdentifier device,
|
||||
TimePoint from, TimePoint to, boolean inclusive) throws NoCorrespondingServiceRegisteredException {
|
||||
long fromMillis = from.asMillis() - (inclusive ? 1 : 0);
|
||||
long toMillis = to.asMillis() + (inclusive ? 1 : 0);
|
||||
|
||||
Object dbDeviceId = null;
|
||||
try {
|
||||
dbDeviceId = MongoObjectFactoryImpl.storeDeviceId(deviceServiceFinder, device);
|
||||
} catch (TransformationException | NoCorrespondingServiceRegisteredException e) {
|
||||
logger.log(Level.WARNING, "Could not serialize Device ID for MongoDB: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
DBObject query = QueryBuilder.start(FieldNames.DEVICE_ID.name()).is(dbDeviceId)
|
||||
.and(FieldNames.TIME_AS_MILLIS.name()).greaterThan(fromMillis)
|
||||
.and(FieldNames.TIME_AS_MILLIS.name()).lessThan(toMillis).get();
|
||||
TimePoint from, TimePoint to, boolean inclusive) throws NoCorrespondingServiceRegisteredException {
|
||||
long fromMillis = from.asMillis() - (inclusive ? 1 : 0);
|
||||
long toMillis = to.asMillis() + (inclusive ? 1 : 0);
|
||||
|
||||
Object dbDeviceId = null;
|
||||
try {
|
||||
dbDeviceId = MongoObjectFactoryImpl.storeDeviceId(deviceServiceFinder, device);
|
||||
} catch (TransformationException | NoCorrespondingServiceRegisteredException e) {
|
||||
logger.log(Level.WARNING, "Could not serialize Device ID for MongoDB: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
DBObject query = QueryBuilder.start(FieldNames.DEVICE_ID.name()).is(dbDeviceId)
|
||||
.and(FieldNames.TIME_AS_MILLIS.name()).greaterThan(fromMillis)
|
||||
.and(FieldNames.TIME_AS_MILLIS.name()).lessThan(toMillis).get();
|
||||
|
||||
DBCursor result = collection.find(query);
|
||||
for (DBObject fixObject : result) {
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
FixT fix = (FixT) loadGPSFix(fixObject);
|
||||
track.add(fix);
|
||||
} catch (TransformationException e) {
|
||||
logger.log(Level.WARNING, "Could not read fix from MongoDB: " + fixObject);
|
||||
} catch (ClassCastException e) {
|
||||
String type = (String) fixObject.get(FieldNames.GPSFIX_TYPE.name());
|
||||
logger.log(Level.WARNING, "Unexpected fix type (" + type + ") encountered when trying to load track for " + track.getTrackedItem());
|
||||
}
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
FixT fix = (FixT) loadGPSFix(fixObject);
|
||||
track.add(fix);
|
||||
} catch (TransformationException e) {
|
||||
logger.log(Level.WARNING, "Could not read fix from MongoDB: " + fixObject);
|
||||
} catch (ClassCastException e) {
|
||||
String type = (String) fixObject.get(FieldNames.GPSFIX_TYPE.name());
|
||||
logger.log(Level.WARNING, "Unexpected fix type (" + type + ") encountered when trying to load track for " + track.getTrackedItem());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadCompetitorTrack(DynamicGPSFixTrack<Competitor, GPSFixMoving> track, RaceLog raceLog, Competitor competitor) {
|
||||
List<DeviceMapping<Competitor>> mappings = new DeviceCompetitorMappingFinder(raceLog).analyze().get(competitor);
|
||||
|
||||
if (mappings != null) {
|
||||
for (DeviceMapping<Competitor> mapping : mappings) {
|
||||
loadTrack(track, mapping.getDevice(), mapping.getTimeRange().from(), mapping.getTimeRange().to(), true /*inclusive*/);
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void loadCompetitorTrack(DynamicGPSFixTrack<Competitor, GPSFixMoving> track, RaceLog raceLog, Competitor competitor) {
|
||||
List<DeviceMapping<Competitor>> mappings = new DeviceCompetitorMappingFinder(raceLog).analyze().get(competitor);
|
||||
|
||||
@Override
|
||||
public void loadMarkTrack(DynamicGPSFixTrack<Mark, GPSFix> track, RaceLog raceLog, Mark mark) {
|
||||
List<DeviceMapping<Mark>> mappings = new DeviceMarkMappingFinder(raceLog).analyze().get(mark);
|
||||
|
||||
if (mappings != null) {
|
||||
for (DeviceMapping<Mark> mapping : mappings) {
|
||||
loadTrack(track, mapping.getDevice(), mapping.getTimeRange().from(), mapping.getTimeRange().to(), true /*inclusive*/);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mappings != null) {
|
||||
for (DeviceMapping<Competitor> mapping : mappings) {
|
||||
loadTrack(track, mapping.getDevice(), mapping.getTimeRange().from(), mapping.getTimeRange().to(), true /*inclusive*/);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void storeFix(DeviceIdentifier device, GPSFix fix) {
|
||||
try {
|
||||
Object dbDeviceId = MongoObjectFactoryImpl.storeDeviceId(deviceServiceFinder, device);
|
||||
String type = fix.getClass().getName();
|
||||
|
||||
Object fixObject = fixServiceFinder.findService(type).transformForth(fix);
|
||||
DBObject entry = new BasicDBObjectBuilder()
|
||||
.add(FieldNames.DEVICE_ID.name(), dbDeviceId)
|
||||
.add(FieldNames.GPSFIX_TYPE.name(), type)
|
||||
.add(FieldNames.GPSFIX.name(), fixObject).get();
|
||||
mongoOF.storeTimed(fix, entry);
|
||||
@Override
|
||||
public void loadMarkTrack(DynamicGPSFixTrack<Mark, GPSFix> track, RaceLog raceLog, Mark mark) {
|
||||
List<DeviceMapping<Mark>> mappings = new DeviceMarkMappingFinder(raceLog).analyze().get(mark);
|
||||
|
||||
collection.insert(entry);
|
||||
} catch (TransformationException e) {
|
||||
logger.log(Level.WARNING, "Could not store fix in MongoDB");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
notifyListeners(device, fix);
|
||||
}
|
||||
|
||||
private void notifyListeners(DeviceIdentifier device, GPSFix fix) {
|
||||
for (GPSFixReceivedListener listener : listeners.values()) {
|
||||
listener.fixReceived(device, fix);
|
||||
}
|
||||
}
|
||||
if (mappings != null) {
|
||||
for (DeviceMapping<Mark> mapping : mappings) {
|
||||
loadTrack(track, mapping.getDevice(), mapping.getTimeRange().from(), mapping.getTimeRange().to(), true /*inclusive*/);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(GPSFixReceivedListener listener) {
|
||||
listeners.put(listener.hashCode(), listener);
|
||||
}
|
||||
@Override
|
||||
public void storeFix(DeviceIdentifier device, GPSFix fix) {
|
||||
try {
|
||||
Object dbDeviceId = MongoObjectFactoryImpl.storeDeviceId(deviceServiceFinder, device);
|
||||
String type = fix.getClass().getName();
|
||||
|
||||
@Override
|
||||
public void removeListener(GPSFixReceivedListener listener) {
|
||||
listeners.remove(listener.hashCode());
|
||||
}
|
||||
Object fixObject = fixServiceFinder.findService(type).transformForth(fix);
|
||||
DBObject entry = new BasicDBObjectBuilder()
|
||||
.add(FieldNames.DEVICE_ID.name(), dbDeviceId)
|
||||
.add(FieldNames.GPSFIX_TYPE.name(), type)
|
||||
.add(FieldNames.GPSFIX.name(), fixObject).get();
|
||||
mongoOF.storeTimed(fix, entry);
|
||||
|
||||
@Override
|
||||
public void loadCompetitorTrack(DynamicGPSFixTrack<Competitor, GPSFixMoving> track, DeviceMapping<Competitor> mapping) {
|
||||
loadTrack(track, mapping.getDevice(), mapping.getTimeRange().from(), mapping.getTimeRange().to(), true /*inclusive*/);
|
||||
}
|
||||
collection.insert(entry);
|
||||
} catch (TransformationException e) {
|
||||
logger.log(Level.WARNING, "Could not store fix in MongoDB");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadMarkTrack(DynamicGPSFixTrack<Mark, GPSFix> track, DeviceMapping<Mark> mapping) {
|
||||
loadTrack(track, mapping.getDevice(), mapping.getTimeRange().from(), mapping.getTimeRange().to(), true /*inclusive*/);
|
||||
}
|
||||
notifyListeners(device, fix);
|
||||
}
|
||||
|
||||
private void notifyListeners(DeviceIdentifier device, GPSFix fix) {
|
||||
for (GPSFixReceivedListener listener : listeners.values()) {
|
||||
listener.fixReceived(device, fix);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(GPSFixReceivedListener listener) {
|
||||
listeners.put(listener.hashCode(), listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(GPSFixReceivedListener listener) {
|
||||
listeners.remove(listener.hashCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadCompetitorTrack(DynamicGPSFixTrack<Competitor, GPSFixMoving> track, DeviceMapping<Competitor> mapping) {
|
||||
loadTrack(track, mapping.getDevice(), mapping.getTimeRange().from(), mapping.getTimeRange().to(), true /*inclusive*/);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadMarkTrack(DynamicGPSFixTrack<Mark, GPSFix> track, DeviceMapping<Mark> mapping) {
|
||||
loadTrack(track, mapping.getDevice(), mapping.getTimeRange().from(), mapping.getTimeRange().to(), true /*inclusive*/);
|
||||
}
|
||||
}
|
||||
|
||||
+44
-44
@@ -33,50 +33,50 @@ import com.sap.sailing.server.gateway.deserialization.impl.DeviceAndSessionIdent
|
||||
import com.sap.sailing.server.impl.RacingEventServiceImpl;
|
||||
|
||||
public class AbstractGPSFixStoreTest {
|
||||
protected RacingEventService service;
|
||||
protected final MockServiceFinderFactory serviceFinderFactory = new MockServiceFinderFactory();
|
||||
DeviceAndSessionIdentifierWithGPSFixesDeserializer deserializer =
|
||||
new MockDeviceAndSessioinIdentifierWithGPSFixesDeserializer();
|
||||
protected final DeviceIdentifier device = new SmartphoneImeiIdentifier("a");
|
||||
protected RaceLog raceLog;
|
||||
protected GPSFixStore store;
|
||||
protected final Competitor comp = DomainFactory.INSTANCE.getOrCreateCompetitor("comp", "comp", null, null, null);
|
||||
protected final Mark mark = DomainFactory.INSTANCE.getOrCreateMark("mark");
|
||||
|
||||
private final RaceLogEventAuthor author = new RaceLogEventAuthorImpl("author", 0);
|
||||
protected RacingEventService service;
|
||||
protected final MockServiceFinderFactory serviceFinderFactory = new MockServiceFinderFactory();
|
||||
DeviceAndSessionIdentifierWithGPSFixesDeserializer deserializer =
|
||||
new MockDeviceAndSessioinIdentifierWithGPSFixesDeserializer();
|
||||
protected final DeviceIdentifier device = new SmartphoneImeiIdentifier("a");
|
||||
protected RaceLog raceLog;
|
||||
protected GPSFixStore store;
|
||||
protected final Competitor comp = DomainFactory.INSTANCE.getOrCreateCompetitor("comp", "comp", null, null, null);
|
||||
protected final Mark mark = DomainFactory.INSTANCE.getOrCreateMark("mark");
|
||||
|
||||
protected GPSFixMoving createFix(long millis, double lat, double lng, double knots, double degrees) {
|
||||
return new GPSFixMovingImpl(new DegreePosition(lat, lng),
|
||||
new MillisecondsTimePoint(millis), new KnotSpeedWithBearingImpl(knots, new DegreeBearingImpl(degrees)));
|
||||
}
|
||||
private final RaceLogEventAuthor author = new RaceLogEventAuthorImpl("author", 0);
|
||||
|
||||
@Before
|
||||
public void setServiceAndRaceLog() {
|
||||
service = new RacingEventServiceImpl(null, null, serviceFinderFactory);
|
||||
raceLog = new RaceLogImpl("racelog");
|
||||
store = new MongoGPSFixStoreImpl(service.getMongoObjectFactory(), service.getDomainObjectFactory(),
|
||||
serviceFinderFactory);
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
MongoObjectFactoryImpl mongoOF = (MongoObjectFactoryImpl) service.getMongoObjectFactory();
|
||||
mongoOF.getGPSFixCollection().drop();
|
||||
}
|
||||
|
||||
protected void map(Competitor comp, DeviceIdentifier device, long from, long to) {
|
||||
raceLog.add(RaceLogEventFactory.INSTANCE.createDeviceCompetitorMappingEvent(MillisecondsTimePoint.now(), author, device,
|
||||
comp, 0, new MillisecondsTimePoint(from), new MillisecondsTimePoint(to)));
|
||||
}
|
||||
|
||||
protected void map(Mark mark, DeviceIdentifier device, long from, long to) {
|
||||
raceLog.add(RaceLogEventFactory.INSTANCE.createDeviceMarkMappingEvent(MillisecondsTimePoint.now(), author, device,
|
||||
mark, 0, new MillisecondsTimePoint(from), new MillisecondsTimePoint(to)));
|
||||
}
|
||||
|
||||
protected void testLength(Track<?> track, long expected) {
|
||||
track.lockForRead();
|
||||
assertEquals(expected, size(track.getRawFixes()));
|
||||
track.unlockAfterRead();
|
||||
}
|
||||
protected GPSFixMoving createFix(long millis, double lat, double lng, double knots, double degrees) {
|
||||
return new GPSFixMovingImpl(new DegreePosition(lat, lng),
|
||||
new MillisecondsTimePoint(millis), new KnotSpeedWithBearingImpl(knots, new DegreeBearingImpl(degrees)));
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setServiceAndRaceLog() {
|
||||
service = new RacingEventServiceImpl(null, null, serviceFinderFactory);
|
||||
raceLog = new RaceLogImpl("racelog");
|
||||
store = new MongoGPSFixStoreImpl(service.getMongoObjectFactory(), service.getDomainObjectFactory(),
|
||||
serviceFinderFactory);
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
MongoObjectFactoryImpl mongoOF = (MongoObjectFactoryImpl) service.getMongoObjectFactory();
|
||||
mongoOF.getGPSFixCollection().drop();
|
||||
}
|
||||
|
||||
protected void map(Competitor comp, DeviceIdentifier device, long from, long to) {
|
||||
raceLog.add(RaceLogEventFactory.INSTANCE.createDeviceCompetitorMappingEvent(MillisecondsTimePoint.now(), author, device,
|
||||
comp, 0, new MillisecondsTimePoint(from), new MillisecondsTimePoint(to)));
|
||||
}
|
||||
|
||||
protected void map(Mark mark, DeviceIdentifier device, long from, long to) {
|
||||
raceLog.add(RaceLogEventFactory.INSTANCE.createDeviceMarkMappingEvent(MillisecondsTimePoint.now(), author, device,
|
||||
mark, 0, new MillisecondsTimePoint(from), new MillisecondsTimePoint(to)));
|
||||
}
|
||||
|
||||
protected void testLength(Track<?> track, long expected) {
|
||||
track.lockForRead();
|
||||
assertEquals(expected, size(track.getRawFixes()));
|
||||
track.unlockAfterRead();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ public abstract class AbstractJsonOverHttpTest {
|
||||
protected String getUrl(String endOfUrl) {
|
||||
return "http://" + URL_BASE + ":" + PORT + endOfUrl;
|
||||
}
|
||||
|
||||
|
||||
protected String executeRequest(String method, String targetURL, String body) throws IOException {
|
||||
// Create connection
|
||||
URL url = new URL(targetURL);
|
||||
|
||||
+116
-116
@@ -57,121 +57,121 @@ import com.sap.sailing.server.RacingEventService;
|
||||
import com.sap.sailing.server.impl.RacingEventServiceImpl;
|
||||
|
||||
public class CreateAndTrackWithRaceLogTest {
|
||||
private RacingEventService service;
|
||||
|
||||
private final Fleet fleet = new FleetImpl("fleet");
|
||||
private final String columnName = "column";
|
||||
private RegattaLeaderboard leaderboard;
|
||||
private RaceLogTrackingAdapter adapter;
|
||||
private Regatta regatta;
|
||||
private RaceLogEventAuthor author;
|
||||
private GPSFixStore gpsFixStore;
|
||||
|
||||
private long time = 0;
|
||||
|
||||
private static final RaceLogEventFactory factory = RaceLogEventFactory.INSTANCE;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
service = new RacingEventServiceImpl(true, new MockServiceFinderFactory());
|
||||
gpsFixStore = service.getGPSFixStore();
|
||||
service.getMongoObjectFactory().getDatabase().dropDatabase();
|
||||
author = service.getServerAuthor();
|
||||
Series series = new SeriesImpl("series", false, Collections.singletonList(fleet),
|
||||
Collections.singletonList(columnName), service);
|
||||
regatta = service.createRegatta("regatta", "Laser", UUID.randomUUID(), Collections.<Series>singletonList(series),
|
||||
false, new HighPoint(), UUID.randomUUID());
|
||||
leaderboard = service.addRegattaLeaderboard(regatta.getRegattaIdentifier(), "RegattaLeaderboard", new int[] {});
|
||||
adapter = RaceLogTrackingAdapterFactoryImpl.INSTANCE.getAdapter(DomainFactory.INSTANCE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasRaceLog() {
|
||||
assertNotNull(leaderboard.getRaceColumnByName(columnName).getRaceLog(fleet));
|
||||
}
|
||||
|
||||
private TimePoint t() {
|
||||
return new MillisecondsTimePoint(time++);
|
||||
}
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
@Test
|
||||
public void cantAddBeforeDenoting() throws MalformedURLException, FileNotFoundException, URISyntaxException, Exception {
|
||||
RaceColumn column = leaderboard.getRaceColumnByName(columnName);
|
||||
exception.expect(RaceNotCreatedException.class);
|
||||
adapter.addRace(service, regatta.getRegattaIdentifier(), leaderboard, column, fleet, -1);
|
||||
}
|
||||
|
||||
private void testSize(Track<?> track, int expected) {
|
||||
track.lockForRead();
|
||||
assertEquals(expected, size(track.getRawFixes()));
|
||||
track.unlockAfterRead();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canDenote_Add_Track() throws MalformedURLException, FileNotFoundException, URISyntaxException, Exception {
|
||||
|
||||
RaceColumn column = leaderboard.getRaceColumnByName(columnName);
|
||||
RaceLog raceLog = column.getRaceLog(fleet);
|
||||
|
||||
//before denoting, it is not listed as loadable
|
||||
Map<RaceColumn, Collection<Fleet>> loadable = adapter.listRaceLogTrackersThatCanBeAdded(service, leaderboard);
|
||||
assertEquals(0, loadable.size());
|
||||
private RacingEventService service;
|
||||
|
||||
//can denote racelog for tracking
|
||||
assertTrue(raceLog.isEmpty());
|
||||
adapter.denoteForRaceLogTracking(service, leaderboard, column, fleet, "race");
|
||||
assertFalse(raceLog.isEmpty());
|
||||
|
||||
//add a mapping and one fix in, one out of mapping
|
||||
Competitor comp1 = DomainFactory.INSTANCE.getOrCreateCompetitor("comp1", "comp1", null, null, null);
|
||||
DeviceIdentifier dev1 = new SmartphoneImeiIdentifier("dev1");
|
||||
raceLog.add(factory.createDeviceCompetitorMappingEvent(t(), author, dev1, comp1, 0, new MillisecondsTimePoint(0), new MillisecondsTimePoint(10)));
|
||||
gpsFixStore.storeFix(dev1, new GPSFixMovingImpl(new DegreePosition(0, 0), new MillisecondsTimePoint(5), new KnotSpeedWithBearingImpl(10, new DegreeBearingImpl(5))));
|
||||
gpsFixStore.storeFix(dev1, new GPSFixMovingImpl(new DegreePosition(0, 0), new MillisecondsTimePoint(15), new KnotSpeedWithBearingImpl(10, new DegreeBearingImpl(5))));
|
||||
|
||||
//then listed as loadable
|
||||
loadable = adapter.listRaceLogTrackersThatCanBeAdded(service, leaderboard);
|
||||
assertEquals(1, loadable.size());
|
||||
assertEquals(1, loadable.get(column).size());
|
||||
|
||||
//now can add
|
||||
RacesHandle handle = adapter.addRace(service, regatta.getRegattaIdentifier(), leaderboard, column, fleet, -1);
|
||||
|
||||
//no trackedrace yet
|
||||
assertNull(column.getTrackedRace(fleet));
|
||||
|
||||
CourseBase course = new CourseDataImpl("test");
|
||||
course.addWaypoint(0, new WaypointImpl(new MarkImpl("mark")));
|
||||
raceLog.add(factory.createCourseDesignChangedEvent(t(), author, 0, course));
|
||||
|
||||
//start tracking
|
||||
raceLog.add(factory.createStartTrackingEvent(t(), author, 0));
|
||||
|
||||
//now there is a trackedrace
|
||||
TrackedRace race = column.getTrackedRace(fleet);
|
||||
assertNotNull(race);
|
||||
|
||||
//one fix should have been loaded from store
|
||||
testSize(race.getTrack(comp1), 1);
|
||||
|
||||
//further fix arrives in race
|
||||
gpsFixStore.storeFix(dev1, new GPSFixMovingImpl(new DegreePosition(0, 0), new MillisecondsTimePoint(7), new KnotSpeedWithBearingImpl(10, new DegreeBearingImpl(5))));
|
||||
gpsFixStore.storeFix(dev1, new GPSFixMovingImpl(new DegreePosition(0, 0), new MillisecondsTimePoint(14), new KnotSpeedWithBearingImpl(10, new DegreeBearingImpl(5)))); //outside mapping range
|
||||
testSize(race.getTrack(comp1), 2);
|
||||
|
||||
//add another mapping on the fly, other old fixes should be loaded
|
||||
raceLog.add(factory.createDeviceCompetitorMappingEvent(t(), author, dev1, comp1, 0, new MillisecondsTimePoint(11), new MillisecondsTimePoint(20)));
|
||||
testSize(race.getTrack(comp1), 4);
|
||||
|
||||
//add another fix in new mapping range
|
||||
gpsFixStore.storeFix(dev1, new GPSFixMovingImpl(new DegreePosition(0, 0), new MillisecondsTimePoint(18), new KnotSpeedWithBearingImpl(10, new DegreeBearingImpl(5))));
|
||||
testSize(race.getTrack(comp1), 5);
|
||||
|
||||
//stop tracking, then no more fixes arrive at race
|
||||
handle.getRaceTracker().stop();
|
||||
gpsFixStore.storeFix(dev1, new GPSFixMovingImpl(new DegreePosition(0, 0), new MillisecondsTimePoint(8), new KnotSpeedWithBearingImpl(10, new DegreeBearingImpl(5))));
|
||||
testSize(race.getTrack(comp1), 5);
|
||||
}
|
||||
private final Fleet fleet = new FleetImpl("fleet");
|
||||
private final String columnName = "column";
|
||||
private RegattaLeaderboard leaderboard;
|
||||
private RaceLogTrackingAdapter adapter;
|
||||
private Regatta regatta;
|
||||
private RaceLogEventAuthor author;
|
||||
private GPSFixStore gpsFixStore;
|
||||
|
||||
private long time = 0;
|
||||
|
||||
private static final RaceLogEventFactory factory = RaceLogEventFactory.INSTANCE;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
service = new RacingEventServiceImpl(true, new MockServiceFinderFactory());
|
||||
gpsFixStore = service.getGPSFixStore();
|
||||
service.getMongoObjectFactory().getDatabase().dropDatabase();
|
||||
author = service.getServerAuthor();
|
||||
Series series = new SeriesImpl("series", false, Collections.singletonList(fleet),
|
||||
Collections.singletonList(columnName), service);
|
||||
regatta = service.createRegatta("regatta", "Laser", UUID.randomUUID(), Collections.<Series>singletonList(series),
|
||||
false, new HighPoint(), UUID.randomUUID());
|
||||
leaderboard = service.addRegattaLeaderboard(regatta.getRegattaIdentifier(), "RegattaLeaderboard", new int[] {});
|
||||
adapter = RaceLogTrackingAdapterFactoryImpl.INSTANCE.getAdapter(DomainFactory.INSTANCE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasRaceLog() {
|
||||
assertNotNull(leaderboard.getRaceColumnByName(columnName).getRaceLog(fleet));
|
||||
}
|
||||
|
||||
private TimePoint t() {
|
||||
return new MillisecondsTimePoint(time++);
|
||||
}
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
@Test
|
||||
public void cantAddBeforeDenoting() throws MalformedURLException, FileNotFoundException, URISyntaxException, Exception {
|
||||
RaceColumn column = leaderboard.getRaceColumnByName(columnName);
|
||||
exception.expect(RaceNotCreatedException.class);
|
||||
adapter.addRace(service, regatta.getRegattaIdentifier(), leaderboard, column, fleet, -1);
|
||||
}
|
||||
|
||||
private void testSize(Track<?> track, int expected) {
|
||||
track.lockForRead();
|
||||
assertEquals(expected, size(track.getRawFixes()));
|
||||
track.unlockAfterRead();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canDenote_Add_Track() throws MalformedURLException, FileNotFoundException, URISyntaxException, Exception {
|
||||
|
||||
RaceColumn column = leaderboard.getRaceColumnByName(columnName);
|
||||
RaceLog raceLog = column.getRaceLog(fleet);
|
||||
|
||||
//before denoting, it is not listed as loadable
|
||||
Map<RaceColumn, Collection<Fleet>> loadable = adapter.listRaceLogTrackersThatCanBeAdded(service, leaderboard);
|
||||
assertEquals(0, loadable.size());
|
||||
|
||||
//can denote racelog for tracking
|
||||
assertTrue(raceLog.isEmpty());
|
||||
adapter.denoteForRaceLogTracking(service, leaderboard, column, fleet, "race");
|
||||
assertFalse(raceLog.isEmpty());
|
||||
|
||||
//add a mapping and one fix in, one out of mapping
|
||||
Competitor comp1 = DomainFactory.INSTANCE.getOrCreateCompetitor("comp1", "comp1", null, null, null);
|
||||
DeviceIdentifier dev1 = new SmartphoneImeiIdentifier("dev1");
|
||||
raceLog.add(factory.createDeviceCompetitorMappingEvent(t(), author, dev1, comp1, 0, new MillisecondsTimePoint(0), new MillisecondsTimePoint(10)));
|
||||
gpsFixStore.storeFix(dev1, new GPSFixMovingImpl(new DegreePosition(0, 0), new MillisecondsTimePoint(5), new KnotSpeedWithBearingImpl(10, new DegreeBearingImpl(5))));
|
||||
gpsFixStore.storeFix(dev1, new GPSFixMovingImpl(new DegreePosition(0, 0), new MillisecondsTimePoint(15), new KnotSpeedWithBearingImpl(10, new DegreeBearingImpl(5))));
|
||||
|
||||
//then listed as loadable
|
||||
loadable = adapter.listRaceLogTrackersThatCanBeAdded(service, leaderboard);
|
||||
assertEquals(1, loadable.size());
|
||||
assertEquals(1, loadable.get(column).size());
|
||||
|
||||
//now can add
|
||||
RacesHandle handle = adapter.addRace(service, regatta.getRegattaIdentifier(), leaderboard, column, fleet, -1);
|
||||
|
||||
//no trackedrace yet
|
||||
assertNull(column.getTrackedRace(fleet));
|
||||
|
||||
CourseBase course = new CourseDataImpl("test");
|
||||
course.addWaypoint(0, new WaypointImpl(new MarkImpl("mark")));
|
||||
raceLog.add(factory.createCourseDesignChangedEvent(t(), author, 0, course));
|
||||
|
||||
//start tracking
|
||||
raceLog.add(factory.createStartTrackingEvent(t(), author, 0));
|
||||
|
||||
//now there is a trackedrace
|
||||
TrackedRace race = column.getTrackedRace(fleet);
|
||||
assertNotNull(race);
|
||||
|
||||
//one fix should have been loaded from store
|
||||
testSize(race.getTrack(comp1), 1);
|
||||
|
||||
//further fix arrives in race
|
||||
gpsFixStore.storeFix(dev1, new GPSFixMovingImpl(new DegreePosition(0, 0), new MillisecondsTimePoint(7), new KnotSpeedWithBearingImpl(10, new DegreeBearingImpl(5))));
|
||||
gpsFixStore.storeFix(dev1, new GPSFixMovingImpl(new DegreePosition(0, 0), new MillisecondsTimePoint(14), new KnotSpeedWithBearingImpl(10, new DegreeBearingImpl(5)))); //outside mapping range
|
||||
testSize(race.getTrack(comp1), 2);
|
||||
|
||||
//add another mapping on the fly, other old fixes should be loaded
|
||||
raceLog.add(factory.createDeviceCompetitorMappingEvent(t(), author, dev1, comp1, 0, new MillisecondsTimePoint(11), new MillisecondsTimePoint(20)));
|
||||
testSize(race.getTrack(comp1), 4);
|
||||
|
||||
//add another fix in new mapping range
|
||||
gpsFixStore.storeFix(dev1, new GPSFixMovingImpl(new DegreePosition(0, 0), new MillisecondsTimePoint(18), new KnotSpeedWithBearingImpl(10, new DegreeBearingImpl(5))));
|
||||
testSize(race.getTrack(comp1), 5);
|
||||
|
||||
//stop tracking, then no more fixes arrive at race
|
||||
handle.getRaceTracker().stop();
|
||||
gpsFixStore.storeFix(dev1, new GPSFixMovingImpl(new DegreePosition(0, 0), new MillisecondsTimePoint(8), new KnotSpeedWithBearingImpl(10, new DegreeBearingImpl(5))));
|
||||
testSize(race.getTrack(comp1), 5);
|
||||
}
|
||||
}
|
||||
|
||||
+27
-27
@@ -29,36 +29,36 @@ import com.sap.sailing.domain.tracking.impl.DynamicGPSFixMovingTrackImpl;
|
||||
import com.sap.sailing.server.gateway.deserialization.impl.DeviceAndSessionIdentifierWithGPSFixesDeserializer;
|
||||
|
||||
public class RecordFixesTest extends AbstractGPSFixStoreTest {
|
||||
private RecordFixesPostServlet servlet;
|
||||
private final DeviceAndSessionIdentifierWithGPSFixesDeserializer deserializer =
|
||||
new MockDeviceAndSessioinIdentifierWithGPSFixesDeserializer();
|
||||
private final DeviceIdentifier device = new SmartphoneImeiIdentifier("a");
|
||||
private RecordFixesPostServlet servlet;
|
||||
private final DeviceAndSessionIdentifierWithGPSFixesDeserializer deserializer =
|
||||
new MockDeviceAndSessioinIdentifierWithGPSFixesDeserializer();
|
||||
private final DeviceIdentifier device = new SmartphoneImeiIdentifier("a");
|
||||
|
||||
@Before
|
||||
public void setupServlet() {
|
||||
servlet = new RecordFixesPostServlet();
|
||||
servlet = spy(servlet);
|
||||
when(servlet.getRequestDeserializer()).thenReturn(deserializer);
|
||||
doReturn(service).when(servlet).getService();
|
||||
}
|
||||
@Before
|
||||
public void setupServlet() {
|
||||
servlet = new RecordFixesPostServlet();
|
||||
servlet = spy(servlet);
|
||||
when(servlet.getRequestDeserializer()).thenReturn(deserializer);
|
||||
doReturn(service).when(servlet).getService();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void areFixesStoredInDb() throws TransformationException, NoCorrespondingServiceRegisteredException {
|
||||
map(comp, device, 0, 600);
|
||||
@Test
|
||||
public void areFixesStoredInDb() throws TransformationException, NoCorrespondingServiceRegisteredException {
|
||||
map(comp, device, 0, 600);
|
||||
|
||||
int timepoint = 343;
|
||||
List<GPSFix> fixes = new ArrayList<>();
|
||||
fixes.add(createFix(timepoint, 0, 0, 0, 0));
|
||||
fixes.add(createFix(timepoint+1, 0, 0, 0, 0));
|
||||
Triple<DeviceIdentifier, Serializable, List<GPSFix>> data = new Triple<>(device, null, fixes);
|
||||
servlet.process(null, data);
|
||||
|
||||
int timepoint = 343;
|
||||
List<GPSFix> fixes = new ArrayList<>();
|
||||
fixes.add(createFix(timepoint, 0, 0, 0, 0));
|
||||
fixes.add(createFix(timepoint+1, 0, 0, 0, 0));
|
||||
Triple<DeviceIdentifier, Serializable, List<GPSFix>> data = new Triple<>(device, null, fixes);
|
||||
servlet.process(null, data);
|
||||
|
||||
DynamicGPSFixMovingTrackImpl<Competitor> track = new DynamicGPSFixMovingTrackImpl<>(comp, 0);
|
||||
store.loadCompetitorTrack(track, raceLog, comp);
|
||||
track.lockForRead();
|
||||
assertEquals(2, size(track.getRawFixes()));
|
||||
assertEquals(timepoint, track.getFirstRawFix().getTimePoint().asMillis());
|
||||
assertTrue(track.getFirstRawFix() instanceof GPSFixMoving);
|
||||
track.unlockAfterRead();
|
||||
}
|
||||
track.lockForRead();
|
||||
assertEquals(2, size(track.getRawFixes()));
|
||||
assertEquals(timepoint, track.getFirstRawFix().getTimePoint().asMillis());
|
||||
assertTrue(track.getFirstRawFix() instanceof GPSFixMoving);
|
||||
track.unlockAfterRead();
|
||||
}
|
||||
}
|
||||
|
||||
+34
-34
@@ -29,38 +29,38 @@ import com.sap.sailing.domain.tracking.impl.EmptyWindStore;
|
||||
import com.sap.sailing.domain.tracking.impl.TrackedRegattaImpl;
|
||||
|
||||
public class TrackedRaceLoadsFixesTest extends AbstractGPSFixStoreTest {
|
||||
@Test
|
||||
public void areFixesStoredInDb() throws TransformationException, NoCorrespondingServiceRegisteredException, InterruptedException {
|
||||
Competitor comp2 = DomainFactory.INSTANCE.getOrCreateCompetitor("comp2", "comp2", null, null, null);
|
||||
Mark mark2 = DomainFactory.INSTANCE.getOrCreateMark("mark2");
|
||||
DeviceIdentifier device2 = new SmartphoneImeiIdentifier("imei2");
|
||||
DeviceIdentifier device3 = new SmartphoneImeiIdentifier("imei3");
|
||||
BoatClass boatClass = DomainFactory.INSTANCE.getOrCreateBoatClass("49er");
|
||||
|
||||
Course course = new CourseImpl("course", Arrays.asList(new Waypoint[] {new WaypointImpl(mark), new WaypointImpl(mark2)}));
|
||||
RaceDefinition race = new RaceDefinitionImpl("race", course, boatClass, Arrays.asList(new Competitor[] {comp, comp2}));
|
||||
|
||||
map(comp, device, 0, 600);
|
||||
map(comp2, device2, 0, 600);
|
||||
//reuse device for two marks
|
||||
map(mark, device3, 0, 600);
|
||||
map(mark2, device3, 0, 600);
|
||||
|
||||
store.storeFix(device, createFix(100, 10, 20, 30, 40));
|
||||
store.storeFix(device, createFix(101, 10, 20, 30, 40));
|
||||
store.storeFix(device2, createFix(100, 10, 20, 30, 40));
|
||||
store.storeFix(device3, createFix(100, 10, 20, 30, 40));
|
||||
store.storeFix(device3, createFix(100, 10, 20, 30, 40));
|
||||
|
||||
TrackedRegatta regatta = new TrackedRegattaImpl(new RegattaImpl(EmptyRaceLogStore.INSTANCE, "regatta", boatClass, null, null, "a", null));
|
||||
DynamicTrackedRaceImpl trackedRace = new DynamicTrackedRaceImpl(regatta, race, Collections.<Sideline>emptyList(),
|
||||
EmptyWindStore.INSTANCE, store, 0, 0, 0);
|
||||
trackedRace.attachRaceLog(raceLog);
|
||||
trackedRace.waitUntilLoadingFromStoresComplete();
|
||||
|
||||
testLength(trackedRace.getTrack(comp), 2);
|
||||
testLength(trackedRace.getTrack(comp2), 1);
|
||||
testLength(trackedRace.getOrCreateTrack(mark), 1);
|
||||
testLength(trackedRace.getOrCreateTrack(mark2), 1);
|
||||
}
|
||||
@Test
|
||||
public void areFixesStoredInDb() throws TransformationException, NoCorrespondingServiceRegisteredException, InterruptedException {
|
||||
Competitor comp2 = DomainFactory.INSTANCE.getOrCreateCompetitor("comp2", "comp2", null, null, null);
|
||||
Mark mark2 = DomainFactory.INSTANCE.getOrCreateMark("mark2");
|
||||
DeviceIdentifier device2 = new SmartphoneImeiIdentifier("imei2");
|
||||
DeviceIdentifier device3 = new SmartphoneImeiIdentifier("imei3");
|
||||
BoatClass boatClass = DomainFactory.INSTANCE.getOrCreateBoatClass("49er");
|
||||
|
||||
Course course = new CourseImpl("course", Arrays.asList(new Waypoint[] {new WaypointImpl(mark), new WaypointImpl(mark2)}));
|
||||
RaceDefinition race = new RaceDefinitionImpl("race", course, boatClass, Arrays.asList(new Competitor[] {comp, comp2}));
|
||||
|
||||
map(comp, device, 0, 600);
|
||||
map(comp2, device2, 0, 600);
|
||||
//reuse device for two marks
|
||||
map(mark, device3, 0, 600);
|
||||
map(mark2, device3, 0, 600);
|
||||
|
||||
store.storeFix(device, createFix(100, 10, 20, 30, 40));
|
||||
store.storeFix(device, createFix(101, 10, 20, 30, 40));
|
||||
store.storeFix(device2, createFix(100, 10, 20, 30, 40));
|
||||
store.storeFix(device3, createFix(100, 10, 20, 30, 40));
|
||||
store.storeFix(device3, createFix(100, 10, 20, 30, 40));
|
||||
|
||||
TrackedRegatta regatta = new TrackedRegattaImpl(new RegattaImpl(EmptyRaceLogStore.INSTANCE, "regatta", boatClass, null, null, "a", null));
|
||||
DynamicTrackedRaceImpl trackedRace = new DynamicTrackedRaceImpl(regatta, race, Collections.<Sideline>emptyList(),
|
||||
EmptyWindStore.INSTANCE, store, 0, 0, 0);
|
||||
trackedRace.attachRaceLog(raceLog);
|
||||
trackedRace.waitUntilLoadingFromStoresComplete();
|
||||
|
||||
testLength(trackedRace.getTrack(comp), 2);
|
||||
testLength(trackedRace.getTrack(comp2), 1);
|
||||
testLength(trackedRace.getOrCreateTrack(mark), 1);
|
||||
testLength(trackedRace.getOrCreateTrack(mark2), 1);
|
||||
}
|
||||
}
|
||||
|
||||
+66
-66
@@ -29,77 +29,77 @@ import com.sap.sailing.server.gateway.serialization.impl.SmartphoneImeiIdentifie
|
||||
|
||||
public class PostFixes extends AbstractJsonOverHttpTest {
|
||||
protected static final SmartphoneImeiIdentifier device = new SmartphoneImeiIdentifier("a");
|
||||
|
||||
private final DeviceAndSessionIdentifierWithGPSFixesSerializer<SmartphoneImeiIdentifier, GPSFixMoving> fixSerializer =
|
||||
new DeviceAndSessionIdentifierWithGPSFixesSerializer<>(new SmartphoneImeiIdentifierJsonSerializer(), new GPSFixMovingNmeaDTOJsonSerializer());
|
||||
|
||||
private void recordFix(GPSFixMoving... fix) throws IOException {
|
||||
String request = fixSerializer.serialize(
|
||||
new Triple<SmartphoneImeiIdentifier, Serializable, List<GPSFixMoving>>(
|
||||
device, null, Arrays.asList(fix))).toJSONString();
|
||||
|
||||
executeRequest("POST", getUrl(URL_TR + "/recordFixes"), request);
|
||||
}
|
||||
|
||||
private void recordFixes() {
|
||||
final Timer timer = new Timer();
|
||||
final Position p1 = new DegreePosition(54.427119, 10.182583);
|
||||
final Position p2 = new DegreePosition(54.435707, 10.200779);
|
||||
final Position p3 = new DegreePosition(54.425921, 10.188248);
|
||||
private final DeviceAndSessionIdentifierWithGPSFixesSerializer<SmartphoneImeiIdentifier, GPSFixMoving> fixSerializer =
|
||||
new DeviceAndSessionIdentifierWithGPSFixesSerializer<>(new SmartphoneImeiIdentifierJsonSerializer(), new GPSFixMovingNmeaDTOJsonSerializer());
|
||||
|
||||
final int nFirstLeg = 100;
|
||||
final int nSecondLeg = 100;
|
||||
final int n = nFirstLeg + nSecondLeg;
|
||||
long period = 1000;
|
||||
private void recordFix(GPSFixMoving... fix) throws IOException {
|
||||
String request = fixSerializer.serialize(
|
||||
new Triple<SmartphoneImeiIdentifier, Serializable, List<GPSFixMoving>>(
|
||||
device, null, Arrays.asList(fix))).toJSONString();
|
||||
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
int i = 0;
|
||||
GPSFix lastFix;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (i++ > n)
|
||||
timer.cancel();
|
||||
|
||||
Position start;
|
||||
Position end;
|
||||
int iLeg = i;
|
||||
int nLeg;
|
||||
|
||||
if (i < nFirstLeg) {
|
||||
start = p1;
|
||||
end = p2;
|
||||
nLeg = nFirstLeg;
|
||||
} else {
|
||||
start = p2;
|
||||
end = p3;
|
||||
iLeg -= nFirstLeg;
|
||||
nLeg = nSecondLeg;
|
||||
}
|
||||
|
||||
Distance distance = start.getDistance(end);
|
||||
Bearing bearing = start.getBearingGreatCircle(end);
|
||||
Position boat = start.translateGreatCircle(bearing, distance.scale(((double) iLeg) / nLeg));
|
||||
GPSFix fix = new GPSFixImpl(boat, MillisecondsTimePoint.now());
|
||||
SpeedWithBearing speed = lastFix == null ? new KnotSpeedWithBearingImpl(0, new DegreeBearingImpl(0))
|
||||
: lastFix.getSpeedAndBearingRequiredToReach(fix);
|
||||
lastFix = fix;
|
||||
|
||||
try {
|
||||
recordFix(new GPSFixMovingImpl(fix.getPosition(), fix.getTimePoint(), speed));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
executeRequest("POST", getUrl(URL_TR + "/recordFixes"), request);
|
||||
}
|
||||
}, 0, period);
|
||||
}
|
||||
|
||||
public void run() throws IOException, IllegalStateException, ParseException, InterruptedException {
|
||||
recordFixes();
|
||||
}
|
||||
private void recordFixes() {
|
||||
final Timer timer = new Timer();
|
||||
final Position p1 = new DegreePosition(54.427119, 10.182583);
|
||||
final Position p2 = new DegreePosition(54.435707, 10.200779);
|
||||
final Position p3 = new DegreePosition(54.425921, 10.188248);
|
||||
|
||||
public static void main(String[] args) throws IllegalStateException, IOException, ParseException,
|
||||
final int nFirstLeg = 100;
|
||||
final int nSecondLeg = 100;
|
||||
final int n = nFirstLeg + nSecondLeg;
|
||||
long period = 1000;
|
||||
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
int i = 0;
|
||||
GPSFix lastFix;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (i++ > n)
|
||||
timer.cancel();
|
||||
|
||||
Position start;
|
||||
Position end;
|
||||
int iLeg = i;
|
||||
int nLeg;
|
||||
|
||||
if (i < nFirstLeg) {
|
||||
start = p1;
|
||||
end = p2;
|
||||
nLeg = nFirstLeg;
|
||||
} else {
|
||||
start = p2;
|
||||
end = p3;
|
||||
iLeg -= nFirstLeg;
|
||||
nLeg = nSecondLeg;
|
||||
}
|
||||
|
||||
Distance distance = start.getDistance(end);
|
||||
Bearing bearing = start.getBearingGreatCircle(end);
|
||||
Position boat = start.translateGreatCircle(bearing, distance.scale(((double) iLeg) / nLeg));
|
||||
GPSFix fix = new GPSFixImpl(boat, MillisecondsTimePoint.now());
|
||||
SpeedWithBearing speed = lastFix == null ? new KnotSpeedWithBearingImpl(0, new DegreeBearingImpl(0))
|
||||
: lastFix.getSpeedAndBearingRequiredToReach(fix);
|
||||
lastFix = fix;
|
||||
|
||||
try {
|
||||
recordFix(new GPSFixMovingImpl(fix.getPosition(), fix.getTimePoint(), speed));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, 0, period);
|
||||
}
|
||||
|
||||
public void run() throws IOException, IllegalStateException, ParseException, InterruptedException {
|
||||
recordFixes();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IllegalStateException, IOException, ParseException,
|
||||
InterruptedException {
|
||||
new PostFixes().run();
|
||||
}
|
||||
new PostFixes().run();
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -3,11 +3,11 @@ package com.sap.sailing.domain.racelog.tracking.test.mock;
|
||||
import com.sap.sailing.server.gateway.deserialization.impl.DeviceAndSessionIdentifierWithGPSFixesDeserializer;
|
||||
|
||||
public class MockDeviceAndSessioinIdentifierWithGPSFixesDeserializer extends
|
||||
DeviceAndSessionIdentifierWithGPSFixesDeserializer {
|
||||
DeviceAndSessionIdentifierWithGPSFixesDeserializer {
|
||||
|
||||
public MockDeviceAndSessioinIdentifierWithGPSFixesDeserializer() {
|
||||
super(new MockGPSFixJsonServiceFinder(),
|
||||
new MockSmartphoneImeiJsonServiceFinder());
|
||||
}
|
||||
public MockDeviceAndSessioinIdentifierWithGPSFixesDeserializer() {
|
||||
super(new MockGPSFixJsonServiceFinder(),
|
||||
new MockSmartphoneImeiJsonServiceFinder());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+8
-8
@@ -11,14 +11,14 @@ import com.sap.sailing.server.gateway.serialization.racelog.tracking.GPSFixJsonH
|
||||
|
||||
public class MockGPSFixJsonHandler implements GPSFixJsonHandler {
|
||||
|
||||
@Override
|
||||
public JSONObject transformForth(GPSFix object) {
|
||||
return new GPSFixMovingJsonSerializer().serialize((GPSFixMoving) object);
|
||||
}
|
||||
@Override
|
||||
public JSONObject transformForth(GPSFix object) {
|
||||
return new GPSFixMovingJsonSerializer().serialize((GPSFixMoving) object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GPSFix transformBack(JSONObject json) throws JsonDeserializationException {
|
||||
return new GPSFixMovingJsonDeserializer().deserialize(json);
|
||||
}
|
||||
@Override
|
||||
public GPSFix transformBack(JSONObject json) throws JsonDeserializationException {
|
||||
return new GPSFixMovingJsonDeserializer().deserialize(json);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import com.sap.sailing.server.gateway.serialization.racelog.tracking.GPSFixJsonH
|
||||
|
||||
public class MockGPSFixJsonServiceFinder implements TypeBasedServiceFinder<GPSFixJsonHandler> {
|
||||
private final MockGPSFixJsonHandler handler = new MockGPSFixJsonHandler();
|
||||
|
||||
|
||||
@Override
|
||||
public GPSFixJsonHandler findService(String fixType) {
|
||||
if (fixType.equals(GPSFixMovingJsonDeserializer.TYPE)) {
|
||||
|
||||
+3
-3
@@ -10,9 +10,9 @@ import com.sap.sailing.domain.tracking.impl.GPSFixImpl;
|
||||
import com.sap.sailing.domain.tracking.impl.GPSFixMovingImpl;
|
||||
|
||||
public class MockGPSFixMongoServiceFinder implements TypeBasedServiceFinder<GPSFixMongoHandler> {
|
||||
private final MongoObjectFactoryImpl mof = new MongoObjectFactoryImpl(null);
|
||||
private final DomainObjectFactoryImpl dof = new DomainObjectFactoryImpl(null, null);
|
||||
|
||||
private final MongoObjectFactoryImpl mof = new MongoObjectFactoryImpl(null);
|
||||
private final DomainObjectFactoryImpl dof = new DomainObjectFactoryImpl(null, null);
|
||||
|
||||
@Override
|
||||
public GPSFixMongoHandler findService(String fixType) {
|
||||
if (fixType.equals(GPSFixMovingImpl.class.getName())) return new GPSFixMovingMongoHandlerImpl(mof, dof);
|
||||
|
||||
+10
-10
@@ -20,18 +20,18 @@ import com.sap.sailing.server.gateway.serialization.racelog.tracking.GPSFixJsonH
|
||||
*
|
||||
*/
|
||||
public class MockServiceFinderFactory implements TypeBasedServiceFinderFactory {
|
||||
Map<Class<?>, TypeBasedServiceFinder<?>> serviceFinders = new HashMap<>();
|
||||
|
||||
public MockServiceFinderFactory() {
|
||||
serviceFinders.put(DeviceIdentifierMongoHandler.class, new MockSmartphoneImeiMongoServiceFinder());
|
||||
serviceFinders.put(DeviceIdentifierJsonHandler.class, new MockSmartphoneImeiJsonServiceFinder());
|
||||
serviceFinders.put(GPSFixMongoHandler.class, new MockGPSFixMongoServiceFinder());
|
||||
serviceFinders.put(GPSFixJsonHandler.class, new MockGPSFixJsonServiceFinder());
|
||||
}
|
||||
|
||||
Map<Class<?>, TypeBasedServiceFinder<?>> serviceFinders = new HashMap<>();
|
||||
|
||||
public MockServiceFinderFactory() {
|
||||
serviceFinders.put(DeviceIdentifierMongoHandler.class, new MockSmartphoneImeiMongoServiceFinder());
|
||||
serviceFinders.put(DeviceIdentifierJsonHandler.class, new MockSmartphoneImeiJsonServiceFinder());
|
||||
serviceFinders.put(GPSFixMongoHandler.class, new MockGPSFixMongoServiceFinder());
|
||||
serviceFinders.put(GPSFixJsonHandler.class, new MockGPSFixJsonServiceFinder());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <ServiceT> TypeBasedServiceFinder<ServiceT> createServiceFinder(Class<ServiceT> clazz) {
|
||||
return (TypeBasedServiceFinder<ServiceT>) serviceFinders.get(clazz);
|
||||
return (TypeBasedServiceFinder<ServiceT>) serviceFinders.get(clazz);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -9,8 +9,8 @@ import com.sap.sailing.domain.common.WithID;
|
||||
* @author Fredrik Teschke
|
||||
*/
|
||||
public interface DeviceMapping<ItemType extends WithID> extends Timed {
|
||||
ItemType getMappedTo();
|
||||
DeviceIdentifier getDevice();
|
||||
|
||||
TimeRange getTimeRange();
|
||||
ItemType getMappedTo();
|
||||
DeviceIdentifier getDevice();
|
||||
|
||||
TimeRange getTimeRange();
|
||||
}
|
||||
|
||||
+1
-1
@@ -16,5 +16,5 @@ import com.sap.sailing.domain.racelog.RaceLogEvent;
|
||||
*
|
||||
*/
|
||||
public interface RegisterCompetitorEvent extends RaceLogEvent {
|
||||
Competitor getCompetitor();
|
||||
Competitor getCompetitor();
|
||||
}
|
||||
|
||||
+3
-3
@@ -6,9 +6,9 @@ import java.util.Map;
|
||||
import com.sap.sailing.domain.base.SharedDomainFactory;
|
||||
|
||||
public class SmartphoneImeiIdentifier implements DeviceIdentifier {
|
||||
private static final long serialVersionUID = -1830014229310181702L;
|
||||
private static final long serialVersionUID = -1830014229310181702L;
|
||||
|
||||
public static final String TYPE = "smartphoneImei";
|
||||
public static final String TYPE = "smartphoneImei";
|
||||
|
||||
private static final Map<String, SmartphoneImeiIdentifier> cache = new HashMap<String, SmartphoneImeiIdentifier>();
|
||||
|
||||
@@ -43,7 +43,7 @@ public class SmartphoneImeiIdentifier implements DeviceIdentifier {
|
||||
public String toString() {
|
||||
return "IMEI " + imei;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof SmartphoneImeiIdentifier) {
|
||||
|
||||
+7
-7
@@ -7,12 +7,12 @@ import com.sap.sailing.domain.racelog.tracking.DeviceMappingEvent;
|
||||
|
||||
public class DeviceCompetitorMappingFinder extends DeviceMappingFinder<Competitor> {
|
||||
|
||||
public DeviceCompetitorMappingFinder(RaceLog raceLog) {
|
||||
super(raceLog);
|
||||
}
|
||||
public DeviceCompetitorMappingFinder(RaceLog raceLog) {
|
||||
super(raceLog);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isValidMapping(DeviceMappingEvent<?> mapping) {
|
||||
return mapping instanceof DeviceCompetitorMappingEvent;
|
||||
}
|
||||
@Override
|
||||
protected boolean isValidMapping(DeviceMappingEvent<?> mapping) {
|
||||
return mapping instanceof DeviceCompetitorMappingEvent;
|
||||
}
|
||||
}
|
||||
|
||||
+117
-117
@@ -41,100 +41,100 @@ import com.sap.sailing.domain.tracking.impl.TimedComparator;
|
||||
*/
|
||||
public abstract class DeviceMappingFinder<ItemT extends WithID> extends RaceLogAnalyzer<Map<ItemT, List<DeviceMapping<ItemT>>>> {
|
||||
public DeviceMappingFinder(RaceLog raceLog) {
|
||||
super(raceLog);
|
||||
}
|
||||
|
||||
super(raceLog);
|
||||
}
|
||||
|
||||
protected abstract boolean isValidMapping(DeviceMappingEvent<?> mapping);
|
||||
|
||||
protected DeviceMapping<ItemT> getMapping(DeviceMappingEvent<ItemT> event) {
|
||||
return new DeviceMappingImpl<ItemT>(event.getMappedTo(), event.getDevice(),
|
||||
new TimeRangeImpl(event.getFrom(), event.getTo()));
|
||||
}
|
||||
protected DeviceMapping<ItemT> getMapping(DeviceMappingEvent<ItemT> event) {
|
||||
return new DeviceMappingImpl<ItemT>(event.getMappedTo(), event.getDevice(),
|
||||
new TimeRangeImpl(event.getFrom(), event.getTo()));
|
||||
}
|
||||
|
||||
protected DeviceMapping<ItemT> getMapping(DeviceIdentifier device, ItemT item,
|
||||
TimePoint from, TimePoint to) {
|
||||
return new DeviceMappingImpl<ItemT>(item, device, new TimeRangeImpl(from, to));
|
||||
}
|
||||
protected DeviceMapping<ItemT> getMapping(DeviceIdentifier device, ItemT item,
|
||||
TimePoint from, TimePoint to) {
|
||||
return new DeviceMappingImpl<ItemT>(item, device, new TimeRangeImpl(from, to));
|
||||
}
|
||||
|
||||
protected DeviceMapping<ItemT> getMapping(DeviceIdentifier device, ItemT item,
|
||||
TimeRange range) {
|
||||
return new DeviceMappingImpl<ItemT>(item, device, range);
|
||||
}
|
||||
protected DeviceMapping<ItemT> getMapping(DeviceIdentifier device, ItemT item,
|
||||
TimeRange range) {
|
||||
return new DeviceMappingImpl<ItemT>(item, device, range);
|
||||
}
|
||||
|
||||
private <T> List<DeviceMapping<ItemT>> getItemSet(Map<T, List<DeviceMapping<ItemT>>> map, T item) {
|
||||
List<DeviceMapping<ItemT>> list = map.get(item);
|
||||
List<DeviceMapping<ItemT>> list = map.get(item);
|
||||
if (list == null) {
|
||||
list = new ArrayList<DeviceMapping<ItemT>>();
|
||||
map.put(item, list);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* If an overlap in time is found between this mapping, and one already found for the same {@code item}, the new
|
||||
* mapping overrides the one in the initialSet for the time of the overlap.
|
||||
*/
|
||||
private List<DeviceMapping<ItemT>> getOverlapFreeMappings(List<DeviceMapping<ItemT>> initial,
|
||||
DeviceMapping<ItemT> toBeAdded) {
|
||||
DeviceMapping<ItemT> toBeAdded) {
|
||||
TimeRange timeRange = toBeAdded.getTimeRange();
|
||||
ItemT item = toBeAdded.getMappedTo();
|
||||
DeviceIdentifier device = toBeAdded.getDevice();
|
||||
List<DeviceMapping<ItemT>> result = new ArrayList<DeviceMapping<ItemT>>();
|
||||
|
||||
|
||||
List<DeviceMapping<ItemT>> result = new ArrayList<DeviceMapping<ItemT>>();
|
||||
|
||||
|
||||
for (DeviceMapping<ItemT> otherMapping : initial) {
|
||||
TimeRange otherTimeRange = otherMapping.getTimeRange();
|
||||
|
||||
//time ranges intersect? further investigate
|
||||
if (otherTimeRange.intersects(timeRange)) {
|
||||
TimeRange otherTimeRange = otherMapping.getTimeRange();
|
||||
|
||||
//same device
|
||||
if (otherMapping.getDevice() == device) {
|
||||
|
||||
//two open ranges that close each other
|
||||
if ((otherTimeRange.openEnd() && timeRange.openBeginning() && otherTimeRange.from().before(timeRange.to())) ||
|
||||
(timeRange.openEnd() && otherTimeRange.openBeginning() && timeRange.from().before(otherTimeRange.to()))) {
|
||||
//shouldn't happen here any more -> dealt with in combineOpenRanges
|
||||
//timeRange = timeRange.intersection(otherTimeRange);
|
||||
|
||||
//otherwise merge
|
||||
} else {
|
||||
timeRange = timeRange.union(otherTimeRange);
|
||||
}
|
||||
//time ranges intersect? further investigate
|
||||
if (otherTimeRange.intersects(timeRange)) {
|
||||
|
||||
//different device -> transform according to four cases
|
||||
} else {
|
||||
if (otherTimeRange.liesWithin(timeRange)) {
|
||||
//case 1: just ignore the other mapping, as it is completely overwritten by the new one
|
||||
} else {
|
||||
if (otherTimeRange.startsBefore(timeRange)) {
|
||||
//case 4
|
||||
result.add(getMapping(device, item, otherTimeRange.from(), timeRange.from().minus(1)));
|
||||
}
|
||||
if (otherTimeRange.endsAfter(timeRange)) {
|
||||
//case 3
|
||||
result.add(getMapping(device, item, timeRange.to().plus(1), otherTimeRange.to()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//no intersection -> add both
|
||||
} else {
|
||||
result.add(otherMapping);
|
||||
}
|
||||
//same device
|
||||
if (otherMapping.getDevice() == device) {
|
||||
|
||||
//two open ranges that close each other
|
||||
if ((otherTimeRange.openEnd() && timeRange.openBeginning() && otherTimeRange.from().before(timeRange.to())) ||
|
||||
(timeRange.openEnd() && otherTimeRange.openBeginning() && timeRange.from().before(otherTimeRange.to()))) {
|
||||
//shouldn't happen here any more -> dealt with in combineOpenRanges
|
||||
//timeRange = timeRange.intersection(otherTimeRange);
|
||||
|
||||
//otherwise merge
|
||||
} else {
|
||||
timeRange = timeRange.union(otherTimeRange);
|
||||
}
|
||||
|
||||
//different device -> transform according to four cases
|
||||
} else {
|
||||
if (otherTimeRange.liesWithin(timeRange)) {
|
||||
//case 1: just ignore the other mapping, as it is completely overwritten by the new one
|
||||
} else {
|
||||
if (otherTimeRange.startsBefore(timeRange)) {
|
||||
//case 4
|
||||
result.add(getMapping(device, item, otherTimeRange.from(), timeRange.from().minus(1)));
|
||||
}
|
||||
if (otherTimeRange.endsAfter(timeRange)) {
|
||||
//case 3
|
||||
result.add(getMapping(device, item, timeRange.to().plus(1), otherTimeRange.to()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//no intersection -> add both
|
||||
} else {
|
||||
result.add(otherMapping);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//other mappings have been checked for conflicts, now add toBeAdded (time range may have grown through merges)
|
||||
result.add(getMapping(device, item, timeRange));
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<ItemT, List<DeviceMapping<ItemT>>> performAnalysis() {
|
||||
Map<ItemT, List<DeviceMapping<ItemT>>> preliminary = new HashMap<ItemT, List<DeviceMapping<ItemT>>>();
|
||||
Map<ItemT, List<DeviceMapping<ItemT>>> result = new HashMap<ItemT, List<DeviceMapping<ItemT>>>();
|
||||
|
||||
Map<ItemT, List<DeviceMapping<ItemT>>> preliminary = new HashMap<ItemT, List<DeviceMapping<ItemT>>>();
|
||||
Map<ItemT, List<DeviceMapping<ItemT>>> result = new HashMap<ItemT, List<DeviceMapping<ItemT>>>();
|
||||
|
||||
/* iterate over events in order
|
||||
* -> events with higher importance (later, higher author prio) are located towards the end, and should
|
||||
* therefore override those before
|
||||
@@ -142,26 +142,26 @@ public abstract class DeviceMappingFinder<ItemT extends WithID> extends RaceLogA
|
||||
for (RaceLogEvent e : raceLog.getUnrevokedEvents()) {
|
||||
if (e instanceof DeviceMappingEvent && isValidMapping(((DeviceMappingEvent<?>) e))) {
|
||||
@SuppressWarnings("unchecked")
|
||||
DeviceMappingEvent<ItemT> mappingEvent = (DeviceMappingEvent<ItemT>) e;
|
||||
DeviceMappingEvent<ItemT> mappingEvent = (DeviceMappingEvent<ItemT>) e;
|
||||
ItemT item = mappingEvent.getMappedTo();
|
||||
getItemSet(preliminary, item).add(getMapping(mappingEvent));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//combine mappings that close each other
|
||||
for (ItemT item : preliminary.keySet()) {
|
||||
preliminary.put(item, combineOpenRanges(preliminary.get(item), item));
|
||||
preliminary.put(item, combineOpenRanges(preliminary.get(item), item));
|
||||
}
|
||||
|
||||
|
||||
//resolve overlaps
|
||||
for (ItemT item : preliminary.keySet()) {
|
||||
for (DeviceMapping<ItemT> mapping : preliminary.get(item)) {
|
||||
for (DeviceMapping<ItemT> mapping : preliminary.get(item)) {
|
||||
List<DeviceMapping<ItemT>> mappings = getOverlapFreeMappings(getItemSet(result, item), mapping);
|
||||
Collections.sort(mappings, new TimedComparator());
|
||||
result.put(item, mappings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -171,54 +171,54 @@ public abstract class DeviceMappingFinder<ItemT extends WithID> extends RaceLogA
|
||||
* One open-ended mapping can close multiple other open-ended mappings, if it is the closest for those.
|
||||
* Mappings without open end are left untouched.
|
||||
*/
|
||||
private List<DeviceMapping<ItemT>> combineOpenRanges(List<DeviceMapping<ItemT>> list, ItemT item) {
|
||||
//sort by devices
|
||||
Map<DeviceIdentifier, List<DeviceMapping<ItemT>>> byDevice = new HashMap<DeviceIdentifier, List<DeviceMapping<ItemT>>>();
|
||||
for (DeviceMapping<ItemT> mapping : list) {
|
||||
getItemSet(byDevice, mapping.getDevice()).add(mapping);
|
||||
}
|
||||
|
||||
List<DeviceMapping<ItemT>> overallResult = new ArrayList<DeviceMapping<ItemT>>();
|
||||
private List<DeviceMapping<ItemT>> combineOpenRanges(List<DeviceMapping<ItemT>> list, ItemT item) {
|
||||
//sort by devices
|
||||
Map<DeviceIdentifier, List<DeviceMapping<ItemT>>> byDevice = new HashMap<DeviceIdentifier, List<DeviceMapping<ItemT>>>();
|
||||
for (DeviceMapping<ItemT> mapping : list) {
|
||||
getItemSet(byDevice, mapping.getDevice()).add(mapping);
|
||||
}
|
||||
|
||||
for (DeviceIdentifier device : byDevice.keySet()) {
|
||||
List<DeviceMapping<ItemT>> result = new ArrayList<DeviceMapping<ItemT>>();
|
||||
List<DeviceMapping<ItemT>> openEnds = new ArrayList<DeviceMapping<ItemT>>();
|
||||
List<DeviceMapping<ItemT>> openBeginnings = new ArrayList<DeviceMapping<ItemT>>();
|
||||
|
||||
//find open-ended
|
||||
for (DeviceMapping<ItemT> mapping : list) {
|
||||
if (mapping.getTimeRange().openEnd()) openEnds.add(mapping);
|
||||
else if (mapping.getTimeRange().openBeginning()) openBeginnings.add(mapping);
|
||||
else result.add(mapping);
|
||||
}
|
||||
List<DeviceMapping<ItemT>> overallResult = new ArrayList<DeviceMapping<ItemT>>();
|
||||
|
||||
Collections.sort(openEnds, Collections.reverseOrder(new TimedComparator()));
|
||||
List<DeviceMapping<ItemT>> usedOpenEnds = new ArrayList<DeviceMapping<ItemT>>();
|
||||
List<DeviceMapping<ItemT>> usedOpenBeginnings = new ArrayList<DeviceMapping<ItemT>>();
|
||||
for (DeviceIdentifier device : byDevice.keySet()) {
|
||||
List<DeviceMapping<ItemT>> result = new ArrayList<DeviceMapping<ItemT>>();
|
||||
List<DeviceMapping<ItemT>> openEnds = new ArrayList<DeviceMapping<ItemT>>();
|
||||
List<DeviceMapping<ItemT>> openBeginnings = new ArrayList<DeviceMapping<ItemT>>();
|
||||
|
||||
//now find closest matching
|
||||
for (DeviceMapping<ItemT> openBeginning : openBeginnings) {
|
||||
TimeRange openBeginningRange = openBeginning.getTimeRange();
|
||||
for (DeviceMapping<ItemT> openEnd : openEnds) {
|
||||
TimeRange openEndRange = openEnd.getTimeRange();
|
||||
if (openEndRange.from().before(openBeginningRange.to())) {
|
||||
usedOpenEnds.add(openEnd);
|
||||
usedOpenBeginnings.add(openBeginning);
|
||||
result.add(getMapping(device, item, openEndRange.intersection(openBeginningRange)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
openEnds.removeAll(usedOpenEnds);
|
||||
openBeginnings.removeAll(usedOpenBeginnings);
|
||||
result.addAll(openEnds);
|
||||
result.addAll(openBeginnings);
|
||||
|
||||
overallResult.addAll(result);
|
||||
}
|
||||
|
||||
Collections.sort(overallResult, RaceLogEventComparator.INSTANCE);
|
||||
return overallResult;
|
||||
}
|
||||
//find open-ended
|
||||
for (DeviceMapping<ItemT> mapping : list) {
|
||||
if (mapping.getTimeRange().openEnd()) openEnds.add(mapping);
|
||||
else if (mapping.getTimeRange().openBeginning()) openBeginnings.add(mapping);
|
||||
else result.add(mapping);
|
||||
}
|
||||
|
||||
Collections.sort(openEnds, Collections.reverseOrder(new TimedComparator()));
|
||||
List<DeviceMapping<ItemT>> usedOpenEnds = new ArrayList<DeviceMapping<ItemT>>();
|
||||
List<DeviceMapping<ItemT>> usedOpenBeginnings = new ArrayList<DeviceMapping<ItemT>>();
|
||||
|
||||
//now find closest matching
|
||||
for (DeviceMapping<ItemT> openBeginning : openBeginnings) {
|
||||
TimeRange openBeginningRange = openBeginning.getTimeRange();
|
||||
for (DeviceMapping<ItemT> openEnd : openEnds) {
|
||||
TimeRange openEndRange = openEnd.getTimeRange();
|
||||
if (openEndRange.from().before(openBeginningRange.to())) {
|
||||
usedOpenEnds.add(openEnd);
|
||||
usedOpenBeginnings.add(openBeginning);
|
||||
result.add(getMapping(device, item, openEndRange.intersection(openBeginningRange)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
openEnds.removeAll(usedOpenEnds);
|
||||
openBeginnings.removeAll(usedOpenBeginnings);
|
||||
result.addAll(openEnds);
|
||||
result.addAll(openBeginnings);
|
||||
|
||||
overallResult.addAll(result);
|
||||
}
|
||||
|
||||
Collections.sort(overallResult, RaceLogEventComparator.INSTANCE);
|
||||
return overallResult;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -7,12 +7,12 @@ import com.sap.sailing.domain.racelog.tracking.DeviceMarkMappingEvent;
|
||||
|
||||
public class DeviceMarkMappingFinder extends DeviceMappingFinder<Mark> {
|
||||
|
||||
public DeviceMarkMappingFinder(RaceLog raceLog) {
|
||||
super(raceLog);
|
||||
}
|
||||
public DeviceMarkMappingFinder(RaceLog raceLog) {
|
||||
super(raceLog);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isValidMapping(DeviceMappingEvent<?> mapping) {
|
||||
return mapping instanceof DeviceMarkMappingEvent;
|
||||
}
|
||||
@Override
|
||||
protected boolean isValidMapping(DeviceMappingEvent<?> mapping) {
|
||||
return mapping instanceof DeviceMarkMappingEvent;
|
||||
}
|
||||
}
|
||||
|
||||
+8
-8
@@ -8,19 +8,19 @@ import com.sap.sailing.domain.racelog.analyzing.impl.RaceLogAnalyzer;
|
||||
import com.sap.sailing.domain.racelog.tracking.DenoteForTrackingEvent;
|
||||
|
||||
public class RaceInformationFinder extends RaceLogAnalyzer<Pair<String, BoatClass>> {
|
||||
public RaceInformationFinder(RaceLog raceLog) {
|
||||
super(raceLog);
|
||||
}
|
||||
public RaceInformationFinder(RaceLog raceLog) {
|
||||
super(raceLog);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pair<String, BoatClass> performAnalysis() {
|
||||
@Override
|
||||
protected Pair<String, BoatClass> performAnalysis() {
|
||||
for (RaceLogEvent event : getAllEvents()) {
|
||||
if (event instanceof DenoteForTrackingEvent) {
|
||||
DenoteForTrackingEvent e = (DenoteForTrackingEvent) event;
|
||||
DenoteForTrackingEvent e = (DenoteForTrackingEvent) event;
|
||||
return new Pair<String, BoatClass>(e.getRaceName(), e.getBoatClass());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+17
-17
@@ -18,23 +18,23 @@ import com.sap.sailing.domain.racelog.tracking.RegisterCompetitorEvent;
|
||||
*/
|
||||
public class RegisteredCompetitorsAnalyzer extends RaceLogAnalyzer<Iterable<Competitor>> {
|
||||
|
||||
public RegisteredCompetitorsAnalyzer(RaceLog raceLog) {
|
||||
super(raceLog);
|
||||
}
|
||||
public RegisteredCompetitorsAnalyzer(RaceLog raceLog) {
|
||||
super(raceLog);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Iterable<Competitor> performAnalysis() {
|
||||
Set<Competitor> result = new HashSet<Competitor>();
|
||||
|
||||
for (RaceLogEvent event : getRaceLog().getUnrevokedEvents()) {
|
||||
if (event instanceof DeviceCompetitorMappingEvent) {
|
||||
result.add(((DeviceCompetitorMappingEvent) event).getMappedTo());
|
||||
} else if (event instanceof RegisterCompetitorEvent) {
|
||||
result.add(((RegisterCompetitorEvent) event).getCompetitor());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
protected Iterable<Competitor> performAnalysis() {
|
||||
Set<Competitor> result = new HashSet<Competitor>();
|
||||
|
||||
for (RaceLogEvent event : getRaceLog().getUnrevokedEvents()) {
|
||||
if (event instanceof DeviceCompetitorMappingEvent) {
|
||||
result.add(((DeviceCompetitorMappingEvent) event).getMappedTo());
|
||||
} else if (event instanceof RegisterCompetitorEvent) {
|
||||
result.add(((RegisterCompetitorEvent) event).getCompetitor());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+29
-29
@@ -12,34 +12,34 @@ import com.sap.sailing.domain.racelog.tracking.DeviceIdentifier;
|
||||
import com.sap.sailing.domain.racelog.tracking.DeviceMappingEvent;
|
||||
|
||||
public abstract class AbstractDeviceMappingEventImpl<ItemType extends WithID> extends RaceLogEventImpl implements
|
||||
DeviceMappingEvent<ItemType> {
|
||||
private static final long serialVersionUID = -8439653251231710356L;
|
||||
DeviceMappingEvent<ItemType> {
|
||||
private static final long serialVersionUID = -8439653251231710356L;
|
||||
|
||||
private final ItemType mappedTo;
|
||||
private final DeviceIdentifier device;
|
||||
private final TimePoint from;
|
||||
private final TimePoint to;
|
||||
|
||||
public AbstractDeviceMappingEventImpl(TimePoint createdAt, RaceLogEventAuthor author,
|
||||
TimePoint logicalTimePoint, Serializable pId, int pPassId, ItemType mappedTo,
|
||||
DeviceIdentifier device, TimePoint from, TimePoint to) {
|
||||
super(createdAt, author, logicalTimePoint, pId, Collections.<Competitor>emptyList(), pPassId);
|
||||
this.mappedTo = mappedTo;
|
||||
this.device = device;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
public ItemType getMappedTo() {
|
||||
return mappedTo;
|
||||
}
|
||||
public DeviceIdentifier getDevice() {
|
||||
return device;
|
||||
}
|
||||
public TimePoint getFrom() {
|
||||
return from;
|
||||
}
|
||||
public TimePoint getTo() {
|
||||
return to;
|
||||
}
|
||||
private final ItemType mappedTo;
|
||||
private final DeviceIdentifier device;
|
||||
private final TimePoint from;
|
||||
private final TimePoint to;
|
||||
|
||||
public AbstractDeviceMappingEventImpl(TimePoint createdAt, RaceLogEventAuthor author,
|
||||
TimePoint logicalTimePoint, Serializable pId, int pPassId, ItemType mappedTo,
|
||||
DeviceIdentifier device, TimePoint from, TimePoint to) {
|
||||
super(createdAt, author, logicalTimePoint, pId, Collections.<Competitor>emptyList(), pPassId);
|
||||
this.mappedTo = mappedTo;
|
||||
this.device = device;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
public ItemType getMappedTo() {
|
||||
return mappedTo;
|
||||
}
|
||||
public DeviceIdentifier getDevice() {
|
||||
return device;
|
||||
}
|
||||
public TimePoint getFrom() {
|
||||
return from;
|
||||
}
|
||||
public TimePoint getTo() {
|
||||
return to;
|
||||
}
|
||||
}
|
||||
|
||||
+25
-25
@@ -12,34 +12,34 @@ import com.sap.sailing.domain.racelog.impl.RaceLogEventImpl;
|
||||
import com.sap.sailing.domain.racelog.tracking.DenoteForTrackingEvent;
|
||||
|
||||
public class DenoteForTrackingEventImpl extends RaceLogEventImpl implements
|
||||
DenoteForTrackingEvent {
|
||||
private static final long serialVersionUID = 6937741283401976385L;
|
||||
|
||||
private final String raceName;
|
||||
private final BoatClass boatClass;
|
||||
DenoteForTrackingEvent {
|
||||
private static final long serialVersionUID = 6937741283401976385L;
|
||||
|
||||
public DenoteForTrackingEventImpl(TimePoint createdAt,
|
||||
RaceLogEventAuthor author, TimePoint logicalTimePoint,
|
||||
Serializable pId, int pPassId,
|
||||
String raceName, BoatClass boatClass) {
|
||||
super(createdAt, author, logicalTimePoint, pId, Collections.<Competitor>emptyList(), pPassId);
|
||||
this.raceName = raceName;
|
||||
this.boatClass = boatClass;
|
||||
}
|
||||
private final String raceName;
|
||||
private final BoatClass boatClass;
|
||||
|
||||
@Override
|
||||
public void accept(RaceLogEventVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
public DenoteForTrackingEventImpl(TimePoint createdAt,
|
||||
RaceLogEventAuthor author, TimePoint logicalTimePoint,
|
||||
Serializable pId, int pPassId,
|
||||
String raceName, BoatClass boatClass) {
|
||||
super(createdAt, author, logicalTimePoint, pId, Collections.<Competitor>emptyList(), pPassId);
|
||||
this.raceName = raceName;
|
||||
this.boatClass = boatClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRaceName() {
|
||||
return raceName;
|
||||
}
|
||||
@Override
|
||||
public void accept(RaceLogEventVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BoatClass getBoatClass() {
|
||||
return boatClass;
|
||||
}
|
||||
@Override
|
||||
public String getRaceName() {
|
||||
return raceName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BoatClass getBoatClass() {
|
||||
return boatClass;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+10
-10
@@ -10,16 +10,16 @@ import com.sap.sailing.domain.racelog.tracking.DeviceCompetitorMappingEvent;
|
||||
import com.sap.sailing.domain.racelog.tracking.DeviceIdentifier;
|
||||
|
||||
public class DeviceCompetitorMappingEventImpl extends AbstractDeviceMappingEventImpl<Competitor>
|
||||
implements DeviceCompetitorMappingEvent {
|
||||
public DeviceCompetitorMappingEventImpl(TimePoint createdAt, RaceLogEventAuthor author, TimePoint logicalTimePoint,
|
||||
Serializable pId, int pPassId, Competitor mappedTo, DeviceIdentifier device, TimePoint from, TimePoint to) {
|
||||
super(createdAt, author, logicalTimePoint, pId, pPassId, mappedTo, device, from, to);
|
||||
}
|
||||
implements DeviceCompetitorMappingEvent {
|
||||
public DeviceCompetitorMappingEventImpl(TimePoint createdAt, RaceLogEventAuthor author, TimePoint logicalTimePoint,
|
||||
Serializable pId, int pPassId, Competitor mappedTo, DeviceIdentifier device, TimePoint from, TimePoint to) {
|
||||
super(createdAt, author, logicalTimePoint, pId, pPassId, mappedTo, device, from, to);
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = -1494030544804758753L;
|
||||
private static final long serialVersionUID = -1494030544804758753L;
|
||||
|
||||
@Override
|
||||
public void accept(RaceLogEventVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
@Override
|
||||
public void accept(RaceLogEventVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
||||
+10
-10
@@ -10,16 +10,16 @@ import com.sap.sailing.domain.racelog.tracking.DeviceIdentifier;
|
||||
import com.sap.sailing.domain.racelog.tracking.DeviceMarkMappingEvent;
|
||||
|
||||
public class DeviceMarkMappingEventImpl extends AbstractDeviceMappingEventImpl<Mark>
|
||||
implements DeviceMarkMappingEvent {
|
||||
public DeviceMarkMappingEventImpl(TimePoint createdAt, RaceLogEventAuthor author, TimePoint logicalTimePoint,
|
||||
Serializable pId, int pPassId, Mark mappedTo, DeviceIdentifier device, TimePoint from, TimePoint to) {
|
||||
super(createdAt, author, logicalTimePoint, pId, pPassId, mappedTo, device, from, to);
|
||||
}
|
||||
implements DeviceMarkMappingEvent {
|
||||
public DeviceMarkMappingEventImpl(TimePoint createdAt, RaceLogEventAuthor author, TimePoint logicalTimePoint,
|
||||
Serializable pId, int pPassId, Mark mappedTo, DeviceIdentifier device, TimePoint from, TimePoint to) {
|
||||
super(createdAt, author, logicalTimePoint, pId, pPassId, mappedTo, device, from, to);
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = -1494030544804758753L;
|
||||
private static final long serialVersionUID = -1494030544804758753L;
|
||||
|
||||
@Override
|
||||
public void accept(RaceLogEventVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
@Override
|
||||
public void accept(RaceLogEventVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
||||
+10
-10
@@ -11,18 +11,18 @@ import com.sap.sailing.domain.racelog.impl.RaceLogEventImpl;
|
||||
import com.sap.sailing.domain.racelog.tracking.StartTrackingEvent;
|
||||
|
||||
public class StartTrackingEventImpl extends RaceLogEventImpl implements
|
||||
StartTrackingEvent {
|
||||
private static final long serialVersionUID = 6017954368580125221L;
|
||||
StartTrackingEvent {
|
||||
private static final long serialVersionUID = 6017954368580125221L;
|
||||
|
||||
public StartTrackingEventImpl(TimePoint createdAt, RaceLogEventAuthor author,
|
||||
TimePoint logicalTimePoint, Serializable pId, int pPassId) {
|
||||
super(createdAt, author, logicalTimePoint, pId, Collections.<Competitor>emptyList(), pPassId);
|
||||
}
|
||||
public StartTrackingEventImpl(TimePoint createdAt, RaceLogEventAuthor author,
|
||||
TimePoint logicalTimePoint, Serializable pId, int pPassId) {
|
||||
super(createdAt, author, logicalTimePoint, pId, Collections.<Competitor>emptyList(), pPassId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void accept(RaceLogEventVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
@Override
|
||||
public void accept(RaceLogEventVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+11
-11
@@ -7,9 +7,9 @@ import com.sap.sailing.domain.racelog.tracking.DeviceIdentifier;
|
||||
import com.sap.sailing.domain.racelog.tracking.DeviceMapping;
|
||||
|
||||
public class DeviceMappingImpl<ItemType extends WithID> implements DeviceMapping<ItemType> {
|
||||
private static final long serialVersionUID = -4602948402371623654L;
|
||||
|
||||
private final ItemType mappedTo;
|
||||
private static final long serialVersionUID = -4602948402371623654L;
|
||||
|
||||
private final ItemType mappedTo;
|
||||
private final DeviceIdentifier device;
|
||||
private final TimeRange timeRange;
|
||||
|
||||
@@ -29,13 +29,13 @@ public class DeviceMappingImpl<ItemType extends WithID> implements DeviceMapping
|
||||
return timeRange;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemType getMappedTo() {
|
||||
return mappedTo;
|
||||
}
|
||||
@Override
|
||||
public ItemType getMappedTo() {
|
||||
return mappedTo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimePoint getTimePoint() {
|
||||
return timeRange.from();
|
||||
}
|
||||
@Override
|
||||
public TimePoint getTimePoint() {
|
||||
return timeRange.from();
|
||||
}
|
||||
}
|
||||
|
||||
+28
-28
@@ -10,38 +10,38 @@ import com.sap.sailing.domain.tracking.GPSFixMoving;
|
||||
public enum EmptyGPSFixStore implements GPSFixStore {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public void storeFix(DeviceIdentifier device, GPSFix fix) {
|
||||
}
|
||||
@Override
|
||||
public void storeFix(DeviceIdentifier device, GPSFix fix) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadCompetitorTrack(DynamicGPSFixTrack<Competitor, GPSFixMoving> track,
|
||||
RaceLog raceLog, Competitor competitor) {
|
||||
}
|
||||
@Override
|
||||
public void loadCompetitorTrack(DynamicGPSFixTrack<Competitor, GPSFixMoving> track,
|
||||
RaceLog raceLog, Competitor competitor) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadMarkTrack(DynamicGPSFixTrack<Mark, GPSFix> track,
|
||||
RaceLog raceLog, Mark mark) {
|
||||
}
|
||||
@Override
|
||||
public void loadMarkTrack(DynamicGPSFixTrack<Mark, GPSFix> track,
|
||||
RaceLog raceLog, Mark mark) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(GPSFixReceivedListener listener) {
|
||||
}
|
||||
@Override
|
||||
public void addListener(GPSFixReceivedListener listener) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(GPSFixReceivedListener listener) {
|
||||
}
|
||||
@Override
|
||||
public void removeListener(GPSFixReceivedListener listener) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadCompetitorTrack(
|
||||
DynamicGPSFixTrack<Competitor, GPSFixMoving> track,
|
||||
DeviceMapping<Competitor> mapping) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void loadCompetitorTrack(
|
||||
DynamicGPSFixTrack<Competitor, GPSFixMoving> track,
|
||||
DeviceMapping<Competitor> mapping) {
|
||||
|
||||
@Override
|
||||
public void loadMarkTrack(DynamicGPSFixTrack<Mark, GPSFix> track,
|
||||
DeviceMapping<Mark> mapping) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadMarkTrack(DynamicGPSFixTrack<Mark, GPSFix> track,
|
||||
DeviceMapping<Mark> mapping) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,5 +3,5 @@ package com.sap.sailing.domain.racelog.tracking;
|
||||
import com.sap.sailing.domain.tracking.GPSFix;
|
||||
|
||||
public interface GPSFixReceivedListener {
|
||||
void fixReceived(DeviceIdentifier device, GPSFix fix);
|
||||
void fixReceived(DeviceIdentifier device, GPSFix fix);
|
||||
}
|
||||
|
||||
+15
-15
@@ -9,34 +9,34 @@ import com.sap.sailing.domain.tracking.GPSFixMoving;
|
||||
|
||||
|
||||
public interface GPSFixStore {
|
||||
/**
|
||||
* Load all fixes that correspond to the {@link DeviceCompetitorMappingEvent}s found in the {@code raceLog}.
|
||||
*/
|
||||
/**
|
||||
* Load all fixes that correspond to the {@link DeviceCompetitorMappingEvent}s found in the {@code raceLog}.
|
||||
*/
|
||||
void loadCompetitorTrack(DynamicGPSFixTrack<Competitor, GPSFixMoving> track, RaceLog raceLog,
|
||||
Competitor competitor);
|
||||
|
||||
/**
|
||||
* Load all fixes that correspond to the {@link DeviceMarkMappingEvent}s found in the {@code raceLog}.
|
||||
*/
|
||||
/**
|
||||
* Load all fixes that correspond to the {@link DeviceMarkMappingEvent}s found in the {@code raceLog}.
|
||||
*/
|
||||
void loadMarkTrack(DynamicGPSFixTrack<Mark, GPSFix> track, RaceLog raceLog, Mark mark);
|
||||
|
||||
/**
|
||||
* Load all fixes that correspond to the {@code mapping}.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Load all fixes that correspond to the {@code mapping}.
|
||||
*/
|
||||
void loadCompetitorTrack(DynamicGPSFixTrack<Competitor, GPSFixMoving> track, DeviceMapping<Competitor> mapping);
|
||||
|
||||
/**
|
||||
* Load all fixes that correspond to the {@code mapping}.
|
||||
*/
|
||||
/**
|
||||
* Load all fixes that correspond to the {@code mapping}.
|
||||
*/
|
||||
void loadMarkTrack(DynamicGPSFixTrack<Mark, GPSFix> track, DeviceMapping<Mark> mapping);
|
||||
|
||||
void storeFix(DeviceIdentifier device, GPSFix fix);
|
||||
|
||||
|
||||
/**
|
||||
* Listeners are notified, whenever a {@link GPSFix} is stored through the {@link #storeFix(DeviceIdentifier, GPSFix)}
|
||||
* method.
|
||||
*/
|
||||
void addListener(GPSFixReceivedListener listener);
|
||||
|
||||
|
||||
void removeListener(GPSFixReceivedListener listener);
|
||||
}
|
||||
|
||||
+10
-10
@@ -371,17 +371,17 @@ public abstract class TrackedRaceImpl extends TrackedRaceWithWindEssentials impl
|
||||
* and {@link #timePointOfOldestEvent}.
|
||||
*/
|
||||
private void updateEventTimePoints(Iterable<? extends Track<? extends Timed>> tracks) {
|
||||
for (Track<? extends Timed> track : tracks) {
|
||||
track.lockForRead();
|
||||
for (Track<? extends Timed> track : tracks) {
|
||||
track.lockForRead();
|
||||
|
||||
try {
|
||||
for (Timed fix : track.getRawFixes()) {
|
||||
updated(fix.getTimePoint());
|
||||
}
|
||||
} finally {
|
||||
track.unlockAfterRead();
|
||||
}
|
||||
}
|
||||
try {
|
||||
for (Timed fix : track.getRawFixes()) {
|
||||
updated(fix.getTimePoint());
|
||||
}
|
||||
} finally {
|
||||
track.unlockAfterRead();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+14
-14
@@ -2215,18 +2215,18 @@ public class RacingEventServiceImpl implements RacingEventService, RegattaListen
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GPSFixStore getGPSFixStore() {
|
||||
return gpsFixStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RaceTracker getRaceTrackerById(Object id) {
|
||||
return raceTrackersByID.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RaceLogEventAuthor getServerAuthor() {
|
||||
return raceLogEventAuthorForServer;
|
||||
}
|
||||
@Override
|
||||
public GPSFixStore getGPSFixStore() {
|
||||
return gpsFixStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RaceTracker getRaceTrackerById(Object id) {
|
||||
return raceTrackersByID.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RaceLogEventAuthor getServerAuthor() {
|
||||
return raceLogEventAuthorForServer;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user