コード例 #1
0
  protected DynamicQuery buildDynamicQuery(
      String kaleoDefinitionName,
      int kaleoDefinitionVersion,
      boolean completed,
      ServiceContext serviceContext) {

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(KaleoInstance.class, getClassLoader());

    Property companyIdProperty = PropertyFactoryUtil.forName("companyId");

    dynamicQuery.add(companyIdProperty.eq(serviceContext.getCompanyId()));

    Property kaleoDefinitionNameProperty = PropertyFactoryUtil.forName("kaleoDefinitionName");

    dynamicQuery.add(kaleoDefinitionNameProperty.eq(kaleoDefinitionName));

    Property kaleoDefinitionVersionProperty = PropertyFactoryUtil.forName("kaleoDefinitionVersion");

    dynamicQuery.add(kaleoDefinitionVersionProperty.eq(kaleoDefinitionVersion));

    if (completed) {
      Property completionDateProperty = PropertyFactoryUtil.forName("completionDate");

      dynamicQuery.add(completionDateProperty.isNotNull());
    } else {
      Property completionDateProperty = PropertyFactoryUtil.forName("completionDate");

      dynamicQuery.add(completionDateProperty.isNull());
    }

    return dynamicQuery;
  }
  protected DynamicQuery getAssetLinkDynamicQuery(
      long companyId, long groupId, String assetEntry1Uuid, String assetEntry2Uuid) {

    // Asset entry 1 dynamic query

    Projection entryIdProjection = ProjectionFactoryUtil.property("entryId");

    DynamicQuery assetEntry1DynamicQuery = _assetEntryLocalService.dynamicQuery();

    assetEntry1DynamicQuery.setProjection(entryIdProjection);

    Property classUuidProperty = PropertyFactoryUtil.forName("classUuid");

    assetEntry1DynamicQuery.add(classUuidProperty.eq(assetEntry1Uuid));

    // Asset entry 2 dynamic query

    DynamicQuery assetEntry2DynamicQuery = _assetEntryLocalService.dynamicQuery();

    assetEntry2DynamicQuery.setProjection(entryIdProjection);

    assetEntry2DynamicQuery.add(classUuidProperty.eq(assetEntry2Uuid));

    // Asset link dynamic query

    DynamicQuery dynamicQuery = _assetLinkLocalService.dynamicQuery();

    Property entryId1IdProperty = PropertyFactoryUtil.forName("entryId1");

    dynamicQuery.add(entryId1IdProperty.eq(assetEntry1DynamicQuery));

    Property entryId2IdProperty = PropertyFactoryUtil.forName("entryId2");

    dynamicQuery.add(entryId2IdProperty.eq(assetEntry2DynamicQuery));

    // Company ID

    if (companyId > 0) {
      Property companyIdProperty = PropertyFactoryUtil.forName("companyId");

      Criterion companyIdCriterion = companyIdProperty.eq(companyId);

      assetEntry1DynamicQuery.add(companyIdCriterion);
      assetEntry2DynamicQuery.add(companyIdCriterion);
      dynamicQuery.add(companyIdCriterion);
    }

    // Group ID

    if (groupId > 0) {
      Property groupIdProperty = PropertyFactoryUtil.forName("groupId");

      Criterion groupIdCriterion = groupIdProperty.eq(groupId);

      assetEntry1DynamicQuery.add(groupIdCriterion);
      assetEntry2DynamicQuery.add(groupIdCriterion);
    }

    return dynamicQuery;
  }
