Skip to content

Correctly return the source file for ScalarValue objects #727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
Expand Up @@ -164,10 +164,9 @@ protected Value buildValue( final RDFNode node, final Optional<Resource> charact
}

if ( node.isResource() ) {
Resource resource = node.asResource();

final Resource resource = node.asResource();
if ( resource.hasProperty( RDF.type, SammNs.SAMM.Value() ) ) {
Optional<String> valueOpt = optionalAttributeValue( resource, SammNs.SAMM.value() ).map( Statement::getString );
final Optional<String> valueOpt = optionalAttributeValue( resource, SammNs.SAMM.value() ).map( Statement::getString );

if ( valueOpt.isEmpty() ) {
throw new AspectLoadingException( "samm:Value must contain a samm:value property" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.apache.jena.rdf.model.Resource;

public class ScalarValueInstantiator extends Instantiator<ScalarValue> {

public ScalarValueInstantiator( final ModelElementFactory modelElementFactory ) {
super( modelElementFactory, ScalarValue.class );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,9 @@ public Set<LangString> getDescriptions() {
return metaModelBaseAttributes.getDescriptions();
}

/**
* Similar to {@link DefaultScalar#getSourceFile()}, scalar values are not defined in Aspect Model files, so this returns null.
*
* @return null
*/
@Override
public AspectModelFile getSourceFile() {
return null;
return metaModelBaseAttributes.getSourceFile();
}

@Override
Expand All @@ -90,7 +85,7 @@ public int compareTo( final ScalarValue other ) {

@SuppressWarnings( "unchecked" )
private <T extends Comparable<T>> int compareTo( final Object value1, final Object value2 ) {
return ((T) value1).compareTo( (T) value2 );
return ( (T) value1 ).compareTo( (T) value2 );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.esmf.metamodel.AbstractEntity;
import org.eclipse.esmf.metamodel.AspectModel;
import org.eclipse.esmf.metamodel.ComplexType;
import org.eclipse.esmf.metamodel.ModelElement;
import org.eclipse.esmf.metamodel.vocabulary.SammNs;
import org.eclipse.esmf.test.InvalidTestAspect;
import org.eclipse.esmf.test.TestAspect;
Expand All @@ -38,8 +39,23 @@
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.Statement;
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 )
void testLoadAspectModelsSourceFilesArePresent( final TestAspect testAspect ) {
final AspectModel aspectModel = TestResources.load( testAspect );
for ( final ModelElement element : aspectModel.elements() ) {
assertThat( element.getSourceFile() )
.describedAs( "Element %s has no source file", element ).isNotNull();
assertThat( element.getSourceFile() )
.describedAs( "Source file %s must contain defintion for %s", element.getSourceFile(), element.urn() )
.elements().contains( element );
}
}

@Test
void loadAspectModelWithoutCharacteristicDatatype() {
assertThatThrownBy( () -> TestResources.load( InvalidTestAspect.INVALID_CHARACTERISTIC_DATATYPE ) )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.util.function.BiFunction;
import java.util.function.Supplier;
import java.util.stream.Stream;

import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.Duration;
import javax.xml.datatype.XMLGregorianCalendar;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;

import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;

Expand Down
Loading