Search in sources :

Example 1 with InRestriction

use of org.opennms.core.criteria.restrictions.InRestriction in project opennms by OpenNMS.

the class LocationBroadcastProcessor method afterPropertiesSet.

/**
 * <p>afterPropertiesSet</p>
 *
 * @throws java.lang.Exception if any.
 */
@Override
public void afterPropertiesSet() throws Exception {
    BeanUtils.assertAutowiring(this);
    m_task = new TimerTask() {

        private Date m_lastRun = new Date();

        @Override
        public void run() {
            final Date now = new Date();
            final Criteria criteria = new Criteria(OnmsEvent.class).addRestriction(new BetweenRestriction("eventTime", m_lastRun, now)).addRestriction(new InRestriction("eventUei", m_events));
            for (final OnmsEvent e : m_eventDao.findMatching(criteria)) {
                handleLocationEvent(e);
            }
            m_lastRun = now;
        }
    };
// m_timer.schedule(m_task, UPDATE_PERIOD, UPDATE_PERIOD);
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) TimerTask(java.util.TimerTask) BetweenRestriction(org.opennms.core.criteria.restrictions.BetweenRestriction) InRestriction(org.opennms.core.criteria.restrictions.InRestriction) Criteria(org.opennms.core.criteria.Criteria) Date(java.util.Date)

Example 2 with InRestriction

use of org.opennms.core.criteria.restrictions.InRestriction in project opennms by OpenNMS.

the class Poller method scheduleServices.

private int scheduleServices() {
    final Criteria criteria = new Criteria(OnmsMonitoredService.class);
    criteria.addRestriction(new InRestriction("status", Arrays.asList("A", "N")));
    return m_transactionTemplate.execute(new TransactionCallback<Integer>() {

        @Override
        public Integer doInTransaction(TransactionStatus arg0) {
            final List<OnmsMonitoredService> services = m_monitoredServiceDao.findMatching(criteria);
            for (OnmsMonitoredService service : services) {
                scheduleService(service);
            }
            return services.size();
        }
    });
}
Also used : InRestriction(org.opennms.core.criteria.restrictions.InRestriction) TransactionStatus(org.springframework.transaction.TransactionStatus) List(java.util.List) Criteria(org.opennms.core.criteria.Criteria) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 3 with InRestriction

use of org.opennms.core.criteria.restrictions.InRestriction in project opennms by OpenNMS.

the class AlarmDetailsDashlet method getDashboardComponent.

