More tester work

This commit is contained in:
jamesagnew 2014-06-25 09:49:13 -04:00
parent 875acee2ac
commit 411644c4ff
10 changed files with 151 additions and 5 deletions

View File

@ -51,6 +51,8 @@ import ca.uhn.fhir.rest.client.exceptions.NonFhirResponseException;
import ca.uhn.fhir.rest.gclient.IClientExecutable; import ca.uhn.fhir.rest.gclient.IClientExecutable;
import ca.uhn.fhir.rest.gclient.ICriterion; import ca.uhn.fhir.rest.gclient.ICriterion;
import ca.uhn.fhir.rest.gclient.ICriterionInternal; import ca.uhn.fhir.rest.gclient.ICriterionInternal;
import ca.uhn.fhir.rest.gclient.IGetPage;
import ca.uhn.fhir.rest.gclient.IGetPageTyped;
import ca.uhn.fhir.rest.gclient.IGetTags; import ca.uhn.fhir.rest.gclient.IGetTags;
import ca.uhn.fhir.rest.gclient.IParam; import ca.uhn.fhir.rest.gclient.IParam;
import ca.uhn.fhir.rest.gclient.IQuery; import ca.uhn.fhir.rest.gclient.IQuery;
@ -63,6 +65,7 @@ import ca.uhn.fhir.rest.method.DeleteMethodBinding;
import ca.uhn.fhir.rest.method.HistoryMethodBinding; import ca.uhn.fhir.rest.method.HistoryMethodBinding;
import ca.uhn.fhir.rest.method.HttpDeleteClientInvocation; import ca.uhn.fhir.rest.method.HttpDeleteClientInvocation;
import ca.uhn.fhir.rest.method.HttpGetClientInvocation; import ca.uhn.fhir.rest.method.HttpGetClientInvocation;
import ca.uhn.fhir.rest.method.HttpSimpleGetClientInvocation;
import ca.uhn.fhir.rest.method.IClientResponseHandler; import ca.uhn.fhir.rest.method.IClientResponseHandler;
import ca.uhn.fhir.rest.method.ReadMethodBinding; import ca.uhn.fhir.rest.method.ReadMethodBinding;
import ca.uhn.fhir.rest.method.SearchMethodBinding; import ca.uhn.fhir.rest.method.SearchMethodBinding;
@ -334,7 +337,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
params.get(parameterName).add(parameterValue); params.get(parameterName).add(parameterValue);
} }
protected <Z> Z invoke(Map<String, List<String>> theParams, IClientResponseHandler<Z> theHandler, HttpGetClientInvocation theInvocation) { protected <Z> Z invoke(Map<String, List<String>> theParams, IClientResponseHandler<Z> theHandler, BaseHttpClientInvocation theInvocation) {
if (myParamEncoding != null) { if (myParamEncoding != null) {
theParams.put(Constants.PARAM_FORMAT, Collections.singletonList(myParamEncoding.getFormatContentType())); theParams.put(Constants.PARAM_FORMAT, Collections.singletonList(myParamEncoding.getFormatContentType()));
} }
@ -519,15 +522,15 @@ public class GenericClient extends BaseClient implements IGenericClient {
@Override @Override
public IGetTags forResource(Class<? extends IResource> theClass, String theId) { public IGetTags forResource(Class<? extends IResource> theClass, String theId) {
setResourceClass(theClass); setResourceClass(theClass);
myId=theId; myId = theId;
return this; return this;
} }
@Override @Override
public IGetTags forResource(Class<? extends IResource> theClass, String theId, String theVersionId) { public IGetTags forResource(Class<? extends IResource> theClass, String theId, String theVersionId) {
setResourceClass(theClass); setResourceClass(theClass);
myId=theId; myId = theId;
myVersionId=theVersionId; myVersionId = theVersionId;
return this; return this;
} }
@ -633,4 +636,49 @@ public class GenericClient extends BaseClient implements IGenericClient {
} }
} }
@Override
public IGetPage loadPage() {
return new LoadPageInternal();
}
private final class LoadPageInternal implements IGetPage {
@Override
public IGetPageTyped previous(Bundle theBundle) {
return new GetPageInternal(theBundle.getLinkPrevious().getValue());
}
@Override
public IGetPageTyped next(Bundle theBundle) {
return new GetPageInternal(theBundle.getLinkNext().getValue());
}
@Override
public IGetPageTyped url(String thePageUrl) {
return new GetPageInternal(thePageUrl);
}
}
private class GetPageInternal extends BaseClientExecutable<IGetPageTyped, Bundle> implements IGetPageTyped {
private String myUrl;
public GetPageInternal(String theUrl) {
myUrl = theUrl;
}
@Override
public Bundle execute() {
BundleResponseHandler binding = new BundleResponseHandler(null);
HttpSimpleGetClientInvocation invocation = new HttpSimpleGetClientInvocation(myUrl);
Map<String, List<String>> params = null;
return invoke(params, binding, invocation);
}
}
} }

View File

