use of org.opennms.netmgt.model.ResourcePath in project opennms by OpenNMS.
the class NewtsResourceStorageDao method children.
@Override
public Set<ResourcePath> children(ResourcePath path, int depth) {
Preconditions.checkArgument(depth >= 0, "depth must be non-negative");
Set<ResourcePath> matches = Sets.newTreeSet();
SearchResults results = searchFor(path, depth, false);
for (Result result : results) {
// Relativize the path
ResourcePath child = toChildResourcePath(path, result.getResource().getId());
if (child == null) {
// This shouldn't happen
LOG.warn("Encountered non-child resource {} when searching for {} with depth {}. Ignoring resource.", result.getResource(), path, depth);
continue;
}
matches.add(child);
}
return matches;
}
use of org.opennms.netmgt.model.ResourcePath in project opennms by OpenNMS.
the class NewtsResourceStorageDao method toChildResourcePath.
protected static ResourcePath toChildResourcePath(ResourcePath parent, String resourceId) {
final ResourcePath child = toResourcePath(resourceId);
final String[] childEls = child.elements();
final String[] parentEls = parent.elements();
if (childEls.length <= parentEls.length) {
return null;
}
String[] els = new String[parentEls.length + 1];
for (int i = 0; i <= parentEls.length; i++) {
els[i] = childEls[i];
}
return ResourcePath.get(els);
}
use of org.opennms.netmgt.model.ResourcePath in project opennms by OpenNMS.
the class NewtsResourceStorageDaoTest method replay.
private void replay() {
EasyMock.expect(m_searcher.search(EasyMock.eq(m_context), EasyMock.anyObject(), EasyMock.anyBoolean())).andAnswer(new IAnswer<SearchResults>() {
public SearchResults answer() throws Throwable {
// Assume there is a single term query
Query q = (Query) EasyMock.getCurrentArguments()[1];
BooleanQuery bq = (BooleanQuery) q;
TermQuery tq = (TermQuery) bq.getClauses().get(0).getQuery();
String field = tq.getTerm().getField("");
String value = tq.getTerm().getValue();
SearchResults searchResults = new SearchResults();
for (Entry<ResourcePath, Set<String>> entry : m_indexedPaths.entrySet()) {
Map<String, String> attributes = Maps.newHashMap();
// Build the indexed attributes and attempt to match them against the given query
NewtsUtils.addIndicesToAttributes(entry.getKey(), attributes);
if (value.equals(attributes.get(field))) {
searchResults.addResult(new Resource(NewtsUtils.toResourceId(entry.getKey())), entry.getValue());
}
}
return searchResults;
}
}).atLeastOnce();
EasyMock.expect(m_searcher.getResourceAttributes(EasyMock.eq(m_context), EasyMock.anyObject())).andReturn(Maps.newHashMap()).anyTimes();
EasyMock.replay(m_searcher);
}
use of org.opennms.netmgt.model.ResourcePath in project opennms by OpenNMS.
the class GenericIndexResourceType method getResourcesForParent.
/** {@inheritDoc} */
@Override
public List<OnmsResource> getResourcesForParent(OnmsResource parent) {
if (parent == null) {
return Collections.emptyList();
}
List<OnmsResource> resources = Lists.newArrayList();
List<String> indexes = getQueryableIndexes(new ResourcePath(parent.getPath(), m_name));
for (String index : indexes) {
resources.add(getResourceByPath(new ResourcePath(parent.getPath(), m_name, index), parent));
}
return OnmsResource.sortIntoResourceList(resources);
}
use of org.opennms.netmgt.model.ResourcePath in project opennms by OpenNMS.
the class InterfaceSnmpResourceType method getResourceByParentPathAndInterface.
private OnmsResource getResourceByParentPathAndInterface(ResourcePath parent, String intf) {
final ResourcePath path = ResourcePath.get(parent, intf);
final LazyResourceAttributeLoader loader = new LazyResourceAttributeLoader(m_resourceStorageDao, path);
final Set<OnmsAttribute> set = new LazySet<OnmsAttribute>(loader);
return new OnmsResource(intf, intf, this, set, path);
}
Aggregations