use of org.hisp.dhis.deduplication.PotentialDuplicateConflictException 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.PotentialDuplicateConflictException in project dhis2-core by dhis2.
the class DeduplicationControllerTest method postPotentialDuplicateAlreadyExists.
@Test
void postPotentialDuplicateAlreadyExists() throws PotentialDuplicateConflictException {
PotentialDuplicate pd = new PotentialDuplicate(teiA, teiB);
when(trackerAccessManager.canRead(any(), eq(trackedEntityInstanceA))).thenReturn(Lists.newArrayList());
when(trackerAccessManager.canRead(any(), eq(trackedEntityInstanceB))).thenReturn(Lists.newArrayList());
when(deduplicationService.exists(pd)).thenReturn(true);
try {
deduplicationController.postPotentialDuplicate(pd);
} catch (OperationNotAllowedException | ConflictException | NotFoundException | BadRequestException | PotentialDuplicateConflictException e) {
assertTrue(e instanceof ConflictException);
}
verify(deduplicationService, times(0)).addPotentialDuplicate(any());
verify(trackerAccessManager).canRead(user, trackedEntityInstanceA);
verify(trackerAccessManager).canRead(user, trackedEntityInstanceB);
verify(deduplicationService).exists(pd);
}
use of org.hisp.dhis.deduplication.PotentialDuplicateConflictException in project dhis2-core by dhis2.
the class DeduplicationControllerTest method postPotentialDuplicateTeiNotFound.
@Test
void postPotentialDuplicateTeiNotFound() {
when(trackedEntityInstanceService.getTrackedEntityInstance(teiA)).thenReturn(null);
try {
deduplicationController.postPotentialDuplicate(new PotentialDuplicate(teiA, teiB));
} catch (OperationNotAllowedException | ConflictException | NotFoundException | BadRequestException | PotentialDuplicateConflictException e) {
assertTrue(e instanceof NotFoundException);
}
verify(deduplicationService, times(0)).addPotentialDuplicate(any());
}
use of org.hisp.dhis.deduplication.PotentialDuplicateConflictException in project dhis2-core by dhis2.
the class DeduplicationControllerTest method postPotentialDuplicateNoAccessToTeiA.
@Test
void postPotentialDuplicateNoAccessToTeiA() {
when(trackerAccessManager.canRead(Mockito.any(), eq(trackedEntityInstanceA))).thenReturn(Lists.newArrayList("Error"));
try {
deduplicationController.postPotentialDuplicate(new PotentialDuplicate(teiA, teiB));
} catch (OperationNotAllowedException | ConflictException | NotFoundException | BadRequestException | PotentialDuplicateConflictException e) {
assertTrue(e instanceof OperationNotAllowedException);
}
verify(deduplicationService, times(0)).addPotentialDuplicate(any());
verify(trackerAccessManager).canRead(user, trackedEntityInstanceA);
}
use of org.hisp.dhis.deduplication.PotentialDuplicateConflictException in project dhis2-core by dhis2.
the class DeduplicationControllerTest method postPotentialDuplicateNoAccessToTeiB.
@Test
void postPotentialDuplicateNoAccessToTeiB() {
when(trackerAccessManager.canRead(Mockito.any(), eq(trackedEntityInstanceA))).thenReturn(Lists.newArrayList());
when(trackerAccessManager.canRead(Mockito.any(), eq(trackedEntityInstanceB))).thenReturn(Lists.newArrayList("Error"));
try {
deduplicationController.postPotentialDuplicate(new PotentialDuplicate(teiA, teiB));
} catch (OperationNotAllowedException | ConflictException | NotFoundException | BadRequestException | PotentialDuplicateConflictException e) {
assertTrue(e instanceof OperationNotAllowedException);
}
verify(deduplicationService, times(0)).addPotentialDuplicate(any());
verify(trackerAccessManager).canRead(user, trackedEntityInstanceA);
verify(trackerAccessManager).canRead(user, trackedEntityInstanceB);
}
Aggregations