Merge remote-tracking branch 'remotes/origin/master' into ks-20200120-near-search
This commit is contained in:
commit
02a95115a4
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
type: fix
|
||||||
|
issue: 1676
|
||||||
|
title: "When validating an XML resource, the validatin failed if the resource contained an
|
||||||
|
`xsi:schemaLocation` declaration. This has been corrected. Thanks to Brian Kaney for reporting!"
|
|
@ -187,7 +187,6 @@ public class ArbitrarySqlTask extends BaseTask<ArbitrarySqlTask> {
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return new HashCodeBuilder(17, 37)
|
return new HashCodeBuilder(17, 37)
|
||||||
.append(myTableName)
|
.append(myTableName)
|
||||||
.append(myExecuteOnlyIfTableExists)
|
|
||||||
.toHashCode();
|
.toHashCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,8 +159,6 @@ public class RenameColumnTask extends BaseTableTask<RenameColumnTask> {
|
||||||
.appendSuper(super.hashCode())
|
.appendSuper(super.hashCode())
|
||||||
.append(myOldName)
|
.append(myOldName)
|
||||||
.append(myNewName)
|
.append(myNewName)
|
||||||
.append(myIsOkayIfNeitherColumnExists)
|
|
||||||
.append(myDeleteTargetColumnFirstIfBothExist)
|
|
||||||
.toHashCode();
|
.toHashCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,9 +50,10 @@ public class Builder {
|
||||||
return new BuilderAddTableRawSql(theVersion, theTableName);
|
return new BuilderAddTableRawSql(theVersion, theTableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder executeRawSql(String theVersion, @Language("SQL") String theSql) {
|
public BuilderCompleteTask executeRawSql(String theVersion, @Language("SQL") String theSql) {
|
||||||
mySink.addTask(new ExecuteRawSqlTask(myRelease, theVersion).addSql(theSql));
|
ExecuteRawSqlTask task = new ExecuteRawSqlTask(myRelease, theVersion).addSql(theSql);
|
||||||
return this;
|
mySink.addTask(task);
|
||||||
|
return new BuilderCompleteTask(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder initializeSchema(String theVersion, ISchemaInitializationProvider theSchemaInitializationProvider) {
|
public Builder initializeSchema(String theVersion, ISchemaInitializationProvider theSchemaInitializationProvider) {
|
||||||
|
@ -72,6 +73,7 @@ public class Builder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Flyway doesn't support these kinds of migrations
|
// Flyway doesn't support these kinds of migrations
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Builder startSectionWithMessage(String theMessage) {
|
public Builder startSectionWithMessage(String theMessage) {
|
||||||
|
@ -395,7 +397,7 @@ public class Builder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class BuilderAddColumnWithName {
|
public class BuilderAddColumnWithName {
|
||||||
private final String myRelease;
|
private final String myRelease;
|
||||||
private final String myVersion;
|
private final String myVersion;
|
||||||
private final String myColumnName;
|
private final String myColumnName;
|
||||||
|
@ -427,11 +429,11 @@ public class Builder {
|
||||||
myNullable = theNullable;
|
myNullable = theNullable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BuilderAddColumnComplete type(AddColumnTask.ColumnTypeEnum theColumnType) {
|
public BuilderCompleteTask type(AddColumnTask.ColumnTypeEnum theColumnType) {
|
||||||
return type(theColumnType, null);
|
return type(theColumnType, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BuilderAddColumnComplete type(AddColumnTask.ColumnTypeEnum theColumnType, Integer theLength) {
|
public BuilderCompleteTask type(AddColumnTask.ColumnTypeEnum theColumnType, Integer theLength) {
|
||||||
AddColumnTask task = new AddColumnTask(myRelease, myVersion);
|
AddColumnTask task = new AddColumnTask(myRelease, myVersion);
|
||||||
task.setColumnName(myColumnName);
|
task.setColumnName(myColumnName);
|
||||||
task.setNullable(myNullable);
|
task.setNullable(myNullable);
|
||||||
|
@ -441,24 +443,26 @@ public class Builder {
|
||||||
}
|
}
|
||||||
myTaskSink.addTask(task);
|
myTaskSink.addTask(task);
|
||||||
|
|
||||||
return new BuilderAddColumnComplete(task);
|
return new BuilderCompleteTask(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BuilderAddColumnComplete {
|
|
||||||
|
|
||||||
private final AddColumnTask myTask;
|
|
||||||
|
|
||||||
public BuilderAddColumnComplete(AddColumnTask theTask) {
|
|
||||||
myTask = theTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BuilderAddColumnComplete failureAllowed() {
|
|
||||||
myTask.setFailureAllowed(true);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class BuilderCompleteTask {
|
||||||
|
|
||||||
|
private final BaseTask<?> myTask;
|
||||||
|
|
||||||
|
public BuilderCompleteTask(BaseTask<?> theTask) {
|
||||||
|
myTask = theTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BuilderCompleteTask failureAllowed() {
|
||||||
|
myTask.setFailureAllowed(true);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
package ca.uhn.fhir.jpa.migrate.taskdef;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.jpa.migrate.tasks.api.BaseMigrationTasks;
|
||||||
|
import ca.uhn.fhir.util.VersionEnum;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
public class ExecuteRawSqlTaskTest extends BaseTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testExecuteSql() {
|
||||||
|
executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))");
|
||||||
|
|
||||||
|
BaseMigrationTasks<VersionEnum> tasks = new BaseMigrationTasks<>();
|
||||||
|
tasks
|
||||||
|
.forVersion(VersionEnum.V4_0_0)
|
||||||
|
.executeRawSql("2001.01", "INSERT INTO SOMETABLE (PID, TEXTCOL) VALUES (123, 'abc')");
|
||||||
|
|
||||||
|
getMigrator().addTasks(tasks.getTasks(VersionEnum.V0_1, VersionEnum.V4_0_0));
|
||||||
|
getMigrator().migrate();
|
||||||
|
|
||||||
|
List<Map<String, Object>> output = executeQuery("SELECT PID FROM SOMETABLE");
|
||||||
|
assertEquals(1, output.size());
|
||||||
|
assertEquals(123L, output.get(0).get("PID"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testExecuteSql_AllowedToFail() {
|
||||||
|
executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))");
|
||||||
|
|
||||||
|
BaseMigrationTasks<VersionEnum> tasks = new BaseMigrationTasks<>();
|
||||||
|
tasks
|
||||||
|
.forVersion(VersionEnum.V4_0_0)
|
||||||
|
.executeRawSql("2001.01", "INSERT INTO SOMETABLE (PID_BAD_COLUMN, TEXTCOL) VALUES (123, 'abc')")
|
||||||
|
.failureAllowed();
|
||||||
|
|
||||||
|
getMigrator().addTasks(tasks.getTasks(VersionEnum.V0_1, VersionEnum.V4_0_0));
|
||||||
|
getMigrator().migrate();
|
||||||
|
|
||||||
|
List<Map<String, Object>> output = executeQuery("SELECT PID FROM SOMETABLE");
|
||||||
|
assertEquals(0, output.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -82,6 +82,7 @@ public class ValidatorWrapper {
|
||||||
v.setNoTerminologyChecks(myNoTerminologyChecks);
|
v.setNoTerminologyChecks(myNoTerminologyChecks);
|
||||||
v.setErrorForUnknownProfiles(myErrorForUnknownProfiles);
|
v.setErrorForUnknownProfiles(myErrorForUnknownProfiles);
|
||||||
v.getExtensionDomains().addAll(myExtensionDomains);
|
v.getExtensionDomains().addAll(myExtensionDomains);
|
||||||
|
v.setAllowXsiLocation(true);
|
||||||
|
|
||||||
List<ValidationMessage> messages = new ArrayList<>();
|
List<ValidationMessage> messages = new ArrayList<>();
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ import ca.uhn.fhir.validation.ValidationResult;
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.lang3.Validate;
|
import org.apache.commons.lang3.Validate;
|
||||||
import org.hl7.fhir.dstu3.hapi.validation.ResourceValidatorDstu3Test;
|
|
||||||
import org.hl7.fhir.exceptions.FHIRException;
|
import org.hl7.fhir.exceptions.FHIRException;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
import org.hl7.fhir.r4.conformance.ProfileUtilities;
|
import org.hl7.fhir.r4.conformance.ProfileUtilities;
|
||||||
|
@ -36,7 +35,11 @@ import org.hl7.fhir.r4.utils.FHIRPathEngine;
|
||||||
import org.hl7.fhir.r5.utils.IResourceValidator;
|
import org.hl7.fhir.r5.utils.IResourceValidator;
|
||||||
import org.hl7.fhir.utilities.validation.ValidationMessage;
|
import org.hl7.fhir.utilities.validation.ValidationMessage;
|
||||||
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
|
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
|
||||||
import org.junit.*;
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
import org.junit.rules.TestRule;
|
import org.junit.rules.TestRule;
|
||||||
import org.junit.rules.TestWatcher;
|
import org.junit.rules.TestWatcher;
|
||||||
import org.junit.runner.Description;
|
import org.junit.runner.Description;
|
||||||
|
@ -44,13 +47,25 @@ import org.mockito.invocation.InvocationOnMock;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.util.ArrayList;
|
||||||
import java.util.*;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.zip.GZIPInputStream;
|
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
import static org.junit.Assert.*;
|
import static org.hamcrest.Matchers.empty;
|
||||||
|
import static org.hamcrest.Matchers.greaterThan;
|
||||||
|
import static org.hamcrest.Matchers.hasSize;
|
||||||
|
import static org.hamcrest.Matchers.lessThan;
|
||||||
|
import static org.hamcrest.Matchers.not;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.ArgumentMatchers.nullable;
|
import static org.mockito.ArgumentMatchers.nullable;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
@ -127,8 +142,8 @@ public class FhirInstanceValidatorR4Test extends BaseTest {
|
||||||
});
|
});
|
||||||
when(myMockSupport.isCodeSystemSupported(nullable(FhirContext.class), nullable(String.class))).thenAnswer(new Answer<Boolean>() {
|
when(myMockSupport.isCodeSystemSupported(nullable(FhirContext.class), nullable(String.class))).thenAnswer(new Answer<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public Boolean answer(InvocationOnMock theInvocation) throws Throwable {
|
public Boolean answer(InvocationOnMock theInvocation) {
|
||||||
boolean retVal = myValidSystems.contains(theInvocation.getArguments()[1]);
|
boolean retVal = myValidSystems.contains(theInvocation.getArgument(1, String.class));
|
||||||
ourLog.debug("isCodeSystemSupported({}) : {}", new Object[]{theInvocation.getArguments()[1], retVal});
|
ourLog.debug("isCodeSystemSupported({}) : {}", new Object[]{theInvocation.getArguments()[1], retVal});
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
@ -139,7 +154,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest {
|
||||||
IBaseResource retVal;
|
IBaseResource retVal;
|
||||||
String id = (String) theInvocation.getArguments()[2];
|
String id = (String) theInvocation.getArguments()[2];
|
||||||
if ("Questionnaire/q_jon".equals(id)) {
|
if ("Questionnaire/q_jon".equals(id)) {
|
||||||
retVal = ourCtx.newJsonParser().parseResource(IOUtils.toString(FhirInstanceValidatorR4Test.class.getResourceAsStream("/q_jon.json")));
|
retVal = ourCtx.newJsonParser().parseResource(loadResource("/q_jon.json"));
|
||||||
} else {
|
} else {
|
||||||
retVal = myDefaultValidationSupport.fetchResource((FhirContext) theInvocation.getArguments()[0], (Class<IBaseResource>) theInvocation.getArguments()[1], id);
|
retVal = myDefaultValidationSupport.fetchResource((FhirContext) theInvocation.getArguments()[0], (Class<IBaseResource>) theInvocation.getArguments()[1], id);
|
||||||
}
|
}
|
||||||
|
@ -210,7 +225,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<SingleValidationMessage> logResultsAndReturnAll(ValidationResult theOutput) {
|
private List<SingleValidationMessage> logResultsAndReturnAll(ValidationResult theOutput) {
|
||||||
List<SingleValidationMessage> retVal = new ArrayList<SingleValidationMessage>();
|
List<SingleValidationMessage> retVal = new ArrayList<>();
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (SingleValidationMessage next : theOutput.getMessages()) {
|
for (SingleValidationMessage next : theOutput.getMessages()) {
|
||||||
|
@ -264,6 +279,27 @@ public class FhirInstanceValidatorR4Test extends BaseTest {
|
||||||
assertEquals("Primitive types must have a value that is not empty", all.get(0).getMessage());
|
assertEquals("Primitive types must have a value that is not empty", all.get(0).getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See #1676 - We should ignore schema location
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testValidateResourceWithSchemaLocation() {
|
||||||
|
String input = "<Patient xmlns=\"http://hl7.org/fhir\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://hl7.org/fhir ../../schema/foo.xsd\">" +
|
||||||
|
" <text>\n" +
|
||||||
|
" <status value=\"generated\"/>\n" +
|
||||||
|
" <div xmlns=\"http://www.w3.org/1999/xhtml\">AAA</div>\n" +
|
||||||
|
" </text>" +
|
||||||
|
" <active value=\"true\"/>" +
|
||||||
|
"</Patient>";
|
||||||
|
|
||||||
|
FhirValidator val = ourCtx.newValidator();
|
||||||
|
val.registerValidatorModule(new FhirInstanceValidator(myDefaultValidationSupport));
|
||||||
|
|
||||||
|
ValidationResult result = val.validateWithResult(input);
|
||||||
|
logResultsAndReturnAll(result);
|
||||||
|
assertTrue(result.isSuccessful());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See #942
|
* See #942
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue