use of org.opennms.core.criteria.Criteria in project opennms by OpenNMS.
the class DefaultPollerBackEnd method checkForDisconnectedMonitors.
/**
* <p>checkForDisconnectedMonitors</p>
*/
@Override
public void checkForDisconnectedMonitors() {
LOG.debug("Checking for disconnected monitors: disconnectedTimeout = {}", m_disconnectedTimeout);
try {
final Date now = m_timeKeeper.getCurrentDate();
final Date earliestAcceptable = new Date(now.getTime() - m_disconnectedTimeout);
final Criteria criteria = new Criteria(OnmsLocationMonitor.class);
criteria.addRestriction(new EqRestriction("status", MonitorStatus.STARTED));
criteria.addRestriction(new NotNullRestriction("lastUpdated"));
criteria.addRestriction(new LtRestriction("lastUpdated", earliestAcceptable));
// Lock all of the records for update since we will be marking them as DISCONNECTED
criteria.setLockType(LockType.PESSIMISTIC_READ);
final Collection<OnmsLocationMonitor> monitors = m_locMonDao.findMatching(criteria);
LOG.debug("Found {} monitor(s) that are transitioning to disconnected state", monitors.size());
for (final OnmsLocationMonitor monitor : monitors) {
LOG.debug("Monitor {} has stopped responding", monitor.getName());
monitor.setStatus(MonitorStatus.DISCONNECTED);
m_locMonDao.update(monitor);
sendDisconnectedEvent(monitor);
}
} catch (final Throwable e) {
LOG.warn("An error occurred checking for disconnected monitors.", e);
}
}
use of org.opennms.core.criteria.Criteria in project opennms by OpenNMS.
the class DefaultLocationDataService method getLocationInfoForMonitor.
/**
* {@inheritDoc}
*/
@Transactional
@Override
public LocationInfo getLocationInfoForMonitor(Integer monitorId) {
waitForGeocoding("getLocationInfoForMonitor");
final Criteria criteria = new Criteria(OnmsLocationMonitor.class).addRestriction(new EqRestriction("id", monitorId));
final List<OnmsLocationMonitor> monitors = m_locationDao.findMatching(criteria);
if (monitors == null) {
LOG.warn("unable to get location monitor list for monitor ID '{}'", monitorId);
return null;
}
final String definitionName = monitors.get(0).getLocation();
final OnmsMonitoringLocation def = m_monitoringLocationDao.get(definitionName);
if (def == null) {
LOG.warn("unable to find monitoring location definition for '{}'", definitionName);
return null;
}
return getLocationInfo(def);
}
use of org.opennms.core.criteria.Criteria in project opennms by OpenNMS.
the class LocationBroadcastProcessor method afterPropertiesSet.
/**
* <p>afterPropertiesSet</p>
*
* @throws java.lang.Exception if any.
*/
@Override
public void afterPropertiesSet() throws Exception {
BeanUtils.assertAutowiring(this);
m_task = new TimerTask() {
private Date m_lastRun = new Date();
@Override
public void run() {
final Date now = new Date();
final Criteria criteria = new Criteria(OnmsEvent.class).addRestriction(new BetweenRestriction("eventTime", m_lastRun, now)).addRestriction(new InRestriction("eventUei", m_events));
for (final OnmsEvent e : m_eventDao.findMatching(criteria)) {
handleLocationEvent(e);
}
m_lastRun = now;
}
};
// m_timer.schedule(m_task, UPDATE_PERIOD, UPDATE_PERIOD);
}
use of org.opennms.core.criteria.Criteria in project opennms by OpenNMS.
the class AbstractDaoRestServiceWithDTO 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);
// Map the entities to the corresponding DTOs
final List<D> collOfDtos = coll.stream().map(this::mapEntityToDTO).collect(Collectors.toList());
final JaxbListWrapper<D> list = createListWrapper(collOfDtos);
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();
}
}
use of org.opennms.core.criteria.Criteria in project opennms by OpenNMS.
the class AbstractDaoRestServiceWithDTO method deleteMany.
@DELETE
public Response deleteMany(@Context final SecurityContext securityContext, @Context final UriInfo uriInfo, @Context final SearchContext searchContext) {
writeLock();
try {
Criteria crit = getCriteria(uriInfo, searchContext);
final List<T> objects = getDao().findMatching(crit);
if (objects == null || objects.size() == 0) {
return Response.status(Status.NOT_FOUND).build();
}
for (T object : objects) {
doDelete(securityContext, uriInfo, object);
}
return Response.noContent().build();
} finally {
writeUnlock();
}
}
Aggregations