Skip to content

Commit 87acaf6

Browse files
committed
Fix code expecting invalid samm-c:OPEN in models
1 parent 1a749ed commit 87acaf6

File tree

6 files changed

+76
-53
lines changed

6 files changed

+76
-53
lines changed

core/esmf-aspect-model-document-generators/src/main/resources/diagram/samm_1_0_0/constraint2boxmodel.sparql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,22 @@ construct {
218218
bind( "AT_MOST" as ?upperBoundDefinitionValue )
219219
}
220220

221+
# no lowerBoundDefinition exists (RangeConstraint)
222+
optional {
223+
?constraint a samm-c:RangeConstraint .
224+
filter( not exists { ?constraint samm-c:minValue [] } )
225+
filter( not exists { ?constraint samm-c:lowerBoundDefinition [] } )
226+
bind( "OPEN" as ?lowerBoundDefinitionValue )
227+
}
228+
229+
# no upperBoundDefinition exists (RangeConstraint)
230+
optional {
231+
?constraint a samm-c:RangeConstraint .
232+
filter( not exists { ?constraint samm-c:maxValue [] } )
233+
filter( not exists { ?constraint samm-c:upperBoundDefinition [] } )
234+
bind( "OPEN" as ?upperBoundDefinitionValue )
235+
}
236+
221237
# scale and integer (FixedPoint Constraint)
222238
optional {
223239
?constraint a samm-c:FixedPointConstraint .

core/esmf-aspect-model-document-generators/src/main/resources/diagram/samm_2_0_0/constraint2boxmodel.sparql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,22 @@ construct {
188188
bind( "AT_MOST" as ?upperBoundDefinitionValue )
189189
}
190190

191+
# no lowerBoundDefinition exists (RangeConstraint)
192+
optional {
193+
?constraint a samm-c:RangeConstraint .
194+
filter( not exists { ?constraint samm-c:minValue [] } )
195+
filter( not exists { ?constraint samm-c:lowerBoundDefinition [] } )
196+
bind( "OPEN" as ?lowerBoundDefinitionValue )
197+
}
198+
199+
# no upperBoundDefinition exists (RangeConstraint)
200+
optional {
201+
?constraint a samm-c:RangeConstraint .
202+
filter( not exists { ?constraint samm-c:maxValue [] } )
203+
filter( not exists { ?constraint samm-c:upperBoundDefinition [] } )
204+
bind( "OPEN" as ?upperBoundDefinitionValue )
205+
}
206+
191207
# scale and integer (FixedPoint Constraint)
192208
optional {
193209
?constraint a samm-c:FixedPointConstraint .

core/esmf-aspect-model-document-generators/src/test/java/org/eclipse/esmf/aspectmodel/generator/diagram/RangeConstraint2BoxModelTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ sparqlQueryFileName, boxSelectorStatement( metaModelVersion, constraintIdentifie
5858
@ParameterizedTest
5959
@MethodSource( value = "allVersions" )
6060
public void testRangeConstraintWithOnlyMinValue( final KnownVersion metaModelVersion ) {
61-
final String constraintIdentifier = "RangeConstraint45aa6b0";
61+
final String constraintIdentifier = "RangeConstraint65abcea";
6262
final TestContext context = new TestContext( TestAspect.ASPECT_WITH_RANGE_CONSTRAINT_WITH_ONLY_MIN_VALUE, metaModelVersion );
6363
context.executeAttributeIsPresentTest( sparqlQueryFileName, boxSelectorStatement( metaModelVersion, constraintIdentifier, true ),
6464
entriesSelectorStatement( metaModelVersion, constraintIdentifier, true ), totalNumberOfExpectedEntriesPerMetaModelVersion.get( metaModelVersion ),

core/esmf-aspect-model-serializer/src/main/java/org/eclipse/esmf/aspectmodel/serializer/RdfModelCreatorVisitor.java

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -37,58 +37,58 @@
3737
import org.apache.jena.rdf.model.Statement;
3838
import org.apache.jena.vocabulary.RDF;
3939
import org.apache.jena.vocabulary.XSD;
40-
import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn;
41-
42-
import org.eclipse.esmf.aspectmodel.vocabulary.SAMM;
43-
import org.eclipse.esmf.samm.KnownVersion;
4440
import org.eclipse.esmf.aspectmodel.resolver.exceptions.InvalidModelException;
4541
import org.eclipse.esmf.aspectmodel.resolver.services.DataType;
4642
import org.eclipse.esmf.aspectmodel.resolver.services.ExtendedXsdDataType;
43+
import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn;
44+
import org.eclipse.esmf.aspectmodel.vocabulary.Namespace;
45+
import org.eclipse.esmf.aspectmodel.vocabulary.SAMM;
4746
import org.eclipse.esmf.aspectmodel.vocabulary.SAMMC;
4847
import org.eclipse.esmf.aspectmodel.vocabulary.SAMME;
49-
import org.eclipse.esmf.aspectmodel.vocabulary.Namespace;
5048
import org.eclipse.esmf.aspectmodel.vocabulary.UNIT;
49+
import org.eclipse.esmf.characteristic.Code;
50+
import org.eclipse.esmf.characteristic.Collection;
51+
import org.eclipse.esmf.characteristic.Duration;
52+
import org.eclipse.esmf.characteristic.Either;
53+
import org.eclipse.esmf.characteristic.Enumeration;
54+
import org.eclipse.esmf.characteristic.Measurement;
55+
import org.eclipse.esmf.characteristic.Quantifiable;
56+
import org.eclipse.esmf.characteristic.Set;
57+
import org.eclipse.esmf.characteristic.SingleEntity;
58+
import org.eclipse.esmf.characteristic.SortedSet;
59+
import org.eclipse.esmf.characteristic.State;
60+
import org.eclipse.esmf.characteristic.StructuredValue;
61+
import org.eclipse.esmf.characteristic.TimeSeries;
62+
import org.eclipse.esmf.characteristic.Trait;
63+
import org.eclipse.esmf.constraint.EncodingConstraint;
64+
import org.eclipse.esmf.constraint.FixedPointConstraint;
65+
import org.eclipse.esmf.constraint.LanguageConstraint;
66+
import org.eclipse.esmf.constraint.LengthConstraint;
67+
import org.eclipse.esmf.constraint.LocaleConstraint;
68+
import org.eclipse.esmf.constraint.RangeConstraint;
69+
import org.eclipse.esmf.constraint.RegularExpressionConstraint;
5170
import org.eclipse.esmf.metamodel.AbstractEntity;
5271
import org.eclipse.esmf.metamodel.Aspect;
53-
import org.eclipse.esmf.metamodel.ModelElement;
5472
import org.eclipse.esmf.metamodel.Characteristic;
55-
import org.eclipse.esmf.characteristic.Code;
56-
import org.eclipse.esmf.characteristic.Collection;
5773
import org.eclipse.esmf.metamodel.CollectionValue;
5874
import org.eclipse.esmf.metamodel.ComplexType;
5975
import org.eclipse.esmf.metamodel.Constraint;
60-
import org.eclipse.esmf.characteristic.Duration;
61-
import org.eclipse.esmf.characteristic.Either;
62-
import org.eclipse.esmf.constraint.EncodingConstraint;
6376
import org.eclipse.esmf.metamodel.EntityInstance;
64-
import org.eclipse.esmf.characteristic.Enumeration;
6577
import org.eclipse.esmf.metamodel.Event;
66-
import org.eclipse.esmf.constraint.FixedPointConstraint;
6778
import org.eclipse.esmf.metamodel.HasProperties;
79+
import org.eclipse.esmf.metamodel.ModelElement;
6880
import org.eclipse.esmf.metamodel.NamedElement;
69-
import org.eclipse.esmf.constraint.LanguageConstraint;
70-
import org.eclipse.esmf.constraint.LengthConstraint;
71-
import org.eclipse.esmf.constraint.LocaleConstraint;
72-
import org.eclipse.esmf.characteristic.Measurement;
7381
import org.eclipse.esmf.metamodel.Operation;
7482
import org.eclipse.esmf.metamodel.Property;
75-
import org.eclipse.esmf.characteristic.Quantifiable;
7683
import org.eclipse.esmf.metamodel.QuantityKind;
77-
import org.eclipse.esmf.constraint.RangeConstraint;
78-
import org.eclipse.esmf.constraint.RegularExpressionConstraint;
7984
import org.eclipse.esmf.metamodel.Scalar;
8085
import org.eclipse.esmf.metamodel.ScalarValue;
81-
import org.eclipse.esmf.characteristic.Set;
82-
import org.eclipse.esmf.characteristic.SingleEntity;
83-
import org.eclipse.esmf.characteristic.SortedSet;
84-
import org.eclipse.esmf.characteristic.State;
85-
import org.eclipse.esmf.characteristic.StructuredValue;
86-
import org.eclipse.esmf.characteristic.TimeSeries;
87-
import org.eclipse.esmf.characteristic.Trait;
8886
import org.eclipse.esmf.metamodel.Type;
8987
import org.eclipse.esmf.metamodel.Unit;
9088
import org.eclipse.esmf.metamodel.datatypes.LangString;
89+
import org.eclipse.esmf.metamodel.impl.BoundDefinition;
9190
import org.eclipse.esmf.metamodel.visitor.AspectVisitor;
91+
import org.eclipse.esmf.samm.KnownVersion;
9292

9393
/**
9494
* AspectVisitor that translates an {@link Aspect} into the corresponding {@link Model}.
@@ -175,7 +175,8 @@ private Model serializeDescriptions( final Resource elementResource, final Named
175175

176176
@SuppressWarnings( "squid:S2250" )
177177
// Amount of elements in list is regarding amount of properties in Aspect Model. Even in bigger aspects this should not lead to performance issues
178-
private Model serializePropertiesOrParameters( final Resource elementResource, final HasProperties element, final org.apache.jena.rdf.model.Property theProperty ) {
178+
private Model serializePropertiesOrParameters( final Resource elementResource, final HasProperties element,
179+
final org.apache.jena.rdf.model.Property theProperty ) {
179180
final Model model = ModelFactory.createDefaultModel();
180181
final List<RDFNode> propertiesList = new ArrayList<>();
181182
if ( resourceList.contains( elementResource ) ) {
@@ -388,10 +389,14 @@ public ElementModel visitRangeConstraint( final RangeConstraint rangeConstraint,
388389
.flatMap( maxValue -> maxValue.accept( this, rangeConstraint ).getFocusElement().stream() )
389390
.map( literal -> createStatement( resource, sammc.maxValue(), literal ) )
390391
.forEach( model::add );
391-
model.add( resource, sammc.lowerBoundDefinition(),
392-
sammc.resource( rangeConstraint.getLowerBoundDefinition().toString().replace( " ", "_" ).toUpperCase() ) );
393-
model.add( resource, sammc.upperBoundDefinition(),
394-
sammc.resource( rangeConstraint.getUpperBoundDefinition().toString().replace( " ", "_" ).toUpperCase() ) );
392+
if ( rangeConstraint.getLowerBoundDefinition() != BoundDefinition.OPEN ) {
393+
model.add( resource, sammc.lowerBoundDefinition(),
394+
sammc.resource( rangeConstraint.getLowerBoundDefinition().toString().replace( " ", "_" ).toUpperCase() ) );
395+
}
396+
if ( rangeConstraint.getUpperBoundDefinition() != BoundDefinition.OPEN ) {
397+
model.add( resource, sammc.upperBoundDefinition(),
398+
sammc.resource( rangeConstraint.getUpperBoundDefinition().toString().replace( " ", "_" ).toUpperCase() ) );
399+
}
395400
return new ElementModel( model, Optional.of( resource ) );
396401
}
397402

core/esmf-aspect-model-serializer/src/test/java/org/eclipse/esmf/aspectmodel/serializer/RdfModelCreatorVisitorTest.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,17 @@
2222

2323
import org.apache.jena.rdf.model.Model;
2424
import org.eclipse.esmf.aspectmodel.resolver.services.VersionedModel;
25-
import org.junit.jupiter.params.ParameterizedTest;
26-
import org.junit.jupiter.params.provider.EnumSource;
27-
28-
import org.eclipse.esmf.samm.KnownVersion;
29-
3025
import org.eclipse.esmf.aspectmodel.vocabulary.Namespace;
3126
import org.eclipse.esmf.metamodel.Aspect;
3227
import org.eclipse.esmf.metamodel.loader.AspectModelLoader;
28+
import org.eclipse.esmf.samm.KnownVersion;
3329
import org.eclipse.esmf.test.MetaModelVersions;
3430
import org.eclipse.esmf.test.TestAspect;
3531
import org.eclipse.esmf.test.TestModel;
3632
import org.eclipse.esmf.test.TestResources;
33+
import org.junit.jupiter.params.ParameterizedTest;
34+
import org.junit.jupiter.params.provider.EnumSource;
35+
3736
import io.vavr.control.Try;
3837

3938
public class RdfModelCreatorVisitorTest extends MetaModelVersions {
@@ -64,11 +63,8 @@ public class RdfModelCreatorVisitorTest extends MetaModelVersions {
6463
"MODEL_WITH_BROKEN_CYCLES",
6564
"MODEL_WITH_BLANK_AND_ADDITIONAL_NODES"
6665
} )
67-
public void testRdfModelCreatorVisitor( final TestAspect aspect ) {
68-
testRdfCreation( aspect, KnownVersion.getLatest() );
69-
}
70-
71-
private void testRdfCreation( final TestAspect testAspect, final KnownVersion knownVersion ) {
66+
public void testRdfModelCreatorVisitor( final TestAspect testAspect ) {
67+
final KnownVersion knownVersion = KnownVersion.getLatest();
7268
final VersionedModel versionedModel = TestResources.getModel( testAspect, knownVersion ).get();
7369

7470
final Try<Aspect> tryAspect = AspectModelLoader.getSingleAspect( versionedModel );

core/esmf-aspect-model-validator/src/test/java/org/eclipse/esmf/aspectmodel/validation/services/AspectModelValidatorTest.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,9 @@ public void testValidAspect( final KnownVersion metaModelVersion ) {
6565

6666
@ParameterizedTest
6767
@EnumSource( value = TestAspect.class, mode = EnumSource.Mode.EXCLUDE, names = {
68-
"ASPECT_WITH_CONSTRAINTS",
69-
// uses samm-c:OPEN which is not specified, see https://github.com/eclipse-esmf/esmf-semantic-aspect-meta-model/issues/174
7068
"ASPECT_WITH_FIXED_POINT",
7169
"ASPECT_WITH_FIXED_POINT_CONSTRAINT",
7270
"ASPECT_WITH_LANGUAGE_CONSTRAINT",
73-
"ASPECT_WITH_RANGE_CONSTRAINT_ON_CONSTRAINED_NUMERIC_TYPE", // uses samm-c:OPEN
74-
"ASPECT_WITH_RANGE_CONSTRAINT_WITHOUT_MIN_MAX_DOUBLE_VALUE", // uses samm-c:OPEN
75-
"ASPECT_WITH_RANGE_CONSTRAINT_WITHOUT_MIN_MAX_INTEGER_VALUE", // uses samm-c:OPEN
76-
"ASPECT_WITH_RANGE_CONSTRAINT_WITH_ONLY_LOWER_BOUND", // uses samm-c:OPEN
77-
"ASPECT_WITH_RANGE_CONSTRAINT_WITH_ONLY_LOWER_BOUND_INCL_BOUND_DEFINITION", // uses samm-c:OPEN
78-
"ASPECT_WITH_RANGE_CONSTRAINT_WITH_ONLY_MIN_VALUE", // uses samm-c:OPEN
79-
"ASPECT_WITH_RANGE_CONSTRAINT_WITH_ONLY_UPPER_BOUND", // uses samm-c:OPEN
80-
"ASPECT_WITH_RANGE_CONSTRAINT_WITH_ONLY_UPPER_BOUND_INCL_BOUND_DEFINITION", // uses samm-c:OPEN
8171
"MODEL_WITH_CYCLES",
8272
"MODEL_WITH_BROKEN_CYCLES"// contains cycles
8373
} )

0 commit comments

Comments
 (0)