use of org.hisp.dhis.deduplication.PotentialDuplicate in project dhis2-core by dhis2.
the class DeduplicationControllerTest method postPotentialDuplicate.
@Test
void postPotentialDuplicate() throws OperationNotAllowedException, ConflictException, NotFoundException, BadRequestException, PotentialDuplicateConflictException {
Mockito.when(deduplicationService.exists(new PotentialDuplicate(teiA, teiB))).thenReturn(false);
PotentialDuplicate potentialDuplicate = new PotentialDuplicate(teiA, teiB);
deduplicationController.postPotentialDuplicate(potentialDuplicate);
verify(deduplicationService).addPotentialDuplicate(potentialDuplicate);
verify(trackedEntityInstanceService, times(2)).getTrackedEntityInstance(anyString());
verify(trackedEntityInstanceService).getTrackedEntityInstance(teiA);
verify(trackedEntityInstanceService).getTrackedEntityInstance(teiB);
verify(trackerAccessManager, times(2)).canRead(eq(user), any(TrackedEntityInstance.class));
verify(trackerAccessManager).canRead(user, trackedEntityInstanceA);
verify(trackerAccessManager).canRead(user, trackedEntityInstanceB);
verify(deduplicationService).exists(potentialDuplicate);
}
use of org.hisp.dhis.deduplication.PotentialDuplicate in project dhis2-core by dhis2.
the class DeduplicationControllerTest method shouldThrowUpdatePotentialDuplicateMergedStatusDb.
@Test
void shouldThrowUpdatePotentialDuplicateMergedStatusDb() {
PotentialDuplicate potentialDuplicate = new PotentialDuplicate(teiA, teiB);
potentialDuplicate.setStatus(DeduplicationStatus.MERGED);
when(deduplicationService.getPotentialDuplicateByUid(uid)).thenReturn(potentialDuplicate);
assertThrows(BadRequestException.class, () -> deduplicationController.updatePotentialDuplicate(uid, DeduplicationStatus.INVALID.name()));
}
use of org.hisp.dhis.deduplication.PotentialDuplicate in project dhis2-core by dhis2.
the class DeduplicationControllerTest method shouldUpdatePotentialDuplicate.
@Test
void shouldUpdatePotentialDuplicate() throws NotFoundException, BadRequestException {
PotentialDuplicate potentialDuplicate = new PotentialDuplicate(teiA, teiB);
when(deduplicationService.getPotentialDuplicateByUid(uid)).thenReturn(potentialDuplicate);
deduplicationController.updatePotentialDuplicate(uid, DeduplicationStatus.INVALID.name());
ArgumentCaptor<PotentialDuplicate> potentialDuplicateArgumentCaptor = ArgumentCaptor.forClass(PotentialDuplicate.class);
verify(deduplicationService).updatePotentialDuplicate(potentialDuplicateArgumentCaptor.capture());
assertEquals(DeduplicationStatus.INVALID, potentialDuplicateArgumentCaptor.getValue().getStatus());
}
use of org.hisp.dhis.deduplication.PotentialDuplicate in project dhis2-core by dhis2.
the class DeduplicationController method getAllByQuery.
@GetMapping
public Node getAllByQuery(PotentialDuplicateQuery query, HttpServletResponse response) throws BadRequestException {
checkDeduplicationStatusRequestParam(Optional.ofNullable(query.getStatus()).map(Enum::name).orElse(null));
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
}
List<PotentialDuplicate> potentialDuplicates = deduplicationService.getAllPotentialDuplicatesBy(query);
RootNode rootNode = NodeUtils.createMetadata();
if (!query.isSkipPaging()) {
query.setTotal(deduplicationService.countPotentialDuplicates(query));
rootNode.addChild(NodeUtils.createPager(query.getPager()));
}
rootNode.addChild(fieldFilterService.toCollectionNode(PotentialDuplicate.class, new FieldFilterParams(potentialDuplicates, fields)));
setNoStore(response);
return rootNode;
}
use of org.hisp.dhis.deduplication.PotentialDuplicate in project dhis2-core by dhis2.
the class DeduplicationControllerMvcTest method shouldThrowAutoMergeConflictException.
@Test
void shouldThrowAutoMergeConflictException() throws Exception {
String uid = "uid";
PotentialDuplicate potentialDuplicate = new PotentialDuplicate(teiA, teiB);
when(deduplicationService.getPotentialDuplicateByUid(uid)).thenReturn(potentialDuplicate);
doThrow(new PotentialDuplicateConflictException("Conflict")).when(deduplicationService).autoMerge(deduplicationMergeParams);
MergeObject mergeObject = MergeObject.builder().build();
mockMvc.perform(post(ENDPOINT + "/" + uid + "/merge").content(objectMapper.writeValueAsString(mergeObject)).param("mergeStrategy", MergeStrategy.AUTO.name()).contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)).andExpect(result -> assertTrue(result.getResolvedException() instanceof PotentialDuplicateConflictException));
verify(deduplicationService).autoMerge(deduplicationMergeParams);
verify(deduplicationService, times(0)).manualMerge(deduplicationMergeParams);
}
Aggregations