Search in sources :

Example 41 with Criteria

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

the class AlarmStatsRestService method getOldestUnacknowledged.

private OnmsAlarm getOldestUnacknowledged(final OnmsSeverity severity) {
    final CriteriaBuilder builder = getCriteriaBuilder(severity);
    builder.orderBy("firstEventTime").asc();
    builder.orderBy("id").asc();
    builder.limit(1);
    final Criteria criteria = builder.toCriteria();
    LOG.debug("getOldestUnacknowledged({}) criteria = {}", severity, criteria);
    return m_statisticsService.getUnacknowledged(criteria);
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) Criteria(org.opennms.core.criteria.Criteria)

Example 42 with Criteria

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

the class AlarmRestServiceBase method getCriteria.

protected Criteria getCriteria(final MultivaluedMap<String, String> params, final boolean stripOrdering) {
    final CriteriaBuilder cb = getCriteriaBuilder(params, stripOrdering);
    final Criteria criteria = cb.toCriteria();
    LOG.debug("criteria = {}", criteria);
    return criteria;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) Criteria(org.opennms.core.criteria.Criteria)

Example 43 with Criteria

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

the class IfServicesRestService method getServices.

@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
public OnmsMonitoredServiceDetailList getServices(@Context final UriInfo uriInfo) {
    final Criteria c = getCriteria(uriInfo.getQueryParameters());
    final OnmsMonitoredServiceDetailList servicesList = new OnmsMonitoredServiceDetailList();
    final List<OnmsMonitoredService> services = m_serviceDao.findMatching(c);
    for (OnmsMonitoredService svc : services) {
        servicesList.add(new OnmsMonitoredServiceDetail(svc));
    }
    c.setLimit(null);
    c.setOffset(null);
    c.setOrders(new ArrayList<Order>());
    servicesList.setTotalCount(m_serviceDao.countMatching(c));
    return servicesList;
}
Also used : OnmsMonitoredServiceDetailList(org.opennms.netmgt.model.OnmsMonitoredServiceDetailList) OnmsMonitoredServiceDetail(org.opennms.netmgt.model.OnmsMonitoredServiceDetail) Order(org.opennms.core.criteria.Order) Criteria(org.opennms.core.criteria.Criteria) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 44 with Criteria

use of org.opennms.core.criteria.Criteria 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 45 with Criteria

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

the class AbstractDaoRestService method get.

@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_ATOM_XML })
public Response get(@Context final UriInfo uriInfo, @Context final SearchContext searchContext) {
    Criteria crit = getCriteria(uriInfo, searchContext);
    final List<T> coll = getDao().findMatching(crit);
    if (coll == null || coll.size() < 1) {
        return Response.status(Status.NO_CONTENT).build();
    } else {
        Integer offset = crit.getOffset();
        // Remove limit, offset and ordering when fetching count
        crit.setLimit(null);
        crit.setOffset(null);
        crit.setOrders(new ArrayList<Order>());
        int totalCount = getDao().countMatching(crit);
        JaxbListWrapper<T> list = createListWrapper(coll);
        list.setTotalCount(totalCount);
        list.setOffset(offset);
        // Make sure that offset is set to a numeric value when setting the Content-Range header
        offset = (offset == null ? 0 : offset);
        return Response.ok(list).header("Content-Range", String.format("items %d-%d/%d", offset, offset + coll.size() - 1, totalCount)).build();
    }
}
Also used : Order(org.opennms.core.criteria.Order) GET(javax.ws.rs.GET) POST(javax.ws.rs.POST) PUT(javax.ws.rs.PUT) Criteria(org.opennms.core.criteria.Criteria) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Criteria (org.opennms.core.criteria.Criteria)62 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)31 Test (org.junit.Test)16 EqRestriction (org.opennms.core.criteria.restrictions.EqRestriction)16 Date (java.util.Date)13 Alias (org.opennms.core.criteria.Alias)13 ArrayList (java.util.ArrayList)10 Order (org.opennms.core.criteria.Order)9 Transactional (org.springframework.transaction.annotation.Transactional)9 GET (javax.ws.rs.GET)8 PUT (javax.ws.rs.PUT)7 OnmsNode (org.opennms.netmgt.model.OnmsNode)7 POST (javax.ws.rs.POST)6 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)5 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)5 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)5 Produces (javax.ws.rs.Produces)4 EventDao (org.opennms.netmgt.dao.api.EventDao)4 ScanReport (org.opennms.netmgt.model.ScanReport)4 ScanReportRestService (org.opennms.web.rest.v2.ScanReportRestService)4