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);
}
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);
}
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();
}
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;
}
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();
}
}
Aggregations