Search in sources :

Example 1 with EntityVisitor

use of org.opennms.netmgt.model.EntityVisitor in project opennms by OpenNMS.

the class DefaultProvisionService method updateNode.

/**
 * {@inheritDoc}
 */
@Transactional
@Override
public void updateNode(final OnmsNode node, String rescanExisting) {
    updateLocation(node);
    final OnmsNode dbNode = m_nodeDao.getHierarchy(node.getId());
    // on an update, leave categories alone, let the NodeScan handle applying requisitioned categories
    node.setCategories(dbNode.getCategories());
    final EventAccumulator accumulator = new EventAccumulator(m_eventForwarder);
    dbNode.mergeNode(node, accumulator, false);
    updateNodeHostname(dbNode);
    m_nodeDao.update(dbNode);
    m_nodeDao.flush();
    accumulator.flush();
    final EntityVisitor eventAccumlator = new UpdateEventVisitor(m_eventForwarder, rescanExisting);
    dbNode.visit(eventAccumlator);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) AbstractEntityVisitor(org.opennms.netmgt.model.AbstractEntityVisitor) EntityVisitor(org.opennms.netmgt.model.EntityVisitor) UpdateEventVisitor(org.opennms.netmgt.model.events.UpdateEventVisitor) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with EntityVisitor

use of org.opennms.netmgt.model.EntityVisitor in project opennms by OpenNMS.

the class DefaultProvisionService method insertNode.

/**
 * {@inheritDoc}
 */
@Transactional
@Override
public void insertNode(final OnmsNode node) {
    updateLocation(node);
    m_nodeDao.save(node);
    m_nodeDao.flush();
    final EntityVisitor visitor = new AddEventVisitor(m_eventForwarder);
    node.visit(visitor);
}
Also used : AddEventVisitor(org.opennms.netmgt.model.events.AddEventVisitor) AbstractEntityVisitor(org.opennms.netmgt.model.AbstractEntityVisitor) EntityVisitor(org.opennms.netmgt.model.EntityVisitor) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with EntityVisitor

use of org.opennms.netmgt.model.EntityVisitor in project opennms by OpenNMS.

the class FilterResourceWalker method walk.

/**
 * <p>walk</p>
 */
public void walk() {
    EntityVisitor visitor = new AbstractEntityVisitor() {

        @Override
        public void visitNode(OnmsNode node) {
            walk(node);
        }
    };
    SortedMap<Integer, String> map = getFilterDao().getNodeMap(m_filter);
    for (final Integer nodeId : map.keySet()) {
        final OnmsNode node = getNodeDao().load(nodeId);
        visitor.visitNode(node);
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) AbstractEntityVisitor(org.opennms.netmgt.model.AbstractEntityVisitor) EntityVisitor(org.opennms.netmgt.model.EntityVisitor) AbstractEntityVisitor(org.opennms.netmgt.model.AbstractEntityVisitor)

Example 4 with EntityVisitor

use of org.opennms.netmgt.model.EntityVisitor in project opennms by OpenNMS.

the class JdbcFilterDaoIT method testWalkNodes.

@Test
public void testWalkNodes() throws Exception {
    final List<OnmsNode> nodes = new ArrayList<>();
    EntityVisitor visitor = new AbstractEntityVisitor() {

        @Override
        public void visitNode(OnmsNode node) {
            nodes.add(node);
        }
    };
    FilterWalker walker = new FilterWalker();
    walker.setFilterDao(m_dao);
    walker.setNodeDao(m_nodeDao);
    walker.setFilter("ipaddr == '10.1.1.1'");
    walker.setVisitor(visitor);
    walker.walk();
    assertEquals("node list size", 1, nodes.size());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) ArrayList(java.util.ArrayList) AbstractEntityVisitor(org.opennms.netmgt.model.AbstractEntityVisitor) EntityVisitor(org.opennms.netmgt.model.EntityVisitor) AbstractEntityVisitor(org.opennms.netmgt.model.AbstractEntityVisitor) Test(org.junit.Test)

Aggregations

AbstractEntityVisitor (org.opennms.netmgt.model.AbstractEntityVisitor)4 EntityVisitor (org.opennms.netmgt.model.EntityVisitor)4 OnmsNode (org.opennms.netmgt.model.OnmsNode)3 Transactional (org.springframework.transaction.annotation.Transactional)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 AddEventVisitor (org.opennms.netmgt.model.events.AddEventVisitor)1 UpdateEventVisitor (org.opennms.netmgt.model.events.UpdateEventVisitor)1