use of net.geoprism.dhis2.dhis2adapter.response.DHIS2Response in project geoprism-registry by terraframe.
the class Dhis2IdCache method fetchIds.
/**
* Fetches more ids from DHIS2 and adds them to our internal cache.
*
* @throws HTTPException
* @throws InvalidLoginException
* @throws UnexpectedResponseException
* @throws BadServerUriException
*/
public DHIS2Response fetchIds() throws HTTPException, InvalidLoginException, UnexpectedResponseException, BadServerUriException {
List<NameValuePair> nvp = new ArrayList<NameValuePair>();
nvp.add(new BasicNameValuePair("limit", String.valueOf(FETCH_NUM)));
DHIS2Response response = dhis2.apiGet("system/id.json", nvp);
if (response.getStatusCode() != 200) {
throw new HTTPException("Unable to get new ids from DHIS2. " + response.getResponse());
}
JsonObject json = response.getJsonObject();
if (json.has("codes")) {
JsonArray codes = json.get("codes").getAsJsonArray();
for (int i = 0; i < codes.size(); ++i) {
String id = codes.get(i).getAsString();
cache.push(id);
}
} else {
throw new UnexpectedResponseException(response);
}
return response;
}
use of net.geoprism.dhis2.dhis2adapter.response.DHIS2Response in project geoprism-registry by terraframe.
the class HTTPConnector method httpPatch.
public DHIS2Response httpPatch(String url, List<NameValuePair> params, HttpEntity body) throws InvalidLoginException, HTTPException, BadServerUriException {
try {
if (!isInitialized()) {
initialize();
}
HttpPatch patch = new HttpPatch(this.buildUri(url, params));
patch.addHeader("Content-Type", "application/json");
patch.setEntity(body);
try (CloseableHttpResponse response = client.execute(patch, this.getContext())) {
return this.convertResponse(response);
}
} catch (IOException | URISyntaxException e) {
throw new HTTPException(e);
}
}
use of net.geoprism.dhis2.dhis2adapter.response.DHIS2Response in project geoprism-registry by terraframe.
the class HTTPConnector method httpGet.
public DHIS2Response httpGet(String url, List<NameValuePair> params) throws InvalidLoginException, HTTPException, BadServerUriException {
try {
if (!isInitialized()) {
initialize();
}
HttpGet get = new HttpGet(this.buildUri(url, params));
get.addHeader("Accept", "application/json");
try (CloseableHttpResponse response = client.execute(get, getContext())) {
return this.convertResponse(response);
}
} catch (URISyntaxException | IOException e) {
throw new HTTPException(e);
}
}
use of net.geoprism.dhis2.dhis2adapter.response.DHIS2Response in project geoprism-registry by terraframe.
the class DHIS2BridgeTest method testSystemInfo.
@Test
public void testSystemInfo() throws Exception {
String file = IOUtils.toString(DHIS2BridgeTest.class.getResourceAsStream("/default/system-info.json"), "UTF-8");
DHIS2Bridge facade = TestBridgeBuilder.buildDefault(file, 200);
facade.initialize();
DHIS2Response resp = facade.systemInfo();
Assert.assertEquals(200, resp.getStatusCode());
JsonObject jo = resp.getJsonObject();
Assert.assertEquals("2.31.9", jo.get("version").getAsString());
Assert.assertEquals(Constants.DHIS2_URL, jo.get("contextPath").getAsString());
}
use of net.geoprism.dhis2.dhis2adapter.response.DHIS2Response in project geoprism-registry by terraframe.
the class DHIS2BridgeTest method testEntityIdGet.
// @Test
// public void testMetadataGet() throws Exception
// {
// List<NameValuePair> params = new ArrayList<NameValuePair>();
// params.add(new BasicNameValuePair("organisationUnits", "true"));
// params.add(new BasicNameValuePair("code", "OU_525"));
//
// DHIS2Response resp = facade.metadataGet(params);
//
// System.out.println(resp.getResponse());
// }
@Test
public void testEntityIdGet() throws Exception {
String file = IOUtils.toString(DHIS2BridgeTest.class.getResourceAsStream("/default/entityId-organisationUnit.json"), "UTF-8");
DHIS2Bridge facade = TestBridgeBuilder.buildDefault(file, 200);
facade.initialize();
List<NameValuePair> params = new ArrayList<NameValuePair>();
// params.add(new BasicNameValuePair("organisationUnits", "true"));
// params.add(new BasicNameValuePair("code", "OU_525"));
DHIS2Response resp = facade.entityIdGet("organisationUnits", "ImspTQPwCqd", params);
// System.out.println(resp.getResponse());
}
Aggregations