コード例 #3
0
  @SuppressWarnings("unchecked")
  public List<AuditEntry> findByclassName_classPK_filterByActions(
      String className, long classPK, List<String> actions) throws SystemException {
    DynamicQuery dq = auditEntryLocalService.dynamicQuery();
    Criterion criterion = PropertyFactoryUtil.forName("classname").eq(className);
    if (classPK > 0) {
      criterion =
          RestrictionsFactoryUtil.and(
              criterion, PropertyFactoryUtil.forName("classPK").eq(classPK));
    }
    Criterion criterionAux = criterion;
    for (int i = 0; i < actions.size(); i++) {
      if (i == 0) {
        criterion =
            RestrictionsFactoryUtil.and(
                criterion, PropertyFactoryUtil.forName("action").eq(actions.get(i)));
      } else {
        Criterion criterionAnd =
            RestrictionsFactoryUtil.and(
                criterionAux, PropertyFactoryUtil.forName("action").eq(actions.get(i)));
        criterion = RestrictionsFactoryUtil.or(criterion, criterionAnd);
      }
    }
    dq.add(criterion);

    return auditEntryLocalService.dynamicQuery(dq);
  }
コード例 #4
0
  protected List<Layout> getPrototypeLinkedLayouts(long groupId, boolean privateLayout)
      throws SystemException {

    Class<?> clazz = getClass();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(Layout.class, clazz.getClassLoader());

    Property groupIdProperty = PropertyFactoryUtil.forName("groupId");

    dynamicQuery.add(groupIdProperty.eq(groupId));

    Property layoutPrototypeUuidProperty = PropertyFactoryUtil.forName("layoutPrototypeUuid");

    dynamicQuery.add(layoutPrototypeUuidProperty.isNotNull());

    Property privateLayoutProperty = PropertyFactoryUtil.forName("privateLayout");

    dynamicQuery.add(privateLayoutProperty.eq(privateLayout));

    Property sourcePrototypeLayoutUuidProperty =
        PropertyFactoryUtil.forName("sourcePrototypeLayoutUuid");

    dynamicQuery.add(sourcePrototypeLayoutUuidProperty.isNotNull());

    return LayoutLocalServiceUtil.dynamicQuery(dynamicQuery);
  }
コード例 #5
0
  protected List<ResourceTypePermission> getResourceTypePermissions(
      PortletDataContext portletDataContext, Role importedRole) throws SystemException {

    DynamicQuery dynamicQuery = ResourceTypePermissionLocalServiceUtil.dynamicQuery();

    Property companyIdProperty = PropertyFactoryUtil.forName("companyId");

    dynamicQuery.add(companyIdProperty.eq(portletDataContext.getCompanyId()));

    Junction junction = RestrictionsFactoryUtil.disjunction();

    long[] permissibleGroupIds = {
      GroupConstants.DEFAULT_PARENT_GROUP_ID,
      portletDataContext.getCompanyId(),
      portletDataContext.getCompanyGroupId(),
      portletDataContext.getUserPersonalSiteGroupId()
    };

    for (long permissibleGroupId : permissibleGroupIds) {
      Property property = PropertyFactoryUtil.forName("groupId");

      junction.add(property.eq(permissibleGroupId));
    }

    dynamicQuery.add(junction);

    Property roleIdProperty = PropertyFactoryUtil.forName("roleId");

    dynamicQuery.add(roleIdProperty.eq(importedRole.getRoleId()));

    return ResourceTypePermissionLocalServiceUtil.dynamicQuery(dynamicQuery);
  }
コード例 #6
0
  protected void addReindexCriteria(DynamicQuery dynamicQuery, long groupId, long folderId) {

    Property groupIdProperty = PropertyFactoryUtil.forName("groupId");

    dynamicQuery.add(groupIdProperty.eq(groupId));

    Property folderIdProperty = PropertyFactoryUtil.forName("folderId");

    dynamicQuery.add(folderIdProperty.eq(folderId));
  }
コード例 #7
0
  protected void addReindexCriteria(DynamicQuery dynamicQuery, long companyId, int status) {

    Property companyIdProperty = PropertyFactoryUtil.forName("companyId");

    dynamicQuery.add(companyIdProperty.eq(companyId));

    Property statusProperty = PropertyFactoryUtil.forName("status");

    dynamicQuery.add(statusProperty.eq(status));
  }
