Search in sources :

Example 1 with Disjunction

use of com.liferay.portal.kernel.dao.orm.Disjunction in project liferay-ide by liferay.

the class KBArticleLocalServiceImpl method buildDynamicQuery.

protected DynamicQuery buildDynamicQuery(long groupId, String title, String content, int status, Date startDate, Date endDate, boolean andOperator) {
    Junction junction = null;
    if (andOperator) {
        junction = RestrictionsFactoryUtil.conjunction();
    } else {
        junction = RestrictionsFactoryUtil.disjunction();
    }
    Map<String, String> terms = new HashMap<String, String>();
    if (Validator.isNotNull(title)) {
        terms.put("title", title);
    }
    if (Validator.isNotNull(content)) {
        terms.put("content", content);
    }
    for (Map.Entry<String, String> entry : terms.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        Disjunction disjunction = RestrictionsFactoryUtil.disjunction();
        for (String keyword : KnowledgeBaseUtil.splitKeywords(value)) {
            Criterion criterion = RestrictionsFactoryUtil.ilike(key, StringUtil.quote(keyword, StringPool.PERCENT));
            disjunction.add(criterion);
        }
        junction.add(disjunction);
    }
    if (status != WorkflowConstants.STATUS_ANY) {
        Property property = PropertyFactoryUtil.forName("status");
        junction.add(property.eq(status));
    }
    if ((endDate != null) && (startDate != null)) {
        Disjunction disjunction = RestrictionsFactoryUtil.disjunction();
        String[] propertyNames = { "createDate", "modifiedDate" };
        for (String propertyName : propertyNames) {
            Property property = PropertyFactoryUtil.forName(propertyName);
            Conjunction conjunction = RestrictionsFactoryUtil.conjunction();
            conjunction.add(property.gt(startDate));
            conjunction.add(property.lt(endDate));
            disjunction.add(conjunction);
        }
        junction.add(disjunction);
    }
    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(KBArticle.class, getClassLoader());
    if (status == WorkflowConstants.STATUS_ANY) {
        Property property = PropertyFactoryUtil.forName("latest");
        dynamicQuery.add(property.eq(Boolean.TRUE));
    } else if (status == WorkflowConstants.STATUS_APPROVED) {
        Property property = PropertyFactoryUtil.forName("main");
        dynamicQuery.add(property.eq(Boolean.TRUE));
    }
    if (groupId > 0) {
        Property property = PropertyFactoryUtil.forName("groupId");
        dynamicQuery.add(property.eq(groupId));
    }
    return dynamicQuery.add(junction);
}
Also used : Disjunction(com.liferay.portal.kernel.dao.orm.Disjunction) HashMap(java.util.HashMap) Criterion(com.liferay.portal.kernel.dao.orm.Criterion) DynamicQuery(com.liferay.portal.kernel.dao.orm.DynamicQuery) Conjunction(com.liferay.portal.kernel.dao.orm.Conjunction) Junction(com.liferay.portal.kernel.dao.orm.Junction) Map(java.util.Map) HashMap(java.util.HashMap) Property(com.liferay.portal.kernel.dao.orm.Property)

Example 2 with Disjunction

use of com.liferay.portal.kernel.dao.orm.Disjunction in project liferay-ide by liferay.

the class KBTemplateLocalServiceImpl method buildDynamicQuery.

protected DynamicQuery buildDynamicQuery(long groupId, String title, String content, Date startDate, Date endDate, boolean andOperator) {
    Junction junction = null;
    if (andOperator) {
        junction = RestrictionsFactoryUtil.conjunction();
    } else {
        junction = RestrictionsFactoryUtil.disjunction();
    }
    Map<String, String> terms = new HashMap<String, String>();
    if (Validator.isNotNull(title)) {
        terms.put("title", title);
    }
    if (Validator.isNotNull(content)) {
        terms.put("content", content);
    }
    for (Map.Entry<String, String> entry : terms.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        Disjunction disjunction = RestrictionsFactoryUtil.disjunction();
        for (String keyword : KnowledgeBaseUtil.splitKeywords(value)) {
            Criterion criterion = RestrictionsFactoryUtil.ilike(key, StringUtil.quote(keyword, StringPool.PERCENT));
            disjunction.add(criterion);
        }
        junction.add(disjunction);
    }
    if ((endDate != null) && (startDate != null)) {
        Disjunction disjunction = RestrictionsFactoryUtil.disjunction();
        String[] propertyNames = { "createDate", "modifiedDate" };
        for (String propertyName : propertyNames) {
            Property property = PropertyFactoryUtil.forName(propertyName);
            Conjunction conjunction = RestrictionsFactoryUtil.conjunction();
            conjunction.add(property.gt(startDate));
            conjunction.add(property.lt(endDate));
            disjunction.add(conjunction);
        }
        junction.add(disjunction);
    }
    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(KBTemplate.class, getClassLoader());
    if (groupId > 0) {
        Property property = PropertyFactoryUtil.forName("groupId");
        dynamicQuery.add(property.eq(groupId));
    }
    return dynamicQuery.add(junction);
}
Also used : Disjunction(com.liferay.portal.kernel.dao.orm.Disjunction) HashMap(java.util.HashMap) Criterion(com.liferay.portal.kernel.dao.orm.Criterion) DynamicQuery(com.liferay.portal.kernel.dao.orm.DynamicQuery) Conjunction(com.liferay.portal.kernel.dao.orm.Conjunction) Junction(com.liferay.portal.kernel.dao.orm.Junction) HashMap(java.util.HashMap) Map(java.util.Map) Property(com.liferay.portal.kernel.dao.orm.Property)

Aggregations

Conjunction (com.liferay.portal.kernel.dao.orm.Conjunction)2 Criterion (com.liferay.portal.kernel.dao.orm.Criterion)2 Disjunction (com.liferay.portal.kernel.dao.orm.Disjunction)2 DynamicQuery (com.liferay.portal.kernel.dao.orm.DynamicQuery)2 Junction (com.liferay.portal.kernel.dao.orm.Junction)2 Property (com.liferay.portal.kernel.dao.orm.Property)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2