Skip to content

Commit 2202c8c

Browse files
authored
Merge pull request #155 from bci-oss/90-remove-name-attribute
Remove bamm:name attribute
2 parents 14eee2a + 44662fd commit 2202c8c

File tree

280 files changed

+773
-1795
lines changed

Some content is hidden

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

280 files changed

+773
-1795
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import java.util.Collections;
1717
import java.util.List;
1818
import java.util.Locale;
19-
import java.util.Map;
2019
import java.util.Optional;
2120

2221
import io.openmanufacturing.sds.aspectmodel.urn.AspectModelUrn;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ private Statement getDataType( final Resource resource ) {
152152

153153
protected Optional<Unit> findOrCreateUnit( final Resource unitResource ) {
154154
if ( unit.getNamespace().equals( unitResource.getNameSpace() ) ) {
155-
return Units.fromName( unitResource.getProperty( bamm.name() ).getString(), metaModelVersion );
155+
final AspectModelUrn unitUrn = AspectModelUrn.fromUrn( unitResource.getURI() );
156+
return Units.fromName( unitUrn.getName(), metaModelVersion );
156157
}
157158

158159
return Optional.of( new DefaultUnit(

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

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@
2121
import java.util.Set;
2222
import java.util.UUID;
2323
import java.util.stream.Collectors;
24-
import java.util.stream.Stream;
2524

25+
import org.apache.commons.lang3.StringUtils;
2626
import org.apache.jena.rdf.model.Model;
2727
import org.apache.jena.rdf.model.RDFNode;
2828
import org.apache.jena.rdf.model.Resource;
29-
import org.apache.jena.rdf.model.Statement;
3029
import org.apache.jena.vocabulary.RDF;
3130

3231
import com.google.common.collect.ImmutableList;
@@ -159,32 +158,31 @@ public static MetaModelBaseAttributes fromMetaModelElement( final KnownVersion m
159158
final Set<LangString> preferredNames = getLanguages( metaModelElement, bamm.preferredName(), model );
160159
final Set<LangString> descriptions = getLanguages( metaModelElement, bamm.description(), model );
161160
final List<String> seeValues = getSeeValues( metaModelElement, model, bamm );
162-
final Optional<String> nameGivenInModel = Optional
163-
.ofNullable( model.getProperty( metaModelElement, bamm.name() ) )
164-
.map( Statement::getString );
165-
final Optional<String> nameFromUrn = urn.map( AspectModelUrn::getName );
166-
final Optional<String> actualName = Stream.of( nameGivenInModel, nameFromUrn )
167-
.filter( Optional::isPresent )
168-
.map( Optional::get )
169-
.findFirst();
170-
final String name = actualName.orElseGet( () -> getSyntheticName( metaModelElement, model ) );
161+
final Optional<String> actualName = urn.map( AspectModelUrn::getName );
162+
final String name = actualName.orElseGet( () -> getSyntheticName( metaModelElement, model, bamm ) );
171163
final boolean isSyntheticName = actualName.isEmpty();
172-
return new MetaModelBaseAttributes( metaModelVersion, urn.orElse( null ), name, preferredNames, descriptions,
173-
seeValues, isSyntheticName );
164+
return new MetaModelBaseAttributes( metaModelVersion, urn.orElse( null ), name, preferredNames, descriptions, seeValues, isSyntheticName );
174165
}
175166

176167
/**
177-
* Generates a synthetic name for a model element, when the model element is defined as an anonymous node and
178-
* has no bamm:name set. The synthetic name is a random string that prefixed with the type of the model element
179-
* if it can be determined easily. For example, for the following model element:
168+
* Generates a synthetic name for a model element, when the model element is defined as an anonymous node.
169+
* The synthetic name consists of the name of the first named parent element of the model element suffixed with the type of the model element if it can be
170+
* determined easily. For example, for the LengthConstraint in the following model:
180171
* <code>
181-
* [ a bamm-c:LengthConstraint; bamm-c:minValue 5 ]
172+
* :aProperty a bamm:Property ;
173+
* bamm:characteristic [
174+
* a bamm:Trait ;
175+
* bamm-c:baseCharacteristic ... ;
176+
* bamm-c:constraint [
177+
* a bamm-c:LengthConstraint; bamm-c:minValue 5
178+
* ]
179+
* ]
182180
* </code>
183-
* a synthetic name of "LengthConstraint12345ABC" would be generated (with the last part being a random string).
181+
* a synthetic name of "APropertyLengthConstraint" would be generated.
184182
*
185183
* @param modelElement a model element
186184
* @param model the containing model
187-
* @return a synthetic name for the model element, possibly prefixed with the model element's type name
185+
* @return a synthetic name for the model element, possibly suffixed with the model element's type name
188186
*/
189187
private static String getSyntheticName( final Resource modelElement, final Model model ) {
190188
final String randomPart = UUID.nameUUIDFromBytes( modelElement.getId().toString().getBytes() ).toString()
@@ -199,6 +197,29 @@ private static String getSyntheticName( final Resource modelElement, final Model
199197
.orElse( "" ) + randomPart;
200198
}
201199

200+
private static String getSyntheticName( final Resource modelElement, final Model model, final BAMM bamm ) {
201+
Resource parentModelElement = model.listStatements( null, null, modelElement ).next().getSubject();
202+
while ( parentModelElement.isAnon() ) {
203+
parentModelElement = model.listStatements( null, null, parentModelElement ).next().getSubject();
204+
}
205+
206+
final String parentModelElementUri = parentModelElement.getURI();
207+
final String parentModelElementName = metaModelResourceResolver.getAspectModelUrn( parentModelElementUri )
208+
.toJavaOptional()
209+
.map( AspectModelUrn::getName )
210+
.map( StringUtils::capitalize )
211+
.orElse( "" );
212+
213+
final Resource modelElementType = modelElement.getProperty( RDF.type ).getObject().asResource();
214+
final String modelElementTypeUri = modelElementType.getURI();
215+
final String modelElementTypeName = metaModelResourceResolver.getAspectModelUrn( modelElementTypeUri )
216+
.toJavaOptional()
217+
.map( AspectModelUrn::getName )
218+
.orElse( "" );
219+
220+
return parentModelElementName + modelElementTypeName;
221+
}
222+
202223
/**
203224
* @param subject the RDF {@link Resource} representing the Aspect Model element to be processed
204225
* @param property the RDF {@link org.apache.jena.rdf.model.Property} for which the values will be retrieved

core/sds-aspect-meta-model-java/src/test/java/io/openmanufacturing/sds/metamodel/loader/AspectMetaModelInstantiatorTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343

4444
public class AspectMetaModelInstantiatorTest extends MetaModelInstantiatorTest {
4545
@ParameterizedTest
46-
@EnumSource( value = TestAspect.class )
46+
@EnumSource( value = TestAspect.class, mode = EnumSource.Mode.EXCLUDE, names = {
47+
"ASPECT_WITH_TIME_SERIES" // This feature branch does not support bamm:AbstractProperty. When support for this is added, remove this
48+
} )
4749
public void testLoadAspectExpectSuccess( final TestAspect aspect ) {
4850
assertThatCode( () ->
4951
loadAspect( aspect, KnownVersion.getLatest() )

core/sds-aspect-meta-model-java/src/test/java/io/openmanufacturing/sds/metamodel/loader/CollectionInstantiatorTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import static org.assertj.core.api.Assertions.assertThat;
1717

1818
import org.apache.jena.vocabulary.XSD;
19+
import org.junit.jupiter.api.Disabled;
1920
import org.junit.jupiter.params.ParameterizedTest;
2021
import org.junit.jupiter.params.provider.MethodSource;
2122

@@ -139,6 +140,8 @@ public void testSortedSetCharacteristicInstantiationExpectSuccess( final KnownVe
139140

140141
@ParameterizedTest
141142
@MethodSource( value = "versionsStartingWith2_0_0" )
143+
/* This feature branch does not support bamm:AbstractProperty. When support for this is added, remove @Disabled */
144+
@Disabled
142145
public void testTimeSeriesInstantiationExpectSuccess( final KnownVersion metaModelVersion ) {
143146
final AspectModelUrn expectedAspectModelUrn = AspectModelUrn.fromUrn( TestModel.TEST_NAMESPACE + "TestTimeSeries" );
144147
final Aspect aspect = loadAspect( TestAspect.ASPECT_WITH_TIME_SERIES, metaModelVersion );

core/sds-aspect-meta-model-resolver/src/main/java/io/openmanufacturing/sds/aspectmodel/vocabulary/BAMM.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ public Property curie() {
5858
return property( "curie" );
5959
}
6060

61-
public Property name() {
62-
return property( "name" );
63-
}
64-
6561
public Property description() {
6662
return property( "description" );
6763
}

core/sds-aspect-meta-model-resolver/src/test/resources/bamm_2_0_0/invalid_aspect_meta_model_urn_element.ttl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
@prefix bamm: <urn:io.openmanufacturing:foo:1.0.0#> .
1313

1414
<urn:bamm:io.openmanufacturing:aspect-model:TestAspect:1.0.0> a bamm:Aspect ;
15-
bamm:name "TestAspect" ;
1615
bamm:preferredName "Test Aspect"@en ;
1716
bamm:properties ( ) ;
1817
bamm:operations ( ) .

core/sds-aspect-meta-model-resolver/src/test/resources/bamm_2_0_0/invalid_aspect_urn.ttl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
@prefix bamm: <urn:bamm:foo:something:else#> .
1313

1414
<urn:bamm:io.openmanufacturing:TestAspect:1.1.0> a bamm:Aspect;
15-
bamm:name "TestAspect" ;
1615
bamm:preferredName "Test Aspect"@en;
1716
bamm:properties () ;
1817
bamm:operations () .

core/sds-aspect-meta-model-resolver/src/test/resources/bamm_2_0_0/invalid_aspect_urn_prefix.ttl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
@prefix bamm: <urn:foo:io.openmanufacturing:meta-model:2.0.0#> .
1313

1414
<urn:bamm:io.openmanufacturing:aspect-model:TestAspect:1.1.0> a bamm:Aspect ;
15-
bamm:name "TestAspect" ;
1615
bamm:preferredName "Test Aspect"@en ;
1716
bamm:properties ( ) ;
1817
bamm:operations ( ) .

core/sds-aspect-meta-model-resolver/src/test/resources/bamm_2_0_0/invalid_multiple_aspects.ttl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@
1212
@prefix bamm: <urn:bamm:io.openmanufacturing:meta-model:2.0.0#> .
1313

1414
<urn:bamm:io.openmanufacturing:aspect-model:TestAspect:1.1.0> a bamm:Aspect ;
15-
bamm:name "TestAspect" ;
1615
bamm:preferredName "Test Aspect"@en ;
1716
bamm:properties ( ) ;
1817
bamm:operations ( ) .
1918

2019
<urn:bamm:io.openmanufacturing:aspect-model:AnotherTestAspect:1.1.0> a bamm:Aspect ;
21-
bamm:name "AnotherTestAspect" ;
2220
bamm:preferredName "Another Test Aspect"@en ;
2321
bamm:properties ( ) ;
2422
bamm:operations ( ) .

0 commit comments

Comments
 (0)