コード例 #8
0
 @Override
 @SuppressWarnings("unchecked")
 public void onCloseCourse(Course course) throws SystemException {
   for (CourseResult courseResult :
       (List<CourseResult>)
           CourseResultLocalServiceUtil.dynamicQuery(
               CourseResultLocalServiceUtil.dynamicQuery()
                   .add(PropertyFactoryUtil.forName("courseId").eq(course.getCourseId()))
                   .add(PropertyFactoryUtil.forName("passedDate").isNull()))) {
     courseResult.setPassedDate(course.getModifiedDate());
     CourseResultLocalServiceUtil.update(courseResult);
   }
 }
  protected DynamicQuery buildDynamicQuery(
      long kaleoInstanceId, Boolean completed, ServiceContext serviceContext) {

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(KaleoTaskInstanceToken.class, getClassLoader());

    dynamicQuery.add(PropertyFactoryUtil.forName("companyId").eq(serviceContext.getCompanyId()));
    dynamicQuery.add(PropertyFactoryUtil.forName("kaleoInstanceId").eq(kaleoInstanceId));

    addCompletedCriterion(dynamicQuery, completed);

    return dynamicQuery;
  }
  public int getSubmittingUserKaleoTaskInstanceTokensCount(
      long userId, Boolean completed, ServiceContext serviceContext) throws SystemException {

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(KaleoTaskInstanceToken.class, getClassLoader());

    dynamicQuery.add(PropertyFactoryUtil.forName("companyId").eq(serviceContext.getCompanyId()));
    dynamicQuery.add(PropertyFactoryUtil.forName("workflowContext").like("\"userId\":" + userId));

    addCompletedCriterion(dynamicQuery, completed);

    return (int) dynamicQueryCount(dynamicQuery);
  }
コード例 #11
0
  @Override
  public Date getLastPostDateByUserId(long groupId, long userId) {
    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            MBThread.class, MBStatsUserImpl.TABLE_NAME, ClassLoaderUtil.getPortalClassLoader());

    Projection projection = ProjectionFactoryUtil.max("lastPostDate");

    dynamicQuery.setProjection(projection);

    Property property = PropertyFactoryUtil.forName("threadId");

    Disjunction disjunction = RestrictionsFactoryUtil.disjunction();

    QueryDefinition queryDefinition = new QueryDefinition(WorkflowConstants.STATUS_IN_TRASH);

    List<MBThread> threads = mbThreadLocalService.getGroupThreads(groupId, queryDefinition);

    for (MBThread thread : threads) {
      disjunction.add(property.ne(thread.getThreadId()));
    }

    dynamicQuery.add(disjunction);

    List<Date> results = mbStatsUserLocalService.dynamicQuery(dynamicQuery);

    return results.get(0);
  }
コード例 #12
0
  protected void reindexEntries(
      long companyId, long groupId, long folderId, long startEntryId, long endEntryId)
      throws Exception {

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            BookmarksEntry.class, PortalClassLoaderUtil.getClassLoader());

    Property property = PropertyFactoryUtil.forName("entryId");

    dynamicQuery.add(property.ge(startEntryId));
    dynamicQuery.add(property.lt(endEntryId));

    addReindexCriteria(dynamicQuery, groupId, folderId);

    List<BookmarksEntry> entries = BookmarksEntryLocalServiceUtil.dynamicQuery(dynamicQuery);

    if (entries.isEmpty()) {
      return;
    }

    Collection<Document> documents = new ArrayList<Document>();

    for (BookmarksEntry entry : entries) {
      Document document = getDocument(entry);

      documents.add(document);
    }

    SearchEngineUtil.updateDocuments(getSearchEngineId(), companyId, documents);
  }
  protected void addCompletedCriterion(DynamicQuery dynamicQuery, Boolean completed) {

    if (completed == null) {
      return;
    }

    dynamicQuery.add(PropertyFactoryUtil.forName("completed").eq(completed));
  }
  protected void exportLayoutPrototypes(
      PortletDataContext portletDataContext,
      LayoutSetPrototype layoutSetPrototype,
      Element layoutSetPrototypeElement)
      throws Exception {

    DynamicQuery dynamicQuery = _layoutLocalService.dynamicQuery();

    Property groupIdProperty = PropertyFactoryUtil.forName("groupId");

    dynamicQuery.add(groupIdProperty.eq(layoutSetPrototype.getGroupId()));

    Conjunction conjunction = RestrictionsFactoryUtil.conjunction();

    Property layoutPrototypeUuidProperty = PropertyFactoryUtil.forName("layoutPrototypeUuid");

    conjunction.add(layoutPrototypeUuidProperty.isNotNull());
    conjunction.add(layoutPrototypeUuidProperty.ne(StringPool.BLANK));

    dynamicQuery.add(conjunction);

    List<Layout> layouts = _layoutLocalService.dynamicQuery(dynamicQuery);

    boolean exportLayoutPrototypes =
        portletDataContext.getBooleanParameter("layout_set_prototypes", "page-templates");

    for (Layout layout : layouts) {
      String layoutPrototypeUuid = layout.getLayoutPrototypeUuid();

      LayoutPrototype layoutPrototype =
          _layoutPrototypeLocalService.getLayoutPrototypeByUuidAndCompanyId(
              layoutPrototypeUuid, portletDataContext.getCompanyId());

      portletDataContext.addReferenceElement(
          layout,
          layoutSetPrototypeElement,
          layoutPrototype,
          PortletDataContext.REFERENCE_TYPE_DEPENDENCY,
          !exportLayoutPrototypes);

      if (exportLayoutPrototypes) {
        StagedModelDataHandlerUtil.exportStagedModel(portletDataContext, layoutPrototype);
      }
    }
  }
