Search in sources :

Example 51 with OnmsCategory

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

the class DefaultProvisionService method getRequisitionedNode.

/** {@inheritDoc} */
@Transactional
@Override
public OnmsNode getRequisitionedNode(final String foreignSource, final String foreignId) throws ForeignSourceRepositoryException {
    OnmsNodeRequisition nodeReq = null;
    try {
        nodeReq = m_foreignSourceRepository.getNodeRequisition(foreignSource, foreignId);
    } catch (ForeignSourceRepositoryException e) {
    // just fall through, nodeReq will be null
    }
    if (nodeReq == null) {
        LOG.warn("nodeReq for node {}:{} cannot be null!", foreignSource, foreignId);
        return null;
    }
    final OnmsNode node = nodeReq.constructOnmsNodeFromRequisition();
    // fill in real database categories
    final HashSet<OnmsCategory> dbCategories = new HashSet<OnmsCategory>();
    for (final OnmsCategory category : node.getCategories()) {
        dbCategories.add(createCategoryIfNecessary(category.getName()));
    }
    node.setCategories(dbCategories);
    if (node.getLocation() == null || Strings.isNullOrEmpty(node.getLocation().getLocationName())) {
        node.setLocation(m_monitoringLocationDao.getDefaultLocation());
    }
    // fill in real service types
    node.visit(new ServiceTypeFulfiller());
    return node;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) ForeignSourceRepositoryException(org.opennms.netmgt.provision.persist.ForeignSourceRepositoryException) OnmsNodeRequisition(org.opennms.netmgt.provision.persist.OnmsNodeRequisition) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 52 with OnmsCategory

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

the class DefaultProvisionService method saveOrUpdate.

@Transactional
private OnmsNode saveOrUpdate(final OnmsNode node) {
    final Set<OnmsCategory> updatedCategories = new HashSet<OnmsCategory>();
    for (final Iterator<OnmsCategory> it = node.getCategories().iterator(); it.hasNext(); ) {
        final OnmsCategory category = it.next();
        if (category.getId() == null) {
            it.remove();
            updatedCategories.add(createCategoryIfNecessary(category.getName()));
        }
    }
    node.getCategories().addAll(updatedCategories);
    m_nodeDao.saveOrUpdate(node);
    m_nodeDao.flush();
    return node;
}
Also used : OnmsCategory(org.opennms.netmgt.model.OnmsCategory) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 53 with OnmsCategory

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

the class DefaultProvisionService method createCategoryIfNecessary.

/** {@inheritDoc} */
@Transactional
@Override
public OnmsCategory createCategoryIfNecessary(final String name) {
    preloadExistingCategories();
    OnmsCategory category = m_categoryCache.get().get(name);
    if (category == null) {
        category = loadCategory(name);
        m_categoryCache.get().put(category.getName(), category);
    }
    return category;
}
Also used : OnmsCategory(org.opennms.netmgt.model.OnmsCategory) Transactional(org.springframework.transaction.annotation.Transactional)

Example 54 with OnmsCategory

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

the class GroupRestServiceIT method createCategory.

protected void createCategory(final String categoryName) throws Exception {
    OnmsCategory cat = new OnmsCategory(categoryName);
    sendPost("/categories", JaxbUtils.marshal(cat), 201, "/categories/" + categoryName);
}
Also used : OnmsCategory(org.opennms.netmgt.model.OnmsCategory)

Aggregations

OnmsCategory (org.opennms.netmgt.model.OnmsCategory)54 OnmsNode (org.opennms.netmgt.model.OnmsNode)25 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)9 LinkedHashSet (java.util.LinkedHashSet)6 Path (javax.ws.rs.Path)6 HashSet (java.util.HashSet)4 AggregateStatusDefinition (org.opennms.netmgt.model.AggregateStatusDefinition)4 AggregateStatusView (org.opennms.netmgt.model.AggregateStatusView)4 Transactional (org.springframework.transaction.annotation.Transactional)4 StringReader (java.io.StringReader)3 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)3 RowDef (org.opennms.netmgt.config.siteStatusViews.RowDef)3 OnmsAssetRecord (org.opennms.netmgt.model.OnmsAssetRecord)3 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)3 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)3 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)3 AggregateStatus (org.opennms.web.svclayer.model.AggregateStatus)3 Date (java.util.Date)2 Consumes (javax.ws.rs.Consumes)2