Search in sources :

Example 56 with Criteria

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

the class QueryManagerDaoImpl method closeOutagesForInterface.

/**
 * <p>closeOutagesForInterface</p>
 *
 * @param closeDate a {@link java.util.Date} object.
 * @param eventId a int.
 * @param nodeId a int.
 * @param ipAddr a {@link java.lang.String} object.
 */
@Override
public void closeOutagesForInterface(Date closeDate, int eventId, int nodeId, String ipAddr) {
    Criteria criteria = new Criteria(OnmsOutage.class);
    criteria.setAliases(Arrays.asList(new Alias[] { new Alias("monitoredService.ipInterface", "ipInterface", JoinType.LEFT_JOIN), new Alias("ipInterface.node", "node", JoinType.LEFT_JOIN) }));
    criteria.addRestriction(new EqRestriction("node.id", nodeId));
    criteria.addRestriction(new EqRestriction("ipInterface.ipAddress", addr(ipAddr)));
    criteria.addRestriction(new NullRestriction("ifRegainedService"));
    List<OnmsOutage> outages = m_outageDao.findMatching(criteria);
    for (OnmsOutage outage : outages) {
        outage.setIfRegainedService(closeDate);
        outage.setServiceRegainedEvent(m_eventDao.get(eventId));
        m_outageDao.update(outage);
    }
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) Alias(org.opennms.core.criteria.Alias) EqRestriction(org.opennms.core.criteria.restrictions.EqRestriction) NullRestriction(org.opennms.core.criteria.restrictions.NullRestriction) Criteria(org.opennms.core.criteria.Criteria)

Example 57 with Criteria

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

the class QueryManagerDaoImpl method closeOutagesForUnmanagedServices.

/**
 */
@Override
public void closeOutagesForUnmanagedServices() {
    Date closeDate = new java.util.Date();
    Criteria criteria = new Criteria(OnmsOutage.class);
    criteria.setAliases(Arrays.asList(new Alias[] { new Alias("monitoredService", "monitoredService", JoinType.LEFT_JOIN) }));
    criteria.addRestriction(new AnyRestriction(new EqRestriction("monitoredService.status", "D"), new EqRestriction("monitoredService.status", "F"), new EqRestriction("monitoredService.status", "U")));
    criteria.addRestriction(new NullRestriction("ifRegainedService"));
    List<OnmsOutage> outages = m_outageDao.findMatching(criteria);
    for (OnmsOutage outage : outages) {
        outage.setIfRegainedService(closeDate);
        m_outageDao.update(outage);
    }
    criteria = new Criteria(OnmsOutage.class);
    criteria.setAliases(Arrays.asList(new Alias[] { new Alias("monitoredService.ipInterface", "ipInterface", JoinType.LEFT_JOIN) }));
    criteria.addRestriction(new AnyRestriction(new EqRestriction("ipInterface.isManaged", "F"), new EqRestriction("ipInterface.isManaged", "U")));
    criteria.addRestriction(new NullRestriction("ifRegainedService"));
    outages = m_outageDao.findMatching(criteria);
    for (OnmsOutage outage : outages) {
        outage.setIfRegainedService(closeDate);
        m_outageDao.update(outage);
    }
}
Also used : AnyRestriction(org.opennms.core.criteria.restrictions.AnyRestriction) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) Alias(org.opennms.core.criteria.Alias) EqRestriction(org.opennms.core.criteria.restrictions.EqRestriction) NullRestriction(org.opennms.core.criteria.restrictions.NullRestriction) Criteria(org.opennms.core.criteria.Criteria) Date(java.util.Date)

Example 58 with Criteria

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

the class QueryManagerDaoImpl method closeOutagesForService.

/**
 * <p>closeOutagesForService</p>
 *
 * @param closeDate a {@link java.util.Date} object.
 * @param eventId a int.
 * @param nodeId a int.
 * @param ipAddr a {@link java.lang.String} object.
 * @param serviceName a {@link java.lang.String} object.
 */
