Search in sources :

Example 36 with JobConfiguration

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());
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) Test(org.junit.jupiter.api.Test)

Example 37 with JobConfiguration

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());
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) Test(org.junit.jupiter.api.Test)

Example 38 with JobConfiguration

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;
}
Also used : JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration)

Example 39 with 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", "");
}
Also used : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) VelocityContext(org.apache.velocity.VelocityContext) VelocityManager(org.hisp.dhis.system.velocity.VelocityManager) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) DashboardItem(org.hisp.dhis.dashboard.DashboardItem) SimpleDateFormat(java.text.SimpleDateFormat) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration)

Example 40 with JobConfiguration

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);
}
Also used : JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) JmsListener(org.springframework.jms.annotation.JmsListener)

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