use of org.opennms.netmgt.collection.support.AbstractCollectionResource in project opennms by OpenNMS.
the class CollectionSetDTO method buildCollectionResources.
private Set<CollectionResource> buildCollectionResources() {
final Set<CollectionResource> collectionResources = new LinkedHashSet<>();
for (CollectionResourceDTO entry : this.collectionResources) {
final Resource resource = entry.getResource();
final AbstractCollectionResource collectionResource = CollectionSetBuilder.toCollectionResource(resource, agent);
for (Attribute<?> attribute : entry.getAttributes()) {
final AttributeGroupType groupType = new AttributeGroupType(attribute.getGroup(), AttributeGroupType.IF_TYPE_ALL);
final AbstractCollectionAttributeType attributeType = new AbstractCollectionAttributeType(groupType) {
@Override
public AttributeType getType() {
return attribute.getType();
}
@Override
public String getName() {
return attribute.getName();
}
@Override
public void storeAttribute(CollectionAttribute collectionAttribute, Persister persister) {
if (AttributeType.STRING.equals(attribute.getType())) {
persister.persistStringAttribute(collectionAttribute);
} else {
persister.persistNumericAttribute(collectionAttribute);
}
}
@Override
public String toString() {
return attribute.toString();
}
};
collectionResource.addAttribute(new AbstractCollectionAttribute(attributeType, collectionResource) {
@Override
public String getMetricIdentifier() {
return attribute.getName();
}
@Override
public Number getNumericValue() {
return attribute.getNumericValue();
}
@Override
public String getStringValue() {
return attribute.getStringValue();
}
@Override
public boolean shouldPersist(ServiceParameters params) {
return !(Boolean.FALSE.equals(disableCounterPersistence) && AttributeType.COUNTER.equals(attribute.getType()));
}
@Override
public String toString() {
return String.format("Attribute[%s:%s]", getMetricIdentifier(), attribute.getValue());
}
});
}
collectionResources.add(collectionResource);
}
return collectionResources;
}
Aggregations