Search in sources :

Example 1 with OptionSet

use of net.geoprism.dhis2.dhis2adapter.response.model.OptionSet 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;
    }
}
Also used : HTTPException(net.geoprism.dhis2.dhis2adapter.exception.HTTPException) BadServerUriException(net.geoprism.dhis2.dhis2adapter.exception.BadServerUriException) UnexpectedRemoteResponse(net.geoprism.registry.etl.export.UnexpectedRemoteResponse) InvalidLoginException(net.geoprism.dhis2.dhis2adapter.exception.InvalidLoginException) LoginException(net.geoprism.registry.etl.export.LoginException) InvalidLoginException(net.geoprism.dhis2.dhis2adapter.exception.InvalidLoginException) Option(net.geoprism.dhis2.dhis2adapter.response.model.Option) HttpError(net.geoprism.registry.etl.export.HttpError) OptionSet(net.geoprism.dhis2.dhis2adapter.response.model.OptionSet)

Aggregations

BadServerUriException (net.geoprism.dhis2.dhis2adapter.exception.BadServerUriException)1 HTTPException (net.geoprism.dhis2.dhis2adapter.exception.HTTPException)1 InvalidLoginException (net.geoprism.dhis2.dhis2adapter.exception.InvalidLoginException)1 Option (net.geoprism.dhis2.dhis2adapter.response.model.Option)1 OptionSet (net.geoprism.dhis2.dhis2adapter.response.model.OptionSet)1 HttpError (net.geoprism.registry.etl.export.HttpError)1 LoginException (net.geoprism.registry.etl.export.LoginException)1 UnexpectedRemoteResponse (net.geoprism.registry.etl.export.UnexpectedRemoteResponse)1