Package org.hisp.dhis
Class BaseDhis2
java.lang.Object
org.hisp.dhis.BaseDhis2
- Direct Known Subclasses:
Dhis2
- Author:
- Lars Helge Overland
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final StringCategory combo fields.protected static final StringCategory fields.protected static final StringCategory option combo fields.protected static final StringCategory option fields.protected static final StringCategory option group fields.protected static final StringCategory option group set fields.protected final Dhis2Configprotected static final StringData element group set fields.protected static final StringData element fields.protected static final StringData element group set fields.protected static final StringData set fields.protected static final StringValidation Rules fields.protected static final Stringprotected static final Stringprotected final org.apache.hc.client5.http.impl.classic.CloseableHttpClientprotected static final Stringprotected static final StringIndicator fields.protected static final StringIndicator group set fields.protected static final StringIndicator type fields.protected static final StringMe / current user fields.protected static final Stringprotected final com.fasterxml.jackson.databind.ObjectMapperprotected static final StringOption set fields.protected static final StringOrg unit fields.protected static final StringOrg unit group set fields.protected static final StringProgram fields.protected static final StringProgram stage data element fields.protected static final Stringprotected static final StringTracked entity attribute fields.protected static final StringTracked entity type fields.protected static final Stringprotected static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected ResponseaddToCollection(String path, String id, String collection, String item) Adds the item to the collection of the entity with the given identifier.protected <T extends BaseHttpResponse>
TexecuteJsonPostPutRequest(org.apache.hc.client5.http.classic.methods.HttpUriRequestBase request, Object object, Class<T> type) Executes the givenHttpUriRequestBaserequest, which may be a POST or PUT request.protected ResponseexecuteRequest(org.apache.hc.client5.http.classic.methods.HttpUriRequestBase request) Executes the given request without attempting to parse a response body and returns a response message.protected URIgetAnalyticsQuery(org.apache.hc.core5.net.URIBuilder uriBuilder, AnalyticsQuery query) Returns aURIbased on the given analytics query.protected <T> TgetAnalyticsResponse(org.apache.hc.core5.net.URIBuilder uriBuilder, AnalyticsQuery query, Class<T> type) Retrieves an analytics object using HTTP GET.protected URIgetCompleteDataSetRegistrationQuery(org.apache.hc.core5.net.URIBuilder uriBuilder, CompleteDataSetRegistrationQuery query) Returns aURIbased on the given complete dataset registration query.protected URIgetDataSetValidationQuery(org.apache.hc.core5.net.URIBuilder uriBuilder, DataSetValidationQuery query) Returns aURIbased on the given dataSetValidation query.protected ValidationgetDataSetValidationResponse(org.apache.hc.core5.net.URIBuilder uriBuilder, DataSetValidationQuery query) Retrieves aValidationobject using HTTP GET.protected StringgetDataValueFileResponse(org.apache.hc.core5.net.URIBuilder uriBuilder, DataValueQuery query) Retrieves a dataValue object using HTTP GET.protected URIgetDataValueQuery(org.apache.hc.core5.net.URIBuilder uriBuilder, DataValueQuery query) Returns aURIbased on the given dataValue query.protected URIgetDataValueSetImportQuery(org.apache.hc.core5.net.URIBuilder uriBuilder, DataValueSetImportOptions options) Returns aURIbased on the given data value set import options.protected URIgetDataValueSetQuery(org.apache.hc.core5.net.URIBuilder uriBuilder, DataValueSetQuery query) Returns aURIbased on the given dataValueSet query.protected <T> TgetDataValueSetResponse(org.apache.hc.core5.net.URIBuilder uriBuilder, DataValueSetQuery query, Class<T> type) Retrieves a dataValueSet object using HTTP GET.protected URIgetEventsQuery(org.apache.hc.core5.net.URIBuilder uriBuilder, EventsQuery query) Returns aURIbased on the given events query.protected EventsResultgetEventsResponse(org.apache.hc.core5.net.URIBuilder uriBuilder, EventsQuery query) Retrieves events using HTTP GET.protected org.apache.hc.client5.http.impl.classic.CloseableHttpResponsegetJsonHttpResponse(URI url) Gets aCloseableHttpResponsefor the given URL.protected <T> TRetrieves an object using HTTP GET.protected <T> TRetrieves an object.protected <T> TRetrieves an object using HTTP GET.protected <T> TgetObjectFromUrl(URI url, Class<T> type) Retrieves an object using HTTP GET.protected URIgetObjectQuery(org.apache.hc.core5.net.URIBuilder uriBuilder, Query query) Returns aURIbased on the given query.protected org.apache.hc.client5.http.classic.methods.HttpPostgetPostRequest(URI url, org.apache.hc.core5.http.HttpEntity entity) Returns a HTTP post request with JSON content type for the given URL and entity.protected Dhis2ClientExceptionReturns aDhis2ClientExceptionbased on the given exception.protected booleanobjectExists(org.apache.hc.core5.net.URIBuilder uriBuilder) Indicates whether an object exists using HTTP HEAD.protected <T> TDeserializes the given JSON content to an object of the given type.protected ObjectResponseremoveMetadataObject(String path) Removes an object using HTTP DELETE.protected <T extends BaseHttpResponse>
TremoveObject(String path, Class<T> type) Removes an object using HTTP DELETE.protected CompleteDataSetRegistrationResponsesaveCompleteDataSetRegistrations(org.apache.hc.core5.http.HttpEntity entity, CompleteDataSetRegistrationImportOptions options) Save complete data set registrations according to complete data set registration import options.protected ObjectResponsesaveMetadataObject(String path, IdentifiableObject object) Saves a metadata object using HTTP POST.protected ObjectsResponsesaveMetadataObjects(Dhis2Objects objects) Saves or updates metadata objects.protected <T extends BaseHttpResponse>
TsaveObject(String path, Object object, Class<T> type) Saves an object using HTTP POST.protected <T extends BaseHttpResponse>
TsaveObject(org.apache.hc.core5.net.URIBuilder uriBuilder, Object object, Class<T> type) Saves an object using HTTP POST.protected StringtoJsonString(Object object) Serializes the given object to a JSON string.protected List<org.apache.hc.core5.http.NameValuePair>toNameValuePairs(Map<String, String> params) Converts the given map of query parameters to a list of name value pairs.protected ObjectResponseupdateMetadataObject(String path, IdentifiableObject object) Updates an object using HTTP PUT.protected <T extends BaseHttpResponse>
TUpdates an object using HTTP PUT.protected <T extends org.apache.hc.client5.http.classic.methods.HttpUriRequestBase>
TwithAuth(T request) Adds authentication to the given request.protected voidwriteToFile(org.apache.hc.client5.http.impl.classic.CloseableHttpResponse response, File file) Write the givenHttpResponseto the givenFile.
-
Field Details
-
FIELDS_PARAM
- See Also:
-
SKIP_SHARING_PARAM
- See Also:
-
ID_FIELDS
- See Also:
-
NAME_FIELDS
-
OPTION_SET_FIELDS
Option set fields. -
DATA_ELEMENT_FIELDS
Data element fields. -
DATA_ELEMENT_GROUP_SET_FIELDS
Data element group set fields. -
CATEGORY_OPTION_FIELDS
Category option fields. -
CATEGORY_OPTION_COMBO_FIELDS
Category option combo fields. -
CATEGORY_OPTION_GROUP_FIELDS
Category option group fields. -
CATEGORY_OPTION_GROUP_SET_FIELDS
Category option group set fields. -
CATEGORY_COMBO_FIELDS
Category combo fields. -
CATEGORY_FIELDS
Category fields. -
INDICATOR_TYPE_FIELDS
Indicator type fields. -
INDICATOR_FIELDS
Indicator fields. -
INDICATOR_GROUP_SET_FIELDS
Indicator group set fields. -
DATA_SET_FIELDS
Data set fields. -
ORG_UNIT_FIELDS
Org unit fields. -
ORG_UNIT_GROUP_SET_FIELDS
Org unit group set fields. -
TRACKED_ENTITY_ATTRIBUTE_FIELDS
Tracked entity attribute fields. -
PROGRAM_STAGE_DATA_ELEMENT_FIELDS
Program stage data element fields. -
TRACKED_ENTITY_TYPE_FIELDS
Tracked entity type fields. -
PROGRAM_FIELDS
Program fields. -
DASHBOARD_FIELDS
Data element group set fields. -
ME_FIELDS
Me / current user fields. -
DATA_SET_PARAM
Validation Rules fields.- See Also:
-
VALIDATION_SIDE_FIELDS
- See Also:
-
VALIDATION_RULE_FIELDS
-
DATA_SET_VALIDATION_FIELDS
-
config
-
objectMapper
protected final com.fasterxml.jackson.databind.ObjectMapper objectMapper -
httpClient
protected final org.apache.hc.client5.http.impl.classic.CloseableHttpClient httpClient
-
-
Constructor Details
-
BaseDhis2
-
-
Method Details
-
getObject
protected <T> T getObject(org.apache.hc.core5.net.URIBuilder uriBuilder, Query query, Class<T> type) Retrieves an object using HTTP GET.- Type Parameters:
T- type.- Parameters:
uriBuilder- the URI builder.query- theQueryfilters to apply.type- the class type of the object.- Returns:
- the object.
-
objectExists
protected boolean objectExists(org.apache.hc.core5.net.URIBuilder uriBuilder) Indicates whether an object exists using HTTP HEAD.- Parameters:
uriBuilder- the URI builder.- Returns:
- true if the object exists.
-
getObjectQuery
Returns aURIbased on the given query.- Parameters:
uriBuilder- the URI builder.query- theQueryfilters to apply.- Returns:
- a URI.
-
getDataValueSetResponse
protected <T> T getDataValueSetResponse(org.apache.hc.core5.net.URIBuilder uriBuilder, DataValueSetQuery query, Class<T> type) Retrieves a dataValueSet object using HTTP GET.- Type Parameters:
T- type.- Parameters:
uriBuilder- the URI builder.query- theDataValueSetQueryfilters to apply.type- the class type of the object.- Returns:
- the object.
-
getDataSetValidationResponse
protected Validation getDataSetValidationResponse(org.apache.hc.core5.net.URIBuilder uriBuilder, DataSetValidationQuery query) Retrieves aValidationobject using HTTP GET.- Parameters:
uriBuilder- the URI builder.query- theDataSetValidationQueryfilters to apply.- Returns:
- the object.
-
getDataValueFileResponse
protected String getDataValueFileResponse(org.apache.hc.core5.net.URIBuilder uriBuilder, DataValueQuery query) Retrieves a dataValue object using HTTP GET.- Parameters:
uriBuilder- the URI builder.query- theDataValueSetQueryfilters to apply.- Returns:
- the object.
-
getAnalyticsResponse
protected <T> T getAnalyticsResponse(org.apache.hc.core5.net.URIBuilder uriBuilder, AnalyticsQuery query, Class<T> type) Retrieves an analytics object using HTTP GET.- Type Parameters:
T- type.- Parameters:
uriBuilder- the URI builder.query- theAnalyticsQueryfilters to apply.type- the class type of the object.- Returns:
- the object.
-
getAnalyticsQuery
protected URI getAnalyticsQuery(org.apache.hc.core5.net.URIBuilder uriBuilder, AnalyticsQuery query) Returns aURIbased on the given analytics query.- Parameters:
uriBuilder- the URI builder.query- theAnalyticsQueryfilters to apply.- Returns:
- a URI.
-
getDataValueSetImportQuery
protected URI getDataValueSetImportQuery(org.apache.hc.core5.net.URIBuilder uriBuilder, DataValueSetImportOptions options) Returns aURIbased on the given data value set import options.- Parameters:
uriBuilder- the URI builder.options- theDataValueSetImportOptionsto apply.- Returns:
- a URI.
-
saveCompleteDataSetRegistrations
protected CompleteDataSetRegistrationResponse saveCompleteDataSetRegistrations(org.apache.hc.core5.http.HttpEntity entity, CompleteDataSetRegistrationImportOptions options) Save complete data set registrations according to complete data set registration import options.- Parameters:
entity- the POST bodyHttpEntity.options- theCompleteDataSetRegistrationImportOptionsimport options.- Returns:
- POST response body
CompleteDataSetRegistrationResponse.
-
getEventsResponse
protected EventsResult getEventsResponse(org.apache.hc.core5.net.URIBuilder uriBuilder, EventsQuery query) Retrieves events using HTTP GET.- Parameters:
uriBuilder- the URI builder.query- theEventsQuery.- Returns:
- the
Eventsobject.
-
getEventsQuery
Returns aURIbased on the given events query.- Parameters:
uriBuilder- the URI builder.query- theEventsQuery.- Returns:
- a URI.
-
getDataValueSetQuery
protected URI getDataValueSetQuery(org.apache.hc.core5.net.URIBuilder uriBuilder, DataValueSetQuery query) Returns aURIbased on the given dataValueSet query.- Parameters:
uriBuilder- the URI builder.query- theDataValueSetQuery.- Returns:
- a URI.
-
getDataValueQuery
protected URI getDataValueQuery(org.apache.hc.core5.net.URIBuilder uriBuilder, DataValueQuery query) Returns aURIbased on the given dataValue query.- Parameters:
uriBuilder- the URI builder.query- theDataValueQuery.- Returns:
- a URI.
-
getDataSetValidationQuery
protected URI getDataSetValidationQuery(org.apache.hc.core5.net.URIBuilder uriBuilder, DataSetValidationQuery query) Returns aURIbased on the given dataSetValidation query.- Parameters:
uriBuilder- the URI builder.query- theDataSetValidationQuery.- Returns:
- a URI.
-
getCompleteDataSetRegistrationQuery
protected URI getCompleteDataSetRegistrationQuery(org.apache.hc.core5.net.URIBuilder uriBuilder, CompleteDataSetRegistrationQuery query) Returns aURIbased on the given complete dataset registration query.- Parameters:
uriBuilder- the URI builder.query- theCompleteDataSetRegistrationQuery.- Returns:
- a URI.
-
getObject
Retrieves an object.- Type Parameters:
T- type.- Parameters:
path- the URL path.id- the object identifier.type- the class type of the object.- Returns:
- the object.
- Throws:
Dhis2ClientException- if access was denied or resource was not found.
-
executeJsonPostPutRequest
protected <T extends BaseHttpResponse> T executeJsonPostPutRequest(org.apache.hc.client5.http.classic.methods.HttpUriRequestBase request, Object object, Class<T> type) Executes the givenHttpUriRequestBaserequest, which may be a POST or PUT request.- Type Parameters:
T- class.- Parameters:
request- the request.object- the object to pass as JSON in the request body.type- the class type for the response entity.- Returns:
- a
Response. - Throws:
Dhis2ClientException- if access denied or resource not found.
-
executeRequest
protected Response executeRequest(org.apache.hc.client5.http.classic.methods.HttpUriRequestBase request) Executes the given request without attempting to parse a response body and returns a response message.- Parameters:
request- the request.- Returns:
- a response message.
- Throws:
Dhis2ClientException- if access denied or resource not found.
-
getPostRequest
protected org.apache.hc.client5.http.classic.methods.HttpPost getPostRequest(URI url, org.apache.hc.core5.http.HttpEntity entity) Returns a HTTP post request with JSON content type for the given URL and entity.- Parameters:
url- theURI.entity- theHttpEntity.- Returns:
- a
HttpPostrequest.
-
getObjectFromUrl
Retrieves an object using HTTP GET.- Type Parameters:
T- type.- Parameters:
url- the fully qualified URL.type- the class type of the object.- Returns:
- the object.
- Throws:
Dhis2ClientException- if access denied or resource not found.
-
getJsonHttpResponse
protected org.apache.hc.client5.http.impl.classic.CloseableHttpResponse getJsonHttpResponse(URI url) Gets aCloseableHttpResponsefor the given URL.- Parameters:
url- the URL.- Returns:
- a
CloseableHttpResponse.
-
readValue
Deserializes the given JSON content to an object of the given type.- Type Parameters:
T- type.- Parameters:
content- the JSON content.type- the object type.- Returns:
- an object.
- Throws:
IOException
-
writeToFile
protected void writeToFile(org.apache.hc.client5.http.impl.classic.CloseableHttpResponse response, File file) Write the givenHttpResponseto the givenFile.- Parameters:
response- the response.file- the file to write the response to.- Throws:
Dhis2ClientException- if the write operation failed.
-
withAuth
protected <T extends org.apache.hc.client5.http.classic.methods.HttpUriRequestBase> T withAuth(T request) Adds authentication to the given request.- Type Parameters:
T- class.- Parameters:
request- theHttpUriRequestBase.- Returns:
- the request.
-
toJsonString
Serializes the given object to a JSON string.- Parameters:
object- the object to serialize.- Returns:
- a JSON string representation of the object.
- Throws:
Dhis2ClientException- if the serialization failed.
-
newDhis2ClientException
Returns aDhis2ClientExceptionbased on the given exception.- Parameters:
ex- the exception.- Returns:
- a
Dhis2ClientException.
-
saveMetadataObject
Saves a metadata object using HTTP POST.- Parameters:
path- the URL path relative to the API end point.object- the object to save.- Returns:
ObjectResponseholding information about the operation.- Throws:
Dhis2ClientException- if the save operation failed due to client side error.
-
saveObject
Saves an object using HTTP POST.- Type Parameters:
T- class.- Parameters:
path- the URL path relative to the API end point.object- the object to save.type- the class type for the response entity.- Returns:
- object holding information about the operation.
- Throws:
Dhis2ClientException- if the save operation failed due to client side error.
-
saveObject
protected <T extends BaseHttpResponse> T saveObject(org.apache.hc.core5.net.URIBuilder uriBuilder, Object object, Class<T> type) Saves an object using HTTP POST.- Type Parameters:
T- class.- Parameters:
uriBuilder- the URI builder.object- the object to save.type- the class type for the response entity.- Returns:
- object holding information about the operation.
- Throws:
Dhis2ClientException- if the save operation failed due to client side error.
-
saveMetadataObjects
Saves or updates metadata objects.- Parameters:
objects- theDhis2Objects.- Returns:
ObjectsResponseholding information about the operation.
-
updateMetadataObject
Updates an object using HTTP PUT.- Parameters:
path- the URL path relative to the API end point.object- the object to save.- Returns:
ObjectResponseholding information about the operation.
-
updateObject
protected <T extends BaseHttpResponse> T updateObject(String path, Map<String, String> params, Object object, Class<T> type) Updates an object using HTTP PUT.- Type Parameters:
T- class.- Parameters:
path- the URL path relative to the API end point.params- the map of query parameter names and values to include in the URL.object- the object to save.type- the class type for the response entity.- Returns:
- object holding information about the operation.
-
removeMetadataObject
Removes an object using HTTP DELETE.- Parameters:
path- the URL path relative to the API end point.- Returns:
ObjectResponseholding information about the operation.
-
removeObject
Removes an object using HTTP DELETE.- Type Parameters:
T- class.- Parameters:
path- the URL path relative to the API end point.type- the class type for the response entity.- Returns:
- object holding information about the operation.
-
getObject
Retrieves an object using HTTP GET.- Type Parameters:
T- type.- Parameters:
path- the URL path relative to the API end point.type- the class type of the object.- Returns:
- the object.
-
toNameValuePairs
Converts the given map of query parameters to a list of name value pairs.- Parameters:
params- theMapwith query parameter names and values.- Returns:
- a list of
NameValuePair.
-
addToCollection
Adds the item to the collection of the entity with the given identifier.- Parameters:
path- the object path in plural.id- the object identifier.collection- the collection path.item- the item identifier.- Returns:
- a
Responseholding information about the operation.
-