@Override public List<LabsNews> getAllNews() throws ClientException { List<LabsNews> listNews = new ArrayList<LabsNews>(); CoreSession session = getSession(); DocumentModelList listDoc = null; Sorter pageNewsSorter = new PageNewsSorter(); if (session.hasPermission(doc.getRef(), SecurityConstants.WRITE)) { listDoc = session.getChildren( doc.getRef(), LabsSiteConstants.Docs.LABSNEWS.type(), null, null, pageNewsSorter); } else { listDoc = session.getChildren( doc.getRef(), LabsSiteConstants.Docs.LABSNEWS.type(), null, new PageNewsFilter(Calendar.getInstance()), pageNewsSorter); } for (DocumentModel doc : listDoc) { LabsNews news = Tools.getAdapter(LabsNews.class, doc, session); listNews.add(news); } return listNews; }
@Override public LabsNews createNews(String pTitle) throws ClientException { CoreSession session = getSession(); DocumentModel document = session.createDocumentModel( doc.getPathAsString(), LabsSiteUtils.doLabsSlugify(pTitle), LabsSiteConstants.Docs.LABSNEWS.type()); document.setPropertyValue("dc:title", pTitle); return session.createDocument(document).getAdapter(LabsNews.class); }
@Override public List<LabsNews> getTopNews(int pMaxNews) throws ClientException { List<LabsNews> listNews = new ArrayList<LabsNews>(); DocumentModelList listDoc = null; Sorter pageNewsSorter = new PageNewsSorter(); CoreSession session = getSession(); listDoc = session.getChildren( doc.getRef(), LabsSiteConstants.Docs.LABSNEWS.type(), null, new PageNewsFilter(Calendar.getInstance()), pageNewsSorter); int nb = 0; for (DocumentModel doc : listDoc) { if (nb >= pMaxNews) { break; } LabsNews news = Tools.getAdapter(LabsNews.class, doc, session); listNews.add(news); nb++; } return listNews; }