Added event class information (eventType) to DeviceMapping

This commit is contained in:
Benjamin Barth committed 2016-04-04 14:26:05 +02:00
1 parent c7ade94bf0
commit f7a614ace8
5 files changed
+25 -13

No files matched your search

@@ -48,9 +48,9 @@ public abstract class RegattaLogDeviceMappingFinder<ItemT extends WithID> extend
}
protected DeviceMapping<ItemT> createMapping(DeviceIdentifier device, ItemT item,
TimePoint from, TimePoint to, Serializable originalEventId) {
TimePoint from, TimePoint to, Serializable originalEventId, Class<?> type) {
return new DeviceMappingImpl<ItemT>(item, device, new TimeRangeImpl(from, to),
Collections.singletonList(originalEventId));
Collections.singletonList(originalEventId), type);
}
private List<RegattaLogDeviceMappingEvent<ItemT>> getMappingEventsForItem(Map<ItemT, List<RegattaLogDeviceMappingEvent<ItemT>>> map, ItemT item) {
@@ -103,7 +103,7 @@ public abstract class RegattaLogDeviceMappingFinder<ItemT extends WithID> extend
if (to == null) {
to = closingTimePoint;
}
result.add(createMapping(event.getDevice(), item, from, to, event.getId()));
result.add(createMapping(event.getDevice(), item, from, to, event.getId(), event.getClass()));
}
return result;
}
@@ -25,4 +25,7 @@ public interface DeviceMapping<ItemType extends WithID> extends Timed {
DeviceIdentifier getDevice();
TimeRange getTimeRange();
Class<?> getEventType();
}
@@ -19,20 +19,24 @@ public class DeviceMappingImpl<ItemType extends WithID> implements DeviceMapping
private final DeviceIdentifier device;
private final TimeRange timeRange;
private final List<Serializable> originalRaceLogEventIds = new ArrayList<Serializable>();
public DeviceMappingImpl(ItemType mappedTo, DeviceIdentifier device, TimeRange timeRange) {
private final Class<?> eventType;
public DeviceMappingImpl(ItemType mappedTo, DeviceIdentifier device, TimeRange timeRange, Class<?> eventType) {
this.mappedTo = mappedTo;
this.device = device;
this.timeRange = timeRange;
this.eventType = eventType;
}
public DeviceMappingImpl(ItemType mappedTo, DeviceIdentifier device, TimeRange timeRange, Serializable originalRaceLogEventId) {
this(mappedTo, device, timeRange);
public DeviceMappingImpl(ItemType mappedTo, DeviceIdentifier device, TimeRange timeRange,
Serializable originalRaceLogEventId, Class<?> eventType) {
this(mappedTo, device, timeRange, eventType);
if (originalRaceLogEventId != null) originalRaceLogEventIds.add(originalRaceLogEventId);
}
public DeviceMappingImpl(ItemType mappedTo, DeviceIdentifier device, TimeRange timeRange, List<? extends Serializable> originalRaceLogEventIds) {
this(mappedTo, device, timeRange);
public DeviceMappingImpl(ItemType mappedTo, DeviceIdentifier device, TimeRange timeRange,
List<? extends Serializable> originalRaceLogEventIds, Class<?> eventType) {
this(mappedTo, device, timeRange, eventType);
if (originalRaceLogEventIds != null) this.originalRaceLogEventIds.addAll(originalRaceLogEventIds);
}
@@ -56,9 +60,14 @@ public class DeviceMappingImpl<ItemType extends WithID> implements DeviceMapping
return timeRange.from();
}
@Override
public Class<?> getEventType() {
return eventType;
}
public static <T extends WithID> DeviceMapping<T> convertToDeviceMapping(RegattaLogDeviceMappingEvent<T> event) {
return new DeviceMappingImpl<T>(event.getMappedTo(), event.getDevice(), new TimeRangeImpl(event.getFrom(), event.getTo()),
event.getId());
event.getId(), event.getClass());
}
@Override
@@ -141,7 +141,7 @@ public class TopLevelMasterData implements Serializable {
}
DeviceIdentifier device = mappingEvent.getDevice();
gpsFixStore.loadTrack(track, new DeviceMappingImpl<WithID>(mappingEvent.getMappedTo(), device,
new TimeRangeImpl(mappingEvent.getFrom(), mappingEvent.getTo())));
new TimeRangeImpl(mappingEvent.getFrom(), mappingEvent.getTo()), mappingEvent.getClass()));
if (!relevantFixes.containsKey(device)) {
relevantFixes.put(device, new HashSet<>());
}
@@ -5460,11 +5460,11 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
if (dto.mappedTo instanceof MarkDTO) {
Mark mark = convertToMark(((MarkDTO) dto.mappedTo), true);
//expect UUIDs
return new DeviceMappingImpl<Mark>(mark, device, timeRange, dto.originalRaceLogEventIds);
return new DeviceMappingImpl<Mark>(mark, device, timeRange, dto.originalRaceLogEventIds, RegattaLogDeviceMarkMappingEventImpl.class);
} else if (dto.mappedTo instanceof CompetitorDTO) {
Competitor competitor = getService().getCompetitorStore().getExistingCompetitorByIdAsString(
((CompetitorDTO) dto.mappedTo).getIdAsString());
return new DeviceMappingImpl<Competitor>(competitor, device, timeRange, dto.originalRaceLogEventIds);
return new DeviceMappingImpl<Competitor>(competitor, device, timeRange, dto.originalRaceLogEventIds, RegattaLogDeviceCompetitorMappingEventImpl.class);
} else {
throw new RuntimeException("Can only map devices to competitors or marks");
}