Search in sources :

Example 6 with MetadataVersion

use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.

the class MetadataSyncPreProcessor method getLatestVersion.

private MetadataVersion getLatestVersion(List<MetadataVersion> metadataVersionList) {
    Collection<Date> dateCollection = new ArrayList<Date>();
    for (MetadataVersion metadataVersion : metadataVersionList) {
        dateCollection.add(metadataVersion.getCreated());
    }
    Date maxDate = DateUtils.max(dateCollection);
    for (MetadataVersion metadataVersion : metadataVersionList) {
        if (metadataVersion.getCreated().equals(maxDate)) {
            return metadataVersion;
        }
    }
    return null;
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 7 with MetadataVersion

use of org.hisp.dhis.metadata.version.MetadataVersion 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 8 with MetadataVersion

use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.

the class RenderServiceTest method testfromMetadataVersion_should_generate_versions_from_json_stream.

@Test
public void testfromMetadataVersion_should_generate_versions_from_json_stream() throws IOException {
    String jsonString = "{" + "\"metadataversions\":  [" + "{\"name\" : \"version1\",\"type\" : \"ATOMIC\"}," + "{\"name\" : \"version2\",\"type\" : \"ATOMIC\"}," + "{\"name\" : \"version3\",\"type\" : \"ATOMIC\"}" + "]" + "}";
    ByteArrayInputStream bais = new ByteArrayInputStream(jsonString.getBytes());
    List<MetadataVersion> metadataVersions = renderService.fromMetadataVersion(bais, RenderFormat.JSON);
    assertEquals(3, metadataVersions.size());
    assertEquals("version1", metadataVersions.get(0).getName());
    assertEquals("version2", metadataVersions.get(1).getName());
    assertEquals("version3", metadataVersions.get(2).getName());
    assertEquals(VersionType.ATOMIC, metadataVersions.get(0).getType());
    assertEquals(VersionType.ATOMIC, metadataVersions.get(1).getType());
    assertEquals(VersionType.ATOMIC, metadataVersions.get(2).getType());
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 9 with MetadataVersion

use of org.hisp.dhis.metadata.version.MetadataVersion 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 10 with MetadataVersion

use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.

the class DefaultMetadataSyncServiceTest method testShouldNotThrowExceptionWhenDHISVersionsMismatch.

@Test
public void testShouldNotThrowExceptionWhenDHISVersionsMismatch() throws DhisVersionMismatchException {
    MetadataSyncParams syncParams = Mockito.mock(MetadataSyncParams.class);
    MetadataVersion metadataVersion = new MetadataVersion("testVersion", VersionType.ATOMIC);
    String expectedMetadataSnapshot = "{\"date\":\"2016-05-24T05:27:25.128+0000\", \"version\": \"2.26\"}";
    when(syncParams.getVersion()).thenReturn(metadataVersion);
    when(metadataVersionDelegate.downloadMetadataVersionSnapshot(metadataVersion)).thenReturn(expectedMetadataSnapshot);
    when(metadataSyncDelegate.shouldStopSync(expectedMetadataSnapshot)).thenReturn(false);
    when(metadataVersionService.isMetadataPassingIntegrity(metadataVersion, expectedMetadataSnapshot)).thenReturn(true);
    metadataSyncService.doMetadataSync(syncParams);
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)53 DhisSpringTest (org.hisp.dhis.DhisSpringTest)31 Test (org.junit.Test)31 IntegrationTest (org.hisp.dhis.IntegrationTest)15 Date (java.util.Date)14 ArrayList (java.util.ArrayList)12 AvailabilityStatus (org.hisp.dhis.dxf2.synch.AvailabilityStatus)12 MetadataVersionServiceException (org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)10 DhisHttpResponse (org.hisp.dhis.system.util.DhisHttpResponse)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)6 MetadataRetryContext (org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext)6 IOException (java.io.IOException)5 MetadataSyncServiceException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException)5 HttpResponse (org.apache.http.HttpResponse)4 ComplexNode (org.hisp.dhis.node.types.ComplexNode)3 RootNode (org.hisp.dhis.node.types.RootNode)3 BadRequestException (org.hisp.dhis.webapi.controller.exception.BadRequestException)3 MetadataVersionException (org.hisp.dhis.webapi.controller.exception.MetadataVersionException)3 Before (org.junit.Before)3