Search in sources :

Example 16 with PotentialDuplicate

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);
}
Also used : PotentialDuplicate(org.hisp.dhis.deduplication.PotentialDuplicate) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Test(org.junit.jupiter.api.Test)

Example 17 with 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()));
}
Also used : PotentialDuplicate(org.hisp.dhis.deduplication.PotentialDuplicate) Test(org.junit.jupiter.api.Test)

Example 18 with PotentialDuplicate

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());
}
Also used : PotentialDuplicate(org.hisp.dhis.deduplication.PotentialDuplicate) Test(org.junit.jupiter.api.Test)

Example 19 with PotentialDuplicate

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;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) PotentialDuplicate(org.hisp.dhis.deduplication.PotentialDuplicate) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 20 with PotentialDuplicate

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);
}
Also used : PotentialDuplicateConflictException(org.hisp.dhis.deduplication.PotentialDuplicateConflictException) MergeObject(org.hisp.dhis.deduplication.MergeObject) PotentialDuplicate(org.hisp.dhis.deduplication.PotentialDuplicate) Test(org.junit.jupiter.api.Test)

Aggregations

PotentialDuplicate (org.hisp.dhis.deduplication.PotentialDuplicate)23 Test (org.junit.jupiter.api.Test)19 BadRequestException (org.hisp.dhis.webapi.controller.exception.BadRequestException)7 PotentialDuplicateConflictException (org.hisp.dhis.deduplication.PotentialDuplicateConflictException)6 MergeObject (org.hisp.dhis.deduplication.MergeObject)5 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 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)3 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)2 DeduplicationMergeParams (org.hisp.dhis.deduplication.DeduplicationMergeParams)1 DeduplicationStatus (org.hisp.dhis.deduplication.DeduplicationStatus)1 PotentialDuplicateForbiddenException (org.hisp.dhis.deduplication.PotentialDuplicateForbiddenException)1 FieldFilterParams (org.hisp.dhis.fieldfilter.FieldFilterParams)1 RootNode (org.hisp.dhis.node.types.RootNode)1 CrudControllerAdvice (org.hisp.dhis.webapi.controller.CrudControllerAdvice)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 PutMapping (org.springframework.web.bind.annotation.PutMapping)1