Search in sources :

Example 1 with EmptyArticleException

use of com.celements.blog.plugin.EmptyArticleException in project celements-blog by celements.

the class ArticleEngineHQL method getArticlesFromDocs.

private void getArticlesFromDocs(List<Article> articles, List<Object> articleDocNames, String blogArticleSpace) throws XWikiException {
    LOGGER.debug("Matching articles found: " + articleDocNames.size());
    for (Object articleFullNameObj : articleDocNames) {
        String articleFullName = articleFullNameObj.toString();
        XWikiDocument articleDoc = getContext().getWiki().getDocument(articleFullName, getContext());
        Article article = null;
        try {
            article = new Article(articleDoc.newDocument(getContext()), getContext());
        } catch (EmptyArticleException e) {
            LOGGER.info(e);
        }
        if ((article != null) && (blogArticleSpace.equals(articleDoc.getSpace()) || (article.isSubscribable() == Boolean.TRUE))) {
            articles.add(article);
        }
    }
}
Also used : EmptyArticleException(com.celements.blog.plugin.EmptyArticleException) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument)

Example 2 with EmptyArticleException

use of com.celements.blog.plugin.EmptyArticleException in project celements-blog by celements.

the class ArticleEngineLucene method getArticles.

@Override
public List<Article> getArticles(ArticleLoadParameter param) throws ArticleLoadException {
    try {
        List<Article> articles = new ArrayList<>();
        LuceneQuery query = queryBuilder.build(param);
        if (query != null) {
            LuceneSearchResult result = searchService.searchWithoutChecks(query, param.getSortFields(), Arrays.asList("default", param.getLanguage()));
            result.setOffset(param.getOffset()).setLimit(param.getLimit());
            for (EntityReference ref : result.getResults()) {
                if (ref instanceof DocumentReference) {
                    XWikiDocument doc = getContext().getWiki().getDocument((DocumentReference) ref, getContext());
                    try {
                        articles.add(new Article(doc, getContext()));
                    } catch (EmptyArticleException exc) {
                        LOGGER.warn("getArticles: empty article '{}'", exc, doc);
                    }
                } else {
                    LOGGER.warn("getArticles: not expecting Attachment as search result '{}' " + "for search '{}'", ref, param);
                }
            }
        } else {
            LOGGER.warn("got null from query builder for '" + param + "'");
        }
        return articles;
    } catch (LuceneSearchException lse) {
        throw new ArticleLoadException(lse);
    } catch (XWikiException xwe) {
        throw new ArticleLoadException(xwe);
    }
}
Also used : LuceneQuery(com.celements.search.lucene.query.LuceneQuery) EmptyArticleException(com.celements.blog.plugin.EmptyArticleException) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ArrayList(java.util.ArrayList) EntityReference(org.xwiki.model.reference.EntityReference) LuceneSearchException(com.celements.search.lucene.LuceneSearchException) LuceneSearchResult(com.celements.search.lucene.LuceneSearchResult) DocumentReference(org.xwiki.model.reference.DocumentReference) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

EmptyArticleException (com.celements.blog.plugin.EmptyArticleException)2 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)2 LuceneSearchException (com.celements.search.lucene.LuceneSearchException)1 LuceneSearchResult (com.celements.search.lucene.LuceneSearchResult)1 LuceneQuery (com.celements.search.lucene.query.LuceneQuery)1 XWikiException (com.xpn.xwiki.XWikiException)1 ArrayList (java.util.ArrayList)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 EntityReference (org.xwiki.model.reference.EntityReference)1