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