Skip to content

Commit 68f6b01

Browse files
committed
Remove deprecated code
1 parent 8586298 commit 68f6b01

File tree

13 files changed

+39
-963
lines changed

13 files changed

+39
-963
lines changed

core/esmf-aspect-meta-model-java/buildSrc/main/groovy/CreateLegacyMetaModel.groovy

Lines changed: 0 additions & 275 deletions
This file was deleted.

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/metamodel/loader/AspectModelLoader.java

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -72,23 +72,6 @@ public class AspectModelLoader {
7272
private AspectModelLoader() {
7373
}
7474

75-
/**
76-
* Creates an {@link Aspect} instance from a Turtle input model.
77-
*
78-
* @param versionedModel The RDF model representation of the Aspect model
79-
* @return A {@link Try} containing the {@link Aspect} on success and an {@link InvalidRootElementCountException}
80-
* (when the Aspect model does not contain exactly one Aspect) or {@link InvalidVersionException}
81-
* (when the meta model version is not supported by the Aspect loader) on failure
82-
* @deprecated Use {@link #getSingleAspect(VersionedModel)} instead to retain the same semantics, but better use {@link #getElements(VersionedModel)}
83-
* instead to also properly handle models that contain not exactly one Aspect
84-
*
85-
* @see AspectModelResolver
86-
*/
87-
@Deprecated( forRemoval = true )
88-
public static Try<Aspect> fromVersionedModel( final VersionedModel versionedModel ) {
89-
return getSingleAspect( versionedModel );
90-
}
91-
9275
private static void validateNamespaceOfCustomUnits( final SAMM samm, final Model rawModel ) {
9376
final List<String> customUnitsWithSammNamespace = new ArrayList<>();
9477
rawModel.listStatements( null, RDF.type, samm.Unit() )
@@ -104,23 +87,6 @@ private static void validateNamespaceOfCustomUnits( final SAMM samm, final Model
10487
}
10588
}
10689

107-
/**
108-
* Creates an {@link Aspect} instance from a Turtle input model.
109-
*
110-
* @param versionedModel The RDF model representation of the Aspect model
111-
* @return The Aspect
112-
* @deprecated use {@link #getSingleAspectUnchecked(VersionedModel)} instead to retain the same semantics, but better use
113-
* {@link #getElementsUnchecked(VersionedModel)} instead to also properly handle models that contain not exactly one Aspect
114-
* @see #fromVersionedModel(VersionedModel)
115-
*/
116-
@Deprecated( forRemoval = true )
117-
public static Aspect fromVersionedModelUnchecked( final VersionedModel versionedModel ) {
118-
return fromVersionedModel( versionedModel ).getOrElseThrow( cause -> {
119-
LOG.error( "Could not load Aspect", cause );
120-
throw new AspectLoadingException( cause );
121-
} );
122-
}
123-
12490
/**
12591
* Loads elements from an RDF model that possibly contains multiple namespaces, and organize the result into a
12692
* collection of {@link ModelNamespace}. Use this method only when you expect the RDF model to contain more than

core/esmf-aspect-model-validator/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@
3232
<groupId>org.apache.jena</groupId>
3333
<artifactId>jena-core</artifactId>
3434
</dependency>
35-
<dependency>
36-
<groupId>org.topbraid</groupId>
37-
<artifactId>shacl</artifactId>
38-
</dependency>
3935
<dependency>
4036
<groupId>org.eclipse.esmf</groupId>
4137
<artifactId>esmf-semantic-aspect-meta-model</artifactId>

core/esmf-aspect-model-validator/src/main/java/org/eclipse/esmf/aspectmodel/shacl/constraint/SparqlConstraint.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,16 @@
2828
import org.apache.jena.rdf.model.Model;
2929
import org.apache.jena.rdf.model.RDFNode;
3030
import org.apache.jena.sparql.core.Var;
31+
import org.apache.jena.sparql.expr.Expr;
32+
import org.apache.jena.sparql.expr.ExprTransform;
33+
import org.apache.jena.sparql.expr.ExprTransformer;
34+
import org.apache.jena.sparql.syntax.syntaxtransform.ElementTransform;
35+
import org.apache.jena.sparql.syntax.syntaxtransform.ElementTransformSubst;
36+
import org.apache.jena.sparql.syntax.syntaxtransform.ExprTransformNodeElement;
37+
import org.apache.jena.sparql.syntax.syntaxtransform.QueryTransformOps;
3138
import org.eclipse.esmf.aspectmodel.shacl.violation.EvaluationContext;
3239
import org.eclipse.esmf.aspectmodel.shacl.violation.SparqlConstraintViolation;
3340
import org.eclipse.esmf.aspectmodel.shacl.violation.Violation;
34-
import org.topbraid.jenax.util.JenaUtil;
3541

3642
/**
3743
* Implements <a href="https://www.w3.org/TR/shacl/#sparql-constraints">sh:sparql</a>
@@ -43,7 +49,7 @@ public record SparqlConstraint(String message, Query query) implements Constrain
4349
public List<Violation> apply( final RDFNode rdfNode, final EvaluationContext context ) {
4450
final Model model = context.element().getModel();
4551
final Map<Var, Node> substitutions = Map.of( Var.alloc( "this" ), context.element().asNode() );
46-
final Query query1 = JenaUtil.queryWithSubstitutions( query, substitutions );
52+
final Query query1 = substituteVariablesInQuery( query, substitutions );
4753

4854
final List<Violation> results = new ArrayList<>();
4955
try ( final QueryExecution queryExecution = QueryExecutionFactory.create( query1, model ) ) {
@@ -68,4 +74,28 @@ public String name() {
6874
public <T> T accept( final Visitor<T> visitor ) {
6975
return visitor.visitSparqlConstraint( this );
7076
}
77+
78+
/**
79+
* Perform proper query substitutions; unfortunately the substutions done by {@see org.apache.jena.query.ParameterizedSparqlString} are not always correct.
80+
* @param query the query
81+
* @param substitutions the map of substitutions to perform
82+
* @return the updated query
83+
*/
84+
private Query substituteVariablesInQuery( final Query query, final Map<Var, Node> substitutions ) {
85+
final Query result = QueryTransformOps.transform( query, substitutions );
86+
87+
if ( result.hasHaving() ) {
88+
final ElementTransform elementTransform = new ElementTransformSubst( substitutions );
89+
final ExprTransform exprTransform = new ExprTransformNodeElement( node -> substitutions.getOrDefault( node, node ), elementTransform );
90+
final List<Expr> havingExpressions = result.getHavingExprs();
91+
for ( int i = 0; i < havingExpressions.size(); i++ ) {
92+
final Expr expression = havingExpressions.get( i );
93+
final Expr newExpression = ExprTransformer.transform( exprTransform, expression );
94+
if ( newExpression != expression ) {
95+
havingExpressions.set( i, newExpression );
96+
}
97+
}
98+
}
99+
return result;
100+
}
71101
}

0 commit comments

Comments
 (0)