Skip to content

Commit ec24c50

Browse files
authored
Merge pull request #703 from bci-oss/702-add-fluent-builder
Add fluent builder API and custom AssertJ assertions
2 parents 937c862 + 5012464 commit ec24c50

File tree

77 files changed

+6437
-500
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+6437
-500
lines changed

core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/metamodel/Aspect.java

+10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
package org.eclipse.esmf.metamodel;
1515

1616
import java.util.List;
17+
import java.util.Optional;
18+
19+
import org.eclipse.esmf.metamodel.characteristic.Collection;
1720

1821
/**
1922
* An Aspect encapsulates a number of properties and operations that define one functional facet of a Digital Twin.
@@ -31,4 +34,11 @@ public interface Aspect extends StructureElement {
3134
* @since SAMM 2.0.0
3235
*/
3336
List<Event> getEvents();
37+
38+
default boolean isCollectionAspect() {
39+
return getProperties().stream()
40+
.map( Property::getCharacteristic )
41+
.flatMap( Optional::stream )
42+
.filter( Collection.class::isInstance ).count() == 1;
43+
}
3444
}

core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/metamodel/ComplexType.java

+20-4
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717
import java.util.Collections;
1818
import java.util.List;
1919
import java.util.Optional;
20-
import java.util.stream.Collectors;
20+
import java.util.function.Function;
2121
import java.util.stream.Stream;
2222

