Search in sources :

Example 6 with BusinessServiceSearchCriteriaBuilder

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();
}
Also used : BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) BusinessServiceSearchCriteriaBuilder(org.opennms.netmgt.bsm.service.BusinessServiceSearchCriteriaBuilder)

Example 7 with BusinessServiceSearchCriteriaBuilder

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;
}
Also used : Status(org.opennms.netmgt.bsm.service.model.Status) QueryParameters(org.opennms.web.utils.QueryParameters) BusinessServiceManager(org.opennms.netmgt.bsm.service.BusinessServiceManager) Autowired(org.springframework.beans.factory.annotation.Autowired) Query(org.opennms.features.status.api.Query) StatusEntityWrapper(org.opennms.features.status.api.StatusEntityWrapper) BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) Collectors(java.util.stream.Collectors) StatusEntity(org.opennms.features.status.api.StatusEntity) BusinessServiceSearchCriteriaBuilder(org.opennms.netmgt.bsm.service.BusinessServiceSearchCriteriaBuilder) List(java.util.List) StatusSummary(org.opennms.features.status.api.StatusSummary) Status(org.opennms.netmgt.bsm.service.model.Status) Service(org.springframework.stereotype.Service) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) BusinessServiceSearchCriteriaBuilder(org.opennms.netmgt.bsm.service.BusinessServiceSearchCriteriaBuilder) QueryParameters(org.opennms.web.utils.QueryParameters)

Example 8 with BusinessServiceSearchCriteriaBuilder

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);
}
Also used : BusinessServiceSearchCriteriaBuilder(org.opennms.netmgt.bsm.service.BusinessServiceSearchCriteriaBuilder)

Example 9 with BusinessServiceSearchCriteriaBuilder

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));
}
Also used : BusinessServiceSearchCriteriaBuilder(org.opennms.netmgt.bsm.service.BusinessServiceSearchCriteriaBuilder) Test(org.junit.Test)

Example 10 with BusinessServiceSearchCriteriaBuilder

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));
}
Also used : BusinessServiceSearchCriteriaBuilder(org.opennms.netmgt.bsm.service.BusinessServiceSearchCriteriaBuilder) Test(org.junit.Test)

Aggregations

BusinessServiceSearchCriteriaBuilder (org.opennms.netmgt.bsm.service.BusinessServiceSearchCriteriaBuilder)11 Test (org.junit.Test)6 BusinessService (org.opennms.netmgt.bsm.service.model.BusinessService)4 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Query (org.opennms.features.status.api.Query)2 StatusEntity (org.opennms.features.status.api.StatusEntity)2 StatusEntityWrapper (org.opennms.features.status.api.StatusEntityWrapper)2 StatusSummary (org.opennms.features.status.api.StatusSummary)2 BusinessServiceManager (org.opennms.netmgt.bsm.service.BusinessServiceManager)2 Status (org.opennms.netmgt.bsm.service.model.Status)2 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)2 QueryParameters (org.opennms.web.utils.QueryParameters)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Service (org.springframework.stereotype.Service)2 HashMap (java.util.HashMap)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1