Search in sources :

Example 1 with MetadataGetResponse

use of net.geoprism.dhis2.dhis2adapter.response.MetadataGetResponse 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);
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) MetadataGetResponse(net.geoprism.dhis2.dhis2adapter.response.MetadataGetResponse)

Example 2 with MetadataGetResponse

use of net.geoprism.dhis2.dhis2adapter.response.MetadataGetResponse in project geoprism-registry by terraframe.

the class DHIS2SynchronizationManager method init.

// https://play.dhis2.org/2.35.1/api/metadata.xml?organisationUnits=true&filter=level:eq:1
private void init() {
    if (this.ouLevel1 != null) {
        return;
    }
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("filter", "level:eq:1"));
    try {
        MetadataGetResponse<OrganisationUnit> resp = this.dhis2.metadataGet(OrganisationUnit.class, params);
        this.service.validateDhis2Response(resp);
        List<OrganisationUnit> orgUnits = resp.getObjects();
        this.ouLevel1 = orgUnits;
    } catch (InvalidLoginException e) {
        LoginException cgrlogin = new LoginException(e);
        throw cgrlogin;
    } catch (HTTPException | BadServerUriException e) {
        HttpError cgrhttp = new HttpError(e);
        throw cgrhttp;
    }
}
Also used : NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) OrganisationUnit(net.geoprism.dhis2.dhis2adapter.response.model.OrganisationUnit) HTTPException(net.geoprism.dhis2.dhis2adapter.exception.HTTPException) ArrayList(java.util.ArrayList) BadServerUriException(net.geoprism.dhis2.dhis2adapter.exception.BadServerUriException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) 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)

Example 3 with MetadataGetResponse

use of net.geoprism.dhis2.dhis2adapter.response.MetadataGetResponse 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 4 with MetadataGetResponse

use of net.geoprism.dhis2.dhis2adapter.response.MetadataGetResponse in project geoprism-registry by terraframe.

the class DHIS2BridgeTest method testMetadataGetAttributes.

@Test
public void testMetadataGetAttributes() throws Exception {
    String file = IOUtils.toString(DHIS2BridgeTest.class.getResourceAsStream("/default/metadataGet-attributes.json"), "UTF-8");
    DHIS2Bridge facade = TestBridgeBuilder.buildDefault(file, 200);
    facade.initialize();
    MetadataGetResponse<Attribute> metadataGetResp = facade.<Attribute>metadataGet(Attribute.class);
    List<Attribute> attrs = metadataGetResp.getObjects();
    Attribute testAttr = null;
    for (Attribute attr : attrs) {
        if (attr.getName().equals("Classification")) {
            testAttr = attr;
        }
    }
    Assert.assertNotNull(testAttr);
    Assert.assertEquals("CLASSIFICATION", testAttr.getCode());
    Assert.assertEquals(ValueType.TEXT, testAttr.getValueType());
    Assert.assertTrue(testAttr.getIndicatorAttribute());
    Assert.assertFalse(testAttr.getOptionAttribute());
    Assert.assertFalse(testAttr.getCategoryAttribute());
}
Also used : Attribute(net.geoprism.dhis2.dhis2adapter.response.model.Attribute) Test(org.junit.Test)

Example 5 with MetadataGetResponse

use of net.geoprism.dhis2.dhis2adapter.response.MetadataGetResponse 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)

Aggregations

BadServerUriException (net.geoprism.dhis2.dhis2adapter.exception.BadServerUriException)5 HTTPException (net.geoprism.dhis2.dhis2adapter.exception.HTTPException)5 InvalidLoginException (net.geoprism.dhis2.dhis2adapter.exception.InvalidLoginException)5 HttpError (net.geoprism.registry.etl.export.HttpError)5 LoginException (net.geoprism.registry.etl.export.LoginException)5 JsonArray (com.google.gson.JsonArray)3 JsonObject (com.google.gson.JsonObject)3 NameValuePair (org.apache.http.NameValuePair)3 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)3 ProgrammingErrorException (com.runwaysdk.dataaccess.ProgrammingErrorException)2 ArrayList (java.util.ArrayList)2 MetadataGetResponse (net.geoprism.dhis2.dhis2adapter.response.MetadataGetResponse)2 Attribute (net.geoprism.dhis2.dhis2adapter.response.model.Attribute)2 OrganisationUnitGroup (net.geoprism.dhis2.dhis2adapter.response.model.OrganisationUnitGroup)2 UnexpectedRemoteResponse (net.geoprism.registry.etl.export.UnexpectedRemoteResponse)2 GsonBuilder (com.google.gson.GsonBuilder)1 Request (com.runwaysdk.session.Request)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1