use of org.opennms.netmgt.collection.support.builder.Resource in project opennms by OpenNMS.
the class AbstractJsonCollectionHandler method fillCollectionSet.
/**
* Fill collection set.
*
* @param agent the agent
* @param collectionSet the collection set
* @param source the source
* @param json the JSON Object
* @throws ParseException the parse exception
*/
@SuppressWarnings("unchecked")
protected void fillCollectionSet(CollectionAgent agent, CollectionSetBuilder builder, XmlSource source, JSONObject json) throws ParseException {
JXPathContext context = JXPathContext.newContext(json);
for (XmlGroup group : source.getXmlGroups()) {
LOG.debug("fillCollectionSet: getting resources for XML group {} using XPATH {}", group.getName(), group.getResourceXpath());
Date timestamp = getTimeStamp(context, group);
Iterator<Pointer> itr = context.iteratePointers(group.getResourceXpath());
while (itr.hasNext()) {
JXPathContext relativeContext = context.getRelativeContext(itr.next());
String resourceName = getResourceName(relativeContext, group);
LOG.debug("fillCollectionSet: processing XML resource {} of type {}", resourceName, group.getResourceType());
final Resource collectionResource = getCollectionResource(agent, resourceName, group.getResourceType(), timestamp);
LOG.debug("fillCollectionSet: processing resource {}", collectionResource);
for (XmlObject object : group.getXmlObjects()) {
try {
Object obj = relativeContext.getValue(object.getXpath());
if (obj != null) {
builder.withAttribute(collectionResource, group.getName(), object.getName(), obj.toString(), object.getDataType());
}
} catch (JXPathException ex) {
LOG.warn("Unable to get value for {}: {}", object.getXpath(), ex.getMessage());
}
}
processXmlResource(builder, collectionResource, resourceName, group.getName());
}
}
}
use of org.opennms.netmgt.collection.support.builder.Resource in project opennms by OpenNMS.
the class AbstractXmlCollectionHandler method fillCollectionSet.
/**
* Fill collection set.
*
* @param agent the agent
* @param collectionSet the collection set
* @param source the source
* @param doc the doc
* @throws XPathExpressionException the x path expression exception
* @throws ParseException the parse exception
*/
protected void fillCollectionSet(CollectionAgent agent, CollectionSetBuilder builder, XmlSource source, Document doc) throws XPathExpressionException, ParseException {
NamespaceContext nc = new DocumentNamespaceResolver(doc);
XPath xpath = XPathFactory.newInstance().newXPath();
xpath.setNamespaceContext(nc);
for (XmlGroup group : source.getXmlGroups()) {
LOG.debug("fillCollectionSet: getting resources for XML group {} using XPATH {}", group.getName(), group.getResourceXpath());
Date timestamp = getTimeStamp(doc, xpath, group);
NodeList resourceList = (NodeList) xpath.evaluate(group.getResourceXpath(), doc, XPathConstants.NODESET);
for (int j = 0; j < resourceList.getLength(); j++) {
Node resource = resourceList.item(j);
String resourceName = getResourceName(xpath, group, resource);
final Resource collectionResource = getCollectionResource(agent, resourceName, group.getResourceType(), timestamp);
LOG.debug("fillCollectionSet: processing resource {}", collectionResource);
for (XmlObject object : group.getXmlObjects()) {
String value = (String) xpath.evaluate(object.getXpath(), resource, XPathConstants.STRING);
builder.withAttribute(collectionResource, group.getName(), object.getName(), value, object.getDataType());
}
processXmlResource(builder, collectionResource, resourceName, group.getName());
}
}
LOG.debug("fillCollectionSet: finishing collection set with {} resources and {} attributes on {}", builder.getNumResources(), builder.getNumAttributes(), agent);
}
Aggregations