mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-14 22:43:57 +00:00
Bug 5085: added storing of CourseTemplates
This commit is contained in:
1 parent
99c926a526
commit
e746b04c75
8 files changed
+104
-9
No files matched your search
+5
@@ -20,6 +20,7 @@ import com.sap.sailing.domain.base.Series;
|
||||
import com.sap.sailing.domain.base.configuration.DeviceConfiguration;
|
||||
import com.sap.sailing.domain.common.WindSource;
|
||||
import com.sap.sailing.domain.common.dto.AnniversaryType;
|
||||
import com.sap.sailing.domain.coursetemplate.CourseTemplate;
|
||||
import com.sap.sailing.domain.coursetemplate.MarkProperties;
|
||||
import com.sap.sailing.domain.coursetemplate.MarkTemplate;
|
||||
import com.sap.sailing.domain.leaderboard.Leaderboard;
|
||||
@@ -225,4 +226,8 @@ public interface MongoObjectFactory {
|
||||
void storeMarkTemplate(MarkTemplate markTemplate);
|
||||
|
||||
void removeMarkTemplate(UUID markTemplateId);
|
||||
|
||||
void storeCourseTemplate(CourseTemplate courseTemplate);
|
||||
|
||||
void removeCourseTemplate(UUID courseTemplateId);
|
||||
}
|
||||
+5
-1
@@ -2,6 +2,7 @@ package com.sap.sailing.domain.persistence.impl;
|
||||
|
||||
import com.sap.sailing.domain.base.RaceDefinition;
|
||||
import com.sap.sailing.domain.common.tracking.GPSFix;
|
||||
import com.sap.sailing.domain.coursetemplate.CourseTemplate;
|
||||
import com.sap.sailing.domain.coursetemplate.MarkProperties;
|
||||
import com.sap.sailing.domain.coursetemplate.MarkTemplate;
|
||||
import com.sap.sailing.domain.tracking.RaceTrackingConnectivityParameters;
|
||||
@@ -128,5 +129,8 @@ public enum CollectionNames {
|
||||
MARK_PROPERTIES,
|
||||
|
||||
/** Contains the {@link MarkTemplate} objects. */
|
||||
MARK_TEMPLATES
|
||||
MARK_TEMPLATES,
|
||||
|
||||
/** Contains the {@link CourseTemplate}s. */
|
||||
COURSE_TEMPLATES
|
||||
}
|
||||
+9
-1
@@ -178,5 +178,13 @@ public enum FieldNames {
|
||||
COMMON_MARK_PROPERTIES_COLOR, COMMON_MARK_PROPERTIES_NAME, COMMON_MARK_PROPERTIES_PATTERN, COMMON_MARK_PROPERTIES_SHAPE, COMMON_MARK_PROPERTIES_SHORT_NAME, COMMON_MARK_PROPERTIES_TYPE,
|
||||
|
||||
// mark template fields
|
||||
MARK_TEMPLATE_ID;
|
||||
MARK_TEMPLATE_ID,
|
||||
|
||||
// repeatable part
|
||||
REPEATABLE_PART_START, REPEATABLE_PART_END,
|
||||
|
||||
// course template fields
|
||||
COURSE_TEMPLATE_ID, COURSE_TEMPLATE_NAME, COURSE_TEMPLATE_ASSOCIATED_ROLES, COURSE_TEMPLATE_MARK_TEMPLATES, COURSE_TEMPLATE_TAGS, COURSE_TEMPLATE_REPEATABLE_PART, COURSE_TEMPLATE_WAYPOINTS,
|
||||
// waypoint template fields
|
||||
WAYPOINT_TEMPLATE_PASSINGINSTRUCTION, WAYPOINT_TEMPLATE_MARK_TEMPLATES;
|
||||
}
|
||||
+78
@@ -104,8 +104,10 @@ import com.sap.sailing.domain.common.WindSource;
|
||||
import com.sap.sailing.domain.common.dto.AnniversaryType;
|
||||
import com.sap.sailing.domain.common.racelog.tracking.TransformationException;
|
||||
import com.sap.sailing.domain.coursetemplate.CommonMarkProperties;
|
||||
import com.sap.sailing.domain.coursetemplate.CourseTemplate;
|
||||
import com.sap.sailing.domain.coursetemplate.MarkProperties;
|
||||
import com.sap.sailing.domain.coursetemplate.MarkTemplate;
|
||||
import com.sap.sailing.domain.coursetemplate.WaypointTemplate;
|
||||
import com.sap.sailing.domain.leaderboard.FlexibleLeaderboard;
|
||||
import com.sap.sailing.domain.leaderboard.Leaderboard;
|
||||
import com.sap.sailing.domain.leaderboard.LeaderboardGroup;
|
||||
@@ -1900,4 +1902,80 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
|
||||
configurationsCollections.deleteOne(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void storeCourseTemplate(CourseTemplate courseTemplate) {
|
||||
final MongoCollection<Document> collection = database.getCollection(CollectionNames.COURSE_TEMPLATES.name());
|
||||
final Document query = new Document(FieldNames.COURSE_TEMPLATE_ID.name(), courseTemplate.getId().toString());
|
||||
|
||||
final Document entry = storeCourseTemplateToDocument(courseTemplate);
|
||||
collection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, entry,
|
||||
new UpdateOptions().upsert(true));
|
||||
}
|
||||
|
||||
private Document storeCourseTemplateToDocument(CourseTemplate courseTemplate) {
|
||||
final Document result = new Document();
|
||||
|
||||
// store master data
|
||||
result.put(FieldNames.COURSE_TEMPLATE_ID.name(), courseTemplate.getId());
|
||||
result.put(FieldNames.COURSE_TEMPLATE_NAME.name(), courseTemplate.getName());
|
||||
|
||||
// store waypoint templates
|
||||
final BasicDBList waypointTemplates = new BasicDBList();
|
||||
for (WaypointTemplate waypointTemplate : courseTemplate.getWaypointTemplates(1)) {
|
||||
BasicDBObject waypointTemplateObject = storeWaypointTemplate(waypointTemplate);
|
||||
waypointTemplates.add(waypointTemplateObject);
|
||||
}
|
||||
result.put(FieldNames.COURSE_TEMPLATE_WAYPOINTS.name(), waypointTemplates);
|
||||
|
||||
// associated roles
|
||||
final BasicDBList associatedRoles = new BasicDBList();
|
||||
courseTemplate.getAssociatedRoles().entrySet()
|
||||
.forEach(e -> associatedRoles.add(new BasicDBObject(e.getKey().getId().toString(), e.getValue())));
|
||||
result.put(FieldNames.COURSE_TEMPLATE_ASSOCIATED_ROLES.name(), associatedRoles);
|
||||
|
||||
// mark templates
|
||||
final BasicDBList markTemplates = new BasicDBList();
|
||||
courseTemplate.getMarkTemplates().forEach(m -> markTemplates.add(m.getId().toString()));
|
||||
result.put(FieldNames.COURSE_TEMPLATE_MARK_TEMPLATES.name(), markTemplates);
|
||||
|
||||
// tags
|
||||
final BasicDBList tags = new BasicDBList();
|
||||
courseTemplate.getTags().forEach(t -> tags.add(t));
|
||||
result.put(FieldNames.COURSE_TEMPLATE_TAGS.name(), tags);
|
||||
|
||||
// repeatable part
|
||||
if (courseTemplate.hasRepeatablePart()) {
|
||||
final BasicDBObject repeatablePart = storeRepeatablePart(courseTemplate);
|
||||
result.put(FieldNames.COURSE_TEMPLATE_REPEATABLE_PART.name(), repeatablePart);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private BasicDBObject storeWaypointTemplate(WaypointTemplate waypointTemplate) {
|
||||
BasicDBObject waypointTemplateObject = new BasicDBObject();
|
||||
waypointTemplateObject.put(FieldNames.WAYPOINT_TEMPLATE_PASSINGINSTRUCTION.name(),
|
||||
getPassingInstructions(waypointTemplate.getPassingInstruction()));
|
||||
|
||||
final BasicDBList markTemplates = new BasicDBList();
|
||||
waypointTemplate.getControlPointTemplate().getMarks().forEach(m -> markTemplates.add(m.getId().toString()));
|
||||
waypointTemplateObject.put(FieldNames.WAYPOINT_TEMPLATE_MARK_TEMPLATES.name(), markTemplates);
|
||||
return waypointTemplateObject;
|
||||
}
|
||||
|
||||
private BasicDBObject storeRepeatablePart(CourseTemplate courseTemplate) {
|
||||
final BasicDBObject repeatablePart = new BasicDBObject();
|
||||
repeatablePart.put(FieldNames.REPEATABLE_PART_START.name(), courseTemplate.getRepeatablePart().getA());
|
||||
repeatablePart.put(FieldNames.REPEATABLE_PART_END.name(), courseTemplate.getRepeatablePart().getB());
|
||||
return repeatablePart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCourseTemplate(UUID courseTemplateId) {
|
||||
final MongoCollection<Document> configurationsCollections = database
|
||||
.getCollection(CollectionNames.COURSE_TEMPLATES.name());
|
||||
final Document query = new Document(FieldNames.COURSE_TEMPLATE_ID.name(), courseTemplateId.toString());
|
||||
configurationsCollections.deleteOne(query);
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -65,7 +65,7 @@ public class TestLapConfiguration {
|
||||
assertEquals(expected.size(), Util.size(waypointsOfOneLapper));
|
||||
final List<ControlPointTemplate> controlPoints = new ArrayList<>();
|
||||
for (final WaypointTemplate waypoint : waypointsOfOneLapper) {
|
||||
controlPoints.add(waypoint.getControlPoint());
|
||||
controlPoints.add(waypoint.getControlPointTemplate());
|
||||
}
|
||||
assertEquals(expected, controlPoints);
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,6 +3,6 @@ package com.sap.sailing.domain.coursetemplate;
|
||||
import com.sap.sailing.domain.common.PassingInstruction;
|
||||
|
||||
public interface WaypointTemplate {
|
||||
ControlPointTemplate getControlPoint();
|
||||
ControlPointTemplate getControlPointTemplate();
|
||||
PassingInstruction getPassingInstruction();
|
||||
}
|
||||
+1
-1
@@ -67,7 +67,7 @@ public class CourseTemplateImpl extends NamedWithUUIDImpl implements CourseTempl
|
||||
*/
|
||||
private void validateWaypointsAgainstMarks() {
|
||||
for (final WaypointTemplate waypoint : waypoints) {
|
||||
for (final MarkTemplate mark : waypoint.getControlPoint().getMarks()) {
|
||||
for (final MarkTemplate mark : waypoint.getControlPointTemplate().getMarks()) {
|
||||
if (!Util.contains(marks, mark)) {
|
||||
throw new IllegalArgumentException("Mark "+mark+" used by waypoint template "+
|
||||
waypoint+" in course template "+this+" is not provided in the collection of marks");
|
||||
|
||||
+4
-4
@@ -6,16 +6,16 @@ import com.sap.sailing.domain.coursetemplate.WaypointTemplate;
|
||||
|
||||
public class WaypointTemplateImpl implements WaypointTemplate {
|
||||
private final PassingInstruction passingInstruction;
|
||||
private final ControlPointTemplate controlPoint;
|
||||
private final ControlPointTemplate controlPointTemplate;
|
||||
|
||||
public WaypointTemplateImpl(ControlPointTemplate controlPoint, PassingInstruction passingInstruction) {
|
||||
this.passingInstruction = passingInstruction;
|
||||
this.controlPoint = controlPoint;
|
||||
this.controlPointTemplate = controlPoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ControlPointTemplate getControlPoint() {
|
||||
return controlPoint;
|
||||
public ControlPointTemplate getControlPointTemplate() {
|
||||
return controlPointTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user