Search in sources :

Example 6 with DhisVersionMismatchException

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

the class DefaultMetadataSyncServiceTest method testShouldStoreMetadataSnapshotInDataStoreAndImport.

@Test
public void testShouldStoreMetadataSnapshotInDataStoreAndImport() 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(null);
    when(metadataVersionDelegate.downloadMetadataVersionSnapshot(metadataVersion)).thenReturn(expectedMetadataSnapshot);
    when(metadataVersionService.isMetadataPassingIntegrity(metadataVersion, expectedMetadataSnapshot)).thenReturn(true);
    when(metadataSyncImportHandler.importMetadata(syncParams, expectedMetadataSnapshot)).thenReturn(metadataSyncSummary);
    MetadataSyncSummary actualSummary = metadataSyncService.doMetadataSync(syncParams);
    verify(metadataVersionService, times(1)).createMetadataVersionInDataStore(metadataVersion.getName(), expectedMetadataSnapshot);
    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 7 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)

Example 8 with DhisVersionMismatchException

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

the class DefaultMetadataSyncService method doMetadataSync.

@Override
public synchronized MetadataSyncSummary doMetadataSync(MetadataSyncParams syncParams) throws MetadataSyncServiceException, DhisVersionMismatchException {
    MetadataVersion version = getMetadataVersion(syncParams);
    setMetadataImportMode(syncParams, version);
    String metadataVersionSnapshot = getMetadataVersionSnapshot(version);
    if (metadataSyncDelegate.shouldStopSync(metadataVersionSnapshot)) {
        throw new DhisVersionMismatchException("Metadata sync failed because your version of DHIS does not match the master version");
    }
    saveMetadataVersionSnapshotLocally(version, metadataVersionSnapshot);
    MetadataSyncSummary metadataSyncSummary = metadataSyncImportHandler.importMetadata(syncParams, metadataVersionSnapshot);
    log.info("Metadata Sync Summary: " + metadataSyncSummary);
    return metadataSyncSummary;
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) DhisVersionMismatchException(org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException)

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