Search in sources :

Example 1 with ProgressMonitor

use of org.opennms.web.svclayer.model.ProgressMonitor in project opennms by OpenNMS.

the class DefaultSurveillanceServiceIntegrationIT method testCreateSurveillanceServiceTableUsingViewName.

@Test
@Transactional
public void testCreateSurveillanceServiceTableUsingViewName() {
    String viewName = "default";
    SimpleWebTable table = m_surveillanceService.createSurveillanceTable(viewName, new ProgressMonitor() {

        @Override
        public void beginNextPhase(String string) {
            System.err.println("PHASE: " + string);
        }

        @Override
        public void setPhaseCount(int i) {
        }
    });
    assertEquals("default", table.getTitle());
}
Also used : ProgressMonitor(org.opennms.web.svclayer.model.ProgressMonitor) SimpleWebTable(org.opennms.web.svclayer.model.SimpleWebTable) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with ProgressMonitor

use of org.opennms.web.svclayer.model.ProgressMonitor in project opennms by OpenNMS.

the class SurveillanceViewController method createProgressMonitor.

private ProgressMonitor createProgressMonitor(final String viewName) {
    ProgressMonitor progressMonitor;
    final ProgressMonitor monitor = new ProgressMonitor();
    Thread bgRunner = new Thread("SurveillanceView Builder") {

        @Override
        public void run() {
            try {
                m_service.createSurveillanceTable(viewName, monitor);
            } catch (Throwable t) {
                monitor.errorOccurred(t);
            }
        }
    };
    bgRunner.start();
    progressMonitor = monitor;
    return progressMonitor;
}
Also used : ProgressMonitor(org.opennms.web.svclayer.model.ProgressMonitor)

Example 3 with ProgressMonitor

use of org.opennms.web.svclayer.model.ProgressMonitor in project opennms by OpenNMS.

the class SurveillanceViewController method handleRequestInternal.

/** {@inheritDoc} */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse resp) throws Exception {
    if (!m_service.isViewName(req.getParameter(VIEW_NAME_PARAMETER))) {
        SurveillanceViewError viewError = createSurveillanceViewError(WebSecurityUtils.sanitizeString(req.getParameter(VIEW_NAME_PARAMETER)));
        return new ModelAndView("surveillanceViewError", "error", viewError);
    }
    HttpSession session = req.getSession();
    resp.setHeader("Refresh", String.valueOf(m_service.getHeaderRefreshSeconds(WebSecurityUtils.sanitizeString(req.getParameter(VIEW_NAME_PARAMETER)))));
    ProgressMonitor progressMonitor = (ProgressMonitor) session.getAttribute(PROGRESS_MONITOR_KEY);
    if (progressMonitor == null) {
        progressMonitor = createProgressMonitor(WebSecurityUtils.sanitizeString(req.getParameter(VIEW_NAME_PARAMETER)));
        session.setAttribute(PROGRESS_MONITOR_KEY, progressMonitor);
    }
    if (progressMonitor.isError()) {
        session.removeAttribute(PROGRESS_MONITOR_KEY);
        Throwable t = progressMonitor.getThrowable();
        throw new Exception("SurveillanceView Builder Thread threw exception: [" + t.getClass().getName() + "] " + t.getMessage(), t);
    }
    if (progressMonitor.isFinished()) {
        session.removeAttribute(PROGRESS_MONITOR_KEY);
        SimpleWebTable table = (SimpleWebTable) progressMonitor.getResult();
        ModelAndView modelAndView = new ModelAndView("surveillanceView", "webTable", table);
        modelAndView.addObject("viewNames", m_service.getViewNames());
        return modelAndView;
    }
    return new ModelAndView("progressBar", "progress", progressMonitor);
}
Also used : ProgressMonitor(org.opennms.web.svclayer.model.ProgressMonitor) HttpSession(javax.servlet.http.HttpSession) ModelAndView(org.springframework.web.servlet.ModelAndView) SimpleWebTable(org.opennms.web.svclayer.model.SimpleWebTable)

Aggregations

ProgressMonitor (org.opennms.web.svclayer.model.ProgressMonitor)3 SimpleWebTable (org.opennms.web.svclayer.model.SimpleWebTable)2 HttpSession (javax.servlet.http.HttpSession)1 Test (org.junit.Test)1 Transactional (org.springframework.transaction.annotation.Transactional)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1