Search in sources :

Example 1 with DhisVersionMismatchException

use of org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException in project dhis2-core by dhis2.

the class MetadataSyncTask method runSyncTask.

public synchronized void runSyncTask(MetadataRetryContext context) throws MetadataSyncServiceException, DhisVersionMismatchException {
    metadataSyncPreProcessor.setUp(context);
    metadataSyncPreProcessor.handleAggregateDataPush(context);
    metadataSyncPreProcessor.handleEventDataPush(context);
    MetadataVersion metadataVersion = metadataSyncPreProcessor.handleCurrentMetadataVersion(context);
    List<MetadataVersion> metadataVersionList = metadataSyncPreProcessor.handleMetadataVersionsList(context, metadataVersion);
    if (metadataVersionList != null) {
        for (MetadataVersion dataVersion : metadataVersionList) {
            MetadataSyncParams syncParams = new MetadataSyncParams(new MetadataImportParams(), dataVersion);
            boolean isSyncRequired = metadataSyncService.isSyncRequired(syncParams);
            MetadataSyncSummary metadataSyncSummary = null;
            if (isSyncRequired) {
                metadataSyncSummary = handleMetadataSync(context, dataVersion);
            } else {
                metadataSyncPostProcessor.handleVersionAlreadyExists(context, dataVersion);
                break;
            }
            boolean abortStatus = metadataSyncPostProcessor.handleSyncNotificationsAndAbortStatus(metadataSyncSummary, context, dataVersion);
            if (abortStatus) {
                break;
            }
            systemSettingManager.saveSystemSetting(SettingKey.LAST_SUCCESSFUL_METADATA_SYNC, dataVersion.getImportDate());
            clearFailedVersionSettings();
        }
    }
    log.info("Metadata sync cron job ended ");
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataSyncParams(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) MetadataSyncSummary(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary)

Example 2 with DhisVersionMismatchException

use of org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException in project dhis2-core by dhis2.

the class DefaultMetadataSyncServiceTest method testShouldNotStoreMetadataSnapshotInDataStoreWhenAlreadyExistsInLocalStore.

@Test
public void testShouldNotStoreMetadataSnapshotInDataStoreWhenAlreadyExistsInLocalStore() throws DhisVersionMismatchException {
    MetadataSyncParams syncParams = Mockito.mock(MetadataSyncParams.class);
    MetadataVersion metadataVersion = new MetadataVersion("testVersion", VersionType.ATOMIC);
    MetadataImportParams metadataImportParams = new MetadataImportParams();
    MetadataSyncSummary metadataSyncSummary = new MetadataSyncSummary();
    metadataSyncSummary.setMetadataVersion(metadataVersion);
    String expectedMetadataSnapshot = "{\"date\":\"2016-05-24T05:27:25.128+0000\"}";
    when(syncParams.getVersion()).thenReturn(metadataVersion);
    when(syncParams.getImportParams()).thenReturn(metadataImportParams);
    when(metadataVersionService.getVersionData("testVersion")).thenReturn(expectedMetadataSnapshot);
    when(metadataVersionService.isMetadataPassingIntegrity(metadataVersion, expectedMetadataSnapshot)).thenReturn(true);
    when(metadataSyncImportHandler.importMetadata(syncParams, expectedMetadataSnapshot)).thenReturn(metadataSyncSummary);
    MetadataSyncSummary actualSummary = metadataSyncService.doMetadataSync(syncParams);
    verify(metadataVersionService, never()).createMetadataVersionInDataStore(metadataVersion.getName(), expectedMetadataSnapshot);
    verify(metadataVersionDelegate, never()).downloadMetadataVersionSnapshot(metadataVersion);
    assertEquals(null, actualSummary.getImportReport());
    assertEquals(null, actualSummary.getImportSummary());
    assertEquals(metadataVersion, actualSummary.getMetadataVersion());
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 3 with DhisVersionMismatchException

use of org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException 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.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)

Example 4 with DhisVersionMismatchException

use of org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException in project dhis2-core by dhis2.

the class MetadataSyncTaskTest method testShouldAbortIfDHISVersionMismatch.

@Test(expected = DhisVersionMismatchException.class)
public void testShouldAbortIfDHISVersionMismatch() throws Exception {
    metadataVersions.add(metadataVersion);
    when(metadataSyncPreProcessor.handleCurrentMetadataVersion(metadataRetryContext)).thenReturn(metadataVersion);
    when(metadataSyncPreProcessor.handleMetadataVersionsList(metadataRetryContext, metadataVersion)).thenReturn(metadataVersions);
    when(metadataSyncService.doMetadataSync(any(MetadataSyncParams.class))).thenThrow(new DhisVersionMismatchException(""));
    when(metadataSyncService.isSyncRequired(any(MetadataSyncParams.class))).thenReturn(true);
    metadataSyncTask.runSyncTask(metadataRetryContext);
    verify(metadataSyncPreProcessor, times(1)).setUp(metadataRetryContext);
    verify(metadataSyncPreProcessor, times(1)).handleAggregateDataPush(metadataRetryContext);
    verify(metadataSyncPreProcessor, times(1)).handleEventDataPush(metadataRetryContext);
    verify(metadataSyncPreProcessor, times(1)).handleCurrentMetadataVersion(metadataRetryContext);
    verify(metadataSyncPreProcessor, times(1)).handleMetadataVersionsList(metadataRetryContext, metadataVersion);
    verify(metadataSyncService, times(1)).doMetadataSync(any(MetadataSyncParams.class));
}
Also used : MetadataSyncParams(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams) DhisVersionMismatchException(org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 5 with DhisVersionMismatchException

use of org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException in project dhis2-core by dhis2.

the class MetadataSyncTask method handleMetadataSync.

//----------------------------------------------------------------------------------------
// Private Methods
//----------------------------------------------------------------------------------------
private MetadataSyncSummary handleMetadataSync(MetadataRetryContext context, MetadataVersion dataVersion) throws DhisVersionMismatchException {
    MetadataSyncParams syncParams = new MetadataSyncParams(new MetadataImportParams(), dataVersion);
    MetadataSyncSummary metadataSyncSummary = null;
    try {
        metadataSyncSummary = metadataSyncService.doMetadataSync(syncParams);
    } catch (MetadataSyncServiceException e) {
        log.error("Exception happened  while trying to do metadata sync  " + e.getMessage(), e);
        context.updateRetryContext(METADATA_SYNC, e.getMessage(), dataVersion);
        throw e;
    } catch (DhisVersionMismatchException e) {
        context.updateRetryContext(METADATA_SYNC, e.getMessage(), dataVersion);
        throw e;
    }
    return metadataSyncSummary;
}
Also used : MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) MetadataSyncParams(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) DhisVersionMismatchException(org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException) MetadataSyncSummary(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary)

Aggregations

MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)5 MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)5 DhisSpringTest (org.hisp.dhis.DhisSpringTest)4 MetadataSyncParams (org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams)4 DhisVersionMismatchException (org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException)4 Test (org.junit.Test)4 MetadataSyncSummary (org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary)3 MetadataSyncServiceException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException)2 IntegrationTest (org.hisp.dhis.IntegrationTest)1 MetadataSyncImportException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncImportException)1 RemoteServerUnavailableException (org.hisp.dhis.exception.RemoteServerUnavailableException)1 BadRequestException (org.hisp.dhis.webapi.controller.exception.BadRequestException)1 MetadataImportConflictException (org.hisp.dhis.webapi.controller.exception.MetadataImportConflictException)1 MetadataSyncException (org.hisp.dhis.webapi.controller.exception.MetadataSyncException)1 OperationNotAllowedException (org.hisp.dhis.webapi.controller.exception.OperationNotAllowedException)1 ResponseEntity (org.springframework.http.ResponseEntity)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1