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);
}
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;
}
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;
}
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();
}
});
}
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();
}
}
Aggregations