use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class TrackedEntityInstanceRowCallbackHandler method getTei.
private TrackedEntityInstance getTei(ResultSet rs) throws SQLException {
TrackedEntityInstance tei = new TrackedEntityInstance();
tei.setTrackedEntityInstance(rs.getString(getColumnName(UID)));
tei.setOrgUnit(rs.getString(getColumnName(ORGUNIT_UID)));
tei.setTrackedEntityType(rs.getString(getColumnName(TYPE_UID)));
tei.setCreated(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(CREATED))));
tei.setCreatedAtClient(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(CREATEDCLIENT))));
setUserInfoSnapshot(rs, getColumnName(CREATED_BY), tei::setCreatedByUserInfo);
tei.setLastUpdated(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(UPDATED))));
tei.setLastUpdatedAtClient(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(UPDATEDCLIENT))));
setUserInfoSnapshot(rs, getColumnName(LAST_UPDATED_BY), tei::setLastUpdatedByUserInfo);
tei.setInactive(rs.getBoolean(getColumnName(INACTIVE)));
tei.setDeleted(rs.getBoolean(getColumnName(DELETED)));
Optional<Geometry> geo = MapperGeoUtils.resolveGeometry(rs.getBytes(getColumnName(GEOMETRY)));
if (geo.isPresent()) {
tei.setGeometry(geo.get());
tei.setFeatureType(FeatureType.getTypeFromName(geo.get().getGeometryType()));
tei.setCoordinates(GeoUtils.getCoordinatesFromGeometry(geo.get()));
}
return tei;
}
use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class DefaultTrackedEntityInstanceStore method getTrackedEntityInstancesPartitioned.
private Map<String, TrackedEntityInstance> getTrackedEntityInstancesPartitioned(List<Long> ids, AggregateContext ctx) {
TrackedEntityInstanceRowCallbackHandler handler = new TrackedEntityInstanceRowCallbackHandler();
if (!ctx.isSuperUser() && ctx.getTrackedEntityTypes().isEmpty()) {
// empty list.
return new HashMap<>();
}
String sql = getQuery(GET_TEIS_SQL, ctx, "tei.trackedentitytypeid in (:teiTypeIds)", FILTER_OUT_DELETED_TEIS);
jdbcTemplate.query(applySortOrder(sql, StringUtils.join(ids, ","), "trackedentityinstanceid"), createIdsParam(ids).addValue("teiTypeIds", ctx.getTrackedEntityTypes()), handler);
return handler.getItems();
}
use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class TrackerCrudTest method shouldDeleteTrackedEntityWithDeleteStrategy.
@Test
void shouldDeleteTrackedEntityWithDeleteStrategy() {
List<TrackedEntityInstance> trackedEntityInstanceList = Collections.singletonList(trackedEntityInstance);
when(defaultTrackedEntityInstanceService.trackedEntityInstanceExists(trackedEntityInstanceUid)).thenReturn(true);
when(importOptions.getImportStrategy()).thenReturn(ImportStrategy.DELETE);
ImportSummaries importSummaries = trackedEntityInstanceService.mergeOrDeleteTrackedEntityInstances(trackedEntityInstanceList, importOptions, jobConfiguration);
assertFalse(importSummaries.getImportSummaries().stream().anyMatch(is -> is.isStatus(ImportStatus.ERROR)));
verify(defaultTrackedEntityInstanceService, times(1)).deleteTrackedEntityInstance(any());
}
use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class TrackerCrudTest method shouldAddTrackedEntityWithCreateStrategy.
@Test
void shouldAddTrackedEntityWithCreateStrategy() {
List<TrackedEntityInstance> trackedEntityInstanceList = Collections.singletonList(trackedEntityInstance);
when(importOptions.getImportStrategy()).thenReturn(ImportStrategy.CREATE);
ImportSummaries importSummaries = trackedEntityInstanceService.mergeOrDeleteTrackedEntityInstances(trackedEntityInstanceList, importOptions, jobConfiguration);
assertFalse(importSummaries.getImportSummaries().stream().anyMatch(is -> is.isStatus(ImportStatus.ERROR)));
verify(defaultTrackedEntityInstanceService, times(1)).addTrackedEntityInstance(any());
}
use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class TrackerTest method deleteOneEnrollment.
public Enrollment deleteOneEnrollment(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance trackedEntityInstance) {
List<Enrollment> enrollments = trackedEntityInstance.getEnrollments();
assertThat(enrollments, is(not(empty())));
Enrollment enrollment = enrollments.get(0);
ImportSummary importSummary = enrollmentService.deleteEnrollment(enrollment.getEnrollment());
assertEquals(0, importSummary.getConflictCount());
return enrollment;
}
Aggregations