use of org.hisp.dhis.deduplication.PotentialDuplicate in project dhis2-core by dhis2.
the class DeduplicationController method updatePotentialDuplicate.
@PutMapping(value = "/{id}")
@ResponseStatus(value = HttpStatus.OK)
public void updatePotentialDuplicate(@PathVariable String id, @RequestParam(value = "status") String status) throws NotFoundException, BadRequestException {
checkDeduplicationStatusRequestParam(status);
PotentialDuplicate potentialDuplicate = getPotentialDuplicateBy(id);
DeduplicationStatus deduplicationStatus = DeduplicationStatus.valueOf(status);
checkDbAndRequestStatus(potentialDuplicate, deduplicationStatus);
potentialDuplicate.setStatus(deduplicationStatus);
deduplicationService.updatePotentialDuplicate(potentialDuplicate);
}
use of org.hisp.dhis.deduplication.PotentialDuplicate in project dhis2-core by dhis2.
the class DeduplicationController method mergePotentialDuplicate.
@PostMapping(value = "/{id}/merge")
@ResponseStatus(value = HttpStatus.OK)
public void mergePotentialDuplicate(@PathVariable String id, @RequestParam(defaultValue = "AUTO") MergeStrategy mergeStrategy, @RequestBody(required = false) MergeObject mergeObject) throws NotFoundException, PotentialDuplicateConflictException, PotentialDuplicateForbiddenException {
PotentialDuplicate potentialDuplicate = getPotentialDuplicateBy(id);
if (potentialDuplicate.getOriginal() == null || potentialDuplicate.getDuplicate() == null) {
throw new PotentialDuplicateConflictException("PotentialDuplicate is missing references and cannot be merged.");
}
TrackedEntityInstance original = getTei(potentialDuplicate.getOriginal());
TrackedEntityInstance duplicate = getTei(potentialDuplicate.getDuplicate());
if (mergeObject == null) {
mergeObject = new MergeObject();
}
DeduplicationMergeParams params = DeduplicationMergeParams.builder().potentialDuplicate(potentialDuplicate).mergeObject(mergeObject).original(original).duplicate(duplicate).build();
if (MergeStrategy.MANUAL.equals(mergeStrategy)) {
deduplicationService.manualMerge(params);
} else {
deduplicationService.autoMerge(params);
}
}
use of org.hisp.dhis.deduplication.PotentialDuplicate in project dhis2-core by dhis2.
the class DeduplicationControllerMvcTest method shouldMergePotentialDuplicate.
@Test
void shouldMergePotentialDuplicate() throws Exception {
String uid = "uid";
PotentialDuplicate potentialDuplicate = new PotentialDuplicate(teiA, teiB);
when(deduplicationService.getPotentialDuplicateByUid(uid)).thenReturn(potentialDuplicate);
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(status().isOk());
verify(deduplicationService).autoMerge(deduplicationMergeParams);
verify(deduplicationService, times(0)).manualMerge(deduplicationMergeParams);
}
use of org.hisp.dhis.deduplication.PotentialDuplicate in project dhis2-core by dhis2.
the class DeduplicationControllerMvcTest method shouldThrowUpdatePotentialDuplicateAlreadyMerged.
@Test
void shouldThrowUpdatePotentialDuplicateAlreadyMerged() throws Exception {
String uid = "uid";
PotentialDuplicate potentialDuplicate = new PotentialDuplicate(teiA, teiB);
potentialDuplicate.setStatus(DeduplicationStatus.MERGED);
when(deduplicationService.getPotentialDuplicateByUid(uid)).thenReturn(potentialDuplicate);
mockMvc.perform(put(ENDPOINT + "/" + uid).param("status", DeduplicationStatus.INVALID.name()).content(objectMapper.writeValueAsString(potentialDuplicate)).contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)).andExpect(result -> assertTrue(result.getResolvedException() instanceof BadRequestException));
verify(deduplicationService).getPotentialDuplicateByUid(uid);
}
use of org.hisp.dhis.deduplication.PotentialDuplicate in project dhis2-core by dhis2.
the class DeduplicationControllerMvcTest method shouldGetPotentialDuplicateById.
@Test
void shouldGetPotentialDuplicateById() throws Exception {
PotentialDuplicate potentialDuplicate = new PotentialDuplicate(teiA, teiB);
String uid = "uid";
when(deduplicationService.getPotentialDuplicateByUid(uid)).thenReturn(potentialDuplicate);
mockMvc.perform(get(ENDPOINT + "/" + uid).content("{}").contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().contentType("application/json"));
verify(deduplicationService).getPotentialDuplicateByUid(uid);
}
Aggregations