use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.
the class MetadataSyncPreProcessorTest method testHandleMetadataVersionsListShouldReturnNullIfInstanceDoesNotHaveAnyVersions.
@Test
public void testHandleMetadataVersionsListShouldReturnNullIfInstanceDoesNotHaveAnyVersions() throws Exception {
AvailabilityStatus availabilityStatus = new AvailabilityStatus(true, "test_message", null);
when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
MetadataRetryContext mockRetryContext = mock(MetadataRetryContext.class);
MetadataVersion currentVersion = new MetadataVersion();
currentVersion.setType(VersionType.BEST_EFFORT);
currentVersion.setName("test_version");
currentVersion.setCreated(new Date());
currentVersion.setHashCode("samplehashcode");
when(metadataVersionDelegate.getMetaDataDifference(currentVersion)).thenReturn(new ArrayList<MetadataVersion>());
List<MetadataVersion> expectedListOfVersions = metadataSyncPreProcessor.handleMetadataVersionsList(mockRetryContext, currentVersion);
assertTrue(expectedListOfVersions.size() == 0);
}
use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.
the class MetadataSyncPreProcessorTest method testHandleCurrentMetadataVersionShouldReturnCurrentVersionOfSystem.
@Test
public void testHandleCurrentMetadataVersionShouldReturnCurrentVersionOfSystem() throws Exception {
MetadataRetryContext mockRetryContext = mock(MetadataRetryContext.class);
MetadataVersion currentVersion = new MetadataVersion();
currentVersion.setType(VersionType.BEST_EFFORT);
currentVersion.setName("test_version");
currentVersion.setCreated(new Date());
currentVersion.setHashCode("samplehashcode");
when(metadataVersionService.getCurrentVersion()).thenReturn(currentVersion);
MetadataVersion actualVersion = metadataSyncPreProcessor.handleCurrentMetadataVersion(mockRetryContext);
assertEquals(currentVersion, actualVersion);
}
use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.
the class DefaultRenderService method fromMetadataVersion.
@Override
public List<MetadataVersion> fromMetadataVersion(InputStream versions, RenderFormat format) throws IOException {
List<MetadataVersion> metadataVersions = new ArrayList<>();
if (RenderFormat.JSON == format) {
JsonNode rootNode = jsonMapper.readTree(versions);
if (rootNode != null) {
JsonNode versionsNode = rootNode.get("metadataversions");
if (versionsNode instanceof ArrayNode) {
ArrayNode arrayVersionsNode = (ArrayNode) versionsNode;
metadataVersions = jsonMapper.readValue(arrayVersionsNode.toString().getBytes(), new TypeReference<List<MetadataVersion>>() {
});
}
}
}
return metadataVersions;
}
use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.
the class MetadataSyncPreProcessor method handleCurrentMetadataVersion.
public MetadataVersion handleCurrentMetadataVersion(MetadataRetryContext context) {
log.debug("Getting the current version of the system");
MetadataVersion metadataVersion = null;
try {
metadataVersion = metadataVersionService.getCurrentVersion();
log.info("Current Metadata Version of the system: " + metadataVersion);
} catch (MetadataVersionServiceException ex) {
context.updateRetryContext(MetadataSyncTask.GET_METADATAVERSION, ex.getMessage(), null, null);
throw new MetadataSyncServiceException(ex.getMessage(), ex);
}
return metadataVersion;
}
use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.
the class MetadataSyncTask method updateMetadataVersionFailureDetails.
private void updateMetadataVersionFailureDetails(MetadataRetryContext retryContext) {
Object version = retryContext.getRetryContext().getAttribute(VERSION_KEY);
if (version != null) {
MetadataVersion metadataVersion = (MetadataVersion) version;
systemSettingManager.saveSystemSetting(SettingKey.METADATA_FAILED_VERSION, metadataVersion.getName());
systemSettingManager.saveSystemSetting(SettingKey.METADATA_LAST_FAILED_TIME, new Date());
}
}
Aggregations