Search in sources :

Example 41 with TypeReport

use of org.hisp.dhis.feedback.TypeReport in project dhis2-core by dhis2.

the class DefaultObjectBundleService method commitObjectType.

private <T extends IdentifiableObject> void commitObjectType(ObjectBundle bundle, Map<Class<?>, TypeReport> typeReports, Session session, Class<T> klass) {
    List<T> nonPersistedObjects = bundle.getObjects(klass, false);
    List<T> persistedObjects = bundle.getObjects(klass, true);
    List<ObjectBundleHook<? super T>> importHooks = objectBundleHooks.getTypeImportHooks(klass);
    importHooks.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));
    }
    importHooks.forEach(hook -> hook.postTypeImport(klass, persistedObjects, bundle));
    if (FlushMode.AUTO == bundle.getFlushMode()) {
        session.flush();
    }
}
Also used : TypeReport(org.hisp.dhis.feedback.TypeReport)

Example 42 with TypeReport

use of org.hisp.dhis.feedback.TypeReport in project dhis2-core by dhis2.

the class WebMessageUtils method typeReport.

public static TypeReport typeReport(Class clazz, List<ErrorReport> errorReports) {
    ObjectReport objectReport = new ObjectReport(clazz, 0);
    objectReport.addErrorReports(errorReports);
    TypeReport typeReport = new TypeReport(clazz);
    typeReport.addObjectReport(objectReport);
    return typeReport;
}
Also used : TypeReport(org.hisp.dhis.feedback.TypeReport) ObjectReport(org.hisp.dhis.feedback.ObjectReport)

Example 43 with TypeReport

use of org.hisp.dhis.feedback.TypeReport in project dhis2-core by dhis2.

the class ObjectBundleReportTest method testObjectBundleCommitReport.

@Test
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.getErrorReportsCount());
    assertEquals(3, validationReport.getErrorReportsCountByCode(DataElement.class, ErrorCode.E3000));
    assertEquals(3, validationReport.getErrorReportsCountByCode(Indicator.class, ErrorCode.E3000));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) ObjectBundleCommitReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleCommitReport) TypeReport(org.hisp.dhis.feedback.TypeReport) Indicator(org.hisp.dhis.indicator.Indicator) Test(org.junit.jupiter.api.Test)

Example 44 with TypeReport

use of org.hisp.dhis.feedback.TypeReport in project dhis2-core by dhis2.

the class ObjectBundleReportTest method createTypeReport.

private TypeReport createTypeReport(Class<?> mainKlass, Class<?> errorKlass) {
    ObjectReport objectReport0 = new ObjectReport(mainKlass, 0);
    ObjectReport objectReport1 = new ObjectReport(mainKlass, 1);
    ObjectReport objectReport2 = new ObjectReport(mainKlass, 2);
    objectReport0.addErrorReport(new ErrorReport(errorKlass, ErrorCode.E3000, "admin", errorKlass.getSimpleName()));
    objectReport1.addErrorReport(new ErrorReport(errorKlass, ErrorCode.E3000, "admin", errorKlass.getSimpleName()));
    objectReport2.addErrorReport(new ErrorReport(errorKlass, ErrorCode.E3000, "admin", errorKlass.getSimpleName()));
    TypeReport typeReport = new TypeReport(mainKlass);
    typeReport.addObjectReport(objectReport0);
    typeReport.addObjectReport(objectReport1);
    typeReport.addObjectReport(objectReport2);
    return typeReport;
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) TypeReport(org.hisp.dhis.feedback.TypeReport) ObjectReport(org.hisp.dhis.feedback.ObjectReport)

Example 45 with TypeReport

use of org.hisp.dhis.feedback.TypeReport in project dhis2-core by dhis2.

the class ObjectBundleServiceAttributesTest method testValidateMetadataAttributeValuesMandatoryFromPayload.

@Test
void testValidateMetadataAttributeValuesMandatoryFromPayload() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/metadata_with_mandatory_attributes_from_payload_only.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.VALIDATE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    ObjectBundleValidationReport validationReport = objectBundleValidationService.validate(bundle);
    TypeReport typeReport = validationReport.getTypeReport(DataElement.class);
    assertNotNull(typeReport);
    assertEquals(4, typeReport.getObjectReportsCount());
    typeReport.forEachObjectReport(objectReport -> assertEquals(1, objectReport.getErrorReportsCount()));
}
Also used : ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) TypeReport(org.hisp.dhis.feedback.TypeReport) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.jupiter.api.Test)

Aggregations

TypeReport (org.hisp.dhis.feedback.TypeReport)52 ObjectReport (org.hisp.dhis.feedback.ObjectReport)28 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)24 ErrorReport (org.hisp.dhis.feedback.ErrorReport)15 PreheatErrorReport (org.hisp.dhis.preheat.PreheatErrorReport)13 List (java.util.List)7 Test (org.junit.jupiter.api.Test)7 Transactional (org.springframework.transaction.annotation.Transactional)6 ArrayList (java.util.ArrayList)5 ObjectBundleCommitReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleCommitReport)5 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)5 User (org.hisp.dhis.user.User)5 HashMap (java.util.HashMap)4 IdentifiableObjectManager (org.hisp.dhis.common.IdentifiableObjectManager)4 DataElement (org.hisp.dhis.dataelement.DataElement)4 SchemaService (org.hisp.dhis.schema.SchemaService)4 Service (org.springframework.stereotype.Service)4 AllArgsConstructor (lombok.AllArgsConstructor)3 Session (org.hibernate.Session)3 MergeParams (org.hisp.dhis.schema.MergeParams)3