Support _count on JPA search in transaction
This commit is contained in:
parent
1b82b7df65
commit
af33664e7c
|
@ -20,7 +20,9 @@ package ca.uhn.fhir.parser;
|
|||
* #L%
|
||||
*/
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.*;
|
||||
import static org.apache.commons.lang3.StringUtils.defaultString;
|
||||
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
|
|
@ -195,8 +195,7 @@ public abstract class BaseFhirDao implements IDao {
|
|||
|
||||
String typeString = nextValue.getReference().getResourceType();
|
||||
if (isBlank(typeString)) {
|
||||
throw new InvalidRequestException("Invalid resource reference found at path[" + nextPathsUnsplit + "] - Does not contain resource type - "
|
||||
+ nextValue.getReference().getValue());
|
||||
throw new InvalidRequestException("Invalid resource reference found at path[" + nextPathsUnsplit + "] - Does not contain resource type - " + nextValue.getReference().getValue());
|
||||
}
|
||||
Class<? extends IBaseResource> type = getContext().getResourceDefinition(typeString).getImplementingClass();
|
||||
String id = nextValue.getReference().getIdPart();
|
||||
|
@ -689,6 +688,18 @@ public abstract class BaseFhirDao implements IDao {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (Constants.PARAM_COUNT.equals(nextParamName)) {
|
||||
if (paramList.size() > 0 && paramList.get(0).size() > 0) {
|
||||
String intString = paramList.get(0).get(0);
|
||||
try {
|
||||
paramMap.setCount(Integer.parseInt(intString));
|
||||
} catch (NumberFormatException e) {
|
||||
throw new InvalidRequestException("Invalid " + Constants.PARAM_COUNT + " value: " + intString);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
RuntimeSearchParam paramDef = resourceDef.getSearchParam(nextParamName);
|
||||
if (paramDef == null) {
|
||||
throw new InvalidRequestException("Failed to parse match URL[" + theMatchUrl + "] - Resource type " + resourceDef.getName() + " does not have a parameter with name: " + nextParamName);
|
||||
|
|
|
@ -3,6 +3,7 @@ package ca.uhn.fhir.jpa.dao;
|
|||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.emptyString;
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
@ -24,6 +25,7 @@ import org.junit.AfterClass;
|
|||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.jmx.access.InvalidInvocationException;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.context.FhirVersionEnum;
|
||||
|
@ -560,11 +562,56 @@ public class FhirSystemDaoDstu2Test extends BaseJpaTest {
|
|||
|
||||
nextEntry = resp.getEntry().get(3);
|
||||
assertEquals(Bundle.class, nextEntry.getResource().getClass());
|
||||
|
||||
Bundle respBundle = (Bundle) nextEntry.getResource();
|
||||
assertEquals(1, respBundle.getTotal().intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransactionSearchWithCount() {
|
||||
String methodName = "testTransactionSearchWithCount";
|
||||
|
||||
Patient p = new Patient();
|
||||
p.addIdentifier().setSystem("urn:system").setValue(methodName);
|
||||
p.setId("Patient/" + methodName);
|
||||
IdDt idv1 = ourPatientDao.update(p).getId();
|
||||
ourLog.info("Created patient, got id: {}", idv1);
|
||||
|
||||
p = new Patient();
|
||||
p.addIdentifier().setSystem("urn:system").setValue(methodName);
|
||||
p.addName().addFamily("Family Name");
|
||||
p.setId("Patient/" + methodName);
|
||||
IdDt idv2 = ourPatientDao.update(p).getId();
|
||||
ourLog.info("Updated patient, got id: {}", idv2);
|
||||
|
||||
Bundle request = new Bundle();
|
||||
request.addEntry().getTransaction().setMethod(HTTPVerbEnum.GET).setUrl("Patient?" + Constants.PARAM_COUNT + "=1");
|
||||
Bundle resp = ourSystemDao.transaction(request);
|
||||
|
||||
assertEquals(2, resp.getEntry().size());
|
||||
|
||||
Entry nextEntry = resp.getEntry().get(1);
|
||||
assertEquals(Bundle.class, nextEntry.getResource().getClass());
|
||||
Bundle respBundle = (Bundle) nextEntry.getResource();
|
||||
assertEquals(1, respBundle.getTotal().intValue());
|
||||
|
||||
// Invalid _count
|
||||
|
||||
request = new Bundle();
|
||||
request.addEntry().getTransaction().setMethod(HTTPVerbEnum.GET).setUrl("Patient?" + Constants.PARAM_COUNT + "=GKJGKJG");
|
||||
try {
|
||||
ourSystemDao.transaction(request);
|
||||
} catch (InvalidRequestException e) {
|
||||
assertEquals(e.getMessage(), ("Invalid _count value: GKJGKJG"));
|
||||
}
|
||||
|
||||
// Empty _count
|
||||
|
||||
request = new Bundle();
|
||||
request.addEntry().getTransaction().setMethod(HTTPVerbEnum.GET).setUrl("Patient?" + Constants.PARAM_COUNT + "=");
|
||||
respBundle = ourSystemDao.transaction(request);
|
||||
assertThat(respBundle.getEntry().size(), greaterThan(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransactionReadWithIfNoneMatch() {
|
||||
String methodName = "testTransactionReadWithIfNoneMatch";
|
||||
|
|
|
@ -130,6 +130,9 @@
|
|||
precision than the equivalent header, but the client previously
|
||||
gave the header priority.
|
||||
</action>
|
||||
<action type="fix">
|
||||
JPA server supports _count parameter in transaction containing search URL (nested search)
|
||||
</action>
|
||||
</release>
|
||||
<release version="1.0" date="2015-May-8">
|
||||
<action type="add">
|
||||
|
|
Loading…
Reference in New Issue