use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.
the class DefaultProvisionService method getRequisitionedNode.
/** {@inheritDoc} */
@Transactional
@Override
public OnmsNode getRequisitionedNode(final String foreignSource, final String foreignId) throws ForeignSourceRepositoryException {
OnmsNodeRequisition nodeReq = null;
try {
nodeReq = m_foreignSourceRepository.getNodeRequisition(foreignSource, foreignId);
} catch (ForeignSourceRepositoryException e) {
// just fall through, nodeReq will be null
}
if (nodeReq == null) {
LOG.warn("nodeReq for node {}:{} cannot be null!", foreignSource, foreignId);
return null;
}
final OnmsNode node = nodeReq.constructOnmsNodeFromRequisition();
// fill in real database categories
final HashSet<OnmsCategory> dbCategories = new HashSet<OnmsCategory>();
for (final OnmsCategory category : node.getCategories()) {
dbCategories.add(createCategoryIfNecessary(category.getName()));
}
node.setCategories(dbCategories);
if (node.getLocation() == null || Strings.isNullOrEmpty(node.getLocation().getLocationName())) {
node.setLocation(m_monitoringLocationDao.getDefaultLocation());
}
// fill in real service types
node.visit(new ServiceTypeFulfiller());
return node;
}
use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.
the class DefaultProvisionService method saveOrUpdate.
@Transactional
private OnmsNode saveOrUpdate(final OnmsNode node) {
final Set<OnmsCategory> updatedCategories = new HashSet<OnmsCategory>();
for (final Iterator<OnmsCategory> it = node.getCategories().iterator(); it.hasNext(); ) {
final OnmsCategory category = it.next();
if (category.getId() == null) {
it.remove();
updatedCategories.add(createCategoryIfNecessary(category.getName()));
}
}
node.getCategories().addAll(updatedCategories);
m_nodeDao.saveOrUpdate(node);
m_nodeDao.flush();
return node;
}
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 GroupRestServiceIT method createCategory.
protected void createCategory(final String categoryName) throws Exception {
OnmsCategory cat = new OnmsCategory(categoryName);
sendPost("/categories", JaxbUtils.marshal(cat), 201, "/categories/" + categoryName);
}
Aggregations