Search in sources :

Example 1 with PotentialDuplicateConflictException

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);
    }
}
Also used : PotentialDuplicateConflictException(org.hisp.dhis.deduplication.PotentialDuplicateConflictException) MergeObject(org.hisp.dhis.deduplication.MergeObject) PotentialDuplicate(org.hisp.dhis.deduplication.PotentialDuplicate) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) DeduplicationMergeParams(org.hisp.dhis.deduplication.DeduplicationMergeParams) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 2 with PotentialDuplicateConflictException

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);
}
Also used : PotentialDuplicateConflictException(org.hisp.dhis.deduplication.PotentialDuplicateConflictException) PotentialDuplicateConflictException(org.hisp.dhis.deduplication.PotentialDuplicateConflictException) ConflictException(org.hisp.dhis.webapi.controller.exception.ConflictException) PotentialDuplicate(org.hisp.dhis.deduplication.PotentialDuplicate) NotFoundException(org.hisp.dhis.webapi.controller.exception.NotFoundException) BadRequestException(org.hisp.dhis.webapi.controller.exception.BadRequestException) OperationNotAllowedException(org.hisp.dhis.webapi.controller.exception.OperationNotAllowedException) Test(org.junit.jupiter.api.Test)

Example 3 with PotentialDuplicateConflictException

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());
}
Also used : PotentialDuplicateConflictException(org.hisp.dhis.deduplication.PotentialDuplicateConflictException) PotentialDuplicateConflictException(org.hisp.dhis.deduplication.PotentialDuplicateConflictException) ConflictException(org.hisp.dhis.webapi.controller.exception.ConflictException) PotentialDuplicate(org.hisp.dhis.deduplication.PotentialDuplicate) NotFoundException(org.hisp.dhis.webapi.controller.exception.NotFoundException) BadRequestException(org.hisp.dhis.webapi.controller.exception.BadRequestException) OperationNotAllowedException(org.hisp.dhis.webapi.controller.exception.OperationNotAllowedException) Test(org.junit.jupiter.api.Test)

Example 4 with PotentialDuplicateConflictException

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);
}
Also used : PotentialDuplicateConflictException(org.hisp.dhis.deduplication.PotentialDuplicateConflictException) PotentialDuplicateConflictException(org.hisp.dhis.deduplication.PotentialDuplicateConflictException) ConflictException(org.hisp.dhis.webapi.controller.exception.ConflictException) PotentialDuplicate(org.hisp.dhis.deduplication.PotentialDuplicate) NotFoundException(org.hisp.dhis.webapi.controller.exception.NotFoundException) BadRequestException(org.hisp.dhis.webapi.controller.exception.BadRequestException) OperationNotAllowedException(org.hisp.dhis.webapi.controller.exception.OperationNotAllowedException) Test(org.junit.jupiter.api.Test)

Example 5 with PotentialDuplicateConflictException

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);
}
Also used : PotentialDuplicateConflictException(org.hisp.dhis.deduplication.PotentialDuplicateConflictException) PotentialDuplicateConflictException(org.hisp.dhis.deduplication.PotentialDuplicateConflictException) ConflictException(org.hisp.dhis.webapi.controller.exception.ConflictException) PotentialDuplicate(org.hisp.dhis.deduplication.PotentialDuplicate) NotFoundException(org.hisp.dhis.webapi.controller.exception.NotFoundException) BadRequestException(org.hisp.dhis.webapi.controller.exception.BadRequestException) OperationNotAllowedException(org.hisp.dhis.webapi.controller.exception.OperationNotAllowedException) Test(org.junit.jupiter.api.Test)

Aggregations

PotentialDuplicate (org.hisp.dhis.deduplication.PotentialDuplicate)6 PotentialDuplicateConflictException (org.hisp.dhis.deduplication.PotentialDuplicateConflictException)6 Test (org.junit.jupiter.api.Test)5 BadRequestException (org.hisp.dhis.webapi.controller.exception.BadRequestException)4 ConflictException (org.hisp.dhis.webapi.controller.exception.ConflictException)4 NotFoundException (org.hisp.dhis.webapi.controller.exception.NotFoundException)4 OperationNotAllowedException (org.hisp.dhis.webapi.controller.exception.OperationNotAllowedException)4 MergeObject (org.hisp.dhis.deduplication.MergeObject)2 DeduplicationMergeParams (org.hisp.dhis.deduplication.DeduplicationMergeParams)1 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1