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);
}
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);
}
Aggregations