Skip to content

Commit b3d5b5c

Browse files
committed
Cycle detection via Java algorithm.
1 parent 3a9cdc6 commit b3d5b5c

File tree

6 files changed

+604
-6
lines changed

6 files changed

+604
-6
lines changed

core/sds-aspect-meta-model-java/src/main/java/io/openmanufacturing/sds/metamodel/loader/instantiator/PropertyInstantiator.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,16 @@ public Property apply( final Resource property ) {
6060
final boolean isAbstract = property.getModel().contains( property, RDF.type, bamm.AbstractProperty() );
6161

6262
final MetaModelBaseAttributes metaModelBaseAttributes = buildBaseAttributes( property );
63-
final DefaultPropertyWrapper defaultPropertyWrapper = new DefaultPropertyWrapper( metaModelBaseAttributes);
63+
final DefaultPropertyWrapper defaultPropertyWrapper = new DefaultPropertyWrapper( metaModelBaseAttributes );
6464

6565
if ( resourcePropertyMap.containsKey( property ) ) {
6666
final Property propertyInstance = resourcePropertyMap.get( property );
67-
resourcePropertyMap.remove( property );
6867
return propertyInstance;
6968
}
7069
resourcePropertyMap.put( property, defaultPropertyWrapper );
71-
DefaultProperty defProperty;
70+
final DefaultProperty defProperty;
7271
if ( isAbstract ) {
73-
defProperty = new DefaultProperty( metaModelBaseAttributes, Optional.of( fallbackCharacteristic), Optional.empty(), isOptional,
72+
defProperty = new DefaultProperty( metaModelBaseAttributes, Optional.of( fallbackCharacteristic ), Optional.empty(), isOptional,
7473
isNotInPayload, payloadName, isAbstract, extends_ );
7574
} else {
7675
final Resource characteristicResource = attributeValue( property, bamm.characteristic() ).getResource();
@@ -91,7 +90,7 @@ public Property apply( final Resource property ) {
9190
return new DefaultScalarValue( value, type );
9291
} ) );
9392

94-
defProperty = new DefaultProperty( metaModelBaseAttributes, Optional.of( characteristic), exampleValue, isOptional,
93+
defProperty = new DefaultProperty( metaModelBaseAttributes, Optional.of( characteristic ), exampleValue, isOptional,
9594
isNotInPayload, payloadName, isAbstract, extends_ );
9695
}
9796
defaultPropertyWrapper.setProperty( defProperty );

core/sds-test-aspect-models/src/main/java/io/openmanufacturing/sds/test/TestAspect.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,10 @@ public enum TestAspect implements TestModel {
182182
ENTITY_INSTANCE_TEST3,
183183
ENTITY_INSTANCE_TEST4,
184184
ASPECT_WITH_ENUM_ONLY_ONE_SEE,
185-
MOVEMENT;
185+
MOVEMENT,
186+
187+
MODEL_WITH_CYCLES,
188+
MODEL_WITH_BROKEN_CYCLES;
186189

187190
@Override
188191
public String getName() {
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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:1.0.0#> .
13+
@prefix bamm: <urn:bamm:io.openmanufacturing:meta-model:1.0.0#> .
14+
@prefix bamm-c: <urn:bamm:io.openmanufacturing:characteristic:1.0.0#> .
15+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
16+
17+
:ModelWithBrokenCycles a bamm:Aspect ;
18+
bamm:name "" ;
19+
bamm:properties ( :a :e :h ) ;
20+
bamm:operations ( ) .
21+
22+
#############################################################
23+
# direct cycle between two properties broken by bamm:optional
24+
#############################################################
25+
26+
:a a bamm:Property;
27+
bamm:name "a" ;
28+
bamm:characteristic :aCharacteristic.
29+
30+
:aCharacteristic a bamm:Characteristic;
31+
bamm:name "aCharacteristic" ;
32+
bamm:dataType :AEntity.
33+
34+
:AEntity a bamm:Entity;
35+
bamm:name "AEntity" ;
36+
bamm:properties ( :b ) .
37+
38+
:b a bamm:Property;
39+
bamm:name "b" ;
40+
bamm:characteristic :bCharacteristic.
41+
42+
:bCharacteristic a bamm:Characteristic;
43+
bamm:name "bCharacteristic" ;
44+
bamm:dataType :BEntity.
45+
46+
:BEntity a bamm:Entity;
47+
bamm:name "BEntity" ;
48+
bamm:properties ( [ bamm:property :a ; bamm:optional true ; ] ) .
49+
50+
#####################################################################
51+
# indirect cycle via an intermediate property broken by bamm:optional
52+
#####################################################################
53+
54+
:e a bamm:Property;
55+
bamm:name "e" ;
56+
bamm:characteristic :eCharacteristic.
57+
58+
:eCharacteristic a bamm:Characteristic;
59+
bamm:name "eCharacteristic" ;
60+
bamm:dataType :EEntity.
61+
62+
:EEntity a bamm:Entity;
63+
bamm:name "EEntity" ;
64+
bamm:properties ( :f ) .
65+
66+
:f a bamm:Property;
67+
bamm:name "f" ;
68+
bamm:characteristic :fCharacteristic.
69+
70+
:fCharacteristic a bamm:Characteristic;
71+
bamm:name "fCharacteristic" ;
72+
bamm:dataType :FEntity.
73+
74+
:FEntity a bamm:Entity;
75+
bamm:name "FEntity" ;
76+
bamm:properties ( :g ) .
77+
78+
:g a bamm:Property;
79+
bamm:name "g" ;
80+
bamm:characteristic :gCharacteristic.
81+
82+
:gCharacteristic a bamm:Characteristic;
83+
bamm:name "gCharacteristic" ;
84+
bamm:dataType :GEntity.
85+
86+
:GEntity a bamm:Entity;
87+
bamm:name "GEntity" ;
88+
bamm:properties ( [ bamm:property :e ; bamm:optional true ; ] ) .
89+
90+
########################################################
91+
# cycle but only in one of the branches of bamm-c:Either
92+
########################################################
93+
:h a bamm:Property;
94+
bamm:name "h" ;
95+
bamm:characteristic :hCharacteristic.
96+
97+
:hCharacteristic a bamm-c:Either;
98+
bamm:name "hCharacteristic" ;
99+
bamm-c:left :leftCharacteristic ;
100+
bamm-c:right :rightCharacteristic.
101+
102+
:leftCharacteristic a bamm:Characteristic;
103+
bamm:name "leftCharacteristic" ;
104+
bamm:dataType :LeftEntity.
105+
106+
:rightCharacteristic a bamm:Characteristic;
107+
bamm:name "rightCharacteristic" ;
108+
bamm:dataType :RightEntity.
109+
110+
:LeftEntity a bamm:Entity;
111+
bamm:name "LeftEntity" ;
112+
bamm:properties ( :h ) . # direct cycle
113+
114+
:RightEntity a bamm:Entity;
115+
bamm:name "RightEntity" ;
116+
bamm:properties ( :i ) . # no cycle
117+
118+
:i a bamm:Property;
119+
bamm:name "i" ;
120+
bamm:characteristic :iCharacteristic.
121+
122+
:iCharacteristic a bamm:Characteristic;
123+
bamm:name "iCharacteristic" ;
124+
bamm:dataType xsd:string.
125+
126+
#############################################################
127+
# a cycle, but the properties are not referenced by an Aspect
128+
#############################################################
129+
:j a bamm:Property;
130+
bamm:name "j" ;
131+
bamm:characteristic :jCharacteristic.
132+
133+
:jCharacteristic a bamm:Characteristic;
134+
bamm:name "jCharacteristic" ;
135+
bamm:dataType :JEntity.
136+
137+
:JEntity a bamm:Entity;
138+
bamm:name "JEntity" ;
139+
bamm:properties ( :k ) .
140+
141+
:k a bamm:Property;
142+
bamm:name "k" ;
143+
bamm:characteristic :kCharacteristic.
144+
145+
:kCharacteristic a bamm:Characteristic;
146+
bamm:name "kCharacteristic" ;
147+
bamm:dataType :KEntity.
148+
149+
:KEntity a bamm:Entity;
150+
bamm:name "KEntity" ;
151+
bamm:properties ( :j ) .
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
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:1.0.0#> .
13+
@prefix bamm: <urn:bamm:io.openmanufacturing:meta-model:1.0.0#> .
14+
@prefix bamm-c: <urn:bamm:io.openmanufacturing:characteristic:1.0.0#> .
15+
@prefix bamm-e: <urn:bamm:io.openmanufacturing:entity:1.0.0#> .
16+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
17+
18+
:ModelWithCycles a bamm:Aspect ;
19+
bamm:name "ModelWithCycles" ;
20+
bamm:properties ( :a :e :h :l :n ) ;
21+
bamm:operations ( ) .
22+
23+
#####################################
24+
# direct cycle between two properties
25+
#####################################
26+
:a a bamm:Property;
27+
bamm:name "a" ;
28+
bamm:characteristic :aCharacteristic.
29+
30+
:aCharacteristic a bamm:Characteristic;
31+
bamm:name "aCharacteristic" ;
32+
bamm:dataType :AEntity.
33+
34+
:AEntity a bamm:Entity;
35+
bamm:name "AEntity" ;
36+
bamm:properties ( :b ) .
37+
38+
:b a bamm:Property;
39+
bamm:name "b" ;
40+
bamm:characteristic :bCharacteristic.
41+
42+
:bCharacteristic a bamm:Characteristic;
43+
bamm:name "bCharacteristic" ;
44+
bamm:dataType :BEntity.
45+
46+
:BEntity a bamm:Entity;
47+
bamm:name "BEntity" ;
48+
bamm:properties ( :a ) .
49+
50+
#############################################
51+
# indirect cycle via an intermediate property
52+
#############################################
53+
:e a bamm:Property;
54+
bamm:name "e" ;
55+
bamm:characteristic :eCharacteristic.
56+
57+
:eCharacteristic a bamm:Characteristic;
58+
bamm:name "eCharacteristic" ;
59+
bamm:dataType :EEntity.
60+
61+
:EEntity a bamm:Entity;
62+
bamm:name "EEntity" ;
63+
bamm:properties ( :f ) .
64+
65+
:f a bamm:Property;
66+
bamm:name "f" ;
67+
bamm:characteristic :fCharacteristic.
68+
69+
:fCharacteristic a bamm:Characteristic;
70+
bamm:name "fCharacteristic" ;
71+
bamm:dataType :FEntity.
72+
73+
:FEntity a bamm:Entity;
74+
bamm:name "FEntity" ;
75+
bamm:properties ( :g ) .
76+
77+
:g a bamm:Property;
78+
bamm:name "g" ;
79+
bamm:characteristic :gCharacteristic.
80+
81+
:gCharacteristic a bamm:Characteristic;
82+
bamm:name "gCharacteristic" ;
83+
bamm:dataType :GEntity.
84+
85+
:GEntity a bamm:Entity;
86+
bamm:name "GEntity" ;
87+
bamm:properties ( :e ) .
88+
89+
##############################################
90+
# cycle via both branches of bamm-c:Either
91+
##############################################
92+
:h a bamm:Property;
93+
bamm:name "h" ;
94+
bamm:characteristic :hCharacteristic.
95+
96+
:hCharacteristic a bamm-c:Either;
97+
bamm:name "hCharacteristic" ;
98+
bamm-c:left :leftCharacteristic ;
99+
bamm-c:right :rightCharacteristic.
100+
101+
:leftCharacteristic a bamm:Characteristic;
102+
bamm:name "leftCharacteristic" ;
103+
bamm:dataType :LeftEntity.
104+
105+
:rightCharacteristic a bamm:Characteristic;
106+
bamm:name "rightCharacteristic" ;
107+
bamm:dataType :RightEntity.
108+
109+
:LeftEntity a bamm:Entity;
110+
bamm:name "LeftEntity" ;
111+
bamm:properties ( :h ) . # direct cycle
112+
113+
:RightEntity a bamm:Entity;
114+
bamm:name "RightEntity" ;
115+
bamm:properties ( :i ) . # cycle via an intermediary property
116+
117+
:i a bamm:Property;
118+
bamm:name "i" ;
119+
bamm:characteristic :iCharacteristic.
120+
121+
:iCharacteristic a bamm:Characteristic;
122+
bamm:name "iCharacteristic" ;
123+
bamm:dataType :IEntity.
124+
125+
:IEntity a bamm:Entity;
126+
bamm:name "IEntity" ;
127+
bamm:properties ( :h ) .
128+
129+
#############################################
130+
# cycle via bamm-c:baseCharacteristic
131+
#############################################
132+
:l a bamm:Property;
133+
bamm:name "l" ;
134+
bamm:characteristic :lCharacteristic .
135+
136+
:lCharacteristic a bamm-c:Trait;
137+
bamm:name "lCharacteristic" ;
138+
bamm-c:baseCharacteristic :MEntityList ;
139+
bamm-c:constraint [
140+
a bamm-c:LengthConstraint ;
141+
bamm-c:maxValue "10"^^xsd:nonNegativeInteger ;
142+
] .
143+
144+
:MEntityList a bamm-c:List ;
145+
bamm:name "MEntityList" ;
146+
bamm:dataType :MEntity .
147+
148+
:MEntity a bamm:Entity;
149+
bamm:name "MEntity" ;
150+
bamm:properties ( :l ) .
151+
152+
####################################################
153+
# cycle via bamm-e:TimeSeriesEntity and bamm:extends
154+
####################################################
155+
:n a bamm:Property ;
156+
bamm:name "n" ;
157+
bamm:characteristic :NTimeSeries .
158+
159+
:NTimeSeries a bamm-c:TimeSeries ;
160+
bamm:name "NTimeSeries" ;
161+
bamm:dataType :NTimeSeriesEntity .
162+
163+
:NTimeSeriesEntity a bamm:Entity ;
164+
bamm:name "NTimeSeriesEntity" ;
165+
bamm:extends bamm-e:TimeSeriesEntity ;
166+
bamm:properties ( [ bamm:extends bamm-e:value ; bamm:characteristic :oCharacteristic ] ) .
167+
168+
:oCharacteristic a bamm:Characteristic;
169+
bamm:name "mCharacteristic" ;
170+
bamm:dataType :OEntity.
171+
172+
:OEntity a bamm:Entity;
173+
bamm:name "MEntity" ;
174+
bamm:properties ( :n ) .
175+
176+
177+
178+
179+
180+

0 commit comments

Comments
 (0)