Search in sources :

Example 21 with Criteria

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);
    }
}
Also used : NotNullRestriction(org.opennms.core.criteria.restrictions.NotNullRestriction) LtRestriction(org.opennms.core.criteria.restrictions.LtRestriction) EqRestriction(org.opennms.core.criteria.restrictions.EqRestriction) Criteria(org.opennms.core.criteria.Criteria) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) Date(java.util.Date)

Example 22 with Criteria

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);
}
Also used : EqRestriction(org.opennms.core.criteria.restrictions.EqRestriction) Criteria(org.opennms.core.criteria.Criteria) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with Criteria

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);
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) TimerTask(java.util.TimerTask) BetweenRestriction(org.opennms.core.criteria.restrictions.BetweenRestriction) InRestriction(org.opennms.core.criteria.restrictions.InRestriction) Criteria(org.opennms.core.criteria.Criteria) Date(java.util.Date)

Example 24 with Criteria

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

Example 25 with Criteria

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();
    }
}
Also used : GET(javax.ws.rs.GET) POST(javax.ws.rs.POST) PUT(javax.ws.rs.PUT) Criteria(org.opennms.core.criteria.Criteria) DELETE(javax.ws.rs.DELETE)

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