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;
}
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 ");
}
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());
}
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());
}
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);
}
Aggregations