Search in sources :

Example 56 with OnmsCategory

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

the class CategoryRestServiceIT method testUpdateCategory.

@Test
@JUnitTemporaryDatabase
public void testUpdateCategory() throws Exception {
    // create
    OnmsCategory createMe = new OnmsCategory();
    createMe.setDescription("This is a description");
    createMe.setName("myName");
    createCategory(createMe);
    // verify creation
    String url = "/categories";
    String xml = sendRequest(GET, url, 200);
    assertTrue(xml.contains("<description>This is a description</description>"));
    assertTrue(xml.contains("name=\"myName\""));
    // change
    url += "/myName";
    sendPut(url, "description=My Equipment&name=NewCategory", 204);
    xml = sendRequest(GET, url, 200);
    assertTrue(xml.contains("<description>My Equipment</description>"));
    assertTrue(xml.contains("name=\"NewCategory\""));
    xml = sendRequest(DELETE, url, 204);
    assertFalse(xml.contains("<description>My Equipment</description>"));
    assertFalse(xml.contains("name=\"NewCategory\""));
    assertFalse(xml.contains("name=\"myName\""));
    assertFalse(xml.contains("<description>This is a description</description>"));
    sendRequest(GET, url, 200);
}
Also used : OnmsCategory(org.opennms.netmgt.model.OnmsCategory) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 57 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)

Example 58 with OnmsCategory

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

the class DefaultSurveillanceViewService method createQuery.

/**
     * Creates a SQL query string for filtering on categories.
     *
     * @param rowCategories the row categories
     * @param colCategories the column categories
     * @return the SQL query string
     */
private static String createQuery(final String nodeIdProperty, final Set<OnmsCategory> rowCategories, final Set<OnmsCategory> colCategories) {
    StringBuffer stringBuffer = new StringBuffer();
    boolean first = true;
    stringBuffer.append(nodeIdProperty + " in (select distinct cn.nodeId from category_node cn join categories c on cn.categoryId = c.categoryId where c.categoryName in (");
    for (OnmsCategory onmsCategory : rowCategories) {
        if (first) {
            stringBuffer.append("'");
            first = false;
        } else {
            stringBuffer.append(",'");
        }
        stringBuffer.append(onmsCategory.getName());
        stringBuffer.append("'");
    }
    stringBuffer.append("))");
    first = true;
    stringBuffer.append("and " + nodeIdProperty + " in (select distinct cn.nodeId from category_node cn join categories c on cn.categoryId = c.categoryId where c.categoryName in (");
    for (OnmsCategory onmsCategory : colCategories) {
        if (first) {
            stringBuffer.append("'");
            first = false;
        } else {
            stringBuffer.append(",'");
        }
        stringBuffer.append(onmsCategory.getName());
        stringBuffer.append("'");
    }
    stringBuffer.append("))");
    return stringBuffer.toString();
}
Also used : OnmsCategory(org.opennms.netmgt.model.OnmsCategory)

Example 59 with OnmsCategory

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

the class DatabasePopulator method getCategory.

private OnmsCategory getCategory(final String categoryName) {
    OnmsCategory cat = m_categoryDao.findByName(categoryName, true);
    if (cat == null) {
        cat = new OnmsCategory(categoryName);
        m_categoryDao.save(cat);
        m_categoryDao.flush();
    }
    return cat;
}
Also used : OnmsCategory(org.opennms.netmgt.model.OnmsCategory)

Example 60 with OnmsCategory

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

the class NodeRestService method addCategoryToNode.

@POST
@Path("/{nodeCriteria}/categories/{categoryName}")
public Response addCategoryToNode(@Context final UriInfo uriInfo, @PathParam("nodeCriteria") String nodeCriteria, @PathParam("categoryName") final String categoryName) {
    writeLock();
    try {
        OnmsNode node = m_nodeDao.get(nodeCriteria);
        if (node == null) {
            throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
        }
        OnmsCategory found = m_categoryDao.findByName(categoryName);
        if (found == null) {
            throw getException(Status.BAD_REQUEST, "Category {} was not found.", categoryName);
        }
        if (!node.getCategories().contains(found)) {
            LOG.debug("addCategory: Adding category {} to node {}", found, nodeCriteria);
            node.addCategory(found);
            m_nodeDao.save(node);
            return Response.created(getRedirectUri(uriInfo, categoryName)).build();
        } else {
            throw getException(Status.BAD_REQUEST, "Category '{}' already added to node '{}'", categoryName, nodeCriteria);
        }
    } finally {
        writeUnlock();
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

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