Search in sources :

Example 21 with TrackedEntityInstance

use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.

the class TrackerCrudTest method shouldUpdateTrackedEntityWithUpdateStrategy.

@Test
void shouldUpdateTrackedEntityWithUpdateStrategy() {
    List<TrackedEntityInstance> trackedEntityInstanceList = Collections.singletonList(trackedEntityInstance);
    when(importOptions.getImportStrategy()).thenReturn(ImportStrategy.UPDATE);
    ImportSummaries importSummaries = trackedEntityInstanceService.mergeOrDeleteTrackedEntityInstances(trackedEntityInstanceList, importOptions, jobConfiguration);
    assertFalse(importSummaries.getImportSummaries().stream().anyMatch(is -> is.isStatus(ImportStatus.ERROR)));
    verify(defaultTrackedEntityInstanceService, times(1)).getTrackedEntityInstance(trackedEntityInstanceUid, user);
    verify(defaultTrackedEntityInstanceService, times(1)).updateTrackedEntityInstance(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 22 with TrackedEntityInstance

use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.

the class TrackedEntityInstanceServiceTest method testAddTrackedEntityInstancePotentialDuplicateFlag.

@Test
void testAddTrackedEntityInstancePotentialDuplicateFlag() {
    TrackedEntityInstance tei = new TrackedEntityInstance();
    tei.setOrgUnit(organisationUnitA.getUid());
    tei.setTrackedEntityInstance(CodeGenerator.generateUid());
    Attribute attribute = new Attribute("value");
    attribute.setAttribute(trackedEntityAttributeB.getUid());
    tei.getAttributes().add(attribute);
    tei.setTrackedEntityType(trackedEntityType.getUid());
    tei.setPotentialDuplicate(true);
    List<TrackedEntityInstance> teis = Lists.newArrayList(tei);
    ImportOptions importOptions = new ImportOptions();
    importOptions.setImportStrategy(ImportStrategy.CREATE);
    ImportSummaries importSummaries = trackedEntityInstanceService.addTrackedEntityInstances(teis, importOptions);
    assertEquals(ImportStatus.SUCCESS, importSummaries.getStatus());
    assertTrue(trackedEntityInstanceService.getTrackedEntityInstance(tei.getTrackedEntityInstance()).isPotentialDuplicate());
}
Also used : Attribute(org.hisp.dhis.dxf2.events.trackedentity.Attribute) TrackedEntityTypeAttribute(org.hisp.dhis.trackedentity.TrackedEntityTypeAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 23 with TrackedEntityInstance

use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.

the class TrackedEntityInstanceServiceTest method testTooLongTrackedEntityAttributeValue.

@Test
void testTooLongTrackedEntityAttributeValue() {
    TrackedEntityInstance tei = new TrackedEntityInstance();
    String testValue = StringUtils.repeat("x", 1201);
    Attribute attribute = new Attribute(testValue);
    attribute.setAttribute(trackedEntityAttributeB.getUid());
    tei.getAttributes().add(attribute);
    tei.setTrackedEntityType(trackedEntityType.getUid());
    List<TrackedEntityInstance> teis = Lists.newArrayList(tei);
    ImportOptions importOptions = new ImportOptions();
    importOptions.setImportStrategy(ImportStrategy.UPDATE);
    ImportSummaries importSummaries = trackedEntityInstanceService.addTrackedEntityInstances(teis, importOptions);
    assertEquals(ImportStatus.ERROR, importSummaries.getStatus());
    ImportSummary importSummary = importSummaries.getImportSummaries().get(0);
    assertEquals(1, importSummary.getConflictCount());
    assertEquals(String.format("Value exceeds the character limit of 1200 characters: '%s...'", testValue.substring(0, 25)), importSummary.getConflicts().iterator().next().getValue());
}
Also used : Attribute(org.hisp.dhis.dxf2.events.trackedentity.Attribute) TrackedEntityTypeAttribute(org.hisp.dhis.trackedentity.TrackedEntityTypeAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 24 with TrackedEntityInstance

use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.

the class TrackedEntityInstanceServiceTest method testUpdateTrackedEntityInstancePotentialDuplicateFlag.

@Test
void testUpdateTrackedEntityInstancePotentialDuplicateFlag() {
    assertFalse(trackedEntityInstanceService.getTrackedEntityInstance(maleA.getUid()).isPotentialDuplicate());
    TrackedEntityInstance trackedEntityInstance = trackedEntityInstanceService.getTrackedEntityInstance(maleA.getUid());
    trackedEntityInstance.setPotentialDuplicate(true);
    ImportOptions importOptions = new ImportOptions();
    importOptions.setImportStrategy(ImportStrategy.UPDATE);
    ImportSummary importSummaries = trackedEntityInstanceService.updateTrackedEntityInstance(trackedEntityInstance, null, importOptions, true);
    assertEquals(ImportStatus.SUCCESS, importSummaries.getStatus());
    assertTrue(trackedEntityInstanceService.getTrackedEntityInstance(maleA.getUid()).isPotentialDuplicate());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 25 with TrackedEntityInstance

use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.

the class EventController method queryEventsXml.

@GetMapping(value = "/query", produces = ContextUtils.CONTENT_TYPE_XML)
public void queryEventsXml(@RequestParam(required = false) String program, @RequestParam(required = false) String programStage, @RequestParam(required = false) ProgramStatus programStatus, @RequestParam(required = false) Boolean followUp, @RequestParam(required = false) String trackedEntityInstance, @RequestParam(required = false) String orgUnit, @RequestParam(required = false) OrganisationUnitSelectionMode ouMode, @RequestParam(required = false) AssignedUserSelectionMode assignedUserMode, @RequestParam(required = false) String assignedUser, @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @RequestParam(required = false) Date dueDateStart, @RequestParam(required = false) Date dueDateEnd, @RequestParam(required = false) Date lastUpdated, @RequestParam(required = false) Date lastUpdatedStartDate, @RequestParam(required = false) Date lastUpdatedEndDate, @RequestParam(required = false) EventStatus status, @RequestParam(required = false) String attributeCc, @RequestParam(required = false) String attributeCos, @RequestParam(required = false) boolean skipMeta, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer pageSize, @RequestParam(required = false) boolean totalPages, @RequestParam(required = false) Boolean skipPaging, @RequestParam(required = false) Boolean paging, @RequestParam(required = false) List<OrderCriteria> order, @RequestParam(required = false) String attachment, @RequestParam(required = false, defaultValue = "false") boolean includeDeleted, @RequestParam(required = false) String event, @RequestParam(required = false) Set<String> filter, @RequestParam(required = false) Set<String> dataElement, @RequestParam(required = false, defaultValue = "false") boolean includeAllDataElements, @RequestParam Map<String, String> parameters, IdSchemes idSchemes, Model model, HttpServletResponse response, HttpServletRequest request) throws Exception {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    CategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(attributeCc, attributeCos, false);
    if (attributeOptionCombo == null) {
        throw new WebMessageException(conflict("Illegal attribute option combo identifier: " + attributeCc + " " + attributeCos));
    }
    Set<String> eventIds = TextUtils.splitToArray(event, TextUtils.SEMICOLON);
    Set<String> assignedUserIds = TextUtils.splitToArray(assignedUser, TextUtils.SEMICOLON);
    lastUpdatedStartDate = lastUpdatedStartDate != null ? lastUpdatedStartDate : lastUpdated;
    skipPaging = PagerUtils.isSkipPaging(skipPaging, paging);
    EventSearchParams params = requestToSearchParamsMapper.map(program, programStage, programStatus, followUp, orgUnit, ouMode, trackedEntityInstance, startDate, endDate, dueDateStart, dueDateEnd, lastUpdatedStartDate, lastUpdatedEndDate, null, status, attributeOptionCombo, idSchemes, page, pageSize, totalPages, skipPaging, null, getGridOrderParams(order), false, eventIds, false, assignedUserMode, assignedUserIds, filter, dataElement, includeAllDataElements, includeDeleted);
    contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_XML, CacheStrategy.NO_CACHE);
    Grid grid = eventService.getEventsGrid(params);
    GridUtils.toXml(grid, response.getOutputStream());
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) EventSearchParams(org.hisp.dhis.dxf2.events.event.EventSearchParams) Grid(org.hisp.dhis.common.Grid) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) GetMapping(org.springframework.web.bind.annotation.GetMapping)

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