use of org.hisp.dhis.scheduling.JobConfiguration in project dhis2-core by dhis2.
the class JobConfigurationObjectBundleHookTest method validateInternalNonConfigurableShownValidationErrorNonE7010.
@Test
void validateInternalNonConfigurableShownValidationErrorNonE7010() {
Mockito.when(jobConfigurationService.getJobConfigurationByUid(Mockito.eq("jsdhJSJHD"))).thenReturn(analyticsTableJobConfig);
Mockito.when(jobService.getJob(Mockito.eq(JobType.ANALYTICSTABLE_UPDATE))).thenReturn(job);
Mockito.when(job.validate()).thenReturn(new ErrorReport(Class.class, ErrorCode.E7000));
JobConfiguration jobConfiguration = new JobConfiguration();
jobConfiguration.setUid("jsdhJSJHD");
jobConfiguration.setJobType(JobType.ANALYTICSTABLE_UPDATE);
jobConfiguration.setCronExpression(CRON_HOURLY);
jobConfiguration.setEnabled(true);
List<ErrorReport> errorReports = hook.validate(jobConfiguration, null);
Assertions.assertEquals(1, errorReports.size());
Assertions.assertEquals(ErrorCode.E7000, errorReports.get(0).getErrorCode());
}
use of org.hisp.dhis.scheduling.JobConfiguration in project dhis2-core by dhis2.
the class JobConfigurationObjectBundleHookTest method validateCronExpressionForCronTypeJobs.
@Test
void validateCronExpressionForCronTypeJobs() {
String jobConfigUid = "jsdhJSJHD";
Mockito.when(jobConfigurationService.getJobConfigurationByUid(Mockito.eq(jobConfigUid))).thenReturn(analyticsTableJobConfig);
Mockito.when(jobService.getJob(Mockito.eq(JobType.ANALYTICSTABLE_UPDATE))).thenReturn(job);
JobConfiguration jobConfiguration = new JobConfiguration();
jobConfiguration.setUid(jobConfigUid);
jobConfiguration.setJobType(JobType.ANALYTICSTABLE_UPDATE);
jobConfiguration.setEnabled(true);
List<ErrorReport> errorReports = hook.validate(jobConfiguration, null);
Assertions.assertEquals(1, errorReports.size());
Assertions.assertEquals(ErrorCode.E7004, errorReports.get(0).getErrorCode());
}
use of org.hisp.dhis.scheduling.JobConfiguration in project dhis2-core by dhis2.
the class JobConfigurationSanitizer method convert.
@Override
public JobConfiguration convert(JobConfiguration value) {
if (value == null) {
return null;
}
final JobConfiguration jobConfiguration = new JobConfiguration(value.getName(), value.getJobType(), value.getCronExpression(), value.getJobParameters(), value.isEnabled(), value.isInMemoryJob());
jobConfiguration.setDelay(value.getDelay());
jobConfiguration.setLeaderOnlyJob(value.isLeaderOnlyJob());
jobConfiguration.setUid(value.getUid());
return jobConfiguration;
}
use of org.hisp.dhis.scheduling.JobConfiguration in project dhis2-core by dhis2.
the class DefaultPushAnalysisService method generateHtmlReport.
@Override
public String generateHtmlReport(PushAnalysis pushAnalysis, User user, JobConfiguration jobId) throws IOException {
if (jobId == null) {
jobId = new JobConfiguration("inMemoryGenerateHtmlReport", JobType.PUSH_ANALYSIS, currentUserService.getCurrentUser().getUid(), true);
notifier.clear(jobId);
}
user = user == null ? currentUserService.getCurrentUser() : user;
log(jobId, NotificationLevel.INFO, "Generating PushAnalysis for user '" + user.getUsername() + "'.", false, null);
// ----------------------------------------------------------------------
// Pre-process the dashboardItem and store them as Strings
// ----------------------------------------------------------------------
HashMap<String, String> itemHtml = new HashMap<>();
HashMap<String, String> itemLink = new HashMap<>();
for (DashboardItem item : pushAnalysis.getDashboard().getItems()) {
// In normal conditions all DashboardItem has a type.
if (item.getType() != null) {
itemHtml.put(item.getUid(), getItemHtml(item, user, jobId));
itemLink.put(item.getUid(), getItemLink(item));
}
}
DateFormat dateFormat = new SimpleDateFormat("MMMM dd, yyyy");
itemHtml.put("date", dateFormat.format(Calendar.getInstance().getTime()));
itemHtml.put("instanceBaseUrl", dhisConfigurationProvider.getServerBaseUrl());
itemHtml.put("instanceName", systemSettingManager.getStringSetting(SettingKey.APPLICATION_TITLE));
// ----------------------------------------------------------------------
// Set up template context, including pre-processed dashboard items
// ----------------------------------------------------------------------
final VelocityContext context = new VelocityContext();
context.put("pushAnalysis", pushAnalysis);
context.put("itemHtml", itemHtml);
context.put("itemLink", itemLink);
context.put("encoder", encoder);
// ----------------------------------------------------------------------
// Render template and return result after removing newline characters
// ----------------------------------------------------------------------
StringWriter stringWriter = new StringWriter();
new VelocityManager().getEngine().getTemplate("push-analysis-main-html.vm").merge(context, stringWriter);
log(jobId, NotificationLevel.INFO, "Finished generating PushAnalysis for user '" + user.getUsername() + "'.", false, null);
return stringWriter.toString().replaceAll("\\R", "");
}
use of org.hisp.dhis.scheduling.JobConfiguration in project dhis2-core by dhis2.
the class TrackerNotificationMessageManager method consume.
@JmsListener(destination = Topics.TRACKER_IMPORT_NOTIFICATION_TOPIC_NAME, containerFactory = "jmsQueueListenerContainerFactory")
public void consume(TextMessage message) throws JMSException, IOException {
TrackerSideEffectDataBundle bundle = toBundle(message);
if (bundle == null) {
return;
}
JobConfiguration jobConfiguration = new JobConfiguration("", JobType.TRACKER_IMPORT_NOTIFICATION_JOB, bundle.getAccessedBy(), true);
bundle.setJobConfiguration(jobConfiguration);
TrackerNotificationThread notificationThread = trackerNotificationThreadObjectFactory.getObject();
notificationThread.setSideEffectDataBundle(bundle);
executeJob(notificationThread);
}
Aggregations