Package org.linuxforhealth.fhir.config
Class FHIRRequestContext
- java.lang.Object
-
- org.linuxforhealth.fhir.config.FHIRRequestContext
-
public class FHIRRequestContext extends java.lang.Object
This class is used to hold FHIR REST API context information. There are non-static methods for maintaining individual instances, as well as static methods for setting instances on and getting instances from thread local. The overall strategy is for the REST API servlet filter to retrieve the request context information, create an instance of this class and set it on the current thread for use by the FHIR Server as it processes the request.
-
-
Constructor Summary
Constructors Constructor Description FHIRRequestContext()
FHIRRequestContext(java.lang.String tenantId)
FHIRRequestContext(java.lang.String tenantId, java.lang.String dataStoreId)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
endMetric(MetricHandle mh)
Callback to indicate that the current MetricHandle has closed, so we should set the currentMetric to be its parent (which may be null if the current metric is a root-level metric).static FHIRRequestContext
get()
Returns the FHIRRequestContext on the current thread.static java.util.List<CallTimeMetric>
getAndResetMetrics()
Get a snapshot of the current collection of metric values and reset them.java.lang.String
getDataStoreId()
java.lang.Object
getExtendedOperationProperties(java.lang.String name)
get an extended Operation Context propertyHTTPHandlingPreference
getHandlingPreference()
java.util.Map<java.lang.String,java.util.List<java.lang.String>>
getHttpHeaders()
MetricHandle
getMetricHandle(java.lang.String name)
Get a handle to track a new instance of a call.java.lang.String
getOriginalRequestUri()
java.lang.String
getRequestShardKey()
Get the shard key string value provided by the request.java.lang.String
getRequestUniqueId()
HTTPReturnPreference
getReturnPreference()
java.lang.String
getTenantId()
boolean
isBulk()
the status of the FHIR requestboolean
isBulkTransactionConfigured()
boolean
isReadOnly()
Returns true iff the entire request can be processed using only reads in the persistence layer Permits persistence layer implementations to leverage read-only replicas if they are availableboolean
isReturnPreferenceDefault()
static void
remove()
Removes the FHIRRequestContext that's set on the current thread.static void
set(FHIRRequestContext context)
Sets the specified FHIRRequestContext instance on the current thread, so that it can be used by FHIR Server downstream processing.void
setBulk(boolean bulk)
set the bulk statusvoid
setBulkTransactionConfigured(boolean bulkTransactionConfigured)
void
setDataStoreId(java.lang.String datastoreId)
void
setExtendedOperationProperties(java.lang.String name, java.lang.Object value)
set an Operation Context propertyvoid
setHandlingPreference(HTTPHandlingPreference handlingPreference)
void
setHttpHeaders(java.util.Map<java.lang.String,java.util.List<java.lang.String>> httpHeaders)
void
setOriginalRequestUri(java.lang.String originalRequestUri)
void
setReadOnly(boolean flag)
Setter for the readOnly flagvoid
setRequestShardKey(java.lang.String k)
Set the shard key string value provided by the requestvoid
setReturnPreference(HTTPReturnPreference returnPreference)
void
setReturnPreferenceDefault(boolean returnPreferenceIsDefault)
void
setTenantId(java.lang.String tenantId)
java.lang.String
toString()
-
-
-
Constructor Detail
-
FHIRRequestContext
public FHIRRequestContext()
-
FHIRRequestContext
public FHIRRequestContext(java.lang.String tenantId) throws FHIRException
- Throws:
FHIRException
-
FHIRRequestContext
public FHIRRequestContext(java.lang.String tenantId, java.lang.String dataStoreId) throws FHIRException
- Throws:
FHIRException
-
-
Method Detail
-
getTenantId
public java.lang.String getTenantId()
-
isReadOnly
public boolean isReadOnly()
Returns true iff the entire request can be processed using only reads in the persistence layer Permits persistence layer implementations to leverage read-only replicas if they are available- Returns:
-
setReadOnly
public void setReadOnly(boolean flag)
Setter for the readOnly flag- Parameters:
flag
-
-
isBulk
public boolean isBulk()
the status of the FHIR request- Returns:
- the status of the FHIRRequest indicating bulk
-
setBulk
public void setBulk(boolean bulk)
set the bulk status- Parameters:
bulk
-
-
setTenantId
public void setTenantId(java.lang.String tenantId) throws FHIRException
- Parameters:
tenantId
- An alphanumeric string (optionally with '-' or '_' chars); not null- Throws:
FHIRException
-
getDataStoreId
public java.lang.String getDataStoreId()
-
setDataStoreId
public void setDataStoreId(java.lang.String datastoreId) throws FHIRException
- Throws:
FHIRException
-
setRequestShardKey
public void setRequestShardKey(java.lang.String k)
Set the shard key string value provided by the request- Parameters:
k
-
-
getRequestShardKey
public java.lang.String getRequestShardKey()
Get the shard key string value provided by the request. This value is not filtered in any way because the value eventually gets hashed into a short (2 byte integer number) before being used.- Returns:
-
setExtendedOperationProperties
public void setExtendedOperationProperties(java.lang.String name, java.lang.Object value)
set an Operation Context property- Parameters:
name
-value
-
-
getExtendedOperationProperties
public java.lang.Object getExtendedOperationProperties(java.lang.String name)
get an extended Operation Context property- Parameters:
name
-- Returns:
-
set
public static void set(FHIRRequestContext context)
Sets the specified FHIRRequestContext instance on the current thread, so that it can be used by FHIR Server downstream processing. This method is called when the FHIR Server starts processing a request.
-
get
public static FHIRRequestContext get()
Returns the FHIRRequestContext on the current thread. If it doesn't exist yet, this method will create a default instance and associate that with the current thread before returning it.
-
remove
public static void remove()
Removes the FHIRRequestContext that's set on the current thread. This method is called when the FHIR Server is finished processing a request.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getRequestUniqueId
public java.lang.String getRequestUniqueId()
-
getHandlingPreference
public HTTPHandlingPreference getHandlingPreference()
- Returns:
- the handlingPreference
-
setHandlingPreference
public void setHandlingPreference(HTTPHandlingPreference handlingPreference)
- Parameters:
handlingPreference
- the handlingPreference to set
-
getReturnPreference
public HTTPReturnPreference getReturnPreference()
- Returns:
- the returnPreference
-
setReturnPreference
public void setReturnPreference(HTTPReturnPreference returnPreference)
- Parameters:
returnPreference
- the returnPreference to set
-
getOriginalRequestUri
public java.lang.String getOriginalRequestUri()
- Returns:
- the originalRequestUri
-
setOriginalRequestUri
public void setOriginalRequestUri(java.lang.String originalRequestUri)
- Parameters:
originalRequestUri
- the originalRequestUri to set
-
getHttpHeaders
public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getHttpHeaders()
- Returns:
- the httpHeaders
-
setHttpHeaders
public void setHttpHeaders(java.util.Map<java.lang.String,java.util.List<java.lang.String>> httpHeaders)
- Parameters:
httpHeaders
- the httpHeaders to set
-
isReturnPreferenceDefault
public boolean isReturnPreferenceDefault()
- Returns:
- the returnPreferenceIsDefault
-
setReturnPreferenceDefault
public void setReturnPreferenceDefault(boolean returnPreferenceIsDefault)
- Parameters:
returnPreferenceIsDefault
- the returnPreferenceIsDefault to set
-
getMetricHandle
public MetricHandle getMetricHandle(java.lang.String name)
Get a handle to track a new instance of a call. Metric names must not include the forward slash '/' character because it is used as a path separator- Parameters:
name
-- Returns:
-
endMetric
protected void endMetric(MetricHandle mh)
Callback to indicate that the current MetricHandle has closed, so we should set the currentMetric to be its parent (which may be null if the current metric is a root-level metric).- Parameters:
mh
- the metric handle being closed- Throws:
java.lang.IllegalStateException
- if the given metric does not match the currentMetric value, indicating a programming error
-
getAndResetMetrics
public static java.util.List<CallTimeMetric> getAndResetMetrics()
Get a snapshot of the current collection of metric values and reset them.- Returns:
-
isBulkTransactionConfigured
public boolean isBulkTransactionConfigured()
- Returns:
- the bulkTransactionConfigured
-
setBulkTransactionConfigured
public void setBulkTransactionConfigured(boolean bulkTransactionConfigured)
- Parameters:
bulkTransactionConfigured
- the bulkTransactionConfigured to set
-
-