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();
}
}
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;
}
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));
}
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;
}
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()));
}
Aggregations