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;
}
Aggregations