Search in sources :

Example 86 with TrackedEntityInstance

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;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance)

Example 87 with TrackedEntityInstance

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();
}
Also used : TrackedEntityInstanceRowCallbackHandler(org.hisp.dhis.dxf2.events.trackedentity.store.mapper.TrackedEntityInstanceRowCallbackHandler) HashMap(java.util.HashMap)

Example 88 with TrackedEntityInstance

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());
}
Also used : ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) Strictness(org.mockito.quality.Strictness) BeforeEach(org.junit.jupiter.api.BeforeEach) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) TrackedEntityAttributeValueService(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService) Mock(org.mockito.Mock) DefaultTrackedEntityInstanceService(org.hisp.dhis.trackedentity.DefaultTrackedEntityInstanceService) ArrayList(java.util.ArrayList) Notifier(org.hisp.dhis.system.notification.Notifier) CALLS_REAL_METHODS(org.mockito.Mockito.CALLS_REAL_METHODS) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) DbmsManager(org.hisp.dhis.dbms.DbmsManager) Mockito.anyBoolean(org.mockito.Mockito.anyBoolean) User(org.hisp.dhis.user.User) Mockito.anyString(org.mockito.Mockito.anyString) ImportStatus(org.hisp.dhis.dxf2.importsummary.ImportStatus) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) EnrollmentService(org.hisp.dhis.dxf2.events.enrollment.EnrollmentService) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) UserService(org.hisp.dhis.user.UserService) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) IdSchemes(org.hisp.dhis.common.IdSchemes) RelationshipService(org.hisp.dhis.dxf2.events.relationship.RelationshipService) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Mockito.times(org.mockito.Mockito.times) AbstractTrackedEntityInstanceService(org.hisp.dhis.dxf2.events.trackedentity.AbstractTrackedEntityInstanceService) SchemaService(org.hisp.dhis.schema.SchemaService) Mockito.when(org.mockito.Mockito.when) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) QueryService(org.hisp.dhis.query.QueryService) Mockito.verify(org.mockito.Mockito.verify) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Test(org.junit.jupiter.api.Test) List(java.util.List) NotificationLevel(org.hisp.dhis.system.notification.NotificationLevel) Mockito.anyList(org.mockito.Mockito.anyList) TrackerAccessManager(org.hisp.dhis.trackedentity.TrackerAccessManager) CachingMap(org.hisp.dhis.commons.collection.CachingMap) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) Mockito.any(org.mockito.Mockito.any) Collections(java.util.Collections) IdScheme(org.hisp.dhis.common.IdScheme) Mockito.mock(org.mockito.Mockito.mock) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) Test(org.junit.jupiter.api.Test)

Example 89 with TrackedEntityInstance

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());
}
Also used : ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) Strictness(org.mockito.quality.Strictness) BeforeEach(org.junit.jupiter.api.BeforeEach) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) TrackedEntityAttributeValueService(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService) Mock(org.mockito.Mock) DefaultTrackedEntityInstanceService(org.hisp.dhis.trackedentity.DefaultTrackedEntityInstanceService) ArrayList(java.util.ArrayList) Notifier(org.hisp.dhis.system.notification.Notifier) CALLS_REAL_METHODS(org.mockito.Mockito.CALLS_REAL_METHODS) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) DbmsManager(org.hisp.dhis.dbms.DbmsManager) Mockito.anyBoolean(org.mockito.Mockito.anyBoolean) User(org.hisp.dhis.user.User) Mockito.anyString(org.mockito.Mockito.anyString) ImportStatus(org.hisp.dhis.dxf2.importsummary.ImportStatus) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) EnrollmentService(org.hisp.dhis.dxf2.events.enrollment.EnrollmentService) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) UserService(org.hisp.dhis.user.UserService) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) IdSchemes(org.hisp.dhis.common.IdSchemes) RelationshipService(org.hisp.dhis.dxf2.events.relationship.RelationshipService) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Mockito.times(org.mockito.Mockito.times) AbstractTrackedEntityInstanceService(org.hisp.dhis.dxf2.events.trackedentity.AbstractTrackedEntityInstanceService) SchemaService(org.hisp.dhis.schema.SchemaService) Mockito.when(org.mockito.Mockito.when) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) QueryService(org.hisp.dhis.query.QueryService) Mockito.verify(org.mockito.Mockito.verify) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Test(org.junit.jupiter.api.Test) List(java.util.List) NotificationLevel(org.hisp.dhis.system.notification.NotificationLevel) Mockito.anyList(org.mockito.Mockito.anyList) TrackerAccessManager(org.hisp.dhis.trackedentity.TrackerAccessManager) CachingMap(org.hisp.dhis.commons.collection.CachingMap) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) Mockito.any(org.mockito.Mockito.any) Collections(java.util.Collections) IdScheme(org.hisp.dhis.common.IdScheme) Mockito.mock(org.mockito.Mockito.mock) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) Test(org.junit.jupiter.api.Test)

Example 90 with TrackedEntityInstance

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;
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment)

Aggregations

TrackedEntityInstance (org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance)61 Test (org.junit.jupiter.api.Test)57 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)50 TrackedEntityInstanceParams (org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams)37 TrackedEntityInstanceQueryParams (org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams)34 Enrollment (org.hisp.dhis.dxf2.events.enrollment.Enrollment)29 Date (java.util.Date)26 TrackerTest (org.hisp.dhis.dxf2.TrackerTest)26 ArrayList (java.util.ArrayList)25 List (java.util.List)25 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)25 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)24 Event (org.hisp.dhis.dxf2.events.event.Event)23 Program (org.hisp.dhis.program.Program)22 ProgramInstance (org.hisp.dhis.program.ProgramInstance)21 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)20 Collectors (java.util.stream.Collectors)19 User (org.hisp.dhis.user.User)17 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)16 ImportStatus (org.hisp.dhis.dxf2.importsummary.ImportStatus)16