Search in sources :

Example 1 with Property

use of com.xpn.xwiki.api.Property in project celements-blog by celements.

the class ArticleEngineHQL method getHQL.

private String getHQL(String blogArticleSpace, String language, List<String> subscribedBlogs, boolean withSubscribable) throws XWikiException {
    String useInt = " ";
    String subscribableHQL = "";
    String subscribedBlogsStr = "";
    LOGGER.debug("if params: (" + subscribedBlogs + "!= null) (" + ((subscribedBlogs != null) ? subscribedBlogs.size() : "null") + " > 0) (withSubscribable = " + withSubscribable + ")");
    if ((subscribedBlogs != null) && (subscribedBlogs.size() > 0) && withSubscribable) {
        // useInt = ", IntegerProperty as int ";
        subscribableHQL = /*
                         * to slow with this query part "and (obj.id = int.id.id " +
                         * "and int.id.name = 'isSubscribable' " + "and int.value='1')
                         */
        ")";
        for (Iterator<String> blogIter = subscribedBlogs.iterator(); blogIter.hasNext(); ) {
            String blogSpace = blogIter.next();
            Document blogDoc = blogService.getBlogPageByBlogSpace(blogSpace).newDocument(getContext());
            com.xpn.xwiki.api.Object obj = blogDoc.getObject("Celements2.BlogConfigClass");
            Property prop = obj.getProperty("is_subscribable");
            LOGGER.debug("blogDoc is '" + blogDoc.getFullName() + "' and obj is '" + obj + "' the is_subscribable property is '" + prop + "'");
            if (prop != null) {
                int isSubscribable = Integer.parseInt(prop.getValue().toString());
                LOGGER.debug("is_subscribable property exists and its value is: '" + isSubscribable + "'");
                if (isSubscribable == 1) {
                    if (subscribedBlogsStr.length() > 0) {
                        subscribedBlogsStr += "or ";
                    } else {
                        subscribedBlogsStr = "or ((";
                    }
                    subscribedBlogsStr += "doc.space='" + blogSpace + "' ";
                }
            }
        }
        if (subscribedBlogsStr.length() > 0) {
            subscribedBlogsStr += ") " + subscribableHQL;
        }
    }
    String hql = "select doc.fullName from XWikiDocument as doc, BaseObject as obj, " + "DateProperty as date, StringProperty as lang" + useInt;
    hql += "where obj.name=doc.fullName ";
    hql += "and obj.className='XWiki.ArticleClass' ";
    hql += "and (doc.space = '" + blogArticleSpace + "' " + subscribedBlogsStr + ") ";
    hql += "and lang.id.id=obj.id ";
    hql += "and lang.id.name='lang' ";
    hql += "and lang.value = '" + language + "' ";
    hql += "and obj.id = date.id.id ";
    hql += "and date.id.name='publishdate' ";
    hql += "order by date.value desc, doc.name asc ";
    LOGGER.debug("hql built: " + hql);
    return hql;
}
Also used : Document(com.xpn.xwiki.api.Document) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Property(com.xpn.xwiki.api.Property)

Example 2 with Property

use of com.xpn.xwiki.api.Property in project celements-blog by celements.

the class Article method init.

public void init(@Nullable com.xpn.xwiki.api.Object obj, @NotNull String space) {
    if (articleObjMap == null) {
        articleObjMap = new HashMap<>();
        defaultLang = context.getWiki().getSpacePreference("default_language", space, "", context);
    }
    LOGGER.debug("Init Article Object");
    if (obj != null) {
        Property prop = obj.getProperty("lang");
        if (prop != null) {
            articleObjMap.put((String) prop.getValue(), obj);
        } else {
            articleObjMap.put("", obj);
        }
    }
}
Also used : Property(com.xpn.xwiki.api.Property)

Aggregations

Property (com.xpn.xwiki.api.Property)2 Document (com.xpn.xwiki.api.Document)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1