Search in sources :

Example 1 with ObjectBundleCommitReport

use of org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleCommitReport in project dhis2-core by dhis2.

the class ObjectBundleReportTest method testImportReportMerge.

@Test
public void testImportReportMerge() {
    TypeReport typeReport0 = createTypeReport(DataElement.class, DataElementGroup.class);
    TypeReport typeReport1 = createTypeReport(Indicator.class, IndicatorGroup.class);
    TypeReport typeReport2 = createTypeReport(Indicator.class, IndicatorGroup.class);
    TypeReport typeReport3 = createTypeReport(OrganisationUnit.class, OrganisationUnitGroup.class);
    ObjectBundleValidationReport objectBundleValidationReport = new ObjectBundleValidationReport();
    objectBundleValidationReport.addTypeReport(typeReport0);
    objectBundleValidationReport.addTypeReport(typeReport1);
    assertEquals(6, objectBundleValidationReport.getErrorReports().size());
    assertEquals(3, objectBundleValidationReport.getErrorReportsByCode(DataElement.class, ErrorCode.E3000).size());
    assertEquals(3, objectBundleValidationReport.getErrorReportsByCode(Indicator.class, ErrorCode.E3000).size());
    ObjectBundleCommitReport objectBundleCommitReport = new ObjectBundleCommitReport();
    objectBundleCommitReport.addTypeReport(typeReport2);
    objectBundleCommitReport.addTypeReport(typeReport3);
    assertEquals(6, objectBundleCommitReport.getErrorReports().size());
    assertEquals(3, objectBundleCommitReport.getErrorReportsByCode(Indicator.class, ErrorCode.E3000).size());
    assertEquals(3, objectBundleCommitReport.getErrorReportsByCode(OrganisationUnit.class, ErrorCode.E3000).size());
    ImportReport importReport = new ImportReport();
    importReport.addTypeReports(objectBundleValidationReport.getTypeReportMap());
    importReport.addTypeReports(objectBundleCommitReport.getTypeReportMap());
    assertEquals(3, importReport.getTypeReportMap().size());
    assertEquals(3, importReport.getTypeReportMap().get(DataElement.class).getErrorReports().size());
    assertEquals(3, importReport.getTypeReportMap().get(OrganisationUnit.class).getErrorReports().size());
    assertEquals(6, importReport.getTypeReportMap().get(Indicator.class).getErrorReports().size());
    assertEquals(3, importReport.getTypeReportMap().get(DataElement.class).getObjectReports().size());
    assertEquals(3, importReport.getTypeReportMap().get(Indicator.class).getObjectReports().size());
    assertEquals(3, importReport.getTypeReportMap().get(OrganisationUnit.class).getObjectReports().size());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ObjectBundleCommitReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleCommitReport) TypeReport(org.hisp.dhis.feedback.TypeReport) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) Indicator(org.hisp.dhis.indicator.Indicator) Test(org.junit.Test)

Example 2 with ObjectBundleCommitReport

use of org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleCommitReport in project dhis2-core by dhis2.

the class DefaultMetadataImportService method importMetadata.

@Override
public ImportReport importMetadata(MetadataImportParams params) {
    Timer timer = new SystemTimer().start();
    ImportReport importReport = new ImportReport();
    importReport.setImportParams(params);
    importReport.setStatus(Status.OK);
    if (params.getUser() == null) {
        params.setUser(currentUserService.getCurrentUser());
    }
    String message = "(" + params.getUsername() + ") Import:Start";
    log.info(message);
    if (params.hasTaskId()) {
        notifier.notify(params.getTaskId(), message);
    }
    ObjectBundleParams bundleParams = params.toObjectBundleParams();
    ObjectBundle bundle = objectBundleService.create(bundleParams);
    prepareBundle(bundle);
    ObjectBundleValidationReport validationReport = objectBundleValidationService.validate(bundle);
    importReport.addTypeReports(validationReport.getTypeReportMap());
    if (!(!validationReport.getErrorReports().isEmpty() && AtomicMode.ALL == bundle.getAtomicMode())) {
        Timer commitTimer = new SystemTimer().start();
        ObjectBundleCommitReport commitReport = objectBundleService.commit(bundle);
        importReport.addTypeReports(commitReport.getTypeReportMap());
        if (!importReport.getErrorReports().isEmpty()) {
            importReport.setStatus(Status.WARNING);
        }
        log.info("(" + bundle.getUsername() + ") Import:Commit took " + commitTimer.toString());
    } else {
        importReport.getStats().ignored();
        importReport.getTypeReports().forEach(tr -> tr.getStats().ignored());
        importReport.setStatus(Status.ERROR);
    }
    message = "(" + bundle.getUsername() + ") Import:Done took " + timer.toString();
    log.info(message);
    if (bundle.hasTaskId()) {
        notifier.notify(bundle.getTaskId(), NotificationLevel.INFO, message, true).addTaskSummary(bundle.getTaskId(), importReport);
    }
    if (ObjectBundleMode.VALIDATE == params.getImportMode()) {
        return importReport;
    }
    Lists.newArrayList(importReport.getTypeReportMap().keySet()).forEach(typeReportKey -> {
        if (importReport.getTypeReportMap().get(typeReportKey).getStats().getTotal() == 0) {
            importReport.getTypeReportMap().remove(typeReportKey);
            return;
        }
        TypeReport typeReport = importReport.getTypeReportMap().get(typeReportKey);
        if (ImportReportMode.ERRORS == params.getImportReportMode()) {
            Lists.newArrayList(typeReport.getObjectReportMap().keySet()).forEach(objectReportKey -> {
                if (typeReport.getObjectReportMap().get(objectReportKey).getErrorReportsByCode().isEmpty()) {
                    typeReport.getObjectReportMap().remove(objectReportKey);
                }
            });
        }
        if (ImportReportMode.DEBUG != params.getImportReportMode()) {
            typeReport.getObjectReports().forEach(objectReport -> objectReport.setDisplayName(null));
        }
    });
    return importReport;
}
Also used : ObjectBundleParams(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams) ObjectBundleCommitReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleCommitReport) ObjectBundle(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle) SystemTimer(org.hisp.dhis.commons.timer.SystemTimer) Timer(org.hisp.dhis.commons.timer.Timer) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) TypeReport(org.hisp.dhis.feedback.TypeReport) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) SystemTimer(org.hisp.dhis.commons.timer.SystemTimer)

