use of org.opennms.netmgt.bsm.service.BusinessServiceSearchCriteriaBuilder in project opennms by OpenNMS.
the class BusinessServiceStatusService method count.
public int count(Query query) {
final BusinessServiceSearchCriteriaBuilder criteria = buildFrom(query);
criteria.prepareForCounting();
final List<BusinessService> services = criteria.apply(businessServiceManager, businessServiceManager.getAllBusinessServices());
return services.size();
}
use of org.opennms.netmgt.bsm.service.BusinessServiceSearchCriteriaBuilder in project opennms by OpenNMS.
the class BusinessServiceStatusService method buildFrom.
private BusinessServiceSearchCriteriaBuilder buildFrom(Query query) {
final BusinessServiceSearchCriteriaBuilder criteriaBuilder = new BusinessServiceSearchCriteriaBuilder();
if (query.getSeverityFilter() != null && !query.getSeverityFilter().getSeverities().isEmpty()) {
final List<Status> statusList = query.getSeverityFilter().getSeverities().stream().map(eachSeverity -> Status.of(eachSeverity.name())).collect(Collectors.toList());
criteriaBuilder.inSeverity(statusList);
} else {
criteriaBuilder.greaterOrEqualSeverity(Status.NORMAL);
}
if (query.getParameters().getOrder() != null) {
final QueryParameters.Order order = query.getParameters().getOrder();
criteriaBuilder.order(order.getColumn(), !order.isDesc());
}
if (query.getParameters().getLimit() != null) {
criteriaBuilder.limit(query.getParameters().getLimit());
}
if (query.getParameters().getOffset() != null) {
criteriaBuilder.offset(query.getParameters().getOffset());
}
return criteriaBuilder;
}
use of org.opennms.netmgt.bsm.service.BusinessServiceSearchCriteriaBuilder in project opennms by OpenNMS.
the class BSMConfigHelper method fromMap.
/**
* Created as business service search criteria for a given map.
*
* @param map the map to inverstigate
* @return the criteria
*/
public static BusinessServiceSearchCriteria fromMap(Map<String, String> map) {
boolean filterByName = getBooleanForKey(map, "filterByName");
String nameValue = getStringForKey(map, "nameValue", "");
boolean filterByAttribute = getBooleanForKey(map, "filterByAttribute");
String attributeKey = getStringForKey(map, "attributeKey", "");
String attributeValue = getStringForKey(map, "attributeValue", "");
boolean filterBySeverity = getBooleanForKey(map, "filterBySeverity");
String severityValue = getStringForKey(map, "severityValue", Status.WARNING.getLabel());
String severityCompareOperator = BSMConfigHelper.getStringForKey(map, "severityCompareOperator", BusinessServiceSearchCriteriaBuilder.CompareOperator.GreaterOrEqual.name());
String orderBy = BSMConfigHelper.getStringForKey(map, "orderBy", BusinessServiceSearchCriteriaBuilder.Order.Name.name());
String orderSequence = BSMConfigHelper.getStringForKey(map, "orderSequence", BusinessServiceSearchCriteriaBuilder.Sequence.Ascending.name());
int resultsLimit = getIntForKey(map, "resultsLimit", 10);
BusinessServiceSearchCriteriaBuilder b = new BusinessServiceSearchCriteriaBuilder();
if (filterByName) {
b.name(nameValue);
}
if (filterByAttribute) {
b.attribute(attributeKey, attributeValue);
}
if (filterBySeverity) {
b.filterSeverity(BusinessServiceSearchCriteriaBuilder.CompareOperator.valueOf(severityCompareOperator), Status.valueOf(severityValue));
}
return b.order(BusinessServiceSearchCriteriaBuilder.Order.valueOf(orderBy)).order(BusinessServiceSearchCriteriaBuilder.Sequence.valueOf(orderSequence)).limit(resultsLimit);
}
use of org.opennms.netmgt.bsm.service.BusinessServiceSearchCriteriaBuilder in project opennms by OpenNMS.
the class BusinessServiceCriteriaTest method testOrderByNameAscAndLimit.
@Test
public void testOrderByNameAscAndLimit() {
BusinessServiceSearchCriteriaBuilder b = new BusinessServiceSearchCriteriaBuilder().order(BusinessServiceSearchCriteriaBuilder.Order.Name).asc().limit(6);
assertEquals(ImmutableList.<BusinessService>builder().add(bs1, bs2, bs3, bs4, bs5, bs6).build(), businessServiceManager.search(b));
}
use of org.opennms.netmgt.bsm.service.BusinessServiceSearchCriteriaBuilder in project opennms by OpenNMS.
the class BusinessServiceCriteriaTest method testFilterByName.
@Test
public void testFilterByName() {
BusinessServiceSearchCriteriaBuilder b = new BusinessServiceSearchCriteriaBuilder().name(".*sG").order(BusinessServiceSearchCriteriaBuilder.Order.Name).asc();
assertEquals(ImmutableList.<BusinessService>builder().add(bs7).build(), businessServiceManager.search(b));
}
Aggregations