Search in sources :

Example 1 with ReportServiceLocatorException

use of org.opennms.reporting.core.svclayer.ReportServiceLocatorException in project opennms by OpenNMS.

the class DefaultSchedulerService method addCronTrigger.

/*
     * (non-Javadoc)
     * @see
     * org.opennms.web.svclayer.support.SchedulerService#addCronTrigger(org
     * .opennms.web.report.database.model.DatabaseReportCriteria,
     * java.lang.String, java.lang.String, java.lang.String,
     * org.springframework.webflow.execution.RequestContext)
     */
/**
 * {@inheritDoc}
 */
@Override
public String addCronTrigger(String id, ReportParameters criteria, DeliveryOptions deliveryOptions, String cronExpression, RequestContext context) {
    CronTriggerImpl cronTrigger = null;
    try {
        if (m_reportWrapperService.validate(criteria, id) == false) {
            LOG.error(PARAMETER_ERROR);
            context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(PARAMETER_ERROR).build());
            return ERROR;
        } else {
            try {
                cronTrigger = new CronTriggerImpl();
                cronTrigger.setGroup(m_triggerGroup);
                cronTrigger.setName(deliveryOptions.getInstanceId());
                cronTrigger.setJobName(m_jobDetail.getKey().getName());
                cronTrigger.setCronExpression(cronExpression);
            // cronTrigger = new CronTrigger(triggerName, m_triggerGroup,
            // cronExpression);
            } catch (ParseException e) {
                LOG.error(TRIGGER_PARSE_ERROR, e);
                context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(TRIGGER_PARSE_ERROR).build());
                context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(e.getMessage()).build());
                return ERROR;
            }
            cronTrigger.setJobName(m_jobDetail.getKey().getName());
            cronTrigger.getJobDataMap().put("criteria", (ReportParameters) criteria);
            cronTrigger.getJobDataMap().put("reportId", id);
            cronTrigger.getJobDataMap().put("mode", ReportMode.SCHEDULED);
            cronTrigger.getJobDataMap().put("deliveryOptions", (DeliveryOptions) deliveryOptions);
            try {
                m_scheduler.scheduleJob(cronTrigger);
            } catch (SchedulerException e) {
                LOG.error(SCHEDULER_ERROR, e);
                context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(SCHEDULER_ERROR).build());
                return ERROR;
            }
            return SUCCESS;
        }
    } catch (ReportServiceLocatorException e) {
        LOG.error(REPORTID_ERROR);
        context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(REPORTID_ERROR).build());
        return ERROR;
    }
}
Also used : SchedulerException(org.quartz.SchedulerException) MessageBuilder(org.springframework.binding.message.MessageBuilder) CronTriggerImpl(org.quartz.impl.triggers.CronTriggerImpl) ParseException(java.text.ParseException) ReportServiceLocatorException(org.opennms.reporting.core.svclayer.ReportServiceLocatorException)

Example 2 with ReportServiceLocatorException

use of org.opennms.reporting.core.svclayer.ReportServiceLocatorException in project opennms by OpenNMS.

the class DefaultSchedulerService method execute.

/*
     * (non-Javadoc)
     * @see
     * org.opennms.web.svclayer.support.SchedulerService#execute(org.opennms
     * .web.report.database.model.DatabaseReportCriteria, java.lang.String,
     * org.springframework.webflow.execution.RequestContext)
     */
/**
 * {@inheritDoc}
 */
@Override
public String execute(String id, ReportParameters criteria, DeliveryOptions deliveryOptions, RequestContext context) {
    try {
        if (m_reportWrapperService.validate(criteria, id) == false) {
            context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(PARAMETER_ERROR).build());
            return ERROR;
        } else {
            SimpleTriggerImpl trigger = new SimpleTriggerImpl(deliveryOptions.getInstanceId(), m_triggerGroup, new Date(), null, 0, 0L);
            trigger.setJobName(m_jobDetail.getKey().getName());
            trigger.getJobDataMap().put("criteria", (ReportParameters) criteria);
            trigger.getJobDataMap().put("reportId", id);
            trigger.getJobDataMap().put("mode", ReportMode.IMMEDIATE);
            trigger.getJobDataMap().put("deliveryOptions", (DeliveryOptions) deliveryOptions);
            try {
                m_scheduler.scheduleJob(trigger);
            } catch (SchedulerException e) {
                LOG.warn(SCHEDULER_ERROR, e);
                context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(SCHEDULER_ERROR).build());
                return ERROR;
            }
            return SUCCESS;
        }
    } catch (ReportServiceLocatorException e) {
        LOG.error(REPORTID_ERROR, e);
        context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(REPORTID_ERROR).build());
        return ERROR;
    }
}
Also used : SimpleTriggerImpl(org.quartz.impl.triggers.SimpleTriggerImpl) SchedulerException(org.quartz.SchedulerException) MessageBuilder(org.springframework.binding.message.MessageBuilder) ReportServiceLocatorException(org.opennms.reporting.core.svclayer.ReportServiceLocatorException) Date(java.util.Date)

Aggregations

ReportServiceLocatorException (org.opennms.reporting.core.svclayer.ReportServiceLocatorException)2 SchedulerException (org.quartz.SchedulerException)2 MessageBuilder (org.springframework.binding.message.MessageBuilder)2 ParseException (java.text.ParseException)1 Date (java.util.Date)1 CronTriggerImpl (org.quartz.impl.triggers.CronTriggerImpl)1 SimpleTriggerImpl (org.quartz.impl.triggers.SimpleTriggerImpl)1