Search in sources :

Example 36 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 37 with OnmsCategory

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

the class SaveOrUpdateOperation method foundCategory.

/**
 * <p>foundCategory</p>
 *
 * @param name a {@link java.lang.String} object.
 */
public void foundCategory(String name) {
    OnmsCategory category = getProvisionService().createCategoryIfNecessary(name);
    m_node.getCategories().add(category);
}
Also used : OnmsCategory(org.opennms.netmgt.model.OnmsCategory)

Example 38 with OnmsCategory

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

the class NodeCategoriesRestService method doCreate.

@Override
protected Response doCreate(SecurityContext securityContext, UriInfo uriInfo, OnmsCategory source) {
    OnmsNode node = getNode(uriInfo);
    if (node == null) {
        throw getException(Status.BAD_REQUEST, "Node was not found.");
    } else if (source == null) {
        throw getException(Status.BAD_REQUEST, "Category object cannot be null");
    } else if (source.getName() == null) {
        throw getException(Status.BAD_REQUEST, "Category's name cannot be null");
    }
    final OnmsCategory category = getCategory(source.getName());
    node.addCategory(category);
    m_nodeDao.saveOrUpdate(node);
    final Event event = EventUtils.createNodeCategoryMembershipChangedEvent("ReST", node.getId(), node.getLabel(), new String[] { category.getName() }, null);
    sendEvent(event);
    return Response.created(RedirectHelper.getRedirectUri(uriInfo, category.getName())).build();
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) Event(org.opennms.netmgt.xml.event.Event)

Example 39 with OnmsCategory

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

the class CategoryRestServiceIT method testCategories.

@Test
@JUnitTemporaryDatabase
public void testCategories() throws Exception {
    // get initial categories
    String xml = sendRequest("GET", "/categories", 200);
    assertNotNull(xml);
    OnmsCategoryCollection categories = JaxbUtils.unmarshal(OnmsCategoryCollection.class, xml);
    int initialSize = categories.size();
    assertNotNull(categories);
    assertEquals(initialSize, categories.size());
    // add category
    createCategory("testCategory");
    xml = sendRequest("GET", "/categories", 200);
    categories = JaxbUtils.unmarshal(OnmsCategoryCollection.class, xml);
    assertEquals(initialSize + 1, categories.size());
    assertTrue(xml.contains("name=\"testCategory\""));
    // add again (should fail)
    sendData("POST", MediaType.APPLICATION_XML, "/categories", JaxbUtils.marshal(new OnmsCategory("testCategory")), 400);
    xml = sendRequest("GET", "/categories", 200);
    categories = JaxbUtils.unmarshal(OnmsCategoryCollection.class, xml);
    assertEquals(initialSize + 1, categories.size());
    assertTrue(xml.contains("name=\"testCategory\""));
    // delete
    sendRequest("DELETE", "/categories/testCategory", 204);
    xml = sendRequest("GET", "/categories", 200);
    categories = JaxbUtils.unmarshal(OnmsCategoryCollection.class, xml);
    assertEquals(initialSize, categories.size());
    assertFalse(xml.contains("name=\"testCategory\""));
}
Also used : OnmsCategory(org.opennms.netmgt.model.OnmsCategory) OnmsCategoryCollection(org.opennms.netmgt.model.OnmsCategoryCollection) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 40 with OnmsCategory

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

the class CategoryRestServiceIT method testAddCategory.

@Test
@JUnitTemporaryDatabase
public void testAddCategory() throws Exception {
    // add with description
    OnmsCategory createMe = new OnmsCategory();
    createMe.setDescription("This is a description");
    createMe.setName("myName");
    createCategory(createMe);
    // verify
    String xml = sendRequest("GET", "/categories/myName", 200);
    OnmsCategory category = JaxbUtils.unmarshal(OnmsCategory.class, xml);
    assertNotNull(category.getId());
    createMe.setId(category.getId());
    assertTrue(category.getId().equals(createMe.getId()));
    assertEquals(createMe, category);
}
Also used : OnmsCategory(org.opennms.netmgt.model.OnmsCategory) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

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