Skip to content

Commit

Permalink
Fix case sensitivity issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesagnew committed Dec 13, 2018
1 parent 8d195ae commit 11b8304
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 17 deletions.
4 changes: 2 additions & 2 deletions hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirTerser.java
Expand Up @@ -53,8 +53,8 @@ private List<String> addNameToList(List<String> theCurrentList, BaseRuntimeChild
if (theChildDefinition == null)
return null;
if (theCurrentList == null || theCurrentList.isEmpty())
return new ArrayList<String>(Arrays.asList(theChildDefinition.getElementName()));
List<String> newList = new ArrayList<String>(theCurrentList);
return new ArrayList<>(Arrays.asList(theChildDefinition.getElementName()));
List<String> newList = new ArrayList<>(theCurrentList);
newList.add(theChildDefinition.getElementName());
return newList;
}
Expand Down
Expand Up @@ -10,22 +10,22 @@
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
import ca.uhn.fhir.rest.server.interceptor.IServerOperationInterceptor;
import ca.uhn.fhir.rest.server.interceptor.InterceptorAdapter;
import ca.uhn.fhir.rest.server.interceptor.ServerOperationInterceptorAdapter;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import ca.uhn.fhir.util.TestUtil;
import org.apache.commons.io.IOUtils;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.hamcrest.Matchers;
import org.hl7.fhir.instance.model.api.IBaseBundle;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.*;
import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.r4.model.Bundle.BundleType;
import org.hl7.fhir.r4.model.Bundle.HTTPVerb;
import org.hl7.fhir.r4.model.Organization;
import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.Reference;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Test;
Expand All @@ -38,6 +38,7 @@
import java.nio.charset.StandardCharsets;
import java.util.stream.Collectors;

import static org.hamcrest.Matchers.in;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -236,6 +237,32 @@ public void testCreateResourceInTransaction() throws IOException {
}

@Test
public void testCreateReflexResourceTheHardWay() throws IOException, ServletException {
ServerOperationInterceptorAdapter interceptor = new ReflexInterceptor();

ourRestServer.registerInterceptor(interceptor);
try {

Patient p = new Patient();
p.setActive(true);
IIdType pid = ourClient.create().resource(p).execute().getId().toUnqualifiedVersionless();

Bundle observations = ourClient
.search()
.forResource("Observation")
.where(Observation.SUBJECT.hasId(pid))
.returnBundle(Bundle.class)
.execute();
assertEquals(1, observations.getEntry().size());
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(observations));

} finally {
ourRestServer.unregisterInterceptor(interceptor);
}
}


@Test
public void testCreateResourceWithVersionedReference() throws IOException, ServletException {
String methodName = "testCreateResourceWithVersionedReference";

Expand Down Expand Up @@ -353,6 +380,26 @@ private void transaction(Bundle theBundle) throws IOException {
}
}

public class ReflexInterceptor extends ServerOperationInterceptorAdapter {
@Override
public void resourceCreated(RequestDetails theRequest, IBaseResource theResource) {
if (theResource instanceof Patient) {
((ServletRequestDetails) theRequest).getServletRequest().setAttribute("CREATED_PATIENT", theResource);
}
}

@Override
public void processingCompletedNormally(ServletRequestDetails theRequestDetails) {
Patient createdPatient = (Patient) theRequestDetails.getServletRequest().getAttribute("CREATED_PATIENT");
if (createdPatient != null) {
Observation observation = new Observation();
observation.setSubject(new Reference(createdPatient.getId()));

ourClient.create().resource(observation).execute();
}
}
}

