Search in sources :

Example 16 with JobConfiguration

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

the class DataIntegrityController method runDataIntegrityAsync.

private WebMessage runDataIntegrityAsync(Collection<String> checks, User currentUser, String description, DataIntegrityReportType type) {
    DataIntegrityJobParameters params = new DataIntegrityJobParameters();
    params.setChecks(toUniformCheckNames(checks));
    params.setType(type);
    JobConfiguration config = new JobConfiguration(description, JobType.DATA_INTEGRITY, null, params, true, true);
    config.setUserUid(currentUser.getUid());
    config.setAutoFields();
    if (!schedulingManager.executeNow(config)) {
        return conflict("Data integrity check is already running");
    }
    return jobConfigurationReport(config);
}
Also used : DataIntegrityJobParameters(org.hisp.dhis.scheduling.parameters.DataIntegrityJobParameters) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration)

Example 17 with JobConfiguration

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

the class CompleteDataSetRegistrationController method asyncImport.

// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private WebMessage asyncImport(ImportOptions importOptions, String format, HttpServletRequest request) throws IOException {
    Pair<InputStream, Path> tmpFile = saveTmpFile(request.getInputStream());
    JobConfiguration jobId = new JobConfiguration("inMemoryCompleteDataSetRegistrationImport", COMPLETE_DATA_SET_REGISTRATION_IMPORT, currentUserService.getCurrentUser().getUid(), true);
    taskExecutor.executeTask(new ImportCompleteDataSetRegistrationsTask(registrationExchangeService, sessionFactory, tmpFile.getLeft(), tmpFile.getRight(), importOptions, format, jobId));
    return jobConfigurationReport(jobId).setLocation("/system/tasks/" + COMPLETE_DATA_SET_REGISTRATION_IMPORT);
}
Also used : Path(java.nio.file.Path) ImportCompleteDataSetRegistrationsTask(org.hisp.dhis.dxf2.dataset.tasks.ImportCompleteDataSetRegistrationsTask) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration)

Example 18 with JobConfiguration

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

the class PredictionController method runPredictors.

@RequestMapping(method = { RequestMethod.POST, RequestMethod.PUT })
@PreAuthorize("hasRole('ALL') or hasRole('F_PREDICTOR_RUN')")
@ResponseBody
public WebMessage runPredictors(@RequestParam Date startDate, @RequestParam Date endDate, @RequestParam(value = "predictor", required = false) List<String> predictors, @RequestParam(value = "predictorGroup", required = false) List<String> predictorGroups, @RequestParam(defaultValue = "false", required = false) boolean async, HttpServletRequest request) {
    if (async) {
        JobConfiguration jobId = new JobConfiguration("inMemoryPrediction", PREDICTOR, currentUserService.getCurrentUser().getUid(), true);
        taskExecutor.executeTask(new PredictionTask(startDate, endDate, predictors, predictorGroups, predictionService, jobId));
        return jobConfigurationReport(jobId).setLocation("/system/tasks/" + PREDICTOR);
    }
    PredictionSummary predictionSummary = predictionService.predictTask(startDate, endDate, predictors, predictorGroups, null);
    return new WebMessage(Status.OK, HttpStatus.OK).setResponse(predictionSummary).withPlainResponseBefore(DhisApiVersion.V38);
}
Also used : PredictionTask(org.hisp.dhis.predictor.PredictionTask) PredictionSummary(org.hisp.dhis.predictor.PredictionSummary) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) WebMessage(org.hisp.dhis.dxf2.webmessage.WebMessage) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 19 with JobConfiguration

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

the class TrackerImportStrategyHandlerImplTest method shouldSendMessageToQueueAsync.

@Test
void shouldSendMessageToQueueAsync() {
    ArgumentCaptor<String> queueNameCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<TrackerMessage> trackerMessageCaptor = ArgumentCaptor.forClass(TrackerMessage.class);
    doNothing().when(messageManager).sendQueue(queueNameCaptor.capture(), trackerMessageCaptor.capture());
    TrackerImportReportRequest trackerImportReportRequest = TrackerImportReportRequest.builder().trackerImportParams(TrackerImportParams.builder().jobConfiguration(new JobConfiguration("", JobType.TRACKER_IMPORT_JOB, "userId", true)).build()).build();
    importAsyncStrategy.importReport(trackerImportReportRequest);
    verify(trackerImportService, times(0)).importTracker(any());
    verify(messageManager).sendQueue(any(), any());
    assertEquals(Topics.TRACKER_IMPORT_JOB_TOPIC_NAME, queueNameCaptor.getValue());
    assertEquals(trackerImportReportRequest.getTrackerImportParams(), trackerMessageCaptor.getValue().getTrackerImportParams());
}
Also used : TrackerImportReportRequest(org.hisp.dhis.webapi.controller.tracker.TrackerImportReportRequest) TrackerMessage(org.hisp.dhis.tracker.job.TrackerMessage) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) Test(org.junit.jupiter.api.Test)

Example 20 with JobConfiguration

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

the class TrackedEntityInstanceController method postTrackedEntityInstance.

private WebMessage postTrackedEntityInstance(ImportStrategy strategy, ImportOptions importOptions, HttpServletRequest request, String mediaType) throws IOException, BadRequestException {
    importOptions.setStrategy(strategy);
    importOptions.setSkipLastUpdated(true);
    InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
    // For in memory Jobs
    JobConfiguration jobId = new JobConfiguration("inMemoryEventImport", TEI_IMPORT, currentUserService.getCurrentUser().getUid(), true);
    TrackerEntityInstanceRequest trackerEntityInstanceRequest = TrackerEntityInstanceRequest.builder().inputStream(inputStream).importOptions(importOptions).mediaType(mediaType).jobConfiguration(jobId).build();
    ImportSummaries importSummaries = trackedEntityInstanceStrategyHandler.mergeOrDeleteTrackedEntityInstances(trackerEntityInstanceRequest);
    if (!importOptions.isAsync()) {
        ImportSummary singleSummary = finalizeTrackedEntityInstancePostRequest(importOptions, request, importSummaries);
        return importSummaries(importSummaries).setLocation(singleSummary == null ? null : "/api/" + "trackedEntityInstances" + "/" + singleSummary.getReference());
    }
    return jobConfigurationReport(jobId).setLocation("/system/tasks/" + TEI_IMPORT);
}
Also used : InputStream(java.io.InputStream) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) TrackerEntityInstanceRequest(org.hisp.dhis.webapi.strategy.old.tracker.imports.request.TrackerEntityInstanceRequest) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration)

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