use of net.geoprism.dhis2.dhis2adapter.exception.BadServerUriException in project geoprism-registry by terraframe.
the class DHIS2SynchronizationManager method init.
// https://play.dhis2.org/2.35.1/api/metadata.xml?organisationUnits=true&filter=level:eq:1
private void init() {
if (this.ouLevel1 != null) {
return;
}
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("filter", "level:eq:1"));
try {
MetadataGetResponse<OrganisationUnit> resp = this.dhis2.metadataGet(OrganisationUnit.class, params);
this.service.validateDhis2Response(resp);
List<OrganisationUnit> orgUnits = resp.getObjects();
this.ouLevel1 = orgUnits;
} catch (InvalidLoginException e) {
LoginException cgrlogin = new LoginException(e);
throw cgrlogin;
} catch (HTTPException | BadServerUriException e) {
HttpError cgrhttp = new HttpError(e);
throw cgrhttp;
}
}
use of net.geoprism.dhis2.dhis2adapter.exception.BadServerUriException in project geoprism-registry by terraframe.
the class DHIS2OptionCache method init.
private void init() {
try {
MetadataGetResponse<OptionSet> resp = dhis2.<OptionSet>metadataGet(OptionSet.class);
if (!resp.isSuccess()) {
// if (resp.hasMessage())
// {
// ExportRemoteException ere = new ExportRemoteException();
// ere.setRemoteError(resp.getMessage());
// throw ere;
// }
// else
// {
UnexpectedRemoteResponse re = new UnexpectedRemoteResponse();
throw re;
// }
}
List<OptionSet> objects = resp.getObjects();
this.optionSets = new HashMap<String, IntegratedOptionSet>(objects.size());
for (OptionSet os : objects) {
this.optionSets.put(os.getId(), new IntegratedOptionSet(os));
}
if (this.optionSets.size() > 0) {
MetadataGetResponse<Option> resp2 = dhis2.<Option>metadataGet(Option.class);
if (!resp2.isSuccess()) {
// if (resp.hasMessage())
// {
// ExportRemoteException ere = new ExportRemoteException();
// ere.setRemoteError(resp.getMessage());
// throw ere;
// }
// else
// {
UnexpectedRemoteResponse re = new UnexpectedRemoteResponse();
throw re;
// }
}
List<Option> options = resp2.getObjects();
for (Option option : options) {
if (option.getOptionSetId() != null && this.optionSets.containsKey(option.getOptionSetId())) {
this.optionSets.get(option.getOptionSetId()).addOption(option);
}
}
}
} catch (InvalidLoginException e) {
LoginException cgrlogin = new LoginException(e);
throw cgrlogin;
} catch (HTTPException e) {
HttpError cgrhttp = new HttpError(e);
throw cgrhttp;
} catch (BadServerUriException e) {
HttpError cgrhttp = new HttpError(e);
throw cgrhttp;
}
}
use of net.geoprism.dhis2.dhis2adapter.exception.BadServerUriException in project geoprism-registry by terraframe.
the class DHIS2Bridge method fetchVersionRemoteServer.
private void fetchVersionRemoteServer() throws UnexpectedResponseException, InvalidLoginException, HTTPException, BadServerUriException {
DHIS2Response resp = this.systemInfo();
if (!resp.isSuccess()) {
throw new UnexpectedResponseException(resp);
}
Matcher m = null;
try {
JsonObject jo = resp.getJsonObject();
this.versionRemoteServer = jo.get("version").getAsString();
Pattern p = Pattern.compile("\\d+\\.(\\d+)\\.\\d+(-.+)?");
m = p.matcher(this.versionRemoteServer);
} catch (Throwable t) {
throw new UnexpectedResponseException(t, resp);
}
if (m.matches()) {
this.versionRemoteServerApi = Integer.parseInt(m.group(1));
} else {
throw new UnexpectedResponseException(resp);
}
}
use of net.geoprism.dhis2.dhis2adapter.exception.BadServerUriException 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.exception.BadServerUriException 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);
}
}
Aggregations