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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations