use of org.hisp.dhis.client.sdk.models.organisationunit.OrganisationUnit in project pictureapp by EyeSeeTea.
the class PullDhisSDKDataSource method pullData.
public void pullData(PullFilters pullFilters, List<OrganisationUnit> organisationUnits, IDataSourceCallback<List<Event>> callback) {
boolean isNetworkAvailable = isNetworkAvailable();
if (!isNetworkAvailable) {
callback.onError(new NetworkException());
} else {
try {
List<Event> events = new ArrayList<>();
for (OrganisationUnit organisationUnit : organisationUnits) {
Scheduler pullEventsThread = Schedulers.newThread();
EventFilters eventFilters = new EventFilters();
eventFilters.setStartDate(pullFilters.getStartDate());
eventFilters.setEndDate(pullFilters.getEndDate());
eventFilters.setMaxEvents(pullFilters.getMaxEvents());
eventFilters.setOrganisationUnitUId(organisationUnit.getUId());
mPullDhisSDKDataSourceStrategy.setEventFilters(eventFilters);
List<Event> eventsByOrgUnit = D2.events().pull(eventFilters).subscribeOn(pullEventsThread).observeOn(pullEventsThread).toBlocking().single();
events.addAll(eventsByOrgUnit);
}
callback.onSuccess(events);
} catch (Exception e) {
callback.onError(e);
}
}
}
use of org.hisp.dhis.client.sdk.models.organisationunit.OrganisationUnit in project pictureapp by EyeSeeTea.
the class SdkPullController method getProgramAndOrganisationUnit.
/**
* This method gets a organisation unit and program for each program(with organisation units)
* and removes it(it removes the organisation unit and the program without organisation units)
*/
private static ProgramAndOrganisationUnitDict getProgramAndOrganisationUnit() {
if (sdkPrograms == null || sdkPrograms.size() == 0 || programsAndOrganisationUnits == null || programsAndOrganisationUnits.size() == 0) {
return null;
}
List<OrganisationUnit> organisationUnits = programsAndOrganisationUnits.get(sdkPrograms.get(0));
OrganisationUnit localOrganisationUnit = null;
if (organisationUnits == null || organisationUnits.size() == 0) {
programsAndOrganisationUnits.remove(sdkPrograms.get(0));
if (programsAndOrganisationUnits.size() == 0) {
return null;
} else {
organisationUnits = programsAndOrganisationUnits.get(sdkPrograms.get(0));
}
}
localOrganisationUnit = organisationUnits.get(0);
organisationUnits.remove(0);
return new ProgramAndOrganisationUnitDict(sdkPrograms.get(0), localOrganisationUnit);
}
use of org.hisp.dhis.client.sdk.models.organisationunit.OrganisationUnit in project pictureapp by EyeSeeTea.
the class SdkPullController method getOrganisationUnits.
/**
* Pull the OrganisationUnits (not work at this moment)
*/
//// FIXME: 16/11/2016 this method is throwing a timeout exception in dev server.
public static void getOrganisationUnits() {
Set<String> organisationUnitUid = new HashSet<String>();
for (org.hisp.dhis.client.sdk.models.program.Program program : sdkPrograms) {
for (OrganisationUnit organisationUnit : program.getOrganisationUnits()) {
organisationUnitUid.add(organisationUnit.getUId());
}
}
if (organisationUnitUid.size() == 0) {
return;
}
Observable<List<OrganisationUnit>> organisationUnitObservable2 = D2.organisationUnits().pull(organisationUnitUid);
organisationUnitObservable2.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<List<OrganisationUnit>>() {
@Override
public void call(List<OrganisationUnit> organisationUnits) {
Log.e(TAG, "OrganisationUnit: Done");
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
errorOnPull = true;
throwable.printStackTrace();
Log.e(TAG, "OrganisationUnit: " + throwable.getLocalizedMessage());
showException("Error pulling OrganisationUnit: ");
}
});
}
Aggregations