public List<ContentMap> getLatest( String path, String maxResultSize, String nodeType, int pageNumber, String nodeTypeName) throws RepositoryException { int resultSize = DEFAULT_LATEST_COUNT; if (StringUtils.isNumeric(maxResultSize)) { resultSize = Integer.parseInt(maxResultSize); } final String sqlBlogItems = buildQuery(path, nodeType); return templatingFunctions.asContentMapList( getWrappedNodesFromQuery(sqlBlogItems, resultSize, pageNumber, nodeTypeName)); }
/** * Get all available nodes of type mgnl:news. * * @param path Start node path in hierarchy * @param maxResultSize Number of items to return. When empty <code>Integer.MAX_VALUE</code> will * be used. * @return List of news nodes sorted by date created in descending order * @throws RepositoryException */ public List<ContentMap> getNews(String path, String maxResultSize) throws RepositoryException { int resultSize = Integer.MAX_VALUE; if (StringUtils.isNumeric(maxResultSize)) { resultSize = Integer.parseInt(maxResultSize); } String customFilters = getTagPredicate(filter) + getCategoryPredicate(filter); final String sqlNewsItems = buildQuery(path, true, customFilters, NEWS_NODE_TYPE); return templatingFunctions.asContentMapList( getWrappedNodesFromQuery( sqlNewsItems, resultSize, getPageNumber(), NewsNodeTypes.News.NAME)); }
public List<ContentMap> getItems(Node item, String nodeType, String workspace) { final List<ContentMap> items = new ArrayList<ContentMap>(0); try { final Value[] values = item.getProperty(nodeType).getValues(); if (values != null) { for (Value value : values) { items.add(templatingFunctions.contentById(value.getString(), workspace)); } } } catch (RepositoryException e) { log.error("Exception while getting items", e.getMessage()); } return items; }
protected String getTagPredicate(Map<String, String> filter) { if (filter.containsKey(PARAM_TAG)) { final ContentMap contentMap = templatingFunctions.contentByPath(filter.get(PARAM_TAG), NewsWorkspaceUtil.COLLABORATION); if (contentMap != null) { final String tagId = (String) contentMap.get("@id"); if (StringUtils.isNotEmpty(tagId)) { return "AND p.tags like '%" + tagId + "%' "; } } else { log.debug("Tag [{}] not found", filter.get(PARAM_TAG)); } } return StringUtils.EMPTY; }
protected String getCategoryPredicate(Map<String, String> filter) { if (filter.containsKey(PARAM_CATEGORY)) { final ContentMap contentMap = templatingFunctions.contentByPath( filter.get(PARAM_CATEGORY), NewsWorkspaceUtil.CATEGORIES); if (contentMap != null) { final String categoryId = (String) contentMap.get("@id"); if (StringUtils.isNotEmpty(categoryId)) { return "AND p.categories like '%" + categoryId + "%' "; } } else { log.debug("Category [{}] not found", filter.get(PARAM_CATEGORY)); } } return StringUtils.EMPTY; }