Search in sources :

Example 1 with CriteriaBuilder

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

the class AlarmSearchProvider method findAlarms.

private List<OnmsAlarm> findAlarms(final List<SearchResult> results, final String queryString) {
    CriteriaBuilder bldr = new CriteriaBuilder(OnmsAlarm.class);
    OnmsSeverity severity = OnmsSeverity.get(queryString);
    List<OnmsAlarm> alarms;
    if (!OnmsSeverity.INDETERMINATE.equals(severity)) {
        bldr = new CriteriaBuilder(OnmsAlarm.class);
        bldr.eq("severity", severity);
        alarms = alarmProvider.findMatchingAlarms(bldr.toCriteria());
        if (alarms.size() > 0) {
            AlarmSearchResult result = new AlarmSearchResult(queryString);
            result.setSeverityQuery(true);
            results.add(result);
        }
    } else {
        bldr.isNotNull("node").ilike("uei", "%" + queryString + "%").orderBy("node");
        alarms = alarmProvider.findMatchingAlarms(bldr.toCriteria());
    }
    return alarms;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm)

Example 2 with CriteriaBuilder

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

the class ApplicationSearchProvider method query.

@Override
public List<SearchResult> query(SearchQuery searchQuery, GraphContainer container) {
    LOG.info("ApplicationServiceSearchProvider->query: called with search query: '{}'", searchQuery);
    List<SearchResult> results = Lists.newArrayList();
    String queryString = searchQuery.getQueryString();
    CriteriaBuilder bldr = new CriteriaBuilder(OnmsApplication.class);
    if (queryString != null && queryString.length() > 0) {
        bldr.ilike("name", String.format("%%%s%%", queryString));
    }
    bldr.orderBy("name", true);
    bldr.limit(10);
    Criteria dbQueryCriteria = bldr.toCriteria();
    for (OnmsApplication application : applicationDao.findMatching(dbQueryCriteria)) {
        final ApplicationVertex applicationVertex = new ApplicationVertex(application);
        SearchResult searchResult = new SearchResult(applicationVertex, true, false);
        results.add(searchResult);
    }
    LOG.info("ApplicationServiceSearchProvider->query: found {} results: {}", results.size(), results);
    return results;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) SearchResult(org.opennms.features.topology.api.topo.SearchResult) Criteria(org.opennms.core.criteria.Criteria) OnmsApplication(org.opennms.netmgt.model.OnmsApplication)

Example 3 with CriteriaBuilder

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

the class MinionRestService method getMinions.

@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
@Transactional
public OnmsMinionCollection getMinions(@Context final UriInfo uriInfo) throws ParseException {
    final CriteriaBuilder builder = getCriteriaBuilder(uriInfo.getQueryParameters());
    final OnmsMinionCollection coll = new OnmsMinionCollection(m_minionDao.findMatching(builder.toCriteria()));
    coll.setTotalCount(m_minionDao.countMatching(builder.clearOrder().toCriteria()));
    return coll;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsMinionCollection(org.opennms.netmgt.model.OnmsMinionCollection) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with CriteriaBuilder

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

the class IfServicesRestService method getCriteria.

private static Criteria getCriteria(final MultivaluedMap<String, String> params) {
    final CriteriaBuilder builder = new CriteriaBuilder(OnmsMonitoredService.class);
    builder.alias("ipInterface.snmpInterface", "snmpInterface", JoinType.LEFT_JOIN);
    builder.alias("ipInterface", "ipInterface", JoinType.LEFT_JOIN);
    builder.alias("ipInterface.node", "node", JoinType.LEFT_JOIN);
    builder.alias("ipInterface.node.categories", "category", JoinType.LEFT_JOIN);
    builder.alias("serviceType", "serviceType", JoinType.LEFT_JOIN);
    builder.orderBy("id");
    applyQueryFilters(params, builder);
    return builder.toCriteria();
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder)

Example 5 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)

Aggregations

CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)155 Test (org.junit.Test)60 Criteria (org.opennms.core.criteria.Criteria)31 OnmsNode (org.opennms.netmgt.model.OnmsNode)25 Transactional (org.springframework.transaction.annotation.Transactional)23 Date (java.util.Date)20 GET (javax.ws.rs.GET)13 ArrayList (java.util.ArrayList)12 Produces (javax.ws.rs.Produces)12 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)11 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)11 InetSocketAddress (java.net.InetSocketAddress)9 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)7 HibernateDaoFactory (org.opennms.smoketest.utils.HibernateDaoFactory)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 EventDao (org.opennms.netmgt.dao.api.EventDao)4 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)4 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)4