/** {@inheritDoc} */ @Override protected String getKey(OnmsCategory category) { return category.getName(); }
private OnmsCategory createCategory() { OnmsCategory category = new OnmsCategory(); category.setName(TopologyGenerator.CATEGORY_NAME); return category; }
@Override public Integer save(final OnmsCategory cat) { if (cat == null) return null; final String categoryName = cat.getName(); if (categoryName == null) return null; final OnmsCategory existingCategory = findByName(categoryName); if (existingCategory == null) { return super.save(cat); } else { cat.setId(existingCategory.getId()); cat.setDescription(existingCategory.getDescription()); cat.setAuthorizedGroups(existingCategory.getAuthorizedGroups()); return cat.getId(); } }
/** * <p>toString</p> * * @return a {@link java.lang.String} object. */ @Override public String toString() { return MoreObjects.toStringHelper(this) .add("id", getId()) .add("name", getName()) .add("description", getDescription()) .add("authorizedGroups", getAuthorizedGroups()) .toString(); }
@Transactional private OnmsNode saveOrUpdate(final OnmsNode node) { final Set<OnmsCategory> updatedCategories = new HashSet<>(); 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; }
private OnmsCategory getCategory(String name) { preloadExistingCategories(); OnmsCategory category = getCategories().get(name); if (category == null) { category = m_categoryDao.findByName(name); if (category == null) { category = new OnmsCategory(name); m_categoryDao.save(category); } getCategories().put(category.getName(), category); } return category; }
@Override protected Integer getId(final OnmsCategory cat) { return cat.getId(); }
public OnmsCategory getCategory(final String categoryName) { if (!m_categoryCache.containsKey(categoryName)) { m_categoryCache.put(categoryName, new OnmsCategory(categoryName)); } return m_categoryCache.get(categoryName); } }
private void setAuthorizedCategories(String groupName, List<String> categoryNames) { List<OnmsCategory> categories = m_categoryDao.getCategoriesWithAuthorizedGroup(groupName); for(OnmsCategory category : categories) { category.getAuthorizedGroups().remove(groupName); } for(String categoryName : categoryNames) { OnmsCategory category = m_categoryDao.findByName(categoryName, false); if (category != null) { category.getAuthorizedGroups().add(groupName); } } } }
/** * <p>Constructor for OnmsCategory.</p> * * @param name a {@link java.lang.String} object. */ public OnmsCategory(String name) { this(); setName(name); }
@Transactional private OnmsNode saveOrUpdate(final OnmsNode node) { final Set<OnmsCategory> updatedCategories = new HashSet<>(); 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; }
@Override protected Integer getId(final OnmsCategory cat) { return cat.getId(); }
@Override public OnmsCategory doInsert() { OnmsCategory category = new OnmsCategory(name); m_categoryDao.save(category); m_categoryDao.flush(); return category; } }.execute();
private void setAuthorizedCategories(String groupName, List<String> categoryNames) { List<OnmsCategory> categories = m_categoryDao.getCategoriesWithAuthorizedGroup(groupName); for(OnmsCategory category : categories) { category.getAuthorizedGroups().remove(groupName); } for(String categoryName : categoryNames) { OnmsCategory category = m_categoryDao.findByName(categoryName, false); if (category != null) { category.getAuthorizedGroups().add(groupName); } } } }
@Override public List<SearchResult> query(SearchQuery searchQuery, GraphContainer graphContainer) { Collection<OnmsCategory> categories = categoryProvider.getAllCategories(); List<SearchResult> results = new ArrayList<>(); for (OnmsCategory category : categories) { if (!checkHiddenPrefix(category.getName()) && searchQuery.matches(category.getName())) { SearchResult result = new SearchResult(CategoryHopCriteria.NAMESPACE, category.getId().toString(), category.getName(), searchQuery.getQueryString(), SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED); CollapsibleCriteria criteria = getMatchingCriteria(graphContainer, category.getName()); if (criteria != null) { result.setCollapsed(criteria.isCollapsed()); } results.add(result); } } return results; }
@Override public Integer save(final OnmsCategory cat) { if (cat == null) return null; final String categoryName = cat.getName(); if (categoryName == null) return null; final OnmsCategory existingCategory = findByName(categoryName); if (existingCategory == null) { return super.save(cat); } else { cat.setId(existingCategory.getId()); cat.setDescription(existingCategory.getDescription()); cat.setAuthorizedGroups(existingCategory.getAuthorizedGroups()); return cat.getId(); } }
/** {@inheritDoc} */ @Override public OnmsCategory addNewCategory(final String name) { OnmsCategory category = new OnmsCategory(); category.setName(name); m_categoryDao.save(category); return category; }
throw new IllegalArgumentException("Could not find category for name '" + categoryString + "'"); categoryIds.add(category.getId());
@Override public OnmsCategory doInsert() { OnmsCategory category = new OnmsCategory(name); m_categoryDao.save(category); m_categoryDao.flush(); return category; } }.execute();