Search in sources :

Example 6 with OnmsCategory

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

the class ProvisionerIT method testRequisitionedCategoriesWithUserCategoryThenUpdateRequisitionToRemoveRequisitionedCategory.

@Test(timeout = 300000)
public void testRequisitionedCategoriesWithUserCategoryThenUpdateRequisitionToRemoveRequisitionedCategory() throws Exception {
    final int nextNodeId = m_nodeDao.getNextNodeId();
    importFromResource("classpath:/provisioner-testCategories-oneCategory.xml", Boolean.TRUE.toString());
    runPendingScans();
    // make sure we have the 1 category we expect
    OnmsNode n = getNodeDao().get(nextNodeId);
    assertEquals(1, n.getCategories().size());
    assertTrue(n.hasCategory("TotallyMadeUpCategoryName"));
    OnmsCategory cat = new OnmsCategory("ThisIsAlsoMadeUp");
    m_categoryDao.save(cat);
    m_categoryDao.flush();
    n.addCategory(m_categoryDao.findByName("ThisIsAlsoMadeUp"));
    getNodeDao().save(n);
    importFromResource("classpath:/provisioner-testCategories-noCategories.xml", Boolean.TRUE.toString());
    runPendingScans();
    // when the scan has completed, the requisitioned category should be removed, but the user-added one should remain
    n = getNodeDao().get(nextNodeId);
    assertEquals(1, n.getCategories().size());
    assertTrue(n.hasCategory("ThisIsAlsoMadeUp"));
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) Test(org.junit.Test)

Example 7 with OnmsCategory

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

the class DefaultAdminCategoryService method findCategory.

private OnmsCategory findCategory(String name) {
    int categoryId = -1;
    try {
        categoryId = WebSecurityUtils.safeParseInt(name);
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException("parameter 'categoryid' " + "with value '" + name + "' could not be parsed " + "as an integer");
    }
    OnmsCategory category = m_categoryDao.get(categoryId);
    if (category == null) {
        throw new IllegalArgumentException("Could not find category " + "with category ID " + categoryId);
    }
    return category;
}
Also used : OnmsCategory(org.opennms.netmgt.model.OnmsCategory)

Example 8 with OnmsCategory

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

the class CategoryRestService method updateCategory.

@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("/{categoryName}")
public Response updateCategory(@PathParam("categoryName") final String categoryName, final MultivaluedMapImpl params) {
    writeLock();
    try {
        OnmsCategory category = m_categoryDao.findByName(categoryName);
        if (category == null) {
            throw getException(Status.BAD_REQUEST, "Category with name '{}' was not found.", categoryName);
        }
        LOG.debug("updateCategory: updating category {}", category);
        BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(category);
        boolean modified = false;
        for (String key : params.keySet()) {
            if (wrapper.isWritableProperty(key)) {
                String stringValue = params.getFirst(key);
                Object value = wrapper.convertIfNecessary(stringValue, (Class<?>) wrapper.getPropertyType(key));
                wrapper.setPropertyValue(key, value);
                modified = true;
            }
        }
        LOG.debug("updateCategory: category {} updated", category);
        if (modified) {
            m_categoryDao.saveOrUpdate(category);
            return Response.noContent().build();
        }
        return Response.notModified().build();
    } finally {
        writeUnlock();
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 9 with OnmsCategory

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

the class HeatMapIT method setUp.

@BeforeTransaction
public void setUp() {
    if (!m_populated) {
        m_databasePopulator.populateDatabase();
        m_populated = true;
    }
    numberOfNodesInCategory = new HashMap();
    List<OnmsCategory> onmsCategories = m_categoryDao.findAll();
    for (OnmsCategory onmsCategory : onmsCategories) {
        int n = m_nodeDao.findByCategory(onmsCategory).size();
        if (n > 0) {
            numberOfNodesInCategory.put(onmsCategory.getName(), n);
        }
    }
}
Also used : OnmsCategory(org.opennms.netmgt.model.OnmsCategory) HashMap(java.util.HashMap) BeforeTransaction(org.springframework.test.context.transaction.BeforeTransaction)

Example 10 with OnmsCategory

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

the class CategoryRestServiceIT method createCategory.

protected void createCategory(final String categoryName) throws Exception {
    OnmsCategory cat = new OnmsCategory();
    cat.setName(categoryName);
    createCategory(cat);
}
Also used : OnmsCategory(org.opennms.netmgt.model.OnmsCategory)

Aggregations

OnmsCategory (org.opennms.netmgt.model.OnmsCategory)63 OnmsNode (org.opennms.netmgt.model.OnmsNode)29 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)9 Path (javax.ws.rs.Path)7 LinkedHashSet (java.util.LinkedHashSet)6 HashSet (java.util.HashSet)5 AggregateStatusDefinition (org.opennms.netmgt.model.AggregateStatusDefinition)4 AggregateStatusView (org.opennms.netmgt.model.AggregateStatusView)4 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)4 Transactional (org.springframework.transaction.annotation.Transactional)4 GET (javax.ws.rs.GET)3 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)3 SearchResult (org.opennms.features.topology.api.topo.SearchResult)3 RowDef (org.opennms.netmgt.config.siteStatusViews.RowDef)3 NetworkBuilder (org.opennms.netmgt.model.NetworkBuilder)3 OnmsAssetRecord (org.opennms.netmgt.model.OnmsAssetRecord)3 OnmsGeolocation (org.opennms.netmgt.model.OnmsGeolocation)3 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)3 AggregateStatus (org.opennms.web.svclayer.model.AggregateStatus)3