Search in sources :

Example 1 with OperationNotAllowedException

use of org.hisp.dhis.webapi.controller.exception.OperationNotAllowedException 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 2 with OperationNotAllowedException

use of org.hisp.dhis.webapi.controller.exception.OperationNotAllowedException 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 3 with OperationNotAllowedException

use of org.hisp.dhis.webapi.controller.exception.OperationNotAllowedException 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 4 with OperationNotAllowedException

use of org.hisp.dhis.webapi.controller.exception.OperationNotAllowedException 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)

Example 5 with OperationNotAllowedException

use of org.hisp.dhis.webapi.controller.exception.OperationNotAllowedException in project dhis2-core by dhis2.

the class MetadataSyncController method metadataSync.

@PreAuthorize("hasRole('ALL') or hasRole('F_METADATA_MANAGE')")
@GetMapping
public ResponseEntity<? extends WebMessageResponse> metadataSync(HttpServletRequest request, HttpServletResponse response) throws MetadataSyncException, BadRequestException, MetadataImportConflictException, OperationNotAllowedException {
    MetadataSyncParams syncParams;
    MetadataSyncSummary metadataSyncSummary = null;
    synchronized (metadataSyncService) {
        try {
            syncParams = metadataSyncService.getParamsFromMap(contextService.getParameterValuesMap());
        } catch (RemoteServerUnavailableException exception) {
            throw new MetadataSyncException(exception.getMessage(), exception);
        } catch (MetadataSyncServiceException serviceException) {
            throw new BadRequestException("Error in parsing inputParams " + serviceException.getMessage(), serviceException);
        }
        try {
            boolean isSyncRequired = metadataSyncService.isSyncRequired(syncParams);
            if (isSyncRequired) {
                metadataSyncSummary = metadataSyncService.doMetadataSync(syncParams);
                validateSyncSummaryResponse(metadataSyncSummary);
            } else {
                throw new MetadataImportConflictException("Version already exists in system and hence not starting the sync.");
            }
        } catch (MetadataSyncImportException importerException) {
            throw new MetadataSyncException("Runtime exception occurred while doing import: " + importerException.getMessage());
        } catch (MetadataSyncServiceException serviceException) {
            throw new MetadataSyncException("Exception occurred while doing metadata sync: " + serviceException.getMessage());
        } catch (DhisVersionMismatchException versionMismatchException) {
            throw new OperationNotAllowedException("Exception occurred while doing metadata sync: " + versionMismatchException.getMessage());
        }
    }
    return new ResponseEntity<MetadataSyncSummary>(metadataSyncSummary, HttpStatus.OK);
}
Also used : MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) MetadataSyncParams(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams) ResponseEntity(org.springframework.http.ResponseEntity) RemoteServerUnavailableException(org.hisp.dhis.dxf2.metadata.sync.exception.RemoteServerUnavailableException) BadRequestException(org.hisp.dhis.webapi.controller.exception.BadRequestException) MetadataSyncImportException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncImportException) DhisVersionMismatchException(org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException) MetadataSyncSummary(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary) OperationNotAllowedException(org.hisp.dhis.webapi.controller.exception.OperationNotAllowedException) MetadataSyncException(org.hisp.dhis.webapi.controller.exception.MetadataSyncException) MetadataImportConflictException(org.hisp.dhis.webapi.controller.exception.MetadataImportConflictException) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

BadRequestException (org.hisp.dhis.webapi.controller.exception.BadRequestException)5 OperationNotAllowedException (org.hisp.dhis.webapi.controller.exception.OperationNotAllowedException)5 PotentialDuplicate (org.hisp.dhis.deduplication.PotentialDuplicate)4 PotentialDuplicateConflictException (org.hisp.dhis.deduplication.PotentialDuplicateConflictException)4 ConflictException (org.hisp.dhis.webapi.controller.exception.ConflictException)4 NotFoundException (org.hisp.dhis.webapi.controller.exception.NotFoundException)4 Test (org.junit.jupiter.api.Test)4 MetadataSyncParams (org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams)1 MetadataSyncSummary (org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary)1 DhisVersionMismatchException (org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException)1 MetadataSyncImportException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncImportException)1 MetadataSyncServiceException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException)1 RemoteServerUnavailableException (org.hisp.dhis.dxf2.metadata.sync.exception.RemoteServerUnavailableException)1 MetadataImportConflictException (org.hisp.dhis.webapi.controller.exception.MetadataImportConflictException)1 MetadataSyncException (org.hisp.dhis.webapi.controller.exception.MetadataSyncException)1 ResponseEntity (org.springframework.http.ResponseEntity)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1