Search in sources :

Example 46 with Criteria

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

the class AbstractDaoRestService method deleteMany.

@DELETE
public Response deleteMany(@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) {
            LOG.debug("delete: deleting object {}", object);
            getDao().delete(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)

Example 47 with Criteria

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

the class AlarmDaoIT method testSortOnNodeLabel.

@Test
@Transactional
public void testSortOnNodeLabel() {
    Criteria criteria = new Criteria(OnmsAlarm.class);
    criteria.setAliases(Arrays.asList(new Alias[] { new Alias("node", "node", JoinType.LEFT_JOIN) }));
    criteria.setOrders(Arrays.asList(new Order[] { Order.asc("node.label") }));
    m_alarmDao.findMatching(criteria);
}
Also used : Order(org.opennms.core.criteria.Order) Alias(org.opennms.core.criteria.Alias) Criteria(org.opennms.core.criteria.Criteria) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 48 with Criteria

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

the class OnmsVaadinContainer method getCriteria.

/**
 * Creates a {@link Criteria} object to get data from database.
 * If considerPaging is set Limit and offset values are added as restriction.
 * @param page
 * @param doOrder
 * @return
 */
protected Criteria getCriteria(Page page, boolean doOrder) {
    Criteria tmpCriteria = new Criteria(getItemClass());
    for (Restriction eachRestriction : m_restrictions) {
        tmpCriteria.addRestriction(eachRestriction);
    }
    if (doOrder) {
        tmpCriteria.setOrders(m_orders);
    }
    if (page != null) {
        tmpCriteria.setOffset(page.offset);
        tmpCriteria.setLimit(page.length);
    }
    addAdditionalCriteriaOptions(tmpCriteria, page, doOrder);
    LOG.debug("query criteria: {}", tmpCriteria);
    return tmpCriteria;
}
Also used : Restriction(org.opennms.core.criteria.restrictions.Restriction) Criteria(org.opennms.core.criteria.Criteria)

Example 49 with Criteria

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

the class AlarmDaoIT method testSave.

@Test
@Transactional
public void testSave() {
    OnmsEvent event = new OnmsEvent();
    event.setEventLog("Y");
    event.setEventDisplay("Y");
    event.setEventCreateTime(new Date());
    event.setDistPoller(m_distPollerDao.whoami());
    event.setEventTime(new Date());
    event.setEventSeverity(OnmsSeverity.CRITICAL.getId());
    event.setEventUei("uei://org/opennms/test/EventDaoTest");
    event.setEventSource("test");
    m_eventDao.save(event);
    OnmsNode node = m_nodeDao.findAll().iterator().next();
    OnmsAlarm alarm = new OnmsAlarm();
    alarm.setNode(node);
    alarm.setUei(event.getEventUei());
    alarm.setSeverityId(event.getEventSeverity());
    alarm.setFirstEventTime(event.getEventTime());
    alarm.setLastEvent(event);
    alarm.setCounter(1);
    alarm.setDistPoller(m_distPollerDao.whoami());
    m_alarmDao.save(alarm);
    // It works we're so smart! hehe
    OnmsAlarm newAlarm = m_alarmDao.load(alarm.getId());
    assertEquals("uei://org/opennms/test/EventDaoTest", newAlarm.getUei());
    assertEquals(alarm.getLastEvent().getId(), newAlarm.getLastEvent().getId());
    Collection<OnmsAlarm> alarms;
    Criteria criteria = new Criteria(OnmsAlarm.class);
    criteria.addRestriction(new EqRestriction("node.id", node.getId()));
    alarms = m_alarmDao.findMatching(criteria);
    assertEquals(1, alarms.size());
    newAlarm = alarms.iterator().next();
    assertEquals("uei://org/opennms/test/EventDaoTest", newAlarm.getUei());
    assertEquals(alarm.getLastEvent().getId(), newAlarm.getLastEvent().getId());
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) EqRestriction(org.opennms.core.criteria.restrictions.EqRestriction) Criteria(org.opennms.core.criteria.Criteria) Date(java.util.Date) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 50 with Criteria

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

the class MockFilterDao method getActiveIPAddressList.

@Override
public List<InetAddress> getActiveIPAddressList(final String rule) throws FilterParseException {
    LOG.debug("rule = {}", rule);
    final List<InetAddress> addrs = new ArrayList<>();
    if (rule.equals("IPADDR != '0.0.0.0'")) {
        Assert.notNull(m_ipInterfaceDao);
        final CriteriaBuilder builder = new CriteriaBuilder(OnmsIpInterface.class);
        builder.ne("ipAddress", "0.0.0.0");
        builder.ne("isManaged", "D");
        builder.distinct();
        final Criteria criteria = builder.toCriteria();
        for (final OnmsIpInterface iface : m_ipInterfaceDao.findMatching(criteria)) {
            addrs.add(iface.getIpAddress());
        }
        return addrs;
    }
    throw new UnsupportedOperationException("Not yet implemented!");
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) ArrayList(java.util.ArrayList) Criteria(org.opennms.core.criteria.Criteria) InetAddress(java.net.InetAddress)

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