use of net.geoprism.dhis2.dhis2adapter.exception.HTTPException in project geoprism-registry by terraframe.
the class DHIS2Bridge method metadataGet.
public <T> MetadataGetResponse<T> metadataGet(Class<?> dhis2Type, List<NameValuePair> params) throws InvalidLoginException, HTTPException, BadServerUriException {
String objectNamePlural = DHIS2Objects.getPluralObjectNameFromClass(dhis2Type);
if (params == null) {
params = new ArrayList<NameValuePair>();
}
boolean hasObjectName = false;
for (NameValuePair param : params) {
if (param.getName().equals(objectNamePlural)) {
hasObjectName = true;
}
}
if (!hasObjectName) {
params.add(new BasicNameValuePair(objectNamePlural, "true"));
}
return new MetadataGetResponse<T>(this.apiGet("metadata", params), objectNamePlural, dhis2Type);
}
use of net.geoprism.dhis2.dhis2adapter.exception.HTTPException in project geoprism-registry by terraframe.
the class HTTPConnector method httpPost.
// public HTTPResponse postAsMultipart(String url, File file)
// {
// try {
// if (!isInitialized())
// {
// initialize();
// }
//
// HttpPost post = new HttpPost(this.getServerUrl() + url);
//
// post.setRequestHeader("Content-Type", "multipart/form-data");
//
// FilePart filePart;
//
// filePart = new FilePart("form_def_file", file, "application/xml", "UTF-8");
//
//
// Part[] parts = { filePart };
// MultipartRequestEntity multipartRequestEntity = new MultipartRequestEntity(parts, post.getParams());
//
// post.setRequestEntity(multipartRequestEntity);
//
// HTTPResponse response = this.httpRequest(post);
//
// if (response.getStatusCode() == 401)
// {
// throw new InvalidLoginException("Unable to log in to " + this.getServerUrl());
// }
//
// return response;
// } catch (FileNotFoundException e) {
// throw new RuntimeException(e);
// }
// }
public DHIS2Response httpPost(String url, List<NameValuePair> params, HttpEntity body) throws InvalidLoginException, HTTPException, BadServerUriException {
try {
if (!isInitialized()) {
initialize();
}
HttpPost post = new HttpPost(this.buildUri(url, params));
post.addHeader("Content-Type", "application/json");
post.setEntity(body);
try (CloseableHttpResponse response = client.execute(post, this.getContext())) {
return this.convertResponse(response);
}
} catch (IOException | URISyntaxException e) {
throw new HTTPException(e);
}
}
use of net.geoprism.dhis2.dhis2adapter.exception.HTTPException in project geoprism-registry by terraframe.
the class HTTPConnector method httpDelete.
@Override
public DHIS2Response httpDelete(String url, List<NameValuePair> params) throws InvalidLoginException, HTTPException, BadServerUriException {
try {
if (!isInitialized()) {
initialize();
}
HttpDelete delete = new HttpDelete(this.buildUri(url, params));
delete.addHeader("Content-Type", "application/json");
try (CloseableHttpResponse response = client.execute(delete, getContext())) {
return this.convertResponse(response);
}
} catch (URISyntaxException | IOException e) {
throw new HTTPException(e);
}
}
use of net.geoprism.dhis2.dhis2adapter.exception.HTTPException in project geoprism-registry by terraframe.
the class HTTPConnector method httpPut.
public DHIS2Response httpPut(String url, List<NameValuePair> params, HttpEntity body) throws InvalidLoginException, HTTPException, BadServerUriException {
try {
if (!isInitialized()) {
initialize();
}
HttpPut post = new HttpPut(this.buildUri(url, params));
post.addHeader("Content-Type", "application/json");
post.setEntity(body);
try (CloseableHttpResponse response = client.execute(post, this.getContext())) {
return this.convertResponse(response);
}
} catch (IOException | URISyntaxException e) {
throw new HTTPException(e);
}
}
use of net.geoprism.dhis2.dhis2adapter.exception.HTTPException in project geoprism-registry by terraframe.
the class FakeIdConnector method httpGetSubclass.
@Override
public DHIS2Response httpGetSubclass(String string, List<NameValuePair> params) throws InvalidLoginException, HTTPException {
Integer limit = null;
for (int i = 0; i < params.size(); ++i) {
NameValuePair param = params.get(i);
if (param.getName().equals("limit")) {
limit = Integer.valueOf(param.getValue());
}
}
JsonArray codes = new JsonArray();
for (int i = 0; i < limit; ++i) {
codes.add(UUID.randomUUID().toString().substring(0, 11));
}
JsonObject resp = new JsonObject();
resp.add("codes", codes);
return new DHIS2Response(resp.toString(), 200);
}
Aggregations