Search in sources :

Example 16 with Metadata

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 ");
}
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 17 with Metadata

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()));
    }
}
Also used : Email(org.hisp.dhis.email.Email) TypeReport(org.hisp.dhis.feedback.TypeReport) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) Stats(org.hisp.dhis.feedback.Stats)

Example 18 with Metadata

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());
}
Also used : ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) List(java.util.List) LegendSet(org.hisp.dhis.legend.LegendSet) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 19 with Metadata

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());
}
Also used : ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) List(java.util.List) LegendSet(org.hisp.dhis.legend.LegendSet) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 20 with Metadata

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());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) DataSet(org.hisp.dhis.dataset.DataSet) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) DataElement(org.hisp.dhis.dataelement.DataElement) List(java.util.List) Chart(org.hisp.dhis.chart.Chart) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

DhisSpringTest (org.hisp.dhis.DhisSpringTest)55 Test (org.junit.Test)55 List (java.util.List)46 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)46 ClassPathResource (org.springframework.core.io.ClassPathResource)42 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)37 DataElement (org.hisp.dhis.dataelement.DataElement)25 User (org.hisp.dhis.user.User)20 MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)19 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)19 Metadata (com.google.android.exoplayer2.metadata.Metadata)18 DataSet (org.hisp.dhis.dataset.DataSet)15 ArrayList (java.util.ArrayList)14 MetadataVersionServiceException (org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 IOException (java.io.IOException)10 Metadata (org.hisp.dhis.dxf2.metadata.Metadata)10 DhisHttpResponse (org.hisp.dhis.system.util.DhisHttpResponse)10 UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)10 IntegrationTest (org.hisp.dhis.IntegrationTest)9