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