@ -30,6 +30,8 @@ import ca.uhn.fhir.model.dstu.resource.Conformance;
import ca.uhn.fhir.model.primitive.DateTimeDt; import ca.uhn.fhir.model.primitive.DateTimeDt;
import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.gclient.IGetPage;
import ca.uhn.fhir.rest.gclient.IGetPageTyped;
import ca.uhn.fhir.rest.gclient.IGetTags; import ca.uhn.fhir.rest.gclient.IGetTags;
import ca.uhn.fhir.rest.gclient.IUntypedQuery; import ca.uhn.fhir.rest.gclient.IUntypedQuery;
@ -226,4 +228,12 @@ public interface IGenericClient {
*/ */
IGetTags getTags(); IGetTags getTags();
/**
* Loads the previous/next bundle of resources from a paged set, using the link specified in the
* "link type=next" tag within the atom bundle.
*
* @see Bundle#getLinkNext()
*/
IGetPage loadPage();
} }

View File

@ -64,4 +64,6 @@ public interface IRestfulClient {
*/ */
String getServerBase(); String getServerBase();
} }

View File

@ -0,0 +1,13 @@
package ca.uhn.fhir.rest.gclient;
import ca.uhn.fhir.model.api.Bundle;
public interface IGetPage {
IGetPageTyped previous(Bundle theBundle);
IGetPageTyped next(Bundle theBundle);
IGetPageTyped url(String thePageUrl);
}

View File

@ -0,0 +1,9 @@
package ca.uhn.fhir.rest.gclient;
import ca.uhn.fhir.model.api.Bundle;
public interface IGetPageTyped extends IClientExecutable<IGetPageTyped, Bundle> {
// nothing for now
}

View File

@ -0,0 +1,47 @@
package ca.uhn.fhir.rest.method;
/*
* #%L
* HAPI FHIR Library
* %%
* Copyright (C) 2014 University Health Network
* %%
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import java.util.List;
import java.util.Map;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpRequestBase;
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.server.EncodingEnum;
public class HttpSimpleGetClientInvocation extends BaseHttpClientInvocation {
private final String myUrl;
public HttpSimpleGetClientInvocation(String theUrlPath) {
myUrl = theUrlPath;
}
@Override
public HttpRequestBase asHttpRequest(String theUrlBase, Map<String, List<String>> theExtraParams, EncodingEnum theEncoding) {
HttpGet retVal = new HttpGet(myUrl);
super.addHeadersToRequest(retVal);
return retVal;
}
}

View File

@ -546,6 +546,8 @@ public class RestfulServer extends HttpServlet {
Bundle bundle = createBundleFromResourceList(theServer.getFhirContext(), theServer.getServerName(), resourceList, theServerBase, theCompleteUrl, theResult.size()); Bundle bundle = createBundleFromResourceList(theServer.getFhirContext(), theServer.getServerName(), resourceList, theServerBase, theCompleteUrl, theResult.size());
bundle.setPublished(theResult.getPublished());
if (searchId != null) { if (searchId != null) {
if (theOffset + numToReturn < theResult.size()) { if (theOffset + numToReturn < theResult.size()) {
bundle.getLinkNext().setValue(createPagingLink(theServerBase, searchId, theOffset + numToReturn, numToReturn)); bundle.getLinkNext().setValue(createPagingLink(theServerBase, searchId, theOffset + numToReturn, numToReturn));

View File

@ -249,6 +249,17 @@ public class RestfulTesterServlet extends HttpServlet {
returnsResource = ResultType.TAGLIST; returnsResource = ResultType.TAGLIST;
outcomeDescription = "Tag List"; outcomeDescription = "Tag List";
} else if ("page".equals(method)) {
String url = defaultString(theReq.getParameter("page-url"));
if (!url.startsWith(myServerBase)) {
theContext.getVariables().put("errorMsg", "Invalid page URL: " + url);
return;
}
returnsResource = ResultType.TAGLIST;
outcomeDescription = "Tag List";
} else if ("delete".equals(method)) { } else if ("delete".equals(method)) {
RuntimeResourceDefinition def = getResourceType(theReq); RuntimeResourceDefinition def = getResourceType(theReq);
String id = StringUtils.defaultString(theReq.getParameter("resource-delete-id")); String id = StringUtils.defaultString(theReq.getParameter("resource-delete-id"));

View File

@ -952,7 +952,7 @@
$('#page-next-btn').click(function() { $('#page-next-btn').click(function() {
var btn = $(this); var btn = $(this);
btn.button('loading'); btn.button('loading');
btn.append($('<input />', { type: 'hidden', name: 'pageUrl', value: '<th:block th:text="${bundle.linkNext}"/>' })); btn.append($('<input />', { type: 'hidden', name: 'page-url', value: '<th:block th:text="${bundle.linkNext}"/>' }));
}); });
</script> </script>
</th:block> </th:block>

View File

@ -8,6 +8,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
import ca.uhn.fhir.jpa.dao.IFhirSystemDao; import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
import ca.uhn.fhir.jpa.provider.JpaConformanceProvider; import ca.uhn.fhir.jpa.provider.JpaConformanceProvider;
import ca.uhn.fhir.jpa.provider.JpaSystemProvider; import ca.uhn.fhir.jpa.provider.JpaSystemProvider;
import ca.uhn.fhir.rest.server.FifoMemoryPagingProvider;
import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.RestfulServer;
@ -45,6 +46,9 @@ public class TestRestfulServer extends RestfulServer {
setServerConformanceProvider(confProvider); setServerConformanceProvider(confProvider);
setUseBrowserFriendlyContentTypes(true); setUseBrowserFriendlyContentTypes(true);
setPagingProvider(new FifoMemoryPagingProvider(10));
} }
@Override @Override