Search in sources :

Example 51 with JobConfiguration

use of org.hisp.dhis.scheduling.JobConfiguration in project dhis2-core by dhis2.

the class ResourceTableController method analytics.

@RequestMapping(value = "/analytics", method = { RequestMethod.PUT, RequestMethod.POST })
@PreAuthorize("hasRole('ALL') or hasRole('F_PERFORM_MAINTENANCE')")
@ResponseBody
public WebMessage analytics(@RequestParam(required = false) boolean skipResourceTables, @RequestParam(required = false) boolean skipAggregate, @RequestParam(required = false) boolean skipEvents, @RequestParam(required = false) boolean skipEnrollment, @RequestParam(required = false) Integer lastYears) {
    Set<AnalyticsTableType> skipTableTypes = new HashSet<>();
    Set<String> skipPrograms = new HashSet<>();
    if (skipAggregate) {
        skipTableTypes.add(AnalyticsTableType.DATA_VALUE);
        skipTableTypes.add(AnalyticsTableType.COMPLETENESS);
        skipTableTypes.add(AnalyticsTableType.COMPLETENESS_TARGET);
    }
    if (skipEvents) {
        skipTableTypes.add(AnalyticsTableType.EVENT);
    }
    if (skipEnrollment) {
        skipTableTypes.add(AnalyticsTableType.ENROLLMENT);
    }
    AnalyticsJobParameters analyticsJobParameters = new AnalyticsJobParameters(lastYears, skipTableTypes, skipPrograms, skipResourceTables);
    JobConfiguration analyticsTableJob = new JobConfiguration("inMemoryAnalyticsJob", JobType.ANALYTICS_TABLE, "", analyticsJobParameters, true, true);
    analyticsTableJob.setUserUid(currentUserService.getCurrentUser().getUid());
    schedulingManager.executeNow(analyticsTableJob);
    return jobConfigurationReport(analyticsTableJob);
}
Also used : AnalyticsTableType(org.hisp.dhis.analytics.AnalyticsTableType) AnalyticsJobParameters(org.hisp.dhis.scheduling.parameters.AnalyticsJobParameters) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) HashSet(java.util.HashSet) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 52 with JobConfiguration

use of org.hisp.dhis.scheduling.JobConfiguration in project dhis2-core by dhis2.

the class EnrollmentController method startAsyncImport.

// -------------------------------------------------------------------------
// HELPERS
// -------------------------------------------------------------------------
/**
 * Starts an asynchronous enrollment task.
 *
 * @param importOptions the ImportOptions.
 * @param enrollments the enrollments to import.
 */
private WebMessage startAsyncImport(ImportOptions importOptions, List<Enrollment> enrollments) {
    JobConfiguration jobId = new JobConfiguration("inMemoryEventImport", ENROLLMENT_IMPORT, currentUserService.getCurrentUser().getUid(), true);
    taskExecutor.executeTask(new ImportEnrollmentsTask(enrollments, enrollmentService, importOptions, jobId));
    return jobConfigurationReport(jobId).setLocation("/system/tasks/" + ENROLLMENT_IMPORT);
}
Also used : ImportEnrollmentsTask(org.hisp.dhis.dxf2.events.enrollment.ImportEnrollmentsTask) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration)

Example 53 with JobConfiguration

use of org.hisp.dhis.scheduling.JobConfiguration in project dhis2-core by dhis2.

the class JobConfigurationController method executeJobConfiguration.

@PostMapping(value = "{uid}/execute", produces = { APPLICATION_JSON_VALUE, "application/javascript" })
public ObjectReport executeJobConfiguration(@PathVariable("uid") String uid) throws WebMessageException {
    JobConfiguration jobConfiguration = jobConfigurationService.getJobConfigurationByUid(uid);
    checkConfigurable(jobConfiguration, HttpStatus.FORBIDDEN, "Job %s is a system job that cannot be executed.");
    ObjectReport objectReport = new ObjectReport(JobConfiguration.class, 0);
    boolean success = schedulingManager.executeNow(jobConfiguration);
    if (!success) {
        objectReport.addErrorReport(new ErrorReport(JobConfiguration.class, new ErrorMessage(ErrorCode.E7006, jobConfiguration.getName())));
    }
    return objectReport;
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) ObjectReport(org.hisp.dhis.feedback.ObjectReport) ErrorMessage(org.hisp.dhis.feedback.ErrorMessage) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 54 with JobConfiguration

use of org.hisp.dhis.scheduling.JobConfiguration in project dhis2-core by dhis2.

the class TrackerImportStrategyImpl method importReport.

@Override
public TrackerImportReport importReport(TrackerImportReportRequest trackerImportReportRequest) {
    setTrackerImportParams(trackerImportReportRequest);
    if (trackerImportReportRequest.isAsync()) {
        return importAsyncStrategy.importReport(trackerImportReportRequest);
    } else {
        JobConfiguration jobConfiguration = new JobConfiguration("", JobType.TRACKER_IMPORT_JOB, trackerImportReportRequest.getUserUid(), trackerImportReportRequest.isAsync());
        jobConfiguration.setUid(trackerImportReportRequest.getUid());
        trackerImportReportRequest.getTrackerImportParams().setJobConfiguration(jobConfiguration);
        return importAsyncFalseStrategy.importReport(trackerImportReportRequest);
    }
}
Also used : JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration)

Example 55 with JobConfiguration

use of org.hisp.dhis.scheduling.JobConfiguration in project dhis2-core by dhis2.

the class TrackerImportStrategyHandlerImplTest method shouldCreateReportAsyncFalse.

@Test
void shouldCreateReportAsyncFalse() {
    TrackerImportReportRequest trackerImportReportRequest = TrackerImportReportRequest.builder().trackerImportParams(TrackerImportParams.builder().jobConfiguration(new JobConfiguration("", JobType.TRACKER_IMPORT_JOB, "userId", false)).build()).trackerBundleReportMode(TrackerBundleReportMode.FULL).build();
    importAsyncFalseStrategy.importReport(trackerImportReportRequest);
    verify(trackerImportService).importTracker(trackerImportReportRequest.getTrackerImportParams());
    verify(trackerImportService).buildImportReport(any(), any());
}
Also used : TrackerImportReportRequest(org.hisp.dhis.webapi.controller.tracker.TrackerImportReportRequest) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) Test(org.junit.jupiter.api.Test)

Aggregations

JobConfiguration (org.hisp.dhis.scheduling.JobConfiguration)55 Test (org.junit.jupiter.api.Test)23 ErrorReport (org.hisp.dhis.feedback.ErrorReport)10 List (java.util.List)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 ArrayList (java.util.ArrayList)5 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 InputStream (java.io.InputStream)4 IdScheme (org.hisp.dhis.common.IdScheme)4 CachingMap (org.hisp.dhis.commons.collection.CachingMap)4 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)4 ImportStrategy (org.hisp.dhis.importexport.ImportStrategy)4 Collections (java.util.Collections)3 HashMap (java.util.HashMap)3 IdSchemes (org.hisp.dhis.common.IdSchemes)3 IdentifiableObjectManager (org.hisp.dhis.common.IdentifiableObjectManager)3 TrackerTrigramIndexJobParameters (org.hisp.dhis.scheduling.parameters.TrackerTrigramIndexJobParameters)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3