Skip to content

Commit 7c1fec3

Browse files
committed
solves #190
In case entities are extended and the entity contains a property which is defined in a different file in a different Entity then an Exception will be thrown because of a missing implementation of IComparable. This was due to not having a comparator in BaseImpl.java
1 parent 332426f commit 7c1fec3

File tree

16 files changed

+777
-8
lines changed

16 files changed

+777
-8
lines changed

core/sds-aspect-meta-model-java/src/main/java/io/openmanufacturing/sds/metamodel/EntityInstance.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import java.util.Map;
1717

18-
public interface EntityInstance extends Base, IsDescribed, Value, Comparable<EntityInstance> {
18+
public interface EntityInstance extends Base, IsDescribed, Value {
1919
Map<Property, Value> getAssertions();
2020

2121
default Entity getEntityType() {

core/sds-aspect-meta-model-java/src/main/java/io/openmanufacturing/sds/metamodel/impl/BaseImpl.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
package io.openmanufacturing.sds.metamodel.impl;
1414

15+
import java.util.Comparator;
1516
import java.util.List;
1617
import java.util.Objects;
1718
import java.util.Optional;
@@ -27,7 +28,7 @@
2728
/**
2829
* The base implemenation of all model elements.
2930
*/
30-
public abstract class BaseImpl implements Base, IsDescribed {
31+
public abstract class BaseImpl implements Base, IsDescribed, Comparable<BaseImpl> {
3132
private final KnownVersion metaModelVersion;
3233
private final Optional<AspectModelUrn> urn;
3334
private final String name;
@@ -121,4 +122,15 @@ public boolean equals( final Object o ) {
121122
public int hashCode() {
122123
return Objects.hash( urn, name );
123124
}
125+
126+
@Override
127+
public int compareTo( BaseImpl o ) {
128+
if(this.urn.isPresent() && o.urn.isPresent())
129+
return this.urn.get().compareTo( o.urn.get() );
130+
return Comparator
131+
.comparing( BaseImpl::getMetaModelVersion )
132+
.thenComparing( BaseImpl::getName )
133+
.thenComparing( BaseImpl::hasSyntheticName )
134+
.compare( this, o );
135+
}
124136
}

core/sds-aspect-meta-model-java/src/main/java/io/openmanufacturing/sds/metamodel/impl/DefaultEntityInstance.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ public Map<Property, Value> getAssertions() {
4444
return assertions;
4545
}
4646

47-
@Override
48-
public int compareTo( final EntityInstance other ) {
49-
return getName().compareTo( other.getName() );
50-
}
51-
5247
@Override
5348
public <T, C> T accept( final AspectVisitor<T, C> visitor, final C context ) {
5449
return visitor.visitEntityInstance( this, context );

core/sds-aspect-model-java-generator/src/test/java/io/openmanufacturing/sds/aspectmodel/java/StaticMetaModelGeneratorTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import io.openmanufacturing.sds.test.MetaModelVersions;
2525
import io.openmanufacturing.sds.test.TestAspect;
2626
import io.openmanufacturing.sds.test.TestResources;
27+
import io.openmanufacturing.sds.test.TestSharedAspect;
28+
import io.openmanufacturing.sds.test.TestSharedModel;
2729

2830
abstract class StaticMetaModelGeneratorTest extends MetaModelVersions {
2931

@@ -41,4 +43,10 @@ Collection<JavaGenerator> getGenerators( final TestAspect aspect, final KnownVer
4143
final JavaGenerator staticGenerator = new StaticMetaModelJavaGenerator( model, false, null );
4244
return List.of( pojoGenerator, staticGenerator );
4345
}
46+
Collection<JavaGenerator> getGenerators( final TestSharedAspect aspect, final KnownVersion version ) {
47+
final VersionedModel model = TestResources.getModel( aspect, version ).get();
48+
final JavaGenerator pojoGenerator = new AspectModelJavaGenerator( model, false, false, null );
49+
final JavaGenerator staticGenerator = new StaticMetaModelJavaGenerator( model, false, null );
50+
return List.of( pojoGenerator, staticGenerator );
51+
}
4452
}

core/sds-aspect-model-urn/src/main/java/io/openmanufacturing/sds/aspectmodel/urn/AspectModelUrn.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* @see <a href="https://openmanufacturingplatform.github.io/sds-bamm-aspect-meta-model/bamm-specification/v1.0.0/namespaces.html">https://openmanufacturingplatform.github.io/sds-bamm-aspect-meta-model/bamm-specification/v1.0.0/namespaces.html</a>
3232
* for the definition of the URN.
3333
*/
34-
public class AspectModelUrn {
34+
public class AspectModelUrn implements Comparable<AspectModelUrn> {
3535
public static final String NAMESPACE_REGEX = "([a-zA-Z0-9()+,\\-.:=@;$_!*']|%[0-9a-fA-F]{2})+";
3636
public static final Pattern NAMESPACE_PATTERN = Pattern.compile( NAMESPACE_REGEX );
3737
public static final String MODEL_ELEMENT_NAME_REGEX = "\\p{Alpha}\\p{Alnum}*";
@@ -351,4 +351,9 @@ public boolean equals( final Object o ) {
351351
public int hashCode() {
352352
return Objects.hash( urn );
353353
}
354+
355+
@Override
356+
public int compareTo( AspectModelUrn o ) {
357+
return urn.compareTo( o.urn );
358+
}
354359
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package io.openmanufacturing.sds.test;
2+
3+
import org.apache.commons.text.CaseUtils;
4+
5+
public enum TestSharedAspect implements TestSharedModel {
6+
ASPECT_WITH_COLLECTION_ENTITY,
7+
ASPECT_WITH_CONSTRAINT_ENTITY,
8+
ASPECT_WITH_EITHER_ENTITY,
9+
ASPECT_WITH_EXTENDED_ENTITY;
10+
11+
@Override
12+
public String getName() {
13+
return CaseUtils.toCamelCase( toString().toLowerCase(), true, '_' );
14+
}
15+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.openmanufacturing.sds.test;
2+
3+
import java.io.StringWriter;
4+
5+
import org.apache.jena.rdf.model.Model;
6+
7+
import io.openmanufacturing.sds.aspectmodel.urn.AspectModelUrn;
8+
9+
public interface TestSharedModel {
10+
String TEST_NAMESPACE = "urn:bamm:io.openmanufacturing.test.shared:1.0.0#";
11+
String RESOURCE_PATH = "io.openmanufacturing.test.shared/1.0.0";
12+
String getName();
13+
14+
default AspectModelUrn getUrn() {
15+
return AspectModelUrn.fromUrn( TEST_NAMESPACE + getName() );
16+
}
17+
18+
static String modelToString( final Model model ) {
19+
final StringWriter stringWriter = new StringWriter();
20+
model.write( stringWriter, "TURTLE" );
21+
return stringWriter.toString();
22+
}
23+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright (c) 2022 Robert Bosch Manufacturing Solutions GmbH
2+
#
3+
# See the AUTHORS file(s) distributed with this work for additional
4+
# information regarding authorship.
5+
#
6+
# This Source Code Form is subject to the terms of the Mozilla Public
7+
# License, v. 2.0. If a copy of the MPL was not distributed with this
8+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
9+
#
10+
# SPDX-License-Identifier: MPL-2.0
11+
12+
@prefix : <urn:bamm:io.openmanufacturing.test.shared:1.0.0#> .
13+
@prefix bamm: <urn:bamm:io.openmanufacturing:meta-model:2.0.0#> .
14+
@prefix bamm-c: <urn:bamm:io.openmanufacturing:characteristic:2.0.0#> .
15+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
16+
@prefix unit: <urn:bamm:io.openmanufacturing:unit:2.0.0#> .
17+
18+
:AspectWithEntity a bamm:Aspect ;
19+
bamm:preferredName "Test Aspect"@en ;
20+
bamm:description "This is a test description"@en ;
21+
bamm:see <http://example.com/omp> ;
22+
bamm:properties ( :testProperty ) ;
23+
bamm:operations ( ) .
24+
25+
:testProperty a bamm:Property ;
26+
bamm:preferredName "Test Property"@en ;
27+
bamm:description "This is a test property."@en ;
28+
bamm:see <http://example.com/omp> ;
29+
bamm:see <http://example.com/me> ;
30+
bamm:characteristic :EntityCharacteristic .
31+
32+
:EntityCharacteristic a bamm-c:SingleEntity ;
33+
bamm:preferredName "Test Entity Characteristic"@en ;
34+
bamm:description "This is a test Entity Characteristic"@en ;
35+
bamm:see <http://example.com/omp> ;
36+
bamm:dataType :TestEntity .
37+
38+
:TestEntity a bamm:Entity ;
39+
bamm:extends :ParentTestEntity ;
40+
bamm:preferredName "Test Entity"@en ;
41+
bamm:description "This is a test entity"@en ;
42+
bamm:properties ( :entityProperty ) .
43+
44+
:entityProperty a bamm:Property ;
45+
bamm:preferredName "Entity Property"@en ;
46+
bamm:description "This is a property for the test entity."@en ;
47+
bamm:characteristic bamm-c:Text .
48+
49+
:ParentTestEntity
50+
a bamm:AbstractEntity ;
51+
bamm:name "ParentTestEntity" ;
52+
bamm:properties ( :testCollectionProperty ) .
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright (c) 2022 Robert Bosch Manufacturing Solutions GmbH
2+
#
3+
# See the AUTHORS file(s) distributed with this work for additional
4+
# information regarding authorship.
5+
#
6+
# This Source Code Form is subject to the terms of the Mozilla Public
7+
# License, v. 2.0. If a copy of the MPL was not distributed with this
8+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
9+
#
10+
# SPDX-License-Identifier: MPL-2.0
11+
12+
@prefix : <urn:bamm:io.openmanufacturing.test.shared:1.0.0#> .
13+
@prefix bamm: <urn:bamm:io.openmanufacturing:meta-model:2.0.0#> .
14+
@prefix bamm-c: <urn:bamm:io.openmanufacturing:characteristic:2.0.0#> .
15+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
16+
@prefix unit: <urn:bamm:io.openmanufacturing:unit:2.0.0#> .
17+
18+
:AspectWithEntity a bamm:Aspect ;
19+
bamm:preferredName "Test Aspect"@en ;
20+
bamm:description "This is a test description"@en ;
21+
bamm:see <http://example.com/omp> ;
22+
bamm:properties ( :testProperty ) ;
23+
bamm:operations ( ) .
24+
25+
:testProperty a bamm:Property ;
26+
bamm:preferredName "Test Property"@en ;
27+
bamm:description "This is a test property."@en ;
28+
bamm:see <http://example.com/omp> ;
29+
bamm:see <http://example.com/me> ;
30+
bamm:characteristic :EntityCharacteristic .
31+
32+
:EntityCharacteristic a bamm-c:SingleEntity ;
33+
bamm:preferredName "Test Entity Characteristic"@en ;
34+
bamm:description "This is a test Entity Characteristic"@en ;
35+
bamm:see <http://example.com/omp> ;
36+
bamm:dataType :TestEntity .
37+
38+
:TestEntity a bamm:Entity ;
39+
bamm:extends :ParentTestEntity ;
40+
bamm:preferredName "Test Entity"@en ;
41+
bamm:description "This is a test entity"@en ;
42+
bamm:properties ( :entityProperty ) .
43+
44+
:entityProperty a bamm:Property ;
45+
bamm:preferredName "Entity Property"@en ;
46+
bamm:description "This is a property for the test entity."@en ;
47+
bamm:characteristic bamm-c:Text .
48+
49+
:ParentTestEntity
50+
a bamm:AbstractEntity ;
51+
bamm:name "ParentTestEntity" ;
52+
bamm:properties ( :stringRegexcProperty ) .
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright (c) 2022 Robert Bosch Manufacturing Solutions GmbH
2+
#
3+
# See the AUTHORS file(s) distributed with this work for additional
4+
# information regarding authorship.
5+
#
6+
# This Source Code Form is subject to the terms of the Mozilla Public
7+
# License, v. 2.0. If a copy of the MPL was not distributed with this
8+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
9+
#
10+
# SPDX-License-Identifier: MPL-2.0
11+
12+
@prefix : <urn:bamm:io.openmanufacturing.test.shared:1.0.0#> .
13+
@prefix bamm: <urn:bamm:io.openmanufacturing:meta-model:2.0.0#> .
14+
@prefix bamm-c: <urn:bamm:io.openmanufacturing:characteristic:2.0.0#> .
15+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
16+
@prefix unit: <urn:bamm:io.openmanufacturing:unit:2.0.0#> .
17+
18+
:AspectWithEntity a bamm:Aspect ;
19+
bamm:preferredName "Test Aspect"@en ;
20+
bamm:description "This is a test description"@en ;
21+
bamm:see <http://example.com/omp> ;
22+
bamm:properties ( :testProperty ) ;
23+
bamm:operations ( ) .
24+
25+
:testProperty a bamm:Property ;
26+
bamm:preferredName "Test Property"@en ;
27+
bamm:description "This is a test property."@en ;
28+
bamm:see <http://example.com/omp> ;
29+
bamm:see <http://example.com/me> ;
30+
bamm:characteristic :EntityCharacteristic .
31+
32+
:EntityCharacteristic a bamm-c:SingleEntity ;
33+
bamm:preferredName "Test Entity Characteristic"@en ;
34+
bamm:description "This is a test Entity Characteristic"@en ;
35+
bamm:see <http://example.com/omp> ;
36+
bamm:dataType :TestEntity .
37+
38+
:TestEntity a bamm:Entity ;
39+
bamm:extends :ParentTestEntity ;
40+
bamm:preferredName "Test Entity"@en ;
41+
bamm:description "This is a test entity"@en ;
42+
bamm:properties ( :entityProperty ) .
43+
44+
:entityProperty a bamm:Property ;
45+
bamm:preferredName "Entity Property"@en ;
46+
bamm:description "This is a property for the test entity."@en ;
47+
bamm:characteristic bamm-c:Text .
48+
49+
:ParentTestEntity
50+
a bamm:AbstractEntity ;
51+
bamm:name "ParentTestEntity" ;
52+
bamm:properties ( :testPropertyWithEither ) .

0 commit comments

Comments
 (0)