コード例 #15
0
  protected void addReindexCriteria(
      DynamicQuery dynamicQuery, long companyId, double version, int status) {

    addReindexCriteria(dynamicQuery, companyId, status);

    Property property = PropertyFactoryUtil.forName("version");

    dynamicQuery.add(property.eq(version));
  }
  public List<KaleoTaskInstanceToken> getSubmittingUserKaleoTaskInstanceTokens(
      long userId,
      Boolean completed,
      int start,
      int end,
      OrderByComparator orderByComparator,
      ServiceContext serviceContext)
      throws SystemException {

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(KaleoTaskInstanceToken.class, getClassLoader());

    dynamicQuery.add(PropertyFactoryUtil.forName("companyId").eq(serviceContext.getCompanyId()));
    dynamicQuery.add(PropertyFactoryUtil.forName("workflowContext").like("\"userId\":" + userId));

    addCompletedCriterion(dynamicQuery, completed);

    return dynamicQuery(dynamicQuery, start, end, orderByComparator);
  }
  @Override
  protected void addCriteria(DynamicQuery dynamicQuery) {
    _portletDataContext.addDateRangeCriteria(dynamicQuery, "modifiedDate");

    if (getStagedModelType().getReferrerClassNameId() >= 0) {
      Property classNameIdProperty = PropertyFactoryUtil.forName("classNameId");

      dynamicQuery.add(classNameIdProperty.eq(getStagedModelType().getReferrerClassNameId()));
    }
  }
コード例 #18
0
  protected DynamicQuery buildDynamicQuery(
      Long userId,
      String[] assetClassNames,
      Long[] assetClassPKs,
      Boolean completed,
      ServiceContext serviceContext) {

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(KaleoInstance.class, getClassLoader());

    Property companyIdProperty = PropertyFactoryUtil.forName("companyId");

    dynamicQuery.add(companyIdProperty.eq(serviceContext.getCompanyId()));

    if (userId != null) {
      Property userIdProperty = PropertyFactoryUtil.forName("userId");

      dynamicQuery.add(userIdProperty.eq(userId));
    }

    if (ArrayUtil.isNotEmpty(assetClassNames)) {
      dynamicQuery.add(getAssetClassNames(assetClassNames));
    }

    if (ArrayUtil.isNotEmpty(assetClassPKs)) {
      dynamicQuery.add(getAssetClassPKs(assetClassPKs));
    }

    if (completed != null) {
      if (completed) {
        Property completionDateProperty = PropertyFactoryUtil.forName("completionDate");

        dynamicQuery.add(completionDateProperty.isNotNull());
      } else {
        Property completionDateProperty = PropertyFactoryUtil.forName("completionDate");

        dynamicQuery.add(completionDateProperty.isNull());
      }
    }

    return dynamicQuery;
  }
