Search in sources :

Example 36 with CriteriaBuilder

use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.

the class NotificationRestService method getCriteriaBuilder.

private static CriteriaBuilder getCriteriaBuilder(final MultivaluedMap<String, String> params) {
    final CriteriaBuilder builder = new CriteriaBuilder(OnmsNotification.class);
    builder.alias("node", "node", JoinType.LEFT_JOIN);
    builder.alias("node.snmpInterfaces", "snmpInterface", JoinType.LEFT_JOIN);
    builder.alias("node.ipInterfaces", "ipInterface", JoinType.LEFT_JOIN);
    builder.alias("event", "event", JoinType.LEFT_JOIN);
    builder.alias("usersNotified", "usersNotified", JoinType.LEFT_JOIN);
    applyQueryFilters(params, builder);
    return builder;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder)

Example 37 with CriteriaBuilder

use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.

the class NetworkElementFactory method getIpPrimaryAddress.

/* (non-Javadoc)
	 * @see org.opennms.web.element.NetworkElementFactoryInterface#getIpPrimaryAddress(int)
	 */
@Override
public String getIpPrimaryAddress(int nodeId) {
    final CriteriaBuilder cb = new CriteriaBuilder(OnmsIpInterface.class);
    cb.and(new EqRestriction("node.id", nodeId), new EqRestriction("isSnmpPrimary", PrimaryType.PRIMARY));
    final List<OnmsIpInterface> ifaces = m_ipInterfaceDao.findMatching(cb.toCriteria());
    if (ifaces.size() > 0) {
        final OnmsIpInterface iface = ifaces.get(0);
        return InetAddressUtils.str(iface.getIpAddress());
    } else {
        return null;
    }
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) EqRestriction(org.opennms.core.criteria.restrictions.EqRestriction)

Example 38 with CriteriaBuilder

use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.

the class NetworkElementFactory method getNodeLabel.

/* (non-Javadoc)
	 * @see org.opennms.web.element.NetworkElementFactoryInterface#getNodeLabel(int)
	 */
@Override
public String getNodeLabel(int nodeId) {
    final CriteriaBuilder cb = new CriteriaBuilder(OnmsNode.class);
    cb.eq("id", nodeId);
    final List<OnmsNode> nodes = m_nodeDao.findMatching(cb.toCriteria());
    if (nodes.size() > 0) {
        final OnmsNode node = nodes.get(0);
        return node.getLabel();
    } else {
        return null;
    }
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode)

Example 39 with CriteriaBuilder

use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.

the class NetworkElementFactory method getNodesFromPhysaddr.

/* (non-Javadoc)
	 * @see org.opennms.web.element.NetworkElementFactoryInterface#getNodesFromPhysaddr(java.lang.String)
	 */
@Override
public List<OnmsNode> getNodesFromPhysaddr(final String physAddr) {
    if (physAddr == null) {
        throw new IllegalArgumentException("Cannot take null parameters.");
    }
    final CriteriaBuilder builder = new CriteriaBuilder(OnmsNode.class);
    builder.alias("snmpInterfaces", "iface").ilike("iface.physAddr", physAddr.replaceAll("[:-]", "")).ne("type", NodeType.DELETED).distinct();
    return m_nodeDao.findMatching(builder.toCriteria());
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder)

Example 40 with CriteriaBuilder

use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.

the class BeanWrapperVisitorTest method testFailedGreaterThanWithLessComparison.

@Test
public void testFailedGreaterThanWithLessComparison() {
    new CriteriaBuilder(TestBean.class).gt("four", 17d).toCriteria().visit(m_visitor);
    assertEquals(0, m_visitor.getMatches().size());
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) Test(org.junit.Test)

Aggregations

CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)128 Test (org.junit.Test)55 Criteria (org.opennms.core.criteria.Criteria)28 OnmsNode (org.opennms.netmgt.model.OnmsNode)21 Transactional (org.springframework.transaction.annotation.Transactional)20 Date (java.util.Date)18 GET (javax.ws.rs.GET)13 Produces (javax.ws.rs.Produces)12 InetSocketAddress (java.net.InetSocketAddress)8 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)8 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)8 ArrayList (java.util.ArrayList)7 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)7 OnmsMinion (org.opennms.netmgt.model.minion.OnmsMinion)6 RateLimiter (com.google.common.util.concurrent.RateLimiter)4 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)4 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)4 ScanReport (org.opennms.netmgt.model.ScanReport)4 ScanReportRestService (org.opennms.web.rest.v2.ScanReportRestService)4 PUT (javax.ws.rs.PUT)3