@Override
public void closeOutagesForService(Date closeDate, int eventId, int nodeId, String ipAddr, String serviceName) {
    Criteria criteria = new Criteria(OnmsOutage.class);
    criteria.setAliases(Arrays.asList(new Alias[] { new Alias("monitoredService.ipInterface", "ipInterface", JoinType.LEFT_JOIN), new Alias("monitoredService.serviceType", "serviceType", JoinType.LEFT_JOIN), new Alias("ipInterface.node", "node", JoinType.LEFT_JOIN) }));
    criteria.addRestriction(new EqRestriction("node.id", nodeId));
    criteria.addRestriction(new EqRestriction("ipInterface.ipAddress", addr(ipAddr)));
    criteria.addRestriction(new EqRestriction("serviceType.name", serviceName));
    criteria.addRestriction(new NullRestriction("ifRegainedService"));
    List<OnmsOutage> outages = m_outageDao.findMatching(criteria);
    for (OnmsOutage outage : outages) {
        outage.setIfRegainedService(closeDate);
        outage.setServiceRegainedEvent(m_eventDao.get(eventId));
        m_outageDao.update(outage);
        LOG.info("Calling closeOutagesForService: {}", outage);
    }
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) Alias(org.opennms.core.criteria.Alias) EqRestriction(org.opennms.core.criteria.restrictions.EqRestriction) NullRestriction(org.opennms.core.criteria.restrictions.NullRestriction) Criteria(org.opennms.core.criteria.Criteria)

Example 59 with Criteria

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

the class AbstractDaoRestServiceWithDTO method getCriteria.

protected Criteria getCriteria(UriInfo uriInfo, SearchContext searchContext) {
    final CriteriaBuilder builder = getCriteriaBuilder(uriInfo);
    if (searchContext != null) {
        try {
            SearchCondition<Q> condition = searchContext.getCondition(getQueryBeanClass(), getSearchBeanPropertyMap());
            if (condition != null) {
                SearchConditionVisitor<Q, CriteriaBuilder> visitor = new CriteriaBuilderSearchVisitor<T, Q>(builder, getDaoClass(), getCriteriaBehaviors());
                condition.accept(visitor);
            }
        } catch (PropertyNotFoundException | ArrayIndexOutOfBoundsException e) {
            LOG.warn(e.getClass().getSimpleName() + " while parsing FIQL search, ignoring: " + e.getMessage(), e);
        }
    }
    // Apply limit, offset, orderBy, order parameters
    final MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
    applyLimitOffsetOrderBy(params, builder);
    Criteria crit = builder.toCriteria();
    /*
         * TODO: Figure out how to do stuff like this
         * 
         * // Don't include deleted nodes by default
         * final String type = params.getFirst("type");
         * if (type == null) {
         *     final List<Restriction> restrictions = new ArrayList<Restriction>(crit.getRestrictions());
         *     restrictions.add(Restrictions.ne("type", "D"));
         *     crit.setRestrictions(restrictions);
         * }
         */
    return crit;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) PropertyNotFoundException(org.apache.cxf.jaxrs.ext.search.PropertyNotFoundException) Criteria(org.opennms.core.criteria.Criteria) CriteriaBuilderSearchVisitor(org.opennms.web.rest.support.CriteriaBuilderSearchVisitor)

Example 60 with Criteria

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

the class CriteriaBuilderSearchVisitorIT method testScanReportTwoConditionsWithIsNotNull.

@Test
public void testScanReportTwoConditionsWithIsNotNull() {
    CriteriaBuilder builder = new ScanReportRestService().getCriteriaBuilder(null);
    CriteriaBuilderSearchVisitor<ScanReport, ScanReport> visitor = new CriteriaBuilderSearchVisitor<>(builder, ScanReport.class);
    visitor.visit(new PrimitiveSearchCondition<ScanReport>("applications", CriteriaBuilderSearchVisitor.NULL_VALUE, String.class, ConditionType.NOT_EQUALS, new ScanReport()));
    visitor.visit(new PrimitiveSearchCondition<ScanReport>("timestamp", new Date(), Date.class, ConditionType.LESS_OR_EQUALS, new ScanReport()));
    Criteria criteria = visitor.getQuery().toCriteria();
    System.out.println(criteria.toString());
    m_dao.countMatching(criteria);
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) ScanReport(org.opennms.netmgt.model.ScanReport) Criteria(org.opennms.core.criteria.Criteria) Date(java.util.Date) ScanReportRestService(org.opennms.web.rest.v2.ScanReportRestService) Test(org.junit.Test)

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