Search in sources :

Example 16 with OnmsCategory

use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.

the class CategorySearchProvider method query.

@Override
public List<SearchResult> query(SearchQuery searchQuery, GraphContainer graphContainer) {
    Collection<OnmsCategory> categories = categoryProvider.getAllCategories();
    List<SearchResult> results = new ArrayList<SearchResult>();
    for (OnmsCategory category : categories) {
        if (!checkHiddenPrefix(category.getName()) && searchQuery.matches(category.getName())) {
            SearchResult result = new SearchResult(CategoryHopCriteria.NAMESPACE, category.getId().toString(), category.getName(), searchQuery.getQueryString(), SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED);
            CollapsibleCriteria criteria = getMatchingCriteria(graphContainer, category.getName());
            if (criteria != null) {
                result.setCollapsed(criteria.isCollapsed());
            }
            results.add(result);
        }
    }
    return results;
}
Also used : OnmsCategory(org.opennms.netmgt.model.OnmsCategory) CollapsibleCriteria(org.opennms.features.topology.api.topo.CollapsibleCriteria) ArrayList(java.util.ArrayList) SearchResult(org.opennms.features.topology.api.topo.SearchResult)

Example 17 with OnmsCategory

use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.

the class FilterParserTest method createNode.

/**
	 * Utility to create and populate a mock opennms node. 
	 * @param id used to set unique id and values for node
	 * @return
	 */
public static OnmsNode createNode(int id) {
    OnmsNode node = new OnmsNode();
    node.setLabel("node-nodelabel_" + id);
    node.setId(id);
    node.setForeignSource("node-foreignsource_" + id);
    node.setForeignId("node-foreignid_" + id);
    node.setSysName("node-nodesysname_" + id);
    node.setSysLocation("node-nodeLocation_" + id);
    node.setOperatingSystem("node-operatingsystem_" + id);
    Set<OnmsCategory> categories = new LinkedHashSet<OnmsCategory>();
    node.setCategories(categories);
    // categories used for multi value tests
    OnmsCategory onmsCategory = new OnmsCategory();
    onmsCategory.setName("category1");
    categories.add(onmsCategory);
    OnmsCategory onmsCategory2 = new OnmsCategory();
    onmsCategory2.setName("category2");
    categories.add(onmsCategory2);
    // parent information
    OnmsNode parent = new OnmsNode();
    node.setParent(parent);
    parent.setLabel("parent-nodelabel");
    parent.setNodeId("1");
    parent.setForeignSource("parent-foreignsource_" + id);
    parent.setForeignId("parent-foreignid_" + id);
    OnmsAssetRecord assetRecord = new OnmsAssetRecord();
    node.setAssetRecord(assetRecord);
    OnmsGeolocation gl = new OnmsGeolocation();
    assetRecord.setGeolocation(gl);
    //geolocation
    gl.setCountry("asset-country_" + id);
    gl.setAddress1("asset-address1_" + id);
    gl.setAddress2("asset-address2_" + id);
    gl.setCity("asset-city_" + id);
    gl.setZip("asset-zip_" + id);
    gl.setState("asset-state_" + id);
    Float lat = Float.valueOf("0");
    gl.setLatitude(lat);
    Float lng = Float.valueOf("0");
    gl.setLongitude(lng);
    //assetRecord
    assetRecord.setRegion("asset-region_" + id);
    assetRecord.setDivision("asset-division_" + id);
    assetRecord.setDepartment("asset-department_" + id);
    assetRecord.setBuilding("asset-building_" + id);
    assetRecord.setFloor("asset-floor_" + id);
    assetRecord.setRoom("asset-room_" + id);
    assetRecord.setRack("asset-rack_" + id);
    assetRecord.setSlot("asset-slot_" + id);
    assetRecord.setPort("asset-port_" + id);
    assetRecord.setCircuitId("asset-circuitid_" + id);
    assetRecord.setCategory("asset-category_" + id);
    assetRecord.setDisplayCategory("asset-displaycategory_" + id);
    assetRecord.setNotifyCategory("asset-notifycategory_" + id);
    assetRecord.setPollerCategory("asset-pollercategory_" + id);
    assetRecord.setThresholdCategory("asset-thresholdcategory_" + id);
    assetRecord.setManagedObjectType("asset-managedobjecttype_" + id);
    assetRecord.setManagedObjectInstance("asset-managedobjectinstance_" + id);
    assetRecord.setManufacturer("asset-manufacturer_" + id);
    assetRecord.setVendor("asset-vendor_" + id);
    assetRecord.setModelNumber("asset-modelnumber_" + id);
    assetRecord.setDescription("asset-description_" + id);
    assetRecord.setOperatingSystem("asset-operatingsystem_" + id);
    return node;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) OnmsAssetRecord(org.opennms.netmgt.model.OnmsAssetRecord) OnmsGeolocation(org.opennms.netmgt.model.OnmsGeolocation)

Example 18 with OnmsCategory

use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.

the class FilterParserTest method getMockNodeList.

/**
	 * Utility to create a mock list of opennms nodes
	 * @return
	 */
public static List<OnmsNode> getMockNodeList() {
    List<OnmsNode> nodeList = new ArrayList<OnmsNode>();
    for (int id = 0; id < 5; id++) {
        OnmsNode n = createNode(id);
        OnmsCategory onmsCategory3 = new OnmsCategory();
        onmsCategory3.setName("category3");
        n.getCategories().add(onmsCategory3);
        nodeList.add(n);
    }
    for (int id = 5; id < 10; id++) {
        OnmsNode n = createNode(id);
        n.setForeignSource("testForeignSource1");
        n.getAssetRecord().setPollerCategory("testPollerCategory1");
        OnmsCategory onmsCategory4 = new OnmsCategory();
        onmsCategory4.setName("category4");
        n.getCategories().add(onmsCategory4);
        nodeList.add(n);
    }
    for (int id = 10; id < 15; id++) {
        OnmsNode n = createNode(id);
        n.setForeignSource("testForeignSource2");
        n.getAssetRecord().setPollerCategory("testPollerCategory1");
        n.getAssetRecord().setDisplayCategory("testDisplayCategory");
        nodeList.add(n);
    }
    for (int id = 15; id < 20; id++) {
        OnmsNode n = createNode(id);
        n.setForeignSource("testForeignSource3");
        n.getAssetRecord().setPollerCategory("testPollerCategory2");
        n.getAssetRecord().setDisplayCategory("testDisplayCategory");
        nodeList.add(n);
    }
    return nodeList;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) ArrayList(java.util.ArrayList)

Example 19 with OnmsCategory

use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.

the class MockNodeDao method updateSubObjects.

private void updateSubObjects(final OnmsNode node) {
    node.getAssetRecord().setNode(node);
    getAssetRecordDao().saveOrUpdate(node.getAssetRecord());
    for (final OnmsCategory cat : node.getCategories()) {
        getCategoryDao().saveOrUpdate(cat);
    }
    /* not sure if this is necessary */
    /*
        getMonitoringLocationDao().saveOrUpdate(node.getLocation());
        */
    /** delete any interfaces that were removed compared to the database **/
    final OnmsNode dbNode = node.getId() == null ? null : get(node.getId());
    if (dbNode != null) {
        for (final OnmsSnmpInterface iface : dbNode.getSnmpInterfaces()) {
            if (!node.getSnmpInterfaces().contains(iface)) {
                getSnmpInterfaceDao().delete(iface);
            }
        }
        for (final OnmsIpInterface iface : dbNode.getIpInterfaces()) {
            if (!node.getIpInterfaces().contains(iface)) {
                getIpInterfaceDao().delete(iface);
            }
        }
    }
    for (final OnmsSnmpInterface iface : node.getSnmpInterfaces()) {
        iface.setNode(node);
        getSnmpInterfaceDao().saveOrUpdate(iface);
    }
    for (final OnmsIpInterface iface : node.getIpInterfaces()) {
        iface.setNode(node);
        getIpInterfaceDao().saveOrUpdate(iface);
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface)

Example 20 with OnmsCategory

use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.

the class GroupRestService method getCategoryForGroup.

@GET
@Path("{groupName}/categories/{categoryName}")
public OnmsCategory getCategoryForGroup(@PathParam("groupName") final String groupName, @PathParam("categoryName") final String categoryName) {
    // check if group exists.
    getOnmsGroup(groupName);
    List<OnmsCategory> categories = m_groupService.getAuthorizedCategories(groupName);
    for (OnmsCategory eachCategory : categories) {
        if (eachCategory.getName().equals(categoryName))
            return eachCategory;
    }
    throw getException(Status.NOT_FOUND, "Category with name '{}' does not exist for group '{}'.", categoryName, groupName);
}
Also used : OnmsCategory(org.opennms.netmgt.model.OnmsCategory) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

OnmsCategory (org.opennms.netmgt.model.OnmsCategory)54 OnmsNode (org.opennms.netmgt.model.OnmsNode)25 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)9 LinkedHashSet (java.util.LinkedHashSet)6 Path (javax.ws.rs.Path)6 HashSet (java.util.HashSet)4 AggregateStatusDefinition (org.opennms.netmgt.model.AggregateStatusDefinition)4 AggregateStatusView (org.opennms.netmgt.model.AggregateStatusView)4 Transactional (org.springframework.transaction.annotation.Transactional)4 StringReader (java.io.StringReader)3 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)3 RowDef (org.opennms.netmgt.config.siteStatusViews.RowDef)3 OnmsAssetRecord (org.opennms.netmgt.model.OnmsAssetRecord)3 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)3 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)3 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)3 AggregateStatus (org.opennms.web.svclayer.model.AggregateStatus)3 Date (java.util.Date)2 Consumes (javax.ws.rs.Consumes)2