Search in sources :

Example 16 with BadServerUriException

use of net.geoprism.dhis2.dhis2adapter.exception.BadServerUriException in project geoprism-registry by terraframe.

the class SynchronizationConfigService method getConfigForExternalSystem.

@Request(RequestType.SESSION)
public JsonObject getConfigForExternalSystem(String sessionId, String externalSystemId, String hierarchyTypeCode) {
    JsonObject ret = new JsonObject();
    // Add GeoObjectTypes
    GeoObjectType[] gots = ServiceFactory.getRegistryService().getGeoObjectTypes(sessionId, null, new String[] { hierarchyTypeCode }, PermissionContext.WRITE);
    CustomSerializer serializer = ServiceFactory.getRegistryService().serializer(sessionId);
    JsonArray jarray = new JsonArray();
    for (int i = 0; i < gots.length; ++i) {
        jarray.add(gots[i].toJSON(serializer));
    }
    ret.add("types", jarray);
    // Add DHIS2 OrgUnitGroups
    DHIS2ExternalSystem system = DHIS2ExternalSystem.get(externalSystemId);
    try {
        DHIS2TransportServiceIF dhis2 = DHIS2ServiceFactory.buildDhis2TransportService(system);
        JsonArray jaGroups = new JsonArray();
        MetadataGetResponse<OrganisationUnitGroup> resp = dhis2.<OrganisationUnitGroup>metadataGet(OrganisationUnitGroup.class);
        List<OrganisationUnitGroup> groups = resp.getObjects();
        for (OrganisationUnitGroup group : groups) {
            JsonObject joGroup = new JsonObject();
            joGroup.addProperty("id", group.getId());
            joGroup.addProperty("name", group.getName());
            jaGroups.add(joGroup);
        }
        ret.add("orgUnitGroups", jaGroups);
    } catch (InvalidLoginException e) {
        LoginException cgrlogin = new LoginException(e);
        throw cgrlogin;
    } catch (HTTPException | UnexpectedResponseException | IllegalArgumentException | BadServerUriException e) {
        HttpError cgrhttp = new HttpError(e);
        throw cgrhttp;
    }
    return ret;
}
Also used : DHIS2TransportServiceIF(net.geoprism.registry.etl.export.dhis2.DHIS2TransportServiceIF) HTTPException(net.geoprism.dhis2.dhis2adapter.exception.HTTPException) DHIS2ExternalSystem(net.geoprism.registry.graph.DHIS2ExternalSystem) JsonObject(com.google.gson.JsonObject) CustomSerializer(org.commongeoregistry.adapter.metadata.CustomSerializer) BadServerUriException(net.geoprism.dhis2.dhis2adapter.exception.BadServerUriException) JsonArray(com.google.gson.JsonArray) OrganisationUnitGroup(net.geoprism.dhis2.dhis2adapter.response.model.OrganisationUnitGroup) GeoObjectType(org.commongeoregistry.adapter.metadata.GeoObjectType) InvalidLoginException(net.geoprism.dhis2.dhis2adapter.exception.InvalidLoginException) LoginException(net.geoprism.registry.etl.export.LoginException) InvalidLoginException(net.geoprism.dhis2.dhis2adapter.exception.InvalidLoginException) UnexpectedResponseException(net.geoprism.dhis2.dhis2adapter.exception.UnexpectedResponseException) HttpError(net.geoprism.registry.etl.export.HttpError) Request(com.runwaysdk.session.Request)

Aggregations

HTTPException (net.geoprism.dhis2.dhis2adapter.exception.HTTPException)12 BadServerUriException (net.geoprism.dhis2.dhis2adapter.exception.BadServerUriException)7 URISyntaxException (java.net.URISyntaxException)6 InvalidLoginException (net.geoprism.dhis2.dhis2adapter.exception.InvalidLoginException)6 HttpError (net.geoprism.registry.etl.export.HttpError)6 LoginException (net.geoprism.registry.etl.export.LoginException)6 JsonObject (com.google.gson.JsonObject)5 IOException (java.io.IOException)5 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)5 JsonArray (com.google.gson.JsonArray)4 UnexpectedResponseException (net.geoprism.dhis2.dhis2adapter.exception.UnexpectedResponseException)4 NameValuePair (org.apache.http.NameValuePair)4 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)4 ArrayList (java.util.ArrayList)3 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)2 Request (com.runwaysdk.session.Request)2 DHIS2Response (net.geoprism.dhis2.dhis2adapter.response.DHIS2Response)2 Attribute (net.geoprism.dhis2.dhis2adapter.response.model.Attribute)2 Option (net.geoprism.dhis2.dhis2adapter.response.model.Option)2 OrganisationUnitGroup (net.geoprism.dhis2.dhis2adapter.response.model.OrganisationUnitGroup)2