コード例 #19
0
  protected Criterion getAssetClassPKs(Long[] assetClassPKs) {
    Disjunction disjunction = RestrictionsFactoryUtil.disjunction();

    for (Long assetClassPK : assetClassPKs) {
      Property classPKProperty = PropertyFactoryUtil.forName("classPK");

      disjunction.add(classPKProperty.eq(assetClassPK));
    }

    return disjunction;
  }
コード例 #20
0
  protected Criterion getAssetClassNames(String[] assetClassNames) {
    Disjunction disjunction = RestrictionsFactoryUtil.disjunction();

    for (String assetClassName : assetClassNames) {
      Property classNameProperty = PropertyFactoryUtil.forName("className");

      disjunction.add(classNameProperty.like(assetClassName));
    }

    return disjunction;
  }
コード例 #21
0
  @Override
  protected void addCriteria(DynamicQuery dynamicQuery) {
    _portletDataContext.addDateRangeCriteria(dynamicQuery, "modifiedDate");

    StagedModelDataHandler<?> stagedModelDataHandler =
        StagedModelDataHandlerRegistryUtil.getStagedModelDataHandler(Album.class.getName());

    Property workflowStatusProperty = PropertyFactoryUtil.forName("status");

    dynamicQuery.add(workflowStatusProperty.in(stagedModelDataHandler.getExportableStatuses()));
  }
コード例 #22
0
  @Test
  public void testCriterion() {
    DynamicQuery dynamicQuery = ClassNameLocalServiceUtil.dynamicQuery();

    Property classNameIdProperty = PropertyFactoryUtil.forName("classNameId");

    ClassName className = _allClassNames.get(10);

    dynamicQuery.add(classNameIdProperty.eq(className.getClassNameId()));

    List<ClassName> classNames = ClassNameLocalServiceUtil.dynamicQuery(dynamicQuery);

    Assert.assertEquals(1, classNames.size());
    Assert.assertEquals(className, classNames.get(0));
  }
コード例 #23
0
  protected List<JournalArticle> getReindexApprovedArticles(
      long companyId, long startId, long endId) throws Exception {

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            JournalArticle.class, PACLClassLoaderUtil.getPortalClassLoader());

    Property property = PropertyFactoryUtil.forName("id");

    dynamicQuery.add(property.ge(startId));
    dynamicQuery.add(property.lt(endId));

    addReindexCriteria(dynamicQuery, companyId, WorkflowConstants.STATUS_APPROVED);

    return JournalArticleLocalServiceUtil.dynamicQuery(dynamicQuery);
  }
コード例 #24
0
  @Test
  public void testOrderBy() {
    DynamicQuery dynamicQuery = ClassNameLocalServiceUtil.dynamicQuery();

    Property classNameIdProperty = PropertyFactoryUtil.forName("classNameId");

    ClassName lastClassName = _allClassNames.get(_allClassNames.size() - 1);

    dynamicQuery.add(classNameIdProperty.le(lastClassName.getClassNameId()));

    dynamicQuery.addOrder(OrderFactoryUtil.desc("classNameId"));

    _allClassNames = new ArrayList<>(_allClassNames);

    Collections.reverse(_allClassNames);

    Assert.assertEquals(
        _allClassNames, ClassNameLocalServiceUtil.<ClassName>dynamicQuery(dynamicQuery));
  }
コード例 #25
0
  protected void reindexRoot(long companyId, long startGroupId, long endGroupId) throws Exception {

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(Group.class, PortalClassLoaderUtil.getClassLoader());

    Property property = PropertyFactoryUtil.forName("groupId");

    dynamicQuery.add(property.ge(startGroupId));
    dynamicQuery.add(property.lt(endGroupId));

    addReindexCriteria(dynamicQuery, companyId);

    List<Group> groups = GroupLocalServiceUtil.dynamicQuery(dynamicQuery);

    for (Group group : groups) {
      long groupId = group.getGroupId();
      long folderId = BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID;

      reindexEntries(companyId, groupId, folderId);
    }
  }
