Search in sources :

Example 1 with Restriction

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

the class Criteria method visit.

public void visit(final CriteriaVisitor visitor) {
    visitor.visitClass(getCriteriaClass());
    for (final Order order : getOrders()) {
        visitor.visitOrder(order);
    }
    visitor.visitOrdersFinished();
    for (final Alias alias : getAliases()) {
        visitor.visitAlias(alias);
    }
    visitor.visitAliasesFinished();
    for (final Fetch fetch : getFetchTypes()) {
        visitor.visitFetch(fetch);
    }
    visitor.visitFetchesFinished();
    for (final Restriction restriction : getRestrictions()) {
        visitor.visitRestriction(restriction);
    }
    visitor.visitRestrictionsFinished();
    visitor.visitDistinct(isDistinct());
    visitor.visitLimit(getLimit());
    visitor.visitOffset(getOffset());
}
Also used : Restriction(org.opennms.core.criteria.restrictions.Restriction)

Example 2 with Restriction

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

the class CriteriaBuilder method or.

public CriteriaBuilder or(final Restriction... restrictions) {
    final Restriction restriction = Restrictions.or(restrictions);
    addRestriction(restriction);
    return this;
}
Also used : Restriction(org.opennms.core.criteria.restrictions.Restriction)

Example 3 with Restriction

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

the class CriteriaTest method testRestrictions.

@Test
public void testRestrictions() {
    CriteriaBuilder cb = new CriteriaBuilder(OnmsAlarm.class);
    final List<Restriction> expected = new ArrayList<Restriction>();
    expected.add(Restrictions.isNull("tticketId"));
    expected.add(Restrictions.isNotNull("severity"));
    cb.isNull("tticketId").isNotNull("severity");
    assertEquals(expected, cb.toCriteria().getRestrictions());
    final Date d = new Date();
    cb = new CriteriaBuilder(OnmsAlarm.class);
    cb.id(1).and(Restrictions.gt("firstEventTime", d), Restrictions.lt("severity", OnmsSeverity.CRITICAL));
    expected.clear();
    expected.add(Restrictions.eq("id", 1));
    expected.add(Restrictions.and(Restrictions.gt("firstEventTime", d), Restrictions.lt("severity", OnmsSeverity.CRITICAL)));
    assertEquals(expected, cb.toCriteria().getRestrictions());
    cb.like("description", "*foo*").ilike("uei", "*bar*");
    expected.add(Restrictions.like("description", "*foo*"));
    expected.add(Restrictions.ilike("uei", "*bar*"));
    assertEquals(expected, cb.toCriteria().getRestrictions());
    final List<String> inValues = new ArrayList<String>();
    inValues.add("a");
    inValues.add("b");
    cb.in("nodeLabel", inValues);
    expected.add(Restrictions.in("nodeLabel", inValues));
    final List<String> notInValues = new ArrayList<String>();
    notInValues.add("c");
    notInValues.add("d");
    cb.not().in("nodeLabel", notInValues);
    expected.add(Restrictions.not(Restrictions.in("nodeLabel", notInValues)));
    assertEquals(expected, cb.toCriteria().getRestrictions());
    cb = new CriteriaBuilder(OnmsAlarm.class);
    expected.clear();
    cb.between("id", 1, 10);
    expected.add(Restrictions.between("id", 1, 10));
    cb.ne("id", 8);
    expected.add(Restrictions.not(Restrictions.eq("id", 8)));
    assertEquals(expected, cb.toCriteria().getRestrictions());
    cb = new CriteriaBuilder(OnmsAlarm.class);
    cb.id(1).and(Restrictions.gt("firstEventTime", d), Restrictions.lt("severity", OnmsSeverity.CRITICAL));
    expected.clear();
    expected.add(Restrictions.eq("id", 1));
    expected.add(Restrictions.and(Restrictions.gt("firstEventTime", d), Restrictions.lt("severity", OnmsSeverity.CRITICAL)));
    cb.like("description", "*foo*").ilike("uei", "*bar*");
    expected.add(Restrictions.like("description", "*foo*"));
    expected.add(Restrictions.ilike("uei", "*bar*"));
    inValues.clear();
    cb.in("nodeLabel", inValues);
    expected.add(Restrictions.in("nodeLabel", inValues));
    assertEquals(expected, cb.toCriteria().getRestrictions());
}
Also used : Restriction(org.opennms.core.criteria.restrictions.Restriction) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) ArrayList(java.util.ArrayList) Date(java.util.Date) Test(org.junit.Test)

Example 4 with Restriction

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

the class OnmsVaadinContainer method getCriteria.

/**
     * Creates a {@link Criteria} object to get data from database.
     * If considerPaging is set Limit and offset values are added as restriction.
     * @param page
     * @param doOrder
     * @return
     */
protected Criteria getCriteria(Page page, boolean doOrder) {
    Criteria tmpCriteria = new Criteria(getItemClass());
    for (Restriction eachRestriction : m_restrictions) {
        tmpCriteria.addRestriction(eachRestriction);
    }
    if (doOrder) {
        tmpCriteria.setOrders(m_orders);
    }
    if (page != null) {
        tmpCriteria.setOffset(page.offset);
        tmpCriteria.setLimit(page.length);
    }
    addAdditionalCriteriaOptions(tmpCriteria, page, doOrder);
    LOG.debug("query criteria: {}", tmpCriteria);
    return tmpCriteria;
}
Also used : Restriction(org.opennms.core.criteria.restrictions.Restriction) Criteria(org.opennms.core.criteria.Criteria)

Example 5 with Restriction

use of org.opennms.core.criteria.restrictions.Restriction 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<Integer>();
                if (alarms.size() > 0) {
                    for (OnmsAlarm onmsAlarm : alarms) {
                        alarmIds.add(onmsAlarm.getId());
                    }
                } else {
                    alarmIds.add(0);
                }
                List<Restriction> restrictions = new LinkedList<Restriction>();
                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) InRestriction(org.opennms.core.criteria.restrictions.InRestriction) Restriction(org.opennms.core.criteria.restrictions.Restriction) 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

Restriction (org.opennms.core.criteria.restrictions.Restriction)9 ArrayList (java.util.ArrayList)3 Criteria (org.opennms.core.criteria.Criteria)3 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)3 List (java.util.List)2 InRestriction (org.opennms.core.criteria.restrictions.InRestriction)2 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)2 Component (com.vaadin.ui.Component)1 UI (com.vaadin.ui.UI)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 PrimitiveStatement (org.apache.cxf.jaxrs.ext.search.PrimitiveStatement)1 Test (org.junit.Test)1 Order (org.opennms.core.criteria.Order)1 AllRestriction (org.opennms.core.criteria.restrictions.AllRestriction)1 AnyRestriction (org.opennms.core.criteria.restrictions.AnyRestriction)1