mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-16 07:10:48 +00:00
generalized handling of MarkProperties referenced by MarkConfiguration;
this to solve in particular the issue with submitting a MarkPropertiesBasedMarkConfiguration with isSaveToInventory==true that has led to the erroneous creation of yet another MarkProperties object
This commit is contained in:
1 parent
f6d7990f36
commit
eb935f2af3
7 files changed
+68
-37
No files matched your search
+6
-4
@@ -12,11 +12,13 @@ package com.sap.sailing.domain.coursetemplate;
|
||||
public interface FreestyleMarkConfiguration extends MarkConfiguration {
|
||||
CommonMarkProperties getFreestyleProperties();
|
||||
|
||||
|
||||
/**
|
||||
* @return a non-{@code null} object if this mark configuration originated from a {@link MarkProperties}
|
||||
* object where the {@link #getFreestyleProperties() freestyle properties} override one or more of the
|
||||
* {@link MarkProperties}' attributes.
|
||||
* @return a non-{@code null} object if this mark configuration originated from a {@link MarkProperties} object
|
||||
* where the {@link #getFreestyleProperties() freestyle properties} override one or more of the
|
||||
* {@link MarkProperties}' attributes. If {@link #isStoreToInventory()} is {@code true}, this means
|
||||
* that the {@link MarkProperties} object returned by this method shall be updated accordingly to
|
||||
* reflect the {@link #getFreestyleProperties() freestyle properties} after the update.
|
||||
*/
|
||||
@Override
|
||||
MarkProperties getOptionalMarkProperties();
|
||||
}
|
||||
+15
-11
@@ -13,22 +13,24 @@ import com.sap.sailing.domain.base.Mark;
|
||||
* <ul>
|
||||
* <li>A {@link MarkTemplate} can provide {@link CommonMarkProperties}</li>
|
||||
* <li>An existing {@link Mark} from the regatta may be selected; the mark may or may not be used to fill the role
|
||||
* defined by the {@link #getOptionalMarkTemplate() mark template}. Regarding the {@link #getEffectiveProperties() effective
|
||||
* properties}, the {@link Mark}'s properties take precedence over the {@link MarkTemplate}'s properties.</li>
|
||||
* <li>A {@link MarkProperties} object may be selected from the inventory or may have been identified as having been
|
||||
* used while creating the {@link #getMark() mark} in the regatta, to provide optional base configuration
|
||||
* ({@link CommonMarkProperties}) as well as tracking/location/device information. All of those are optional in a
|
||||
* {@link MarkProperties} object. Those present will take precedence and will be merged with the properties obtained from the {@link #getOptionalMarkTemplate() mark
|
||||
* template} and the properties obtained from an existing {@link #getMark() mark}.</li>
|
||||
* defined by the {@link #getOptionalMarkTemplate() mark template}. Regarding the {@link #getEffectiveProperties()
|
||||
* effective properties}, the {@link Mark}'s properties take precedence over the {@link MarkTemplate}'s properties.</li>
|
||||
* <li>A {@link MarkProperties} object may be selected from the inventory or may have been
|
||||
* {@link #getOptionalMarkProperties() identified} as having been used while creating the {@link #getMark() mark} in the
|
||||
* regatta, to provide optional base configuration ({@link CommonMarkProperties}) as well as tracking/location/device
|
||||
* information. All of those are optional in a {@link MarkProperties} object. Those present will take precedence and
|
||||
* will be merged with the properties obtained from the {@link #getOptionalMarkTemplate() mark template} and the
|
||||
* properties obtained from an existing {@link #getMark() mark}.</li>
|
||||
* <li></li>
|
||||
* </ul>
|
||||
*
|
||||
* The combined set of properties merged according to the rules above can be obtained by calling
|
||||
* {@link #getEffectiveProperties()}.<p>
|
||||
* {@link #getEffectiveProperties()}.
|
||||
* <p>
|
||||
*
|
||||
* The {@link #isStoreToInventory()} method tells whether, when applying this configuration to create
|
||||
* or use a {@link Mark}, the {@link #getEffectiveProperties() effective mark properties} shall be
|
||||
* recorded as a new {@link MarkProperties} object in the inventory.
|
||||
* The {@link #isStoreToInventory()} method tells whether, when applying this configuration to create or use a
|
||||
* {@link Mark}, the {@link #getEffectiveProperties() effective mark properties} shall be recorded as a new
|
||||
* {@link MarkProperties} object in the inventory.
|
||||
*
|
||||
* @author Axel Uhl (D043530)
|
||||
*
|
||||
@@ -36,6 +38,8 @@ import com.sap.sailing.domain.base.Mark;
|
||||
public interface MarkConfiguration extends ControlPointWithMarkConfiguration {
|
||||
MarkTemplate getOptionalMarkTemplate();
|
||||
|
||||
MarkProperties getOptionalMarkProperties();
|
||||
|
||||
CommonMarkProperties getEffectiveProperties();
|
||||
|
||||
Positioning getEffectivePositioning();
|
||||
|
||||
+9
@@ -11,6 +11,15 @@ package com.sap.sailing.domain.coursetemplate;
|
||||
*/
|
||||
public interface MarkPropertiesBasedMarkConfiguration extends MarkConfiguration {
|
||||
MarkProperties getMarkProperties();
|
||||
|
||||
/**
|
||||
* The "optional" {@link MarkProperties} for this type of mark configuration are the {@link #getMarkProperties()
|
||||
* MarkProperties} referenced by this object and hence never {@code null}.
|
||||
*/
|
||||
@Override
|
||||
default MarkProperties getOptionalMarkProperties() {
|
||||
return getMarkProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* No need to store a {@link MarkProperties} object to the inventory; we are using an unmodified
|
||||
|
||||
+4
-3
@@ -9,8 +9,10 @@ import com.sap.sailing.domain.base.Mark;
|
||||
* location/position/tracking data.
|
||||
* <p>
|
||||
*
|
||||
* An optional non-{@code null} {@link MarkTemplate} may be returned from {@link #getOptionalMarkTemplate()} which then leads to
|
||||
* recording a usage relation between the regatta {@link Mark} and said {@link MarkTemplate}.
|
||||
* An optional non-{@code null} {@link MarkTemplate} may be returned from {@link #getOptionalMarkTemplate()} which then
|
||||
* leads to recording a usage relation between the regatta {@link Mark} and said {@link MarkTemplate}.
|
||||
* {@link #getOptionalMarkProperties()} can reference a {@link MarkProperties} object if the {@link #getMark mark} was
|
||||
* originally created from that {@link MarkProperties} object.
|
||||
* <p>
|
||||
*
|
||||
* The {@link #getEffectiveProperties() effective properties} will contain
|
||||
@@ -23,5 +25,4 @@ import com.sap.sailing.domain.base.Mark;
|
||||
*/
|
||||
public interface RegattaMarkConfiguration extends MarkConfiguration {
|
||||
Mark getMark();
|
||||
MarkProperties getOptionalMarkProperties();
|
||||
}
|
||||
+14
@@ -1,6 +1,8 @@
|
||||
package com.sap.sailing.domain.coursetemplate.impl;
|
||||
|
||||
import com.sap.sailing.domain.coursetemplate.CommonMarkProperties;
|
||||
import com.sap.sailing.domain.coursetemplate.MarkProperties;
|
||||
import com.sap.sailing.domain.coursetemplate.MarkPropertiesBasedMarkConfiguration;
|
||||
import com.sap.sailing.domain.coursetemplate.MarkTemplate;
|
||||
import com.sap.sailing.domain.coursetemplate.MarkTemplateBasedMarkConfiguration;
|
||||
import com.sap.sailing.domain.coursetemplate.StorablePositioning;
|
||||
@@ -29,4 +31,16 @@ public class MarkTemplateBasedMarkConfigurationImpl extends MarkConfigurationImp
|
||||
return getOptionalMarkTemplate().getShortName();
|
||||
}
|
||||
|
||||
/**
|
||||
* When configuring a mark from a {@link MarkTemplate} using an instance of this type, no
|
||||
* {@link MarkProperties} can be specified, and therefore this method always returns {@code null}.
|
||||
* To provide {@link MarkProperties} that configure a mark and connect it with other properties
|
||||
* that are based on a {@link MarkTemplate}, use {@link MarkPropertiesBasedMarkConfiguration}
|
||||
* with a non-{@code null} {@link MarkPropertiesBasedMarkConfiguration#getOptionalMarkTemplate()}
|
||||
* return value.
|
||||
*/
|
||||
@Override
|
||||
public MarkProperties getOptionalMarkProperties() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+4
-7
@@ -152,16 +152,14 @@ public class CourseAndMarkConfigurationFactoryImpl implements CourseAndMarkConfi
|
||||
final Map<MarkConfiguration, MarkConfiguration> effectiveConfigurations = new HashMap<>();
|
||||
for (MarkConfiguration markConfiguration : courseConfiguration.getAllMarks()) {
|
||||
if (markConfiguration.isStoreToInventory()) {
|
||||
MarkProperties markPropertiesOrNull = null;
|
||||
if (markConfiguration instanceof FreestyleMarkConfiguration) {
|
||||
markPropertiesOrNull = ((FreestyleMarkConfiguration) markConfiguration).getOptionalMarkProperties();
|
||||
} else if (markConfiguration instanceof RegattaMarkConfiguration) {
|
||||
markPropertiesOrNull = ((RegattaMarkConfiguration) markConfiguration).getOptionalMarkProperties();
|
||||
}
|
||||
MarkProperties markPropertiesOrNull = markConfiguration.getOptionalMarkProperties();
|
||||
if (markPropertiesOrNull == null) {
|
||||
// If no mark properties exist yet, a new one is created
|
||||
markPropertiesOrNull = getSharedSailingData().createMarkProperties(markConfiguration.getEffectiveProperties(), Collections.emptySet());
|
||||
} else {
|
||||
// in the case of a MarkPropertiesBasedMarkConfiguration, the following call is expected to notice
|
||||
// the identity between the mark properties object to update and the mark properties that constitute
|
||||
// the effective properties and then skip the update.
|
||||
getSharedSailingData().updateMarkProperties(markPropertiesOrNull.getId(), markConfiguration.getEffectiveProperties(), null, null, Collections.emptySet());
|
||||
}
|
||||
Positioning positioningOrNull = markConfiguration.getOptionalPositioning();
|
||||
@@ -243,7 +241,6 @@ public class CourseAndMarkConfigurationFactoryImpl implements CourseAndMarkConfi
|
||||
public CourseConfiguration createCourseTemplateAndUpdatedConfiguration(
|
||||
final CourseConfiguration courseConfiguration, Iterable<String> tags) {
|
||||
final CourseConfigurationWithMarkRoles courseConfigurationAfterInventory = handleSaveToInventory(courseConfiguration);
|
||||
|
||||
final Map<MarkConfiguration, MarkTemplate> markTemplatesByMarkConfigurations = new HashMap<>();
|
||||
final Map<MarkConfiguration, MarkConfiguration> marksConfigurationsMapping = new HashMap<>();
|
||||
for (MarkConfiguration markConfiguration : courseConfigurationAfterInventory.getAllMarks()) {
|
||||
|
||||
+16
-12
@@ -225,8 +225,10 @@ public class SharedSailingDataImpl implements ReplicatingSharedSailingData, Clea
|
||||
if (markProperties == null) {
|
||||
throw new NullPointerException(String.format("Could not find mark properties with id %s", uuid.toString()));
|
||||
}
|
||||
getSecurityService().checkCurrentUserUpdatePermission(markProperties);
|
||||
apply(s -> internalUpdateMarkProperties(uuid, properties, position, deviceIdentifier, tags));
|
||||
if (markProperties != properties) { // no update required if same object
|
||||
getSecurityService().checkCurrentUserUpdatePermission(markProperties);
|
||||
apply(s -> internalUpdateMarkProperties(uuid, properties, position, deviceIdentifier, tags));
|
||||
}
|
||||
return getMarkPropertiesById(uuid);
|
||||
}
|
||||
|
||||
@@ -234,16 +236,18 @@ public class SharedSailingDataImpl implements ReplicatingSharedSailingData, Clea
|
||||
public Void internalUpdateMarkProperties(UUID idOfMarkProperties, CommonMarkProperties properties,
|
||||
Position position, DeviceIdentifier deviceIdentifier, Iterable<String> tags) {
|
||||
final MarkPropertiesImpl markProperties = (MarkPropertiesImpl) markPropertiesById.get(idOfMarkProperties);
|
||||
markProperties.setColor(properties.getColor());
|
||||
markProperties.setFixedPosition(position);
|
||||
markProperties.setPattern(properties.getPattern());
|
||||
markProperties.setShape(properties.getShape());
|
||||
markProperties.setShortName(properties.getShortName());
|
||||
markProperties.setTrackingDeviceIdentifier(deviceIdentifier);
|
||||
markProperties.setType(properties.getType());
|
||||
markProperties.setTags(tags);
|
||||
mongoObjectFactory.storeMarkProperties(deviceIdentifierServiceFinder, markProperties);
|
||||
markPropertiesById.put(idOfMarkProperties, markProperties);
|
||||
if (markProperties != properties) { // no update required if same object
|
||||
markProperties.setColor(properties.getColor());
|
||||
markProperties.setFixedPosition(position);
|
||||
markProperties.setPattern(properties.getPattern());
|
||||
markProperties.setShape(properties.getShape());
|
||||
markProperties.setShortName(properties.getShortName());
|
||||
markProperties.setTrackingDeviceIdentifier(deviceIdentifier);
|
||||
markProperties.setType(properties.getType());
|
||||
markProperties.setTags(tags);
|
||||
mongoObjectFactory.storeMarkProperties(deviceIdentifierServiceFinder, markProperties);
|
||||
markPropertiesById.put(idOfMarkProperties, markProperties);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user