use of org.hisp.dhis.dxf2.metadata.Metadata 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.dxf2.metadata.Metadata in project dhis2-core by dhis2.
the class MetadataSyncPostProcessor method sendSuccessMailToAdmin.
public void sendSuccessMailToAdmin(MetadataSyncSummary metadataSyncSummary) {
ImportReport importReport = metadataSyncSummary.getImportReport();
StringBuilder text = new StringBuilder("Successful Import Report for the scheduler run for Metadata synchronization \n\n").append("Imported Version Details \n ").append("Version Name: " + metadataSyncSummary.getMetadataVersion().getName() + "\n").append("Version Type: " + metadataSyncSummary.getMetadataVersion().getType() + "\n");
Map<Class<?>, TypeReport> typeReportMap = importReport.getTypeReportMap();
if (typeReportMap != null && typeReportMap.entrySet().size() == 0) {
text.append("New Version created. It does not have any metadata changes. \n");
} else if (typeReportMap != null) {
text.append("Imported Object Details: \n");
for (Map.Entry<Class<?>, TypeReport> typeReportEntry : typeReportMap.entrySet()) {
if (typeReportEntry != null) {
Class<?> key = typeReportEntry.getKey();
TypeReport value = typeReportEntry.getValue();
Stats stats = value.getStats();
text.append("Metadata Object Type: ").append(key).append("\n").append("Stats: \n").append("total: " + stats.getTotal() + "\n");
if (stats.getCreated() > 0) {
text.append(" created: " + stats.getCreated() + "\n");
}
if (stats.getUpdated() > 0) {
text.append(" updated: " + stats.getUpdated() + "\n");
}
if (stats.getIgnored() > 0) {
text.append(" ignored: " + stats.getIgnored() + "\n");
}
}
}
text.append("\n\n");
}
if (text.length() > 0) {
log.info("Success mail will be sent with the following message: " + text);
emailService.sendSystemEmail(new Email("Success Notification: Metadata Synchronization", text.toString()));
}
}
use of org.hisp.dhis.dxf2.metadata.Metadata in project dhis2-core by dhis2.
the class ObjectBundleServiceFavoritesTest method testDeleteLegendSet.
@Test
public void testDeleteLegendSet() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/favorites/legends.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
assertTrue(validate.getErrorReports().isEmpty());
objectBundleService.commit(bundle);
List<LegendSet> legendSets = manager.getAll(LegendSet.class);
assertEquals(1, legendSets.size());
LegendSet legendSet = legendSets.get(0);
assertEquals("fqs276KXCXi", legendSet.getUid());
assertEquals("ANC Coverage", legendSet.getName());
assertEquals(7, legendSet.getLegends().size());
manager.delete(legendSet);
legendSets = manager.getAll(LegendSet.class);
assertTrue(legendSets.isEmpty());
}
use of org.hisp.dhis.dxf2.metadata.Metadata in project dhis2-core by dhis2.
the class ObjectBundleServiceFavoritesTest method testCreateLegendSets.
@Test
public void testCreateLegendSets() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/favorites/legends.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
assertTrue(validate.getErrorReports().isEmpty());
objectBundleService.commit(bundle);
List<LegendSet> legendSets = manager.getAll(LegendSet.class);
assertEquals(1, legendSets.size());
LegendSet legendSet = legendSets.get(0);
assertEquals("fqs276KXCXi", legendSet.getUid());
assertEquals("ANC Coverage", legendSet.getName());
assertEquals(7, legendSet.getLegends().size());
}
use of org.hisp.dhis.dxf2.metadata.Metadata in project dhis2-core by dhis2.
the class ObjectBundleServiceFavoritesTest method testCreateMetadataWithChartsWithPeriods1.
@Test
public void testCreateMetadataWithChartsWithPeriods1() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/favorites/metadata_with_chart_periods1.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
assertTrue(validate.getErrorReports().isEmpty());
objectBundleService.commit(bundle);
List<DataSet> dataSets = manager.getAll(DataSet.class);
List<OrganisationUnit> organisationUnits = manager.getAll(OrganisationUnit.class);
List<DataElement> dataElements = manager.getAll(DataElement.class);
List<Chart> charts = manager.getAll(Chart.class);
assertEquals(1, dataSets.size());
assertEquals(1, organisationUnits.size());
assertEquals(4, dataElements.size());
assertEquals(4, charts.size());
Chart chart = manager.get(Chart.class, "ziCoxdcXRQz");
assertNotNull(chart);
assertEquals(5, chart.getPeriods().size());
}
Aggregations