Search in sources :

Example 1 with UnexpectedRemoteResponse

use of net.geoprism.registry.etl.export.UnexpectedRemoteResponse 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)

Example 2 with UnexpectedRemoteResponse

use of net.geoprism.registry.etl.export.UnexpectedRemoteResponse in project geoprism-registry by terraframe.

the class DHIS2FeatureService method getDHIS2Attributes.

private List<Attribute> getDHIS2Attributes(DHIS2TransportServiceIF dhis2) {
    try {
        MetadataGetResponse<Attribute> resp = dhis2.<Attribute>metadataGet(Attribute.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<Attribute> attrs = resp.getObjects();
        attrs.addAll(buildDefaultDhis2OrgUnitAttributes());
        return attrs;
    } catch (InvalidLoginException e) {
        LoginException cgrlogin = new LoginException(e);
        throw cgrlogin;
    } catch (HTTPException | BadServerUriException e) {
        HttpError cgrhttp = new HttpError(e);
        throw cgrhttp;
    }
}
Also used : HTTPException(net.geoprism.dhis2.dhis2adapter.exception.HTTPException) Attribute(net.geoprism.dhis2.dhis2adapter.response.model.Attribute) DefaultAttribute(org.commongeoregistry.adapter.constants.DefaultAttribute) InvalidLoginException(net.geoprism.dhis2.dhis2adapter.exception.InvalidLoginException) LoginException(net.geoprism.registry.etl.export.LoginException) InvalidLoginException(net.geoprism.dhis2.dhis2adapter.exception.InvalidLoginException) HttpError(net.geoprism.registry.etl.export.HttpError) BadServerUriException(net.geoprism.dhis2.dhis2adapter.exception.BadServerUriException) UnexpectedRemoteResponse(net.geoprism.registry.etl.export.UnexpectedRemoteResponse)

Example 3 with UnexpectedRemoteResponse

use of net.geoprism.registry.etl.export.UnexpectedRemoteResponse in project geoprism-registry by terraframe.

the class DHIS2FeatureService method validateDhis2Response.

public void validateDhis2Response(DHIS2Response resp) {
    if (!resp.isSuccess()) {
        if (resp.hasMessage()) {
            ExportRemoteException ere = new ExportRemoteException();
            ere.setRemoteError(resp.getMessage());
            throw ere;
        } else {
            UnexpectedRemoteResponse re = new UnexpectedRemoteResponse();
            throw re;
        }
    }
}
Also used : ExportRemoteException(net.geoprism.registry.etl.export.ExportRemoteException) UnexpectedRemoteResponse(net.geoprism.registry.etl.export.UnexpectedRemoteResponse)

Aggregations

UnexpectedRemoteResponse (net.geoprism.registry.etl.export.UnexpectedRemoteResponse)3 BadServerUriException (net.geoprism.dhis2.dhis2adapter.exception.BadServerUriException)2 HTTPException (net.geoprism.dhis2.dhis2adapter.exception.HTTPException)2 InvalidLoginException (net.geoprism.dhis2.dhis2adapter.exception.InvalidLoginException)2 HttpError (net.geoprism.registry.etl.export.HttpError)2 LoginException (net.geoprism.registry.etl.export.LoginException)2 Attribute (net.geoprism.dhis2.dhis2adapter.response.model.Attribute)1 Option (net.geoprism.dhis2.dhis2adapter.response.model.Option)1 OptionSet (net.geoprism.dhis2.dhis2adapter.response.model.OptionSet)1 ExportRemoteException (net.geoprism.registry.etl.export.ExportRemoteException)1 DefaultAttribute (org.commongeoregistry.adapter.constants.DefaultAttribute)1