Skip to content

Commit

Permalink
#487: Added library id and version to error annotations in the ELM an…
Browse files Browse the repository at this point in the history
…d ensured they are successfully reported through the ELM
  • Loading branch information
brynrhodes committed Mar 21, 2020
1 parent 28ca672 commit f489151
Show file tree
Hide file tree
Showing 4 changed files with 578 additions and 560 deletions.
2 changes: 2 additions & 0 deletions Src/cql-lm/schema/elm/cqlannotations.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
</xs:sequence>
</xs:complexType>
<xs:complexType name="Locator">
<xs:attribute name="libraryId" type="xs:string" use="optional"/>
<xs:attribute name="libraryVersion" type="xs:string" use="optional"/>
<xs:attribute name="startLine" type="xs:int" use="optional"/>
<xs:attribute name="startChar" type="xs:int" use="optional"/>
<xs:attribute name="endLine" type="xs:int" use="optional"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@ public void recordParsingException(CqlTranslatorException e) {
err.setErrorType(e instanceof CqlSyntaxException ? ErrorType.SYNTAX : (e instanceof CqlSemanticException ? ErrorType.SEMANTIC : ErrorType.INTERNAL));
err.setErrorSeverity(toErrorSeverity(e.getSeverity()));
if (e.getLocator() != null) {
if (e.getLocator().getLibrary() != null) {
err.setLibraryId(e.getLocator().getLibrary().getId());
err.setLibraryVersion(e.getLocator().getLibrary().getVersion());
}
err.setStartLine(e.getLocator().getStartLine());
err.setEndLine(e.getLocator().getEndLine());
err.setStartChar(e.getLocator().getStartChar());
Expand Down Expand Up @@ -517,7 +521,7 @@ public void addInclude(IncludeDef includeDef) {
TranslatedLibrary referencedLibrary = libraryManager.resolveLibrary(libraryIdentifier,
this.getErrorLevel(), this.getSignatureLevel(), this.getTranslatorOptions(), errors);
for (CqlTranslatorException error : errors) {
this.addException(error);
this.recordParsingException(error);
}
libraries.put(includeDef.getLocalIdentifier(), referencedLibrary);
loadConversionMap(referencedLibrary);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package org.cqframework.cql.cql2elm;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.*;
import static org.testng.Assert.assertTrue;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.cqframework.cql.cql2elm.LibraryBuilder.SignatureLevel;
import org.hl7.cql_annotations.r1.CqlToElmError;
import org.hl7.elm.r1.AggregateExpression;
import org.hl7.elm.r1.ExpressionDef;
import org.hl7.elm.r1.Library;
Expand Down Expand Up @@ -131,6 +129,16 @@ public void testInvalidBaseLibrary() {
translator = CqlTranslator.fromStream(LibraryTests.class.getResourceAsStream("LibraryTests/ReferencingInvalidBaseLibrary.cql"), modelManager, libraryManager);
assertThat(translator.getErrors().size(), is(1));
assertThat(translator.getErrors().get(0), instanceOf(CqlTranslatorException.class));
assertThat(translator.getErrors().get(0).getLocator(), notNullValue());
assertThat(translator.getErrors().get(0).getLocator().getLibrary(), notNullValue());
assertThat(translator.getErrors().get(0).getLocator().getLibrary().getId(), is("InvalidBaseLibrary"));

assertThat(translator.toELM(), notNullValue());
assertThat(translator.toELM().getAnnotation(), notNullValue());
assertThat(translator.toELM().getAnnotation().size(), greaterThan(0));
assertThat(translator.toELM().getAnnotation().get(0), instanceOf(CqlToElmError.class));
CqlToElmError invalidBaseLibraryError = (CqlToElmError)translator.toELM().getAnnotation().get(0);
assertThat(invalidBaseLibraryError.getLibraryId(), is("InvalidBaseLibrary"));
}
catch (IOException e) {
e.printStackTrace();
Expand Down
Loading

0 comments on commit f489151

Please sign in to comment.