Example 3 with ObjectBundleCommitReport

use of org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleCommitReport in project dhis2-core by dhis2.

the class DefaultObjectBundleService method commit.

@Override
public ObjectBundleCommitReport commit(ObjectBundle bundle) {
    Map<Class<?>, TypeReport> typeReports = new HashMap<>();
    ObjectBundleCommitReport commitReport = new ObjectBundleCommitReport(typeReports);
    if (ObjectBundleMode.VALIDATE == bundle.getObjectBundleMode()) {
        // skip if validate only
        return commitReport;
    }
    List<Class<? extends IdentifiableObject>> klasses = getSortedClasses(bundle);
    Session session = sessionFactory.getCurrentSession();
    objectBundleHooks.forEach(hook -> hook.preCommit(bundle));
    for (Class<? extends IdentifiableObject> klass : klasses) {
        List<IdentifiableObject> nonPersistedObjects = bundle.getObjects(klass, false);
        List<IdentifiableObject> persistedObjects = bundle.getObjects(klass, true);
        objectBundleHooks.forEach(hook -> hook.preTypeImport(klass, nonPersistedObjects, bundle));
        if (bundle.getImportMode().isCreateAndUpdate()) {
            TypeReport typeReport = new TypeReport(klass);
            typeReport.merge(handleCreates(session, klass, nonPersistedObjects, bundle));
            typeReport.merge(handleUpdates(session, klass, persistedObjects, bundle));
            typeReports.put(klass, typeReport);
        } else if (bundle.getImportMode().isCreate()) {
            typeReports.put(klass, handleCreates(session, klass, nonPersistedObjects, bundle));
        } else if (bundle.getImportMode().isUpdate()) {
            typeReports.put(klass, handleUpdates(session, klass, persistedObjects, bundle));
        } else if (bundle.getImportMode().isDelete()) {
            typeReports.put(klass, handleDeletes(session, klass, persistedObjects, bundle));
        }
        objectBundleHooks.forEach(hook -> hook.postTypeImport(klass, persistedObjects, bundle));
        if (FlushMode.AUTO == bundle.getFlushMode())
            session.flush();
    }
    if (!bundle.getImportMode().isDelete()) {
        objectBundleHooks.forEach(hook -> hook.postCommit(bundle));
    }
    dbmsManager.clearSession();
    cacheManager.clearCache();
    bundle.setObjectBundleStatus(ObjectBundleStatus.COMMITTED);
    return commitReport;
}
Also used : ObjectBundleCommitReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleCommitReport) HashMap(java.util.HashMap) TypeReport(org.hisp.dhis.feedback.TypeReport) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Session(org.hibernate.Session)

Example 4 with ObjectBundleCommitReport

use of org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleCommitReport in project dhis2-core by dhis2.

the class ObjectBundleReportTest method testObjectBundleCommitReport.

@Test
public void testObjectBundleCommitReport() {
    TypeReport typeReport0 = createTypeReport(DataElement.class, DataElementGroup.class);
    TypeReport typeReport1 = createTypeReport(Indicator.class, IndicatorGroup.class);
    ObjectBundleCommitReport validationReport = new ObjectBundleCommitReport();
    validationReport.addTypeReport(typeReport0);
    validationReport.addTypeReport(typeReport1);
    assertEquals(6, validationReport.getErrorReports().size());
    assertEquals(3, validationReport.getErrorReportsByCode(DataElement.class, ErrorCode.E3000).size());
    assertEquals(3, validationReport.getErrorReportsByCode(Indicator.class, ErrorCode.E3000).size());
}
Also used : ObjectBundleCommitReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleCommitReport) TypeReport(org.hisp.dhis.feedback.TypeReport) Test(org.junit.Test)

Aggregations

ObjectBundleCommitReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleCommitReport)4 TypeReport (org.hisp.dhis.feedback.TypeReport)4 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 Session (org.hibernate.Session)1 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)1 SystemTimer (org.hisp.dhis.commons.timer.SystemTimer)1 Timer (org.hisp.dhis.commons.timer.Timer)1 DataElement (org.hisp.dhis.dataelement.DataElement)1 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)1 ObjectBundle (org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle)1 ObjectBundleParams (org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams)1 Indicator (org.hisp.dhis.indicator.Indicator)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1