Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Robert Bosch Manufacturing Solutions GmbH
* Copyright (c) 2025 Robert Bosch Manufacturing Solutions GmbH
*
* See the AUTHORS file(s) distributed with this work for additional
* information regarding authorship.
Expand All @@ -17,6 +17,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.JarURLConnection;
import java.net.URI;
import java.nio.file.Path;
import java.util.ArrayDeque;
Expand All @@ -25,6 +26,7 @@
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -121,7 +123,7 @@ public AspectModelLoader( final ResolutionStrategy resolutionStrategy ) {
*/
public AspectModelLoader( final List<ResolutionStrategy> resolutionStrategies ) {
TurtleLoader.init();
if ( resolutionStrategies.size() == 1 ) {
if ( 1 == resolutionStrategies.size() ) {
resolutionStrategy = resolutionStrategies.get( 0 );
} else if ( resolutionStrategies.isEmpty() ) {
resolutionStrategy = DEFAULT_STRATEGY.get();
Expand Down Expand Up @@ -416,7 +418,7 @@ public AspectModel loadNamespacePackage( final byte[] binaryContent, final URI l
* {@code https://example.com/package.zip}, the files in the package will have a location URI such as
* {@code jar:file:/some/path/package.zip!/com.example.namespace/1.0.0/AspectModel.ttl} or
* {@code jar:https://example.com/package.zip!/com.example.namespace/1.0.0/AspectModel.ttl}, respectively, as described in
* the JavaDoc for {@link java.net.JarURLConnection}.
* the JavaDoc for {@link JarURLConnection}.
*
* @param location the source location
* @param inputStream the input stream to load the ZIP content from
Expand Down Expand Up @@ -453,7 +455,7 @@ private record LoaderContext(
Deque<AspectModelFile> unresolvedFiles
) {
private LoaderContext() {
this( new HashSet<>(), new HashSet<>(), new HashSet<>(), new ArrayDeque<>(), new ArrayDeque<>() );
this( new HashSet<>(), new LinkedHashSet<>(), new HashSet<>(), new ArrayDeque<>(), new ArrayDeque<>() );
}
}

Expand All @@ -473,7 +475,8 @@ private String replaceLegacyBammUrn( final String urn ) {
private boolean containsType( final Model model, final String urn ) {
if ( model.contains( model.createResource( urn ), RDF.type, (RDFNode) null ) ) {
return true;
} else if ( urn.startsWith( AspectModelUrn.PROTOCOL_AND_NAMESPACE_PREFIX ) ) {
}
if ( urn.startsWith( AspectModelUrn.PROTOCOL_AND_NAMESPACE_PREFIX ) ) {
// when deriving a URN from file (via "fileToUrn" method - mainly in samm-cli scenarios),
// we assume new "samm" format, but could actually have been the old "bamm"
return model.contains( model.createResource( toLegacyBammUrn( urn ) ), RDF.type, (RDFNode) null );
Expand All @@ -495,7 +498,7 @@ private Optional<AspectModelFile> applyResolutionStrategy( final String urn ) {

try {
final AspectModelUrn aspectModelUrn = AspectModelUrn.fromUrn( replaceLegacyBammUrn( urn ) );
if ( aspectModelUrn.getElementType() != ElementType.NONE ) {
if ( ElementType.NONE != aspectModelUrn.getElementType() ) {
return Optional.empty();
}
final AspectModelFile resolutionResult = resolutionStrategy.apply( aspectModelUrn, this );
Expand Down Expand Up @@ -674,7 +677,7 @@ public AspectModel loadAspectModelFiles( final Collection<AspectModelFile> input
.findFirst()
.ifPresent( aspect -> mergedModel.setNsPrefix( "", aspect.urn().getUrnPrefix() ) );
for ( final AspectModelFile file : files ) {
if ( file.aspects().size() > 1 ) {
if ( 1 < file.aspects().size() ) {
throw new AspectLoadingException(
"Aspect Model file " + file.humanReadableLocation() + " contains " + file.aspects().size()
+ " aspects, but may only contain one." );
Expand Down Expand Up @@ -709,7 +712,7 @@ private void setNamespaces( final Collection<AspectModelFile> files, final Colle
MetaModelBaseAttributes namespaceDefinition = null;
AspectModelFile fileContainingNamespaceDefinition = null;
final List<ModelElement> elementsForUrn = elementsGroupedByNamespaceUrn.get( namespaceUrn );
if ( elementsForUrn != null ) {
if ( null != elementsForUrn ) {
for ( final ModelElement element : elementsForUrn ) {
final AspectModelFile elementFile = element.getSourceFile();
if ( elementFile.sourceModel().contains( null, RDF.type, SammNs.SAMM.Namespace() ) ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Robert Bosch Manufacturing Solutions GmbH
* Copyright (c) 2025 Robert Bosch Manufacturing Solutions GmbH
*
* See the AUTHORS file(s) distributed with this work for additional
* information regarding authorship.
Expand All @@ -20,6 +20,7 @@
import java.net.URI;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand All @@ -34,16 +35,19 @@
import org.eclipse.esmf.metamodel.ComplexType;
import org.eclipse.esmf.metamodel.ModelElement;
import org.eclipse.esmf.test.InvalidTestAspect;
import org.eclipse.esmf.test.OrderingTestAspect;
import org.eclipse.esmf.test.TestAspect;
import org.eclipse.esmf.test.TestResources;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

class AspectModelLoaderTest {
@ParameterizedTest
@EnumSource( value = TestAspect.class )
@EnumSource( TestAspect.class )
void testLoadAspectModelsSourceFilesArePresent( final TestAspect testAspect ) {
final AspectModel aspectModel = TestResources.load( testAspect );
for ( final ModelElement element : aspectModel.elements() ) {
Expand Down Expand Up @@ -90,11 +94,11 @@ void testOfAbstractEntityCyclomaticCreation() {
assertThat( entities ).extracting( "AbstractTestEntity" ).isInstanceOf( AbstractEntity.class );
final AbstractEntity abstractEntity = (AbstractEntity) entities.get( "AbstractTestEntity" );
assertThat( entities ).extracting( "testEntityOne" ).isInstanceOfSatisfying( ComplexType.class, type -> {
org.assertj.core.api.Assertions.assertThat( type ).extracting( ComplexType::getExtends ).extracting( Optional::get )
Assertions.assertThat( type ).extracting( ComplexType::getExtends ).extracting( Optional::get )
.isSameAs( abstractEntity );
} );
assertThat( entities ).extracting( "testEntityTwo" ).isInstanceOfSatisfying( ComplexType.class, type ->
org.assertj.core.api.Assertions.assertThat( type ).extracting( ComplexType::getExtends ).extracting( Optional::get )
Assertions.assertThat( type ).extracting( ComplexType::getExtends ).extracting( Optional::get )
.isSameAs( abstractEntity ) );
}

Expand Down Expand Up @@ -129,4 +133,15 @@ void testLoadMultipleFilesWithOverlappingRdfStatements() {
assertThat( exception ).hasMessageContaining( "Duplicate definition" );
} );
}

@RepeatedTest( 10 )
void testAspectUploadOrdering() {
final OrderingTestAspect aspectName = OrderingTestAspect.ASPECT;
final AspectModel aspectModel = TestResources.load( aspectName );
assertThat( aspectModel ).aspects()
.filteredOn( aspect -> Objects.equals( aspectName.getName(), aspect.getName() ) )
.first()
.satisfies(
aspect -> assertThat( aspect.urn().toString() ).isEqualTo( "urn:samm:org.eclipse.esmf.test.ordering:1.0.0#Aspect" ) );
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Robert Bosch Manufacturing Solutions GmbH
* Copyright (c) 2025 Robert Bosch Manufacturing Solutions GmbH
*
* See the AUTHORS file(s) distributed with this work for additional
* information regarding authorship.
Expand Down Expand Up @@ -41,6 +41,14 @@ public static AspectModel load( final TestModel model ) {
return new AspectModelLoader( testModelsResolutionStrategy ).load( inputStream, URI.create( "testmodel:" + path ) );
}

public static AspectModel load( final OrderingTestAspect model ) {
final String path = String.format( "valid/%s/%s/%s.ttl", model.getUrn().getNamespaceMainPart(), model.getUrn().getVersion(),
model.getName() );
final InputStream inputStream = TestResources.class.getClassLoader().getResourceAsStream( path );
final ResolutionStrategy testModelsResolutionStrategy = new ClasspathStrategy( "valid" );
return new AspectModelLoader( testModelsResolutionStrategy ).load( inputStream, URI.create( "testmodel:" + path ) );
}

public static AspectModel load( final InvalidTestAspect model ) {
final KnownVersion metaModelVersion = KnownVersion.getLatest();
final String path = String.format( "invalid/%s/%s/%s.ttl", model.getUrn().getNamespaceMainPart(), model.getUrn().getVersion(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2025 Robert Bosch Manufacturing Solutions GmbH
*
* See the AUTHORS file(s) distributed with this work for additional
* information regarding authorship.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SPDX-License-Identifier: MPL-2.0
*/

package org.eclipse.esmf.test;

import org.apache.commons.text.CaseUtils;

public enum OrderingTestAspect implements TestOrderingModel {
ASPECT;

@Override
public String getName() {
return CaseUtils.toCamelCase( toString().toLowerCase(), true, '_' );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2025 Robert Bosch Manufacturing Solutions GmbH
*
* See the AUTHORS file(s) distributed with this work for additional
* information regarding authorship.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SPDX-License-Identifier: MPL-2.0
*/

package org.eclipse.esmf.test;

import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn;

public interface TestOrderingModel extends TestModel {
String TEST_NAMESPACE = "urn:samm:org.eclipse.esmf.test.ordering:1.0.0#";

@Override
default AspectModelUrn getUrn() {
return AspectModelUrn.fromUrn( TEST_NAMESPACE + getName() );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (c) 2025 Robert Bosch Manufacturing Solutions GmbH
#
# See the AUTHORS file(s) distributed with this work for additional
# information regarding authorship.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0

@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.2.0#> .
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.2.0#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

@prefix : <urn:samm:org.eclipse.esmf.test.ordering.dependency:1.0.0#> .

:Aspect a samm:Aspect ;
samm:description "Test dependency aspect "@en ;
samm:properties ( :test ) ;
samm:operations ( ) ;
samm:events ( ) .

:test a samm:Property ;
samm:name "test property" ;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this line, "samm:name" was removed in SAMM 2.0.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, my initial thought when I started investigating this issue was to fix this part of the code: AbstractInputHandler#expectedAspectName(). However, I encountered a problem. When we talk about expectedAspectName as a short name, it’s easy to compare it with the aspect name because our implementation has enough information for this type of name:

AspectModelUrnInputHandler → urn.getName()
GitHubUrlInputHandler → Extract the name from the URL
FileInputHandler → Extract the name from the file name
The problem arises when we try to compare it with the URN:

AspectModelUrnInputHandler → We already have the URN
GitHubUrlInputHandler → We can create the URN from the URL
FileInputHandler → In this case, we don’t have enough information about the URN, and we need to extract it from inside the file, if I’m not mistaken
That’s why I tried to decrease the chances of reproducing this issue by adding an order to the file upload process.

I will now try to enrich the context for FileInputHandler with the URN.

samm:characteristic :TestCharacteristic .

:TestCharacteristic a samm:Characteristic ;
samm:preferredName "Test Characteristic"@en ;
samm:dataType xsd:short .
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (c) 2025 Robert Bosch Manufacturing Solutions GmbH
#
# See the AUTHORS file(s) distributed with this work for additional
# information regarding authorship.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0

@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.2.0#> .
@prefix ref: <urn:samm:org.eclipse.esmf.test.ordering.dependency:1.0.0#> .

@prefix : <urn:samm:org.eclipse.esmf.test.ordering:1.0.0#> .

:Aspect a samm:Aspect ;
samm:preferredName "Test Aspect"@en ;
samm:description "This is a test description"@en ;
samm:properties (
ref:test
) ;
samm:operations ( ) .