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