2323
/**
2424
* Defines the data type of a {@link Characteristic} as being a complex value.
2525
*/
2626
public interface ComplexType extends Type, StructureElement {
27-
2827
/**
2928
* @return a {@link java.util.List} of {@link ComplexType}s which extend this Entity
3029
*/
@@ -41,12 +40,18 @@ default boolean isAbstractEntity() {
4140
*/
4241
default List<Property> getAllProperties() {
4342
if ( getExtends().isPresent() ) {
44-
return Stream.of( getProperties(), getExtends().get().getAllProperties() ).flatMap( Collection::stream )
45-
.collect( Collectors.toList() );
43+
return Stream.of( getProperties(), getExtends().get().getAllProperties() ).flatMap( Collection::stream ).toList();
4644
}
4745
return List.copyOf( getProperties() );
4846
}
4947

48+
default List<ComplexType> getAllSuperTypes() {
49+
if ( getExtends().isPresent() ) {
50+
return Stream.of( getExtends().stream(), getExtends().get().getAllSuperTypes().stream() ).flatMap( Function.identity() ).toList();
51+
}
52+
return List.of();
53+
}
54+
5055
@Override
5156
default String getUrn() {
5257
return urn().toString();
@@ -63,4 +68,15 @@ default Optional<ComplexType> getExtends() {
6368
default boolean isComplexType() {
6469
return true;
6570
}
71+
72+
@Override
73+
default boolean isTypeOrSubtypeOf( final Type other ) {
74+
if ( equals( other ) ) {
75+
return true;
76+
}
77+
if ( !other.isComplexType() ) {
78+
return false;
79+
}
80+
return ( (ComplexType) other ).getAllSuperTypes().contains( this );
81+
}
6682
}

core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/metamodel/Scalar.java

+70
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313

1414
package org.eclipse.esmf.metamodel;
1515

16+
import java.util.Map;
17+
18+
import org.eclipse.esmf.metamodel.vocabulary.SammNs;
19+
20+
import com.google.common.collect.ImmutableList;
21+
import com.google.common.collect.ImmutableMap;
22+
import org.apache.jena.vocabulary.RDF;
23+
import org.apache.jena.vocabulary.XSD;
24+
1625
/**
1726
* Defines the data type of a {@link Characteristic} as being a scalar value.
1827
*/
@@ -21,4 +30,65 @@ public interface Scalar extends Type {
2130
default boolean isScalar() {
2231
return true;
2332
}
33+
34+
private boolean transitivelyCastable( final String from, final String to ) {
35+
if ( from.equals( to ) ) {
36+
return true;
37+
}
38+
final Map<String, String> castable = ImmutableMap.<String, String> builder()
39+
.put( XSD.xbyte.getURI(), XSD.xshort.getURI() )
40+
.put( XSD.xshort.getURI(), XSD.xint.getURI() )
41+
.put( XSD.xint.getURI(), XSD.xlong.getURI() )
42+
.put( XSD.xlong.getURI(), XSD.integer.getURI() )
43+
.put( XSD.integer.getURI(), XSD.decimal.getURI() )
44+
.put( XSD.unsignedByte.getURI(), XSD.unsignedShort.getURI() )
45+
.put( XSD.unsignedShort.getURI(), XSD.unsignedInt.getURI() )
46+
.put( XSD.unsignedInt.getURI(), XSD.unsignedLong.getURI() )
47+
.put( XSD.unsignedLong.getURI(), XSD.nonNegativeInteger.getURI() )
48+
.put( XSD.positiveInteger.getURI(), XSD.nonNegativeInteger.getURI() )
49+
.put( XSD.nonNegativeInteger.getURI(), XSD.integer.getURI() )
50+
.put( XSD.negativeInteger.getURI(), XSD.nonPositiveInteger.getURI() )
51+
.put( XSD.nonPositiveInteger.getURI(), XSD.integer.getURI() )
52+
.put( XSD.dateTimeStamp.getURI(), XSD.dateTime.getURI() )
53+
.put( XSD.yearMonthDuration.getURI(), XSD.duration.getURI() )
54+
.put( XSD.dayTimeDuration.getURI(), XSD.duration.getURI() )
55+
.build();
56+
57+
final String entry = castable.get( from );
58+
if ( entry == null ) {
59+
return false;
60+
} else if ( entry.equals( to ) ) {
61+
return true;
62+
}
63+
return transitivelyCastable( entry, to );
64+
}
65+
66+
@Override
67+
default boolean isTypeOrSubtypeOf( final Type other ) {
68+
return transitivelyCastable( getUrn(), other.getUrn() );
69+
}
70+
71+
default boolean hasStringLikeValueSpace() {
72+
return ImmutableList.<String> builder()
73+
.add( XSD.xstring.getURI() )
74+
.add( XSD.date.getURI() )
75+
.add( XSD.time.getURI() )
76+
.add( XSD.dateTime.getURI() )
77+
.add( XSD.dateTimeStamp.getURI() )
78+
.add( XSD.gYear.getURI() )
79+
.add( XSD.gMonth.getURI() )
80+
.add( XSD.gDay.getURI() )
81+
.add( XSD.gYearMonth.getURI() )
82+
.add( XSD.gMonthDay.getURI() )
83+
.add( XSD.duration.getURI() )
84+
.add( XSD.yearMonthDuration.getURI() )
85+
.add( XSD.dayTimeDuration.getURI() )
86+
.add( XSD.hexBinary.getURI() )
87+
.add( XSD.base64Binary.getURI() )
88+
.add( XSD.anyURI.getURI() )
89+
.add( SammNs.SAMM.curie().getURI() )
90+
.add( RDF.langString.getURI() )
91+
.build()
92+
.contains( getUrn() );
93+
}
2494
}

core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/metamodel/Type.java

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ default boolean isScalar() {
2929
default boolean isComplexType() {
3030
return false;
3131
}
32+
33+
boolean isTypeOrSubtypeOf( Type other );
3234
}
3335

3436

core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/metamodel/characteristic/Collection.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,26 @@
2424
* @since SAMM 1.0.0
2525
*/
2626
public interface Collection extends Characteristic {
27-
2827
/**
2928
* @return a {@link boolean} which determines whether the elements in the collection are ordered.
3029
*/
3130
boolean isOrdered();
3231

32+
/**
33+
* @deprecated Use {@link #allowsDuplicates()} instead
34+
*/
35+
@Deprecated( forRemoval = true )
36+
default boolean isAllowDuplicates() {
37+
return allowsDuplicates();
38+
}
39+
3340
/**
3441
* @return a {@link boolean} which determines whether the collection may contain duplicate values.
3542
*/
36-
boolean isAllowDuplicates();
43+
boolean allowsDuplicates();
3744

3845
/**
3946
* @return {@link Optional} containing the {@link Characteristic} describing the elements of the Collection
40-
*
4147
* @since SAMM 1.0.0
4248
*/
4349
default Optional<Characteristic> getElementCharacteristic() {

core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/metamodel/characteristic/StructuredValue.java

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.List;
1717

1818
import org.eclipse.esmf.metamodel.Characteristic;
19+
import org.eclipse.esmf.metamodel.Property;
1920

2021
/**
2122
* @since SAMM 1.0.0

core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/metamodel/constraint/RangeConstraint.java

+6-8
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,27 @@
2828
public interface RangeConstraint extends Constraint {
2929

3030
/**
31-
* @return the lower bound of the range. The type of the values is determined by the {@link Type} returned by
32-
* {@link RangeConstraint#getDataType()}.
31+
* @return the lower bound of the range. The type of the values is determined by the {@link Type} of the Trait that the Constraint
32+
* is used with.
3333
*/
3434
Optional<ScalarValue> getMinValue();
3535

3636
/**
37-
* @return the upper bound of the range. The type of the values is determined by the {@link Type} returned by
38-
* {@link RangeConstraint#getDataType()}.
37+
* @return the upper bound of the range. The type of the values is determined by the {@link Type} of the Trait that the Constraint
38+
* is used with.
3939
*/
4040
Optional<ScalarValue> getMaxValue();
4141

4242
/**
4343
* @return the definition of how the lower bound of the range is to be interpreted. Possible values are
44-
* 'OPEN', 'AT_LEAST' and 'GREATER_THAN'
45-
*
44+
* 'OPEN', 'AT_LEAST' and 'GREATER_THAN'
4645
* @since SAMM 1.0.0
4746
*/
4847
BoundDefinition getLowerBoundDefinition();
4948

5049
/**
5150
* @return the definition of how the upper bound of the range is to be interpreted. Possible values are
52-
* 'OPEN', 'AT_MOST' and 'LESS_THAN'
53-
*
51+
* 'OPEN', 'AT_MOST' and 'LESS_THAN'
5452
* @since SAMM 1.0.0
5553
*/
5654
BoundDefinition getUpperBoundDefinition();

core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/metamodel/datatype/SammXsdType.java

+4
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ private SammXsdType( final Resource dataTypeResource, final XSSimpleType xstype,
245245
value -> URI.create( (String) XSDDatatype.XSDanyURI.parse( value ) ),
246246
URI::toString, XSDDatatype.XSDanyURI::isValid );
247247

248+
@SuppressWarnings( "checkstyle:LambdaParameterName" )
249+
public static final SammXsdType<String> STRING = new SammXsdType<>(
250+
org.apache.jena.vocabulary.XSD.xstring, String.class, Function.identity(), Function.identity(), __ -> true );
251+
248252
public static final List<RDFDatatype> ALL_TYPES = List
249253
.of( XSDDatatype.XSDstring, BOOLEAN, DECIMAL, INTEGER, DOUBLE, FLOAT, DATE, TIME, DATE_TIME, DATE_TIME_STAMP,
250254
G_YEAR, G_MONTH, G_YEAR_MONTH, G_DAY, G_MONTH_DAY, DURATION, YEAR_MONTH_DURATION, DAY_TIME_DURATION,

core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/metamodel/vocabulary/RdfNamespace.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ default Resource resource( final String name ) {
5353
static Map<String, String> createPrefixMap( final KnownVersion metaModelVersion ) {
5454
final Map<String, String> result = new LinkedHashMap<>();
5555
final SAMM samm = new SAMM( metaModelVersion );
56-
result.put( "samm", samm.getNamespace() );
57-
result.put( "samm-c", new SAMMC( metaModelVersion ).getNamespace() );
56+
result.put( samm.getShortForm(), samm.getNamespace() );
57+
final SAMMC sammc = new SAMMC( metaModelVersion );
58+
result.put( sammc.getShortForm(), sammc.getNamespace() );
5859
result.put( "samm-e", new SAMME( metaModelVersion, samm ).getNamespace() );
59-
result.put( "unit", new UNIT( metaModelVersion, samm ).getNamespace() );
60+
final UNIT unit = new UNIT( metaModelVersion, samm );
61+
result.put( unit.getShortForm(), unit.getNamespace() );
6062
result.put( "rdf", RDF.getURI() );
6163
result.put( "rdfs", RDFS.getURI() );
6264
result.put( "xsd", XSD.getURI() );
@@ -65,10 +67,10 @@ static Map<String, String> createPrefixMap( final KnownVersion metaModelVersion
6567

6668
static Map<String, String> createPrefixMap() {
6769
final Map<String, String> result = new LinkedHashMap<>();
68-
result.put( "samm", SammNs.SAMM.getNamespace() );
69-
result.put( "samm-c", SammNs.SAMMC.getNamespace() );
70-
result.put( "samm-e", SammNs.SAMME.getNamespace() );
71-
result.put( "unit", SammNs.UNIT.getNamespace() );
70+
result.put( SammNs.SAMM.getShortForm(), SammNs.SAMM.getNamespace() );
71+
result.put( SammNs.SAMMC.getShortForm(), SammNs.SAMMC.getNamespace() );
72+
result.put( SammNs.SAMME.getShortForm(), SammNs.SAMME.getNamespace() );
73+
result.put( SammNs.UNIT.getShortForm(), SammNs.UNIT.getNamespace() );
7274
result.put( "rdf", RDF.getURI() );
7375
result.put( "rdfs", RDFS.getURI() );
7476
result.put( "xsd", XSD.getURI() );

core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/metamodel/vocabulary/SAMM.java

+3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
*/
1313
package org.eclipse.esmf.metamodel.vocabulary;
1414

15+
import java.util.List;
16+
1517
import org.eclipse.esmf.samm.KnownVersion;
1618

19+
import com.google.common.collect.ImmutableList;
1720
import org.apache.jena.rdf.model.Property;
1821
import org.apache.jena.rdf.model.Resource;
1922

core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/metamodel/vocabulary/SAMME.java

+16-3
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,21 @@ public Resource TimeSeriesEntity() {
4848
}
4949

5050
@SuppressWarnings( "checkstyle:MethodName" )
51-
public Resource ThreeDimensionalPosition() {
52-
return resource( "ThreeDimensionalPosition" );
51+
public Resource Point3d() {
52+
return resource( "Point3d" );
53+
}
54+
55+
@SuppressWarnings( "checkstyle:MethodName" )
56+
public Resource FileResource() {
57+
return resource( "FileResource" );
58+
}
59+
60+
public Property resource() {
61+
return property( "resource" );
62+
}
63+
64+
public Property mimeType() {
65+
return property( "mimeType" );
5366
}
5467

5568
public Property timestamp() {
@@ -76,6 +89,6 @@ public Property z() {
7689
}
7790

7891
public Stream<Resource> allEntities() {
79-
return Stream.of( TimeSeriesEntity(), ThreeDimensionalPosition() );
92+
return Stream.of( TimeSeriesEntity(), Point3d() );
8093
}
8194
}

core/esmf-aspect-meta-model-java/pom.xml

+11-4
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@
170170
<configuration>
171171
<compileSourceRoots>${build-time-sources}</compileSourceRoots>
172172
<generatedSourcesDirectory>${generated-sources}</generatedSourcesDirectory>
173+
<excludes>
174+
<exclude>**/buildtime/template/*.java</exclude>
175+
</excludes>
173176
</configuration>
174177
</execution>
175178
</executions>
@@ -180,15 +183,19 @@
180183
<artifactId>exec-maven-plugin</artifactId>
181184
<executions>
182185
<execution>
183-
<id>generate-units-and-quantitykinds</id>
186+
<id>generate-sources</id>
184187
<phase>process-sources</phase>
185188
<goals>
186189
<goal>java</goal>
187190
</goals>
188191
<configuration>
189-
<mainClass>org.eclipse.esmf.buildtime.GenerateUnitsTtl</mainClass>
190-
<!-- args[0]: Path to src-gen directory -->
191-
<commandlineArgs>${generated-sources}</commandlineArgs>
192+
<mainClass>org.eclipse.esmf.buildtime.GenerateBuildtimeCode</mainClass>
193+
<arguments>
194+
<!-- args[0]: Path to src-gen directory -->
195+
<argument>${generated-sources}</argument>
196+
<!-- args[1]: Path to src-buildtime directory -->
197+
<argument>${build-time-sources}</argument>
198+
</arguments>
192199
</configuration>
193200
</execution>
194201
</executions>

0 commit comments

Comments
 (0)