use of org.opennms.core.criteria.Criteria in project opennms by OpenNMS.
the class AbstractDaoRestServiceWithDTO method updateMany.
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response updateMany(@Context final SecurityContext securityContext, @Context final UriInfo uriInfo, @Context final SearchContext searchContext, final MultivaluedMapImpl params) {
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) {
RestUtils.setBeanProperties(object, params);
doUpdateProperties(securityContext, uriInfo, object, params);
}
return Response.noContent().build();
} finally {
writeUnlock();
}
}
use of org.opennms.core.criteria.Criteria in project opennms by OpenNMS.
the class CriteriaBuilderSearchVisitorIT method testScanReportAndCondition.
@Test
public void testScanReportAndCondition() {
CriteriaBuilder builder = new ScanReportRestService().getCriteriaBuilder(null);
CriteriaBuilderSearchVisitor<ScanReport, ScanReport> visitor = new CriteriaBuilderSearchVisitor<>(builder, ScanReport.class);
// Simulates /opennms/api/v2/scanreports?_s=applications%3D%3DLocal+Access;timestamp%3Dle%3D2016-02-01T15:07:14.340-0500&limit=20&offset=0&order=desc&orderBy=timestamp
List<SearchCondition<ScanReport>> conditions = new ArrayList<SearchCondition<ScanReport>>();
conditions.add(new PrimitiveSearchCondition<ScanReport>("applications", "blah", String.class, ConditionType.EQUALS, new ScanReport()));
conditions.add(new PrimitiveSearchCondition<ScanReport>("timestamp", new Date(), Date.class, ConditionType.LESS_OR_EQUALS, new ScanReport()));
SearchCondition<ScanReport> andCondition = new AndSearchCondition<ScanReport>(conditions);
visitor.visit(andCondition);
Criteria criteria = visitor.getQuery().toCriteria();
System.out.println(criteria.toString());
m_dao.countMatching(criteria);
}
use of org.opennms.core.criteria.Criteria in project opennms by OpenNMS.
the class CriteriaBuilderSearchVisitorIT method testScanReportTwoConditions.
@Test
public void testScanReportTwoConditions() {
CriteriaBuilder builder = new ScanReportRestService().getCriteriaBuilder(null);
CriteriaBuilderSearchVisitor<ScanReport, ScanReport> visitor = new CriteriaBuilderSearchVisitor<>(builder, ScanReport.class);
visitor.visit(new PrimitiveSearchCondition<ScanReport>("applications", "blah", String.class, ConditionType.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);
}
use of org.opennms.core.criteria.Criteria in project opennms by OpenNMS.
the class QueryManagerDaoImpl method closeOutagesForNode.
/**
* <p>closeOutagesForNode</p>
*
* @param closeDate a {@link java.util.Date} object.
* @param eventId a int.
* @param nodeId a int.
*/
@Override
public void closeOutagesForNode(Date closeDate, int eventId, int nodeId) {
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 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 getNodeServices.
@Override
public List<String[]> getNodeServices(int nodeId) {
final LinkedList<String[]> servicemap = new LinkedList<>();
Criteria criteria = new Criteria(OnmsMonitoredService.class);
criteria.setAliases(Arrays.asList(new Alias[] { new Alias("ipInterface", "ipInterface", JoinType.LEFT_JOIN), new Alias("ipInterface.node", "node", JoinType.LEFT_JOIN) }));
criteria.addRestriction(new EqRestriction("node.id", nodeId));
// Ignore forced-unmanaged
criteria.addRestriction(new NeRestriction("status", "F"));
for (OnmsMonitoredService service : m_monitoredServiceDao.findMatching(criteria)) {
servicemap.add(new String[] { service.getIpAddressAsString(), service.getServiceName() });
}
return servicemap;
}
Aggregations