use of org.netxms.client.ObjectFilter in project netxms by netxms.
the class ObjectFinder method doSearch.
/**
* Do object search
*
* @param searchString search string
* @param classFilter
* @param zoneFilter
* @param addrEnd
* @param addrStart
*/
private void doSearch(final String searchString, final int mode, final List<Integer> classFilter, final List<Long> zoneFilter, final InetAddress addrStart, final InetAddress addrEnd) {
final NXCSession session = ConsoleSharedData.getSession();
new ConsoleJob("Find objects", this, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
final Pattern regexp = (mode == SEARCH_MODE_REGEXP) ? Pattern.compile(searchString, Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.UNICODE_CASE) : null;
final List<AbstractObject> objects = session.filterObjects(new ObjectFilter() {
@Override
public boolean filter(AbstractObject object) {
if (session.isZoningEnabled() && session.getAllZones().size() != zoneFilter.size()) {
if (object instanceof ZoneMember) {
ZoneMember node = (ZoneMember) object;
if (!zoneFilter.contains(node.getZoneId()))
return false;
}
if (object instanceof Sensor) {
AbstractNode proxy = session.findObjectById(((Sensor) object).getProxyId(), AbstractNode.class);
if (proxy != null && zoneFilter.contains(proxy.getZoneId()))
return false;
} else if (object instanceof Interface) {
AbstractNode parent = ((Interface) object).getParentNode();
if (parent != null && !zoneFilter.contains(parent.getZoneId()))
return false;
} else if (object instanceof NetworkService) {
AbstractNode parent = ((NetworkService) object).getParentNode();
if (parent != null && !zoneFilter.contains(parent.getZoneId()))
return false;
} else if (object instanceof VPNConnector) {
AbstractNode parent = ((VPNConnector) object).getParentNode();
if (parent != null && !zoneFilter.contains(parent.getZoneId()))
return false;
} else if (object instanceof AccessPoint) {
AbstractNode parent = ((AccessPoint) object).getParentNode();
if (parent != null && !zoneFilter.contains(parent.getZoneId()))
return false;
} else if (object instanceof GenericObject && !zoneFilter.isEmpty()) {
AbstractObject[] children = ((GenericObject) object).getChildsAsArray();
boolean match = false;
for (AbstractObject o : children) {
if (o instanceof ZoneMember && zoneFilter.contains(((ZoneMember) o).getZoneId()))
match = true;
}
if (!match)
return false;
}
}
if (!classFilter.contains(object.getObjectClass()))
return false;
if ((addrStart != null) && (addrEnd != null)) {
if (!checkAddrRange(addrStart, addrEnd, object))
return false;
}
if (searchString.isEmpty())
return true;
for (String s : object.getStrings()) {
switch(mode) {
case SEARCH_MODE_NORMAL:
if (s.toLowerCase().contains(searchString))
return true;
break;
case SEARCH_MODE_PATTERN:
if (Glob.match(searchString, s.toLowerCase()))
return true;
break;
case SEARCH_MODE_REGEXP:
if (regexp.matcher(s).find())
return true;
break;
}
}
return false;
}
});
runInUIThread(new Runnable() {
@Override
public void run() {
results.setInput(objects);
}
});
}
@Override
protected String getErrorMessage() {
return "Object search failure";
}
}.start();
}
Aggregations