use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.
the class HibernateMetadataVersionStoreTest method testGetAllVersionsInBetween.
@Test
public void testGetAllVersionsInBetween() throws Exception {
DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ssZ");
org.joda.time.DateTime dateTime1 = dateTimeFormatter.parseDateTime("2016-06-20 10:45:50Z");
org.joda.time.DateTime dateTime2 = dateTimeFormatter.parseDateTime("2016-06-21 10:45:50Z");
org.joda.time.DateTime dateTime3 = dateTimeFormatter.parseDateTime("2016-06-22 10:45:50Z");
assertEquals(0, metadataVersionStore.getAllVersionsInBetween(new Date(), new Date()).size());
MetadataVersion metadataVersion2 = new MetadataVersion("version2", VersionType.ATOMIC);
metadataVersion2.setHashCode("12222");
metadataVersion2.setCreated(dateTime1.toDate());
metadataVersionStore.save(metadataVersion2);
MetadataVersion metadataVersion3 = new MetadataVersion("version3", VersionType.ATOMIC);
metadataVersion3.setHashCode("12255");
metadataVersion3.setCreated(dateTime2.toDate());
metadataVersionStore.save(metadataVersion3);
MetadataVersion metadataVersion4 = new MetadataVersion("version4", VersionType.ATOMIC);
metadataVersion4.setHashCode("12267");
metadataVersion4.setCreated(dateTime3.toDate());
metadataVersionStore.save(metadataVersion4);
List<MetadataVersion> allVersionsInBetween = metadataVersionStore.getAllVersionsInBetween(dateTime1.toDate(), dateTime2.toDate());
assertEquals(2, allVersionsInBetween.size());
assertEquals(metadataVersion2, allVersionsInBetween.get(0));
assertEquals(metadataVersion3, allVersionsInBetween.get(1));
assertEquals(0, metadataVersionStore.getAllVersionsInBetween(new Date(), new Date()).size());
metadataVersionStore.delete(metadataVersion2);
metadataVersionStore.delete(metadataVersion3);
metadataVersionStore.delete(metadataVersion4);
}
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());
}
}
use of org.hisp.dhis.metadata.version.MetadataVersion 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;
}
Aggregations