@AfterClass
public static void afterClassClearContext() {
TestUtil.clearAllStaticFieldsForUnitTest();
Expand Down
Expand Up @@ -9,9 +9,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -53,7 +53,7 @@ public static Set<String> getIndexNames(DriverTypeEnum.ConnectionProperties theC
DatabaseMetaData metadata;
try {
metadata = connection.getMetaData();
ResultSet indexes = metadata.getIndexInfo(connection.getCatalog(), connection.getSchema(), theTableName, false, true);
ResultSet indexes = metadata.getIndexInfo(connection.getCatalog(), connection.getSchema(), massageIdentifier(metadata, theTableName), false, true);

Set<String> indexNames = new HashSet<>();
while (indexes.next()) {
Expand Down Expand Up @@ -81,7 +81,7 @@ public static boolean isIndexUnique(DriverTypeEnum.ConnectionProperties theConne
DatabaseMetaData metadata;
try {
metadata = connection.getMetaData();
ResultSet indexes = metadata.getIndexInfo(connection.getCatalog(), connection.getSchema(), theTableName, false, false);
ResultSet indexes = metadata.getIndexInfo(connection.getCatalog(), connection.getSchema(), massageIdentifier(metadata, theTableName), false, false);

while (indexes.next()) {
String indexName = indexes.getString("INDEX_NAME");
Expand Down Expand Up @@ -112,7 +112,7 @@ public static String getColumnType(DriverTypeEnum.ConnectionProperties theConnec
metadata = connection.getMetaData();
String catalog = connection.getCatalog();
String schema = connection.getSchema();
ResultSet indexes = metadata.getColumns(catalog, schema, theTableName, null);
ResultSet indexes = metadata.getColumns(catalog, schema, massageIdentifier(metadata, theTableName), null);

while (indexes.next()) {

Expand Down Expand Up @@ -165,7 +165,7 @@ public static Set<String> getForeignKeys(DriverTypeEnum.ConnectionProperties the
DatabaseMetaData metadata;
try {
metadata = connection.getMetaData();
ResultSet indexes = metadata.getCrossReference(connection.getCatalog(), connection.getSchema(), theTableName, connection.getCatalog(), connection.getSchema(), theForeignTable);
ResultSet indexes = metadata.getCrossReference(connection.getCatalog(), connection.getSchema(), massageIdentifier(metadata, theTableName), connection.getCatalog(), connection.getSchema(), massageIdentifier(metadata, theForeignTable));

Set<String> columnNames = new HashSet<>();
while (indexes.next()) {
Expand Down Expand Up @@ -201,7 +201,7 @@ public static Set<String> getColumnNames(DriverTypeEnum.ConnectionProperties the
DatabaseMetaData metadata;
try {
metadata = connection.getMetaData();
ResultSet indexes = metadata.getColumns(connection.getCatalog(), connection.getSchema(), theTableName, null);
ResultSet indexes = metadata.getColumns(connection.getCatalog(), connection.getSchema(), massageIdentifier(metadata, theTableName), null);

Set<String> columnNames = new HashSet<>();
while (indexes.next()) {
Expand Down Expand Up @@ -253,7 +253,7 @@ public static Set<String> getSequenceNames(DriverTypeEnum.ConnectionProperties t
}
}
return sequenceNames;
} catch (SQLException e ) {
} catch (SQLException e) {
throw new InternalErrorException(e);
}
});
Expand Down Expand Up @@ -298,7 +298,7 @@ public static boolean isColumnNullable(DriverTypeEnum.ConnectionProperties theCo
DatabaseMetaData metadata;
try {
metadata = connection.getMetaData();
ResultSet tables = metadata.getColumns(connection.getCatalog(), connection.getSchema(), theTableName, theColumnName);
ResultSet tables = metadata.getColumns(connection.getCatalog(), connection.getSchema(), massageIdentifier(metadata, theTableName), null);

while (tables.next()) {
String tableName = toUpperCase(tables.getString("TABLE_NAME"), Locale.US);
Expand All @@ -325,4 +325,14 @@ public static boolean isColumnNullable(DriverTypeEnum.ConnectionProperties theCo
});
}
}

private static String massageIdentifier(DatabaseMetaData theMetadata, String theCatalog) throws SQLException {
String retVal = theCatalog;
if (theMetadata.storesLowerCaseIdentifiers()) {
retVal = retVal.toLowerCase();
} else {
retVal = retVal.toUpperCase();
}
return retVal;
}
}
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -518,7 +518,7 @@
<jaxb_api_version>2.3.0</jaxb_api_version>
<jaxb_core_version>2.3.0</jaxb_core_version>
<jersey_version>2.25.1</jersey_version>
<jetty_version>9.4.12.v20180830</jetty_version>
<jetty_version>9.4.14.v20181114</jetty_version>
<jsr305_version>3.0.2</jsr305_version>
<!--<hibernate_version>5.2.10.Final</hibernate_version>-->
<hibernate_version>5.3.6.Final</hibernate_version>
Expand Down
4 changes: 3 additions & 1 deletion src/changes/changes.xml
Expand Up @@ -98,9 +98,11 @@
or authorizing the contents of the response.
</action>
<action type="add">
JPA Migrator tool enhancements:
An invalid SQL syntax issue has been fixed when running the CLI JPA Migrator tool against
Oracle or SQL Server. In addition, when using the "Dry Run" option, all generated SQL
statements will be logged at the end of the run.
statements will be logged at the end of the run. Also, a case sensitivity issue when running against
some Postgres databases has been corrected.
</action>
<action type="add">
In the JPA server, when performing a chained reference search on a search parameter with
Expand Down

0 comments on commit 11b8304

Please sign in to comment.