Add config setting for JPA resource counts in metadata

This commit is contained in:
James Agnew 2017-07-01 16:28:42 -04:00
parent 73a8cf1fca
commit 294d080bd3
3 changed files with 39 additions and 18 deletions

View File

@ -19,9 +19,7 @@ package ca.uhn.fhir.jpa.provider;
* limitations under the License. * limitations under the License.
* #L% * #L%
*/ */
import java.util.*;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -51,6 +49,7 @@ public class JpaConformanceProviderDstu2 extends ServerConformanceProvider {
private volatile Conformance myCachedValue; private volatile Conformance myCachedValue;
private DaoConfig myDaoConfig; private DaoConfig myDaoConfig;
private String myImplementationDescription; private String myImplementationDescription;
private boolean myIncludeResourceCounts;
private RestfulServer myRestfulServer; private RestfulServer myRestfulServer;
private IFhirSystemDao<Bundle, MetaDt> mySystemDao; private IFhirSystemDao<Bundle, MetaDt> mySystemDao;
@ -61,6 +60,7 @@ public class JpaConformanceProviderDstu2 extends ServerConformanceProvider {
public JpaConformanceProviderDstu2(){ public JpaConformanceProviderDstu2(){
super(); super();
super.setCache(false); super.setCache(false);
setIncludeResourceCounts(true);
} }
/** /**
@ -72,13 +72,17 @@ public class JpaConformanceProviderDstu2 extends ServerConformanceProvider {
mySystemDao = theSystemDao; mySystemDao = theSystemDao;
myDaoConfig = theDaoConfig; myDaoConfig = theDaoConfig;
super.setCache(false); super.setCache(false);
setIncludeResourceCounts(true);
} }
@Override @Override
public Conformance getServerConformance(HttpServletRequest theRequest) { public Conformance getServerConformance(HttpServletRequest theRequest) {
Conformance retVal = myCachedValue; Conformance retVal = myCachedValue;
Map<String, Long> counts = mySystemDao.getResourceCounts(); Map<String, Long> counts = Collections.emptyMap();
if (myIncludeResourceCounts) {
counts = mySystemDao.getResourceCounts();
}
FhirContext ctx = myRestfulServer.getFhirContext(); FhirContext ctx = myRestfulServer.getFhirContext();
@ -119,6 +123,10 @@ public class JpaConformanceProviderDstu2 extends ServerConformanceProvider {
return retVal; return retVal;
} }
public boolean isIncludeResourceCounts() {
return myIncludeResourceCounts;
}
public void setDaoConfig(DaoConfig myDaoConfig) { public void setDaoConfig(DaoConfig myDaoConfig) {
this.myDaoConfig = myDaoConfig; this.myDaoConfig = myDaoConfig;
} }
@ -128,6 +136,10 @@ public class JpaConformanceProviderDstu2 extends ServerConformanceProvider {
myImplementationDescription = theImplDesc; myImplementationDescription = theImplDesc;
} }
public void setIncludeResourceCounts(boolean theIncludeResourceCounts) {
myIncludeResourceCounts = theIncludeResourceCounts;
}
@Override @Override
public void setRestfulServer(RestfulServer theRestfulServer) { public void setRestfulServer(RestfulServer theRestfulServer) {
this.myRestfulServer = theRestfulServer; this.myRestfulServer = theRestfulServer;

View File

@ -1,7 +1,5 @@
package ca.uhn.fhir.jpa.provider.dstu3; package ca.uhn.fhir.jpa.provider.dstu3;
import java.util.Collection;
/* /*
* #%L * #%L
* HAPI FHIR JPA Server * HAPI FHIR JPA Server
@ -21,23 +19,18 @@ import java.util.Collection;
* limitations under the License. * limitations under the License.
* #L% * #L%
*/ */
import java.util.*;
import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.hl7.fhir.dstu3.model.*; import org.hl7.fhir.dstu3.model.*;
import org.hl7.fhir.dstu3.model.CapabilityStatement.*; import org.hl7.fhir.dstu3.model.CapabilityStatement.*;
import org.hl7.fhir.dstu3.model.Enumerations.SearchParamType; import org.hl7.fhir.dstu3.model.Enumerations.SearchParamType;
import org.springframework.beans.factory.annotation.Autowired;
import ca.uhn.fhir.context.BaseRuntimeElementDefinition;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.context.RuntimeSearchParam; import ca.uhn.fhir.context.RuntimeSearchParam;
import ca.uhn.fhir.jpa.dao.DaoConfig; import ca.uhn.fhir.jpa.dao.DaoConfig;
import ca.uhn.fhir.jpa.dao.IFhirSystemDao; import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
import ca.uhn.fhir.jpa.dao.ISearchParamRegistry;
import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.util.CoverageIgnore; import ca.uhn.fhir.util.CoverageIgnore;
import ca.uhn.fhir.util.ExtensionConstants; import ca.uhn.fhir.util.ExtensionConstants;
@ -47,9 +40,10 @@ public class JpaConformanceProviderDstu3 extends org.hl7.fhir.dstu3.hapi.rest.se
private volatile CapabilityStatement myCachedValue; private volatile CapabilityStatement myCachedValue;
private DaoConfig myDaoConfig; private DaoConfig myDaoConfig;
private String myImplementationDescription; private String myImplementationDescription;
private boolean myIncludeResourceCounts;
private RestfulServer myRestfulServer; private RestfulServer myRestfulServer;
private IFhirSystemDao<Bundle, Meta> mySystemDao; private IFhirSystemDao<Bundle, Meta> mySystemDao;
/** /**
* Constructor * Constructor
*/ */
@ -57,8 +51,9 @@ public class JpaConformanceProviderDstu3 extends org.hl7.fhir.dstu3.hapi.rest.se
public JpaConformanceProviderDstu3(){ public JpaConformanceProviderDstu3(){
super(); super();
super.setCache(false); super.setCache(false);
setIncludeResourceCounts(true);
} }
/** /**
* Constructor * Constructor
*/ */
@ -68,15 +63,17 @@ public class JpaConformanceProviderDstu3 extends org.hl7.fhir.dstu3.hapi.rest.se
mySystemDao = theSystemDao; mySystemDao = theSystemDao;
myDaoConfig = theDaoConfig; myDaoConfig = theDaoConfig;
super.setCache(false); super.setCache(false);
setIncludeResourceCounts(true);
} }
@Override @Override
public CapabilityStatement getServerConformance(HttpServletRequest theRequest) { public CapabilityStatement getServerConformance(HttpServletRequest theRequest) {
CapabilityStatement retVal = myCachedValue; CapabilityStatement retVal = myCachedValue;
Map<String, Long> counts = mySystemDao.getResourceCounts(); Map<String, Long> counts = Collections.emptyMap();
if (myIncludeResourceCounts) {
FhirContext ctx = myRestfulServer.getFhirContext(); counts = mySystemDao.getResourceCounts();
}
retVal = super.getServerConformance(theRequest); retVal = super.getServerConformance(theRequest);
for (CapabilityStatementRestComponent nextRest : retVal.getRest()) { for (CapabilityStatementRestComponent nextRest : retVal.getRest()) {
@ -148,6 +145,10 @@ public class JpaConformanceProviderDstu3 extends org.hl7.fhir.dstu3.hapi.rest.se
return retVal; return retVal;
} }
public boolean isIncludeResourceCounts() {
return myIncludeResourceCounts;
}
/** /**
* Subclasses may override * Subclasses may override
*/ */
@ -164,6 +165,10 @@ public class JpaConformanceProviderDstu3 extends org.hl7.fhir.dstu3.hapi.rest.se
myImplementationDescription = theImplDesc; myImplementationDescription = theImplDesc;
} }
public void setIncludeResourceCounts(boolean theIncludeResourceCounts) {
myIncludeResourceCounts = theIncludeResourceCounts;
}
@Override @Override
public void setRestfulServer(RestfulServer theRestfulServer) { public void setRestfulServer(RestfulServer theRestfulServer) {
this.myRestfulServer = theRestfulServer; this.myRestfulServer = theRestfulServer;

View File

@ -116,6 +116,10 @@
a resource ID that previously existed but is now deleted. Thanks to Artem a resource ID that previously existed but is now deleted. Thanks to Artem
Sopin for reporting! Sopin for reporting!
</action> </action>
<action type="add">
JpaConformanceProvider now has a configuration setting to enable and
disable adding resource counts to the server metadata.
</action>
</release> </release>
<release version="2.5" date="2017-06-08"> <release version="2.5" date="2017-06-08">
<action type="fix"> <action type="fix">