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