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