@Override
public DashletComponent getDashboardComponent() {
    if (m_dashboardComponent == null) {
        m_dashboardComponent = new AbstractDashletComponent() {

            private AlarmTable m_alarmTable;

            {
                m_alarmTable = new AlarmTable("Alarms", new AlarmDaoContainer(m_alarmDao, m_transactionTemplate), m_alarmRepository);
                m_alarmTable.setSizeFull();
                m_alarmTable.setSortEnabled(false);
                m_alarmTable.addHeaderClickListener(new Table.HeaderClickListener() {

                    @Override
                    public void headerClick(Table.HeaderClickEvent headerClickEvent) {
                        m_alarmTable.setSortContainerPropertyId(headerClickEvent.getPropertyId());
                        m_alarmTable.setSortEnabled(true);
                    }
                });
                final VaadinApplicationContextImpl context = new VaadinApplicationContextImpl();
                final UI currentUI = UI.getCurrent();
                context.setSessionId(currentUI.getSession().getSession().getId());
                context.setUiId(currentUI.getUIId());
                m_alarmTable.setVaadinApplicationContext(context);
                final EventProxy eventProxy = new EventProxy() {

                    @Override
                    public <T> void fireEvent(final T eventObject) {
                        System.out.println("got event: {}" + eventObject);
                    }

                    @Override
                    public <T> void addPossibleEventConsumer(final T possibleEventConsumer) {
                        System.out.println("(ignoring) add consumer: {}" + possibleEventConsumer);
                    }
                };
                m_alarmTable.setEventProxy(eventProxy);
                m_alarmTable.setColumnReorderingAllowed(true);
                m_alarmTable.setColumnCollapsingAllowed(true);
                m_alarmTable.setSortContainerPropertyId("id");
                m_alarmTable.setSortAscending(false);
                m_alarmTable.setCellStyleGenerator(new AlarmTableCellStyleGenerator());
                m_alarmTable.addGeneratedColumn("severity", new SeverityGenerator());
                m_alarmTable.addGeneratedColumn("id", new AlarmIdColumnLinkGenerator(m_alarmDao, "id"));
                m_alarmTable.setVisibleColumns("id", "severity", "nodeLabel", "counter", "lastEventTime", "logMsg");
                m_alarmTable.setColumnHeaders("ID", "Severity", "Node", "Count", "Last Event Time", "Log Message");
                refresh();
            }

            @Override
            public void refresh() {
                List<OnmsAlarm> alarms = getAlarms();
                List<Integer> alarmIds = new LinkedList<>();
                if (alarms.size() > 0) {
                    for (OnmsAlarm onmsAlarm : alarms) {
                        alarmIds.add(onmsAlarm.getId());
                    }
                } else {
                    alarmIds.add(0);
                }
                List<Restriction> restrictions = new LinkedList<>();
                restrictions.add(new InRestriction("id", alarmIds));
                ((OnmsVaadinContainer<?, ?>) m_alarmTable.getContainerDataSource()).setRestrictions(restrictions);
                setBoosted(checkBoosted(alarms));
                m_alarmTable.markAsDirtyRecursive();
            }

            @Override
            public Component getComponent() {
                return m_alarmTable;
            }
        };
    }
    return m_dashboardComponent;
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) InRestriction(org.opennms.core.criteria.restrictions.InRestriction) SeverityGenerator(org.opennms.features.topology.plugins.browsers.SeverityGenerator) AbstractDashletComponent(org.opennms.features.vaadin.dashboard.model.AbstractDashletComponent) VaadinApplicationContextImpl(org.opennms.osgi.VaadinApplicationContextImpl) UI(com.vaadin.ui.UI) AlarmTable(org.opennms.features.topology.plugins.browsers.AlarmTable) AlarmTableCellStyleGenerator(org.opennms.features.topology.plugins.browsers.AlarmTableCellStyleGenerator) AlarmIdColumnLinkGenerator(org.opennms.features.topology.plugins.browsers.AlarmIdColumnLinkGenerator) LinkedList(java.util.LinkedList) List(java.util.List) DashletComponent(org.opennms.features.vaadin.dashboard.model.DashletComponent) AbstractDashletComponent(org.opennms.features.vaadin.dashboard.model.AbstractDashletComponent) Component(com.vaadin.ui.Component) EventProxy(org.opennms.osgi.EventProxy) AlarmDaoContainer(org.opennms.features.topology.plugins.browsers.AlarmDaoContainer)

Aggregations

InRestriction (org.opennms.core.criteria.restrictions.InRestriction)3 List (java.util.List)2 Criteria (org.opennms.core.criteria.Criteria)2 Component (com.vaadin.ui.Component)1 UI (com.vaadin.ui.UI)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 TimerTask (java.util.TimerTask)1 BetweenRestriction (org.opennms.core.criteria.restrictions.BetweenRestriction)1 AlarmDaoContainer (org.opennms.features.topology.plugins.browsers.AlarmDaoContainer)1 AlarmIdColumnLinkGenerator (org.opennms.features.topology.plugins.browsers.AlarmIdColumnLinkGenerator)1 AlarmTable (org.opennms.features.topology.plugins.browsers.AlarmTable)1 AlarmTableCellStyleGenerator (org.opennms.features.topology.plugins.browsers.AlarmTableCellStyleGenerator)1 SeverityGenerator (org.opennms.features.topology.plugins.browsers.SeverityGenerator)1 AbstractDashletComponent (org.opennms.features.vaadin.dashboard.model.AbstractDashletComponent)1 DashletComponent (org.opennms.features.vaadin.dashboard.model.DashletComponent)1 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)1 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)1 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)1 EventProxy (org.opennms.osgi.EventProxy)1