コード例 #26
0
ファイル: CalendarHelper.java プロジェクト: arejae/liferay
  public static List<CalEvent> getEventFromDateRange(
      ThemeDisplay themeDisplay, Date startDate, Date endDate) {
    List<CalEvent> lstEvents = null;
    DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(CalEvent.class);
    dynamicQuery.add(PropertyFactoryUtil.forName("groupId").eq(themeDisplay.getScopeGroupId()));

    Criterion criterion = null;

    criterion = RestrictionsFactoryUtil.between("startDate", startDate, endDate);
    Order defaultOrder = OrderFactoryUtil.asc("startDate");

    dynamicQuery.add(criterion);
    dynamicQuery.addOrder(defaultOrder);
    try {
      lstEvents = CalEventLocalServiceUtil.dynamicQuery(dynamicQuery);
    } catch (SystemException e) {

      _log.error(e);
    }

    return lstEvents;
  }
コード例 #27
0
  @Override
  public long getMessageCountByUserId(long userId) {
    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            MBStatsUser.class, MBStatsUserImpl.TABLE_NAME, ClassLoaderUtil.getPortalClassLoader());

    Projection projection = ProjectionFactoryUtil.sum("messageCount");

    dynamicQuery.setProjection(projection);

    Property property = PropertyFactoryUtil.forName("userId");

    dynamicQuery.add(property.eq(userId));

    List<Long> results = mbStatsUserLocalService.dynamicQuery(dynamicQuery);

    if (results.get(0) == null) {
      return 0;
    }

    return results.get(0);
  }
コード例 #28
0
 public List<AuditEntry> search(
     long companyId,
     long groupId,
     String className,
     long classPK,
     long userId,
     Date startDate,
     Date endDate,
     int start,
     int end)
     throws SystemException {
   DynamicQuery dq = auditEntryLocalService.dynamicQuery();
   Criterion criterion = PropertyFactoryUtil.forName("companyId").eq(companyId);
   dq.add(criterion);
   if (groupId > 0) {
     criterion = PropertyFactoryUtil.forName("groupId").eq(groupId);
     dq.add(criterion);
   }
   if (userId > 0) {
     criterion = PropertyFactoryUtil.forName("userId").eq(userId);
     dq.add(criterion);
   }
   if (startDate != null) {
     criterion = PropertyFactoryUtil.forName("auditDate").ge(startDate);
     dq.add(criterion);
   }
   if (endDate != null) {
     criterion = PropertyFactoryUtil.forName("auditDate").le(endDate);
     dq.add(criterion);
   }
   if (className != null) {
     criterion = PropertyFactoryUtil.forName("classname").eq(className);
     dq.add(criterion);
     if (classPK > 0) {
       criterion = PropertyFactoryUtil.forName("classPK").eq(classPK);
       dq.add(criterion);
     }
   }
   dq.addOrder(OrderFactoryUtil.desc("auditDate"));
   return ((List<AuditEntry>) auditEntryLocalService.dynamicQuery(dq, start, end));
 }
コード例 #29
0
  protected void reindexFolders(long companyId, long startFolderId, long endFolderId)
      throws Exception {

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            BookmarksFolder.class, PortalClassLoaderUtil.getClassLoader());

    Property property = PropertyFactoryUtil.forName("folderId");

    dynamicQuery.add(property.ge(startFolderId));
    dynamicQuery.add(property.lt(endFolderId));

    addReindexCriteria(dynamicQuery, companyId);

    List<BookmarksFolder> folders = BookmarksFolderLocalServiceUtil.dynamicQuery(dynamicQuery);

    for (BookmarksFolder folder : folders) {
      long groupId = folder.getGroupId();
      long folderId = folder.getFolderId();

      reindexEntries(companyId, groupId, folderId);
    }
  }
コード例 #30
0
  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.parseKeywords(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, getClass().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);
  }