use of org.hisp.dhis.tracker.report.TrackerBundleReport in project dhis2-core by dhis2.
the class DefaultTrackerBundleService method commit.
@Override
@Transactional
public TrackerBundleReport commit(TrackerBundle bundle) {
TrackerBundleReport bundleReport = new TrackerBundleReport();
if (TrackerBundleMode.VALIDATE == bundle.getImportMode()) {
return bundleReport;
}
Session session = sessionFactory.getCurrentSession();
Map<TrackerType, TrackerTypeReport> report = bundleReport.getTypeReportMap();
report.put(TrackerType.TRACKED_ENTITY, commitService.getTrackerPersister().persist(session, bundle));
report.put(TrackerType.ENROLLMENT, commitService.getEnrollmentPersister().persist(session, bundle));
report.put(TrackerType.EVENT, commitService.getEventPersister().persist(session, bundle));
report.put(TrackerType.RELATIONSHIP, commitService.getRelationshipPersister().persist(session, bundle));
return bundleReport;
}
use of org.hisp.dhis.tracker.report.TrackerBundleReport in project dhis2-core by dhis2.
the class DefaultTrackerImportService method commitBundle.
protected TrackerBundleReport commitBundle(TrackerBundle trackerBundle) {
TrackerBundleReport bundleReport = trackerBundleService.commit(trackerBundle);
if (!trackerBundle.isSkipSideEffects()) {
List<TrackerSideEffectDataBundle> sideEffectDataBundles = Stream.of(TrackerType.ENROLLMENT, TrackerType.EVENT).map(trackerType -> safelyGetSideEffectsDataBundles(bundleReport, trackerType)).flatMap(Collection::stream).collect(Collectors.toList());
trackerBundleService.handleTrackerSideEffects(sideEffectDataBundles);
}
return bundleReport;
}
use of org.hisp.dhis.tracker.report.TrackerBundleReport in project dhis2-core by dhis2.
the class DefaultTrackerImportService method commit.
private TrackerBundleReport commit(TrackerImportParams params, TrackerTimingsStats opsTimer, TrackerBundle trackerBundle) {
TrackerBundleReport bundleReport;
if (TrackerImportStrategy.DELETE == params.getImportStrategy()) {
bundleReport = opsTimer.exec(COMMIT_OPS, () -> deleteBundle(trackerBundle));
} else {
bundleReport = opsTimer.exec(COMMIT_OPS, () -> commitBundle(trackerBundle));
}
notifyOps(params, COMMIT_OPS, opsTimer);
return bundleReport;
}
use of org.hisp.dhis.tracker.report.TrackerBundleReport in project dhis2-core by dhis2.
the class TrackerImporterServiceTest method setUp.
@BeforeEach
public void setUp() {
subject = new DefaultTrackerImportService(trackerBundleService, trackerValidationService, trackerPreprocessService, trackerUserService, notifier);
final List<Event> events = rnd.objects(Event.class, 3).collect(Collectors.toList());
params = TrackerImportParams.builder().events(events).enrollments(new ArrayList<>()).relationships(new ArrayList<>()).trackedEntities(new ArrayList<>()).userId("123").build();
TrackerBundleReport trackerBundleReport = TrackerBundleReport.builder().build();
when(trackerUserService.getUser(anyString())).thenReturn(getUser());
when(trackerBundleService.commit(any(TrackerBundle.class))).thenReturn(trackerBundleReport);
when(trackerValidationService.validate(any(TrackerBundle.class))).thenReturn(new TrackerValidationReport());
when(trackerValidationService.validateRuleEngine(any(TrackerBundle.class))).thenReturn(new TrackerValidationReport());
when(trackerPreprocessService.preprocess(any(TrackerBundle.class))).thenReturn(ParamsConverter.convert(params));
}
use of org.hisp.dhis.tracker.report.TrackerBundleReport in project dhis2-core by dhis2.
the class DefaultTrackerImportService method importTracker.
@Override
public TrackerImportReport importTracker(TrackerImportParams params) {
User user = trackerUserService.getUser(params.getUserId());
params.setUser(user);
TrackerTimingsStats opsTimer = new TrackerTimingsStats();
startImport(params);
TrackerValidationReport validationReport = new TrackerValidationReport();
TrackerBundleReport bundleReport;
try {
TrackerBundle trackerBundle = preHeat(params, opsTimer);
Map<TrackerType, Integer> bundleSize = calculatePayloadSize(trackerBundle);
preProcess(opsTimer, trackerBundle);
if (addToValidationReport(params, opsTimer, validationReport, trackerBundle)) {
return buildReportAndNotify(params, validationReport, opsTimer, bundleSize);
}
bundleReport = commit(params, opsTimer, trackerBundle);
postCommit(trackerBundle);
TrackerImportReport trackerImportReport = TrackerImportReport.withImportCompleted(TrackerStatus.OK, bundleReport, validationReport, opsTimer.stopTimer(), bundleSize);
endImport(params, trackerImportReport);
return trackerImportReport;
} catch (Exception e) {
log.error("Exception thrown during import.", e);
TrackerImportReport report = TrackerImportReport.withError("Exception:" + e.getMessage(), validationReport, opsTimer.stopTimer());
endImportWithError(params, report, e);
return report;
}
}
Aggregations