use of org.hisp.dhis.android.core.category.CategoryCombo in project dhis2-android-sdk by dhis2.
the class EventEndPointCall method call.
@Override
public Response<Payload<Event>> call() throws Exception {
synchronized (this) {
if (isExecuted) {
throw new IllegalStateException("Already executed");
}
isExecuted = true;
}
String lastSyncedEvents = resourceHandler.getLastUpdated(ResourceModel.Type.EVENT);
Response<Payload<Event>> eventsByLastUpdated;
if (eventQuery.getCategoryCombo() == null || eventQuery.getCategoryOption() == null) {
eventsByLastUpdated = eventService.getEvents(eventQuery.getOrgUnit(), eventQuery.getProgram(), eventQuery.getTrackedEntityInstance(), getSingleFields(), Event.lastUpdated.gt(lastSyncedEvents), Event.uid.in(eventQuery.getUIds()), Boolean.TRUE, eventQuery.getPage(), eventQuery.getPageSize()).execute();
} else {
CategoryCombo categoryCombo = eventQuery.getCategoryCombo();
CategoryOption categoryOption = eventQuery.getCategoryOption();
eventsByLastUpdated = eventService.getEvents(eventQuery.getOrgUnit(), eventQuery.getProgram(), eventQuery.getTrackedEntityInstance(), getSingleFields(), Event.lastUpdated.gt(lastSyncedEvents), Event.uid.in(eventQuery.getUIds()), Boolean.TRUE, eventQuery.getPage(), eventQuery.getPageSize(), categoryCombo.uid(), categoryOption.uid()).execute();
}
if (eventsByLastUpdated.isSuccessful() && eventsByLastUpdated.body().items() != null) {
List<Event> events = eventsByLastUpdated.body().items();
int size = events.size();
if (eventQuery.getPageLimit() > 0) {
size = eventQuery.getPageLimit();
}
for (int i = 0; i < size; i++) {
Transaction transaction = databaseAdapter.beginNewTransaction();
Event event = events.get(i);
try {
eventHandler.handle(event);
transaction.setSuccessful();
} catch (SQLiteConstraintException sql) {
// This catch is necessary to ignore events with bad foreign keys exception
// More info: If the foreign key have the flag
// DEFERRABLE INITIALLY DEFERRED this exception will be throw in transaction
// .end()
// And the rollback will be executed only when the database is closed.
// It is a reported as unfixed bug: https://issuetracker.google
// .com/issues/37001653
Log.d(this.getClass().getSimpleName(), sql.getMessage());
} finally {
transaction.end();
}
}
resourceHandler.handleResource(ResourceModel.Type.EVENT, serverDate);
}
return eventsByLastUpdated;
}
use of org.hisp.dhis.android.core.category.CategoryCombo in project dhis2-android-sdk by dhis2.
the class CategoryComboShould method map_from_json_string.
@Test
public void map_from_json_string() throws IOException, ParseException {
ObjectMapper objectMapper = Inject.objectMapper();
CategoryCombo combo = objectMapper.readValue("{" + "\"code\":\"BIRTHS\"," + "\"created\":\"2011-12-24T12:24:25.203\"," + "\"lastUpdated\":\"2016-04-18T16:04:34.745\"," + "\"name\":\"Births\"," + "\"id\":\"m2jTvAj5kkm\"," + "\"dataDimensionType\":\"DISAGGREGATION\"," + "\"displayName\":\"Births\"," + "\"publicAccess\":\"rw------\"," + "\"externalAccess\":false," + "\"isDefault\":false," + "\"skipTotal\":false," + "\"user\":{\"id\":\"GOLswS44mh8\"}," + "\"userGroupAccesses\":[]," + "\"attributeValues\":[]," + "\"categoryOptionCombos\":[" + "{\"id\":\"b19Ye0TWs1D\"}," + "{\"id\":\"YEmiuCcgNQI\"}," + "{\"id\":\"vP9xV78M67W\"}]," + "\"categories\":[" + "{\"id\":\"KfdsGBcoiCa\"}," + "{\"id\":\"cX5k9anHEHd\"}" + "]" + "}", CategoryCombo.class);
assertThat(combo.uid()).isEqualTo("m2jTvAj5kkm");
assertThat(combo.code()).isEqualTo("BIRTHS");
assertThat(combo.created()).isEqualTo(BaseIdentifiableObject.DATE_FORMAT.parse("2011-12-24T12:24:25.203"));
assertThat(combo.lastUpdated()).isEqualTo(BaseIdentifiableObject.DATE_FORMAT.parse("2016-04-18T16:04:34.745"));
assertThat(combo.name()).isEqualTo("Births");
assertThat(combo.displayName()).isEqualTo("Births");
assertThat(combo.isDefault()).isEqualTo(false);
// categories
assertThat(combo.categories().get(0).uid()).isEqualTo("KfdsGBcoiCa");
assertThat(combo.categories().get(1).uid()).isEqualTo("cX5k9anHEHd");
}
use of org.hisp.dhis.android.core.category.CategoryCombo in project dhis2-android-sdk by dhis2.
the class EventCallFactory method create.
public static EventEndPointCall create(Retrofit retrofit, DatabaseAdapter databaseAdapter, String orgUnit, int pageLimit, String categoryComboUID, String categoryOptionUID) {
EventService eventService = retrofit.create(EventService.class);
EventHandler eventHandler = HandlerFactory.createEventHandler(databaseAdapter);
ResourceHandler resourceHandler = HandlerFactory.createResourceHandler(databaseAdapter);
CategoryCombo categoryCombo = CategoryCombo.builder().uid(categoryComboUID).build();
CategoryOption categoryOption = CategoryOption.builder().uid(categoryOptionUID).build();
EventQuery eventQuery = EventQuery.Builder.create().withOrgUnit(orgUnit).withPageLimit(pageLimit).withCategoryComboAndCategoryOption(categoryCombo, categoryOption).build();
EventEndPointCall eventEndPointCall = new EventEndPointCall(eventService, databaseAdapter, resourceHandler, eventHandler, new Date(), eventQuery);
return eventEndPointCall;
}
use of org.hisp.dhis.android.core.category.CategoryCombo in project dhis2-android-sdk by dhis2.
the class CategoryComboCallFactory method create.
@NonNull
public static CategoryComboEndpointCall create(Retrofit retrofit, DatabaseAdapter databaseAdapter) {
CategoryComboService categoryComboService = retrofit.create(CategoryComboService.class);
ResponseValidator<CategoryCombo> categoryComboResponseValidator = new ResponseValidator<>();
CategoryComboHandler categoryComboHandler = HandlerFactory.createCategoryComboHandler(databaseAdapter);
ResourceHandler resourceHandler = HandlerFactory.createResourceHandler(databaseAdapter);
CategoryComboQuery categoryComboQuery = CategoryComboQuery.defaultQuery();
CategoryComboEndpointCall categoryComboEndpointCall = new CategoryComboEndpointCall(categoryComboQuery, categoryComboService, categoryComboResponseValidator, categoryComboHandler, resourceHandler, databaseAdapter, new Date());
return categoryComboEndpointCall;
}
Aggregations