Search in sources :

Example 1 with TrackerBundleReport

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;
}
Also used : TrackerTypeReport(org.hisp.dhis.tracker.report.TrackerTypeReport) TrackerType(org.hisp.dhis.tracker.TrackerType) TrackerBundleReport(org.hisp.dhis.tracker.report.TrackerBundleReport) Session(org.hibernate.Session) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with TrackerBundleReport

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;
}
Also used : TrackerSideEffectDataBundle(org.hisp.dhis.tracker.job.TrackerSideEffectDataBundle) TrackerBundleReport(org.hisp.dhis.tracker.report.TrackerBundleReport)

Example 3 with TrackerBundleReport

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;
}
Also used : TrackerBundleReport(org.hisp.dhis.tracker.report.TrackerBundleReport)

Example 4 with TrackerBundleReport

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));
}
Also used : TrackerValidationReport(org.hisp.dhis.tracker.report.TrackerValidationReport) ArrayList(java.util.ArrayList) Event(org.hisp.dhis.tracker.domain.Event) DefaultTrackerImportService(org.hisp.dhis.tracker.DefaultTrackerImportService) TrackerBundleReport(org.hisp.dhis.tracker.report.TrackerBundleReport) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with TrackerBundleReport

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;
    }
}
Also used : TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) User(org.hisp.dhis.user.User) TrackerTimingsStats(org.hisp.dhis.tracker.report.TrackerTimingsStats) TrackerValidationReport(org.hisp.dhis.tracker.report.TrackerValidationReport) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) TrackerBundleReport(org.hisp.dhis.tracker.report.TrackerBundleReport)

Aggregations

TrackerBundleReport (org.hisp.dhis.tracker.report.TrackerBundleReport)7 TrackerType (org.hisp.dhis.tracker.TrackerType)2 TrackerTypeReport (org.hisp.dhis.tracker.report.TrackerTypeReport)2 TrackerValidationReport (org.hisp.dhis.tracker.report.TrackerValidationReport)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ArrayList (java.util.ArrayList)1 Session (org.hibernate.Session)1 DefaultTrackerImportService (org.hisp.dhis.tracker.DefaultTrackerImportService)1 TrackerImportParams (org.hisp.dhis.tracker.TrackerImportParams)1 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)1 Event (org.hisp.dhis.tracker.domain.Event)1 TrackerSideEffectDataBundle (org.hisp.dhis.tracker.job.TrackerSideEffectDataBundle)1 TrackerImportReport (org.hisp.dhis.tracker.report.TrackerImportReport)1 TrackerTimingsStats (org.hisp.dhis.tracker.report.TrackerTimingsStats)1 User (org.hisp.dhis.user.User)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1