mirror of
https://github.com/hapifhir/hapi-fhir.git
synced 2025-03-25 01:18:37 +00:00
Add sort on reference param for JPA server
This commit is contained in:
parent
341d039841
commit
a4157c1339
@ -309,7 +309,8 @@
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<runOrder>alphabetical</runOrder>
|
||||
<reuseForks>false</reuseForks>
|
||||
<reuseForks>true</reuseForks>
|
||||
<argLine>-Xms512m -Xmx1024m</argLine>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
@ -1002,7 +1002,7 @@ public abstract class BaseFhirResourceDao<T extends IResource> extends BaseFhirD
|
||||
return singleCode;
|
||||
}
|
||||
|
||||
private void createSort(CriteriaBuilder theBuilder, Root<ResourceTable> theFrom, SortSpec theSort, List<Order> theOrders, List<Predicate> thePredicates) {
|
||||
private void createSort(CriteriaBuilder theBuilder, Root<ResourceTable> theFrom, SortSpec theSort, List<Order> theOrders) {
|
||||
if (theSort == null || isBlank(theSort.getParamName())) {
|
||||
return;
|
||||
}
|
||||
@ -1017,7 +1017,7 @@ public abstract class BaseFhirResourceDao<T extends IResource> extends BaseFhirD
|
||||
theOrders.add(theBuilder.desc(theFrom.get("myId")));
|
||||
}
|
||||
|
||||
createSort(theBuilder, theFrom, theSort.getChain(), theOrders, null);
|
||||
createSort(theBuilder, theFrom, theSort.getChain(), theOrders);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1039,6 +1039,10 @@ public abstract class BaseFhirResourceDao<T extends IResource> extends BaseFhirD
|
||||
joinAttrName = "myParamsDate";
|
||||
sortAttrName = "myValueLow";
|
||||
break;
|
||||
case REFERENCE:
|
||||
joinAttrName = "myResourceLinks";
|
||||
sortAttrName = "myTargetResourcePid";
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException("This server does not support _sort specifications of type " + param.getParamType() + " - Can't serve _sort=" + theSort.getParamName());
|
||||
}
|
||||
@ -1054,7 +1058,7 @@ public abstract class BaseFhirResourceDao<T extends IResource> extends BaseFhirD
|
||||
theOrders.add(theBuilder.desc(stringJoin.get(sortAttrName)));
|
||||
}
|
||||
|
||||
createSort(theBuilder, theFrom, theSort.getChain(), theOrders, null);
|
||||
createSort(theBuilder, theFrom, theSort.getChain(), theOrders);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1142,6 +1146,10 @@ public abstract class BaseFhirResourceDao<T extends IResource> extends BaseFhirD
|
||||
return outcome;
|
||||
}
|
||||
|
||||
/**
|
||||
* May
|
||||
* @param theResource The resource that is about to be stored
|
||||
*/
|
||||
protected void preProcessResourceForStorage(T theResource) {
|
||||
// nothing by default
|
||||
}
|
||||
@ -1655,7 +1663,7 @@ public abstract class BaseFhirResourceDao<T extends IResource> extends BaseFhirD
|
||||
CriteriaQuery<Tuple> cq = builder.createTupleQuery();
|
||||
Root<ResourceTable> from = cq.from(ResourceTable.class);
|
||||
predicates.add(from.get("myId").in(loadPids));
|
||||
createSort(builder, from, theParams.getSort(), orders, predicates);
|
||||
createSort(builder, from, theParams.getSort(), orders);
|
||||
if (orders.size() > 0) {
|
||||
Set<Long> originalPids = loadPids;
|
||||
loadPids = new LinkedHashSet<Long>();
|
||||
|
@ -2210,6 +2210,67 @@ public class FhirResourceDaoDstu2Test extends BaseJpaTest {
|
||||
assertThat(actual, contains(id3, id2, id1, id4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSortByReference() {
|
||||
String methodName = "testSortByReference";
|
||||
|
||||
Organization o1 = new Organization();
|
||||
IdDt oid1 = ourOrganizationDao.create(o1).getId().toUnqualifiedVersionless();
|
||||
|
||||
Organization o2 = new Organization();
|
||||
IdDt oid2 = ourOrganizationDao.create(o2).getId().toUnqualifiedVersionless();
|
||||
|
||||
Patient p = new Patient();
|
||||
p.addIdentifier().setSystem("urn:system").setValue(methodName);
|
||||
p.addName().addFamily("testSortF1").addGiven("testSortG1");
|
||||
p.getManagingOrganization().setReference(oid1);
|
||||
IdDt id1 = ourPatientDao.create(p).getId().toUnqualifiedVersionless();
|
||||
|
||||
p = new Patient();
|
||||
p.addIdentifier().setSystem("urn:system").setValue(methodName);
|
||||
p.addName().addFamily("testSortF2").addGiven("testSortG2");
|
||||
p.getManagingOrganization().setReference(oid2);
|
||||
IdDt id2 = ourPatientDao.create(p).getId().toUnqualifiedVersionless();
|
||||
|
||||
p = new Patient();
|
||||
p.addIdentifier().setSystem("urn:system").setValue(methodName);
|
||||
p.addName().addFamily("testSortF3").addGiven("testSortG3");
|
||||
p.getManagingOrganization().setReference(oid1);
|
||||
IdDt id3 = ourPatientDao.create(p).getId().toUnqualifiedVersionless();
|
||||
|
||||
p = new Patient();
|
||||
p.addIdentifier().setSystem("urn:system").setValue(methodName);
|
||||
p.getManagingOrganization().setReference(oid2);
|
||||
IdDt id4 = ourPatientDao.create(p).getId().toUnqualifiedVersionless();
|
||||
|
||||
SearchParameterMap pm;
|
||||
List<IdDt> actual;
|
||||
|
||||
pm = new SearchParameterMap();
|
||||
pm.add(Patient.SP_IDENTIFIER, new TokenParam("urn:system", methodName));
|
||||
pm.setSort(new SortSpec(Patient.SP_ORGANIZATION));
|
||||
actual = toUnqualifiedVersionlessIds(ourPatientDao.search(pm));
|
||||
assertEquals(4, actual.size());
|
||||
assertThat(actual.subList(0, 2), containsInAnyOrder(id1, id3));
|
||||
assertThat(actual.subList(2, 4), containsInAnyOrder(id2, id4));
|
||||
|
||||
pm = new SearchParameterMap();
|
||||
pm.add(Patient.SP_IDENTIFIER, new TokenParam("urn:system", methodName));
|
||||
pm.setSort(new SortSpec(Patient.SP_ORGANIZATION).setOrder(SortOrderEnum.ASC));
|
||||
actual = toUnqualifiedVersionlessIds(ourPatientDao.search(pm));
|
||||
assertEquals(4, actual.size());
|
||||
assertThat(actual.subList(0, 2), containsInAnyOrder(id1, id3));
|
||||
assertThat(actual.subList(2, 4), containsInAnyOrder(id2, id4));
|
||||
|
||||
pm = new SearchParameterMap();
|
||||
pm.add(Patient.SP_IDENTIFIER, new TokenParam("urn:system", methodName));
|
||||
pm.setSort(new SortSpec(Patient.SP_ORGANIZATION).setOrder(SortOrderEnum.DESC));
|
||||
actual = toUnqualifiedVersionlessIds(ourPatientDao.search(pm));
|
||||
assertEquals(4, actual.size());
|
||||
assertThat(actual.subList(0, 2), containsInAnyOrder(id2, id4));
|
||||
assertThat(actual.subList(2, 4), containsInAnyOrder(id1, id3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoreUnversionedResources() {
|
||||
Organization o1 = new Organization();
|
||||
|
@ -10,19 +10,19 @@
|
||||
<logger name="org.eclipse" additivity="false">
|
||||
</logger>
|
||||
|
||||
<logger name="ca.uhn.fhir.rest.client" additivity="false" level="fatal">
|
||||
<logger name="ca.uhn.fhir.rest.client" additivity="false" level="info">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</logger>
|
||||
|
||||
<logger name="ca.uhn.fhir.jpa.dao" additivity="false" level="fatal">
|
||||
<logger name="ca.uhn.fhir.jpa.dao" additivity="false" level="info">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</logger>
|
||||
|
||||
<logger name="org.hibernate.SQL" additivity="false" level="fatal">
|
||||
<logger name="org.hibernate.SQL" additivity="false" level="info">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</logger>
|
||||
|
||||
<root level="fatal">
|
||||
<root level="info">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
|
||||
|
@ -2,9 +2,7 @@ package ca.uhn.fhir.rest.client;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.servlet.ServletHandler;
|
||||
@ -62,15 +60,18 @@ public class LoggingInterceptorTest {
|
||||
|
||||
@Test
|
||||
public void testLogger() throws Exception {
|
||||
System.out.println("Starting testLogger");
|
||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort);
|
||||
client.registerInterceptor(new LoggingInterceptor(true));
|
||||
Patient patient = client.read(Patient.class, "1");
|
||||
assertFalse(patient.getIdentifierFirstRep().isEmpty());
|
||||
|
||||
verify(myMockAppender).doAppend(argThat(new ArgumentMatcher<ILoggingEvent>() {
|
||||
verify(myMockAppender, atLeastOnce()).doAppend(argThat(new ArgumentMatcher<ILoggingEvent>() {
|
||||
@Override
|
||||
public boolean matches(final Object argument) {
|
||||
return ((LoggingEvent) argument).getFormattedMessage().contains("Content-Type: application/xml+fhir; charset=UTF-8");
|
||||
String formattedMessage = ((LoggingEvent) argument).getFormattedMessage();
|
||||
System.out.println("Verifying: " + formattedMessage);
|
||||
return formattedMessage.contains("Content-Type: application/xml+fhir; charset=UTF-8");
|
||||
}
|
||||
}));
|
||||
}
|
||||
@ -94,7 +95,7 @@ public class LoggingInterceptorTest {
|
||||
proxyHandler.addServletWithMapping(servletHolder, "/*");
|
||||
ourServer.setHandler(proxyHandler);
|
||||
ourServer.start();
|
||||
|
||||
|
||||
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
|
||||
}
|
||||
|
||||
|
@ -119,6 +119,10 @@
|
||||
Generic/fluent client and JPA server now both support _lastUpdated search parameter
|
||||
which was added in DSTU2
|
||||
</action>
|
||||
<action name="fix">
|
||||
JPA server now supports sorting on reference parameters. Thanks to
|
||||
Vishal Kachroo for reporting that this wasn't working!
|
||||
</action>
|
||||
</release>
|
||||
<release version="1.0" date="2015-May-8">
|
||||
<action type="add">
|
||||
|
Loading…
x
Reference in New Issue
Block a user