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