public Hits search(
      long companyId,
      String contactBookCode,
      String contactBookName,
      String contactDescription,
      String sortField,
      int sortType,
      boolean reverse,
      int start,
      int end)
      throws SystemException {
    try {
      BooleanQuery contextQuery = BooleanQueryFactoryUtil.create();
      contextQuery.addRequiredTerm(Field.PORTLET_ID, ContactBookIndexer.PORTLET_ID);

      BooleanQuery contactBookCodeQuery = BooleanQueryFactoryUtil.create();
      BooleanQuery contactBookNameQuery = BooleanQueryFactoryUtil.create();
      BooleanQuery contactDescriptionQuery = BooleanQueryFactoryUtil.create();

      List<BooleanQuery> booleanQueries = new ArrayList<BooleanQuery>();

      if (Validator.isNotNull(contactBookCode)) {
        contactBookCodeQuery.addTerm(ContactBookDisplayTerms.CODE, contactBookCode);
        booleanQueries.add(contactBookCodeQuery);
      }

      if (Validator.isNotNull(contactBookName)) {
        contactBookNameQuery.addTerm(ContactBookDisplayTerms.NAME, contactBookName);
        booleanQueries.add(contactBookNameQuery);
      }

      if (Validator.isNotNull(contactDescription)) {
        contactDescriptionQuery.addTerm(ContactBookDisplayTerms.DESCRIPTION, contactDescription);
        booleanQueries.add(contactDescriptionQuery);
      }

      BooleanQuery fullQuery = BooleanQueryFactoryUtil.create();
      fullQuery.add(contextQuery, BooleanClauseOccur.MUST);

      for (int i = 0; i < booleanQueries.size(); i++) {
        fullQuery.add(booleanQueries.get(i), BooleanClauseOccur.MUST);
      }

      Sort sort;
      sort = new Sort(sortField, sortType, reverse);
      Hits hits = SearchEngineUtil.search(companyId, fullQuery, sort, start, end);
      return hits;
    } catch (Exception e) {
      throw new SystemException(e);
    }
  }
  @Override
  protected Map<String, Query> addSearchLocalizedTerm(
      BooleanQuery searchQuery, SearchContext searchContext, String field, boolean like)
      throws Exception {

    if (Validator.isNull(field)) {
      return Collections.emptyMap();
    }

    String value = String.valueOf(searchContext.getAttribute(field));

    if (Validator.isNull(value)) {
      value = searchContext.getKeywords();
    }

    if (Validator.isNull(value)) {
      return Collections.emptyMap();
    }

    String localizedField = DocumentImpl.getLocalizedName(searchContext.getLocale(), field);

    Map<String, Query> queries = new HashMap<>();

    if (Validator.isNull(searchContext.getKeywords())) {
      BooleanQuery localizedQuery = new BooleanQueryImpl();

      Query query = localizedQuery.addTerm(field, value, like);

      queries.put(field, query);

      Query localizedFieldQuery = localizedQuery.addTerm(localizedField, value, like);

      queries.put(field, localizedFieldQuery);

      BooleanClauseOccur booleanClauseOccur = BooleanClauseOccur.SHOULD;

      if (searchContext.isAndSearch()) {
        booleanClauseOccur = BooleanClauseOccur.MUST;
      }

      searchQuery.add(localizedQuery, booleanClauseOccur);
    } else {
      Query query = searchQuery.addTerm(localizedField, value, like);

      queries.put(field, query);
    }

    return queries;
  }
  protected void addContext(BooleanQuery contextQuery, SearchContext searchContext)
      throws Exception {

    long[] folderIds = searchContext.getFolderIds();

    if (ArrayUtil.isEmpty(folderIds)) {
      return;
    }

    if (folderIds[0] == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
      return;
    }

    BooleanQuery folderIdsQuery = new BooleanQueryImpl();

    for (long folderId : folderIds) {
      try {
        _dlAppService.getFolder(folderId);
      } catch (Exception e) {
        continue;
      }

      folderIdsQuery.addTerm(Field.FOLDER_ID, folderId);
    }

    contextQuery.add(folderIdsQuery, BooleanClauseOccur.MUST);
  }
예제 #4
0
  protected void addSearchNotAllTags(BooleanQuery contextQuery, SearchContext searchContext)
      throws Exception {

    long[][] notAllTagIdsArray = _assetEntryQuery.getNotAllTagIdsArray();

    if (notAllTagIdsArray.length == 0) {
      return;
    }

    BooleanQuery tagIdsArrayQuery = BooleanQueryFactoryUtil.create(searchContext);

    for (long[] notAllTagIds : notAllTagIdsArray) {
      if (notAllTagIds.length == 0) {
        continue;
      }

      BooleanQuery tagIdsQuery = BooleanQueryFactoryUtil.create(searchContext);

      for (long tagId : notAllTagIds) {
        tagIdsQuery.addTerm(Field.ASSET_TAG_IDS, tagId);
      }

      tagIdsArrayQuery.add(tagIdsQuery, BooleanClauseOccur.MUST);
    }

    contextQuery.add(tagIdsArrayQuery, BooleanClauseOccur.MUST_NOT);
  }
  @Override
  public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext)
      throws Exception {

    long[] folderIds = searchContext.getFolderIds();

    if ((folderIds != null) && (folderIds.length > 0)) {
      if (folderIds[0] == BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

        return;
      }

      BooleanQuery folderIdsQuery = BooleanQueryFactoryUtil.create(searchContext);

      for (long folderId : folderIds) {
        try {
          BookmarksFolderServiceUtil.getFolder(folderId);
        } catch (Exception e) {
          continue;
        }

        folderIdsQuery.addTerm(Field.FOLDER_ID, folderId);
      }

      contextQuery.add(folderIdsQuery, BooleanClauseOccur.MUST);
    }

    int status =
        GetterUtil.getInteger(
            searchContext.getAttribute(Field.STATUS), WorkflowConstants.STATUS_APPROVED);

    if (status != WorkflowConstants.STATUS_ANY) {
      contextQuery.addRequiredTerm(Field.STATUS, status);
    }
  }
예제 #6
0
  @Override
  protected void addSearchLocalizedTerm(
      BooleanQuery searchQuery, SearchContext searchContext, String field, boolean like)
      throws Exception {

    if (Validator.isNull(field)) {
      return;
    }

    String value = String.valueOf(searchContext.getAttribute(field));

    if (Validator.isNull(value)) {
      value = searchContext.getKeywords();
    }

    if (Validator.isNull(value)) {
      return;
    }

    field = DocumentImpl.getLocalizedName(searchContext.getLocale(), field);

    if (searchContext.isAndSearch()) {
      searchQuery.addRequiredTerm(field, value, like);
    } else {
      searchQuery.addTerm(field, value, like);
    }
  }
예제 #7
0
  protected void addSearchAnyTags(BooleanQuery contextQuery, SearchContext searchContext)
      throws Exception {

    PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();

    long[] anyTagIds = _assetEntryQuery.getAnyTagIds();

    if (anyTagIds.length == 0) {
      return;
    }

    long[] filteredAnyTagIds = AssetUtil.filterTagIds(permissionChecker, anyTagIds);

    if (filteredAnyTagIds.length == 0) {
      addImpossibleTerm(contextQuery, Field.ASSET_TAG_IDS);

      return;
    }

    BooleanQuery tagIdsQuery = BooleanQueryFactoryUtil.create(searchContext);

    for (long tagId : anyTagIds) {
      tagIdsQuery.addTerm(Field.ASSET_TAG_IDS, tagId);
    }

    contextQuery.add(tagIdsQuery, BooleanClauseOccur.MUST);
  }
예제 #8
0
  @Override
  public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext)
      throws Exception {

    long[] folderIds = searchContext.getFolderIds();

    if ((folderIds != null) && (folderIds.length > 0)) {
      if (folderIds[0] == BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

        return;
      }

      BooleanQuery folderIdsQuery = BooleanQueryFactoryUtil.create(searchContext);

      for (long folderId : folderIds) {
        try {
          BookmarksFolderServiceUtil.getFolder(folderId);
        } catch (Exception e) {
          continue;
        }

        folderIdsQuery.addTerm(Field.FOLDER_ID, folderId);
      }

      contextQuery.add(folderIdsQuery, BooleanClauseOccur.MUST);
    }
  }
예제 #9
0
  @Override
  public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext)
      throws Exception {

    Long classNameId = (Long) searchContext.getAttribute(Field.CLASS_NAME_ID);

    if (classNameId != null) {
      contextQuery.addRequiredTerm("classNameId", classNameId.toString());
    }

    int status =
        GetterUtil.getInteger(
            searchContext.getAttribute(Field.STATUS), WorkflowConstants.STATUS_APPROVED);

    if (status != WorkflowConstants.STATUS_ANY) {
      contextQuery.addRequiredTerm(Field.STATUS, status);
    }

    long[] folderIds = searchContext.getFolderIds();

    if ((folderIds != null) && (folderIds.length > 0)) {
      if (folderIds[0] == JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

        return;
      }

      BooleanQuery folderIdsQuery = BooleanQueryFactoryUtil.create(searchContext);

      for (long folderId : folderIds) {
        try {
          JournalFolderServiceUtil.getFolder(folderId);
        } catch (Exception e) {
          continue;
        }

        folderIdsQuery.addTerm(Field.FOLDER_ID, folderId);
      }

      contextQuery.add(folderIdsQuery, BooleanClauseOccur.MUST);
    }

    String articleType = (String) searchContext.getAttribute("articleType");

    if (Validator.isNotNull(articleType)) {
      contextQuery.addRequiredTerm(Field.TYPE, articleType);
    }

    String structureId = (String) searchContext.getAttribute("structureId");

    if (Validator.isNotNull(structureId)) {
      contextQuery.addRequiredTerm("structureId", structureId);
    }

    String templateId = (String) searchContext.getAttribute("templateId");

    if (Validator.isNotNull(templateId)) {
      contextQuery.addRequiredTerm("templateId", templateId);
    }
  }
예제 #10
0
  @SuppressWarnings("unchecked")
  public List<Document> filterByFields(
      SearchContext searchContext,
      Map<String, Object> filters,
      Sort sort,
      long companyId,
      int start,
      int end)
      throws ParseException {
    final List<Query> queries = new ArrayList<>();
    if (filters != null) {
      Date effectiveDateFrom =
          filters.get(EmpDisciplineField.EFFECTIVE_DATE_FROM) != null
              ? (Date) filters.get(EmpDisciplineField.EFFECTIVE_DATE_FROM)
              : null;

      Date effectiveDateTo =
          filters.get(EmpDisciplineField.EFFECTIVE_DATE_TO) != null
              ? (Date) filters.get(EmpDisciplineField.EFFECTIVE_DATE_TO)
              : null;
      for (Map.Entry<String, Object> filter : filters.entrySet()) {
        final String filterProperty = filter.getKey();
        final Object filterValue = filter.getValue();
        LOGGER.info("Filter Property: " + filterProperty);

        if (filterValue instanceof String) {
          LOGGER.info("Filter Property Value: " + filterValue);
          // TODO
          BooleanQuery stringFilterQuery = BooleanQueryFactoryUtil.create(searchContext);
          stringFilterQuery.addTerm(
              filterProperty, (String) filterValue, true, BooleanClauseOccur.MUST);
          queries.add(stringFilterQuery);

        } else if (filterValue instanceof List<?>) {
          queries.add(
              empLocalService.createStringListQuery(
                  filterProperty, (List<String>) filterValue, searchContext));
        } else if (filterValue instanceof Date) {
          Query effectiveDateQuery =
              empLocalService.createDateTermRangeQuery(
                  EmpDisciplineField.EFFECTIVE_DATE,
                  effectiveDateFrom,
                  effectiveDateTo,
                  true,
                  true,
                  searchContext);
          if (effectiveDateQuery != null) {
            queries.add(effectiveDateQuery);
          }
        }
      }
    }
    /* SORT */
    if (sort == null) {
      sort = new Sort(EmpDisciplineField.ID, false);
    }
    return searchAllDocuments(searchContext, queries, companyId, sort, start, end);
  }
예제 #11
0
  protected void addContextQueryParams(
      BooleanQuery contextQuery, SearchContext searchContext, String key, Object value)
      throws Exception {

    if (key.equals("usersGroups")) {
      if (value instanceof Long[]) {
        Long[] values = (Long[]) value;

        BooleanQuery usersGroupsQuery = BooleanQueryFactoryUtil.create(searchContext);

        for (long groupId : values) {
          usersGroupsQuery.addTerm("groupIds", groupId);
        }

        contextQuery.add(usersGroupsQuery, BooleanClauseOccur.MUST);
      } else {
        contextQuery.addRequiredTerm("groupIds", String.valueOf(value));
      }
    } else if (key.equals("usersOrgs")) {
      if (value instanceof Long[]) {
        Long[] values = (Long[]) value;

        BooleanQuery usersOrgsQuery = BooleanQueryFactoryUtil.create(searchContext);

        for (long organizationId : values) {
          usersOrgsQuery.addTerm("organizationIds", organizationId);
          usersOrgsQuery.addTerm("ancestorOrganizationIds", organizationId);
        }

        contextQuery.add(usersOrgsQuery, BooleanClauseOccur.MUST);
      } else {
        contextQuery.addRequiredTerm("organizationIds", String.valueOf(value));
      }
    } else if (key.equals("usersOrgsCount")) {
      contextQuery.addRequiredTerm("organizationCount", String.valueOf(value));
    } else if (key.equals("usersRoles")) {
      contextQuery.addRequiredTerm("roleIds", String.valueOf(value));
    } else if (key.equals("usersTeams")) {
      contextQuery.addRequiredTerm("teamIds", String.valueOf(value));
    } else if (key.equals("usersUserGroups")) {
      contextQuery.addRequiredTerm("userGroupIds", String.valueOf(value));
    }
  }
  protected void addRequiredMemberRole(Group group, BooleanQuery permissionQuery) throws Exception {

    if (group.isOrganization()) {
      Role organizationUserRole =
          RoleLocalServiceUtil.getRole(group.getCompanyId(), RoleConstants.ORGANIZATION_USER);

      permissionQuery.addTerm(
          Field.GROUP_ROLE_ID,
          group.getGroupId() + StringPool.DASH + organizationUserRole.getRoleId());
    }

    if (group.isSite()) {
      Role siteMemberRole =
          RoleLocalServiceUtil.getRole(group.getCompanyId(), RoleConstants.SITE_MEMBER);

      permissionQuery.addTerm(
          Field.GROUP_ROLE_ID, group.getGroupId() + StringPool.DASH + siteMemberRole.getRoleId());
    }
  }
  @Override
  public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext)
      throws Exception {

    addStatus(contextQuery, searchContext);

    if (searchContext.isIncludeAttachments()) {
      addRelatedClassNames(contextQuery, searchContext);
    }

    contextQuery.addRequiredTerm(Field.HIDDEN, searchContext.isIncludeAttachments());

    addSearchClassTypeIds(contextQuery, searchContext);

    String ddmStructureFieldName = (String) searchContext.getAttribute("ddmStructureFieldName");
    Serializable ddmStructureFieldValue = searchContext.getAttribute("ddmStructureFieldValue");

    if (Validator.isNotNull(ddmStructureFieldName) && Validator.isNotNull(ddmStructureFieldValue)) {

      String[] ddmStructureFieldNameParts =
          StringUtil.split(ddmStructureFieldName, StringPool.SLASH);

      DDMStructure structure =
          DDMStructureLocalServiceUtil.getStructure(
              GetterUtil.getLong(ddmStructureFieldNameParts[1]));

      String fieldName =
          StringUtil.replaceLast(
              ddmStructureFieldNameParts[2],
              StringPool.UNDERLINE.concat(LocaleUtil.toLanguageId(searchContext.getLocale())),
              StringPool.BLANK);

      try {
        ddmStructureFieldValue =
            DDMUtil.getIndexedFieldValue(ddmStructureFieldValue, structure.getFieldType(fieldName));
      } catch (StructureFieldException sfe) {
      }

      contextQuery.addRequiredTerm(
          ddmStructureFieldName, StringPool.QUOTE + ddmStructureFieldValue + StringPool.QUOTE);
    }

    String[] mimeTypes = (String[]) searchContext.getAttribute("mimeTypes");

    if (ArrayUtil.isNotEmpty(mimeTypes)) {
      BooleanQuery mimeTypesQuery = BooleanQueryFactoryUtil.create(searchContext);

      for (String mimeType : mimeTypes) {
        mimeTypesQuery.addTerm(
            "mimeType", StringUtil.replace(mimeType, CharPool.FORWARD_SLASH, CharPool.UNDERLINE));
      }

      contextQuery.add(mimeTypesQuery, BooleanClauseOccur.MUST);
    }
  }
  @Override
  public void postProcessSearchQuery(
      BooleanQuery searchQuery, BooleanFilter fullQueryBooleanFilter, SearchContext searchContext)
      throws Exception {

    String keywords = searchContext.getKeywords();

    if (Validator.isNotNull(keywords)) {
      searchQuery.addTerm("projectTitles", keywords, true);
    }
  }
  public Hits search(
      long companyId,
      String keywords,
      String sortField,
      int sortType,
      boolean reverse,
      int start,
      int end)
      throws SystemException {
    try {
      BooleanQuery contextQuery = BooleanQueryFactoryUtil.create();
      contextQuery.addRequiredTerm(Field.COMPANY_ID, companyId);

      if (Validator.isNotNull(ContactBookIndexer.PORTLET_ID)) {
        contextQuery.addRequiredTerm(Field.PORTLET_ID, ContactBookIndexer.PORTLET_ID);
      }

      BooleanQuery searchQuery = BooleanQueryFactoryUtil.create();

      if (Validator.isNotNull(keywords)) {
        searchQuery.addTerm(Field.TITLE, keywords);
        searchQuery.addTerm("contactBookCode", keywords + "*");
        searchQuery.addTerm("contactBookName", keywords + "*");
        searchQuery.addTerm("contactDescription", keywords + "*");
      }

      BooleanQuery fullQuery = BooleanQueryFactoryUtil.create();
      fullQuery.add(contextQuery, BooleanClauseOccur.MUST);

      if (searchQuery.clauses().size() > 0) {
        fullQuery.add(searchQuery, BooleanClauseOccur.MUST);
      }

      Sort sort;
      sort = new Sort(sortField, sortType, reverse);
      Hits hits = SearchEngineUtil.search(companyId, fullQuery, sort, start, end);
      return hits;
    } catch (Exception e) {
      throw new SystemException(e);
    }
  }
  @Test
  public void testMatchNotOnlyCompanyIdButAlsoQueryTerms() throws Exception {
    SearchContext searchContext = new SearchContext();

    searchContext.setCompanyId(TestPropsValues.getCompanyId());

    BooleanQuery query = new BooleanQueryImpl();

    query.addTerm("title", RandomTestUtil.randomString());

    assertEquals(0, query, searchContext);
  }
예제 #17
0
  protected void addSearchAllCategories(BooleanQuery contextQuery, SearchContext searchContext)
      throws Exception {

    PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();

    long[] allCategoryIds = _assetEntryQuery.getAllCategoryIds();

    if (allCategoryIds.length == 0) {
      return;
    }

    long[] filteredAllCategoryIds = AssetUtil.filterCategoryIds(permissionChecker, allCategoryIds);

    if (allCategoryIds.length != filteredAllCategoryIds.length) {
      addImpossibleTerm(contextQuery, Field.ASSET_CATEGORY_IDS);

      return;
    }

    BooleanQuery categoryIdsQuery = BooleanQueryFactoryUtil.create(searchContext);

    for (long allCategoryId : filteredAllCategoryIds) {
      AssetCategory assetCategory = AssetCategoryLocalServiceUtil.fetchAssetCategory(allCategoryId);

      if (assetCategory == null) {
        continue;
      }

      List<Long> categoryIds = new ArrayList<>();

      if (PropsValues.ASSET_CATEGORIES_SEARCH_HIERARCHICAL) {
        categoryIds.addAll(AssetCategoryLocalServiceUtil.getSubcategoryIds(allCategoryId));
      }

      if (categoryIds.isEmpty()) {
        categoryIds.add(allCategoryId);
      }

      BooleanQuery categoryIdQuery = BooleanQueryFactoryUtil.create(searchContext);

      for (long categoryId : categoryIds) {
        categoryIdQuery.addTerm(Field.ASSET_CATEGORY_IDS, categoryId);
      }

      categoryIdsQuery.add(categoryIdQuery, BooleanClauseOccur.MUST);
    }

    contextQuery.add(categoryIdsQuery, BooleanClauseOccur.MUST);
  }
  @Override
  public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext)
      throws Exception {

    long[] vocabularyIds = (long[]) searchContext.getAttribute(Field.ASSET_VOCABULARY_IDS);

    if (!ArrayUtil.isEmpty(vocabularyIds)) {
      BooleanQuery vocabularyQuery = BooleanQueryFactoryUtil.create(searchContext);

      for (long vocabularyId : vocabularyIds) {
        vocabularyQuery.addTerm(Field.ASSET_VOCABULARY_ID, String.valueOf(vocabularyId));
      }

      contextQuery.add(vocabularyQuery, BooleanClauseOccur.MUST);
    }
  }
예제 #19
0
  @Override
  protected void addSearchKeywords(BooleanQuery searchQuery, SearchContext searchContext)
      throws Exception {

    String keywords = searchContext.getKeywords();

    if (Validator.isNull(keywords)) {
      return;
    }

    super.addSearchKeywords(searchQuery, searchContext);

    String field = DocumentImpl.getLocalizedName(searchContext.getLocale(), "localized_title");

    searchQuery.addTerm(field, keywords, true);
  }
예제 #20
0
  protected void addSearchNotAllCategories(BooleanQuery contextQuery, SearchContext searchContext)
      throws Exception {

    long[] notAllCategoryIds = _assetEntryQuery.getNotAllCategoryIds();

    if (notAllCategoryIds.length == 0) {
      return;
    }

    BooleanQuery categoryIdsQuery = BooleanQueryFactoryUtil.create(searchContext);

    for (long notAllCategoryId : notAllCategoryIds) {
      AssetCategory assetCategory =
          AssetCategoryLocalServiceUtil.fetchAssetCategory(notAllCategoryId);

      if (assetCategory == null) {
        continue;
      }

      List<Long> categoryIds = new ArrayList<>();

      if (PropsValues.ASSET_CATEGORIES_SEARCH_HIERARCHICAL) {
        categoryIds.addAll(AssetCategoryLocalServiceUtil.getSubcategoryIds(notAllCategoryId));
      }

      if (categoryIds.isEmpty()) {
        categoryIds.add(notAllCategoryId);
      }

      BooleanQuery categoryIdQuery = BooleanQueryFactoryUtil.create(searchContext);

      for (long categoryId : categoryIds) {
        categoryIdQuery.addTerm(Field.ASSET_CATEGORY_IDS, categoryId);
      }

      categoryIdsQuery.add(categoryIdQuery, BooleanClauseOccur.MUST);
    }

    contextQuery.add(categoryIdsQuery, BooleanClauseOccur.MUST_NOT);
  }
  protected Query doGetPermissionQuery_6(
      long companyId,
      long[] groupIds,
      long userId,
      String className,
      Query query,
      SearchContext searchContext,
      AdvancedPermissionChecker advancedPermissionChecker,
      List<Group> groups,
      List<Role> roles,
      List<UserGroupRole> userGroupRoles,
      Map<Long, List<Role>> groupIdsToRoles)
      throws Exception {

    BooleanQuery permissionQuery = BooleanQueryFactoryUtil.create(searchContext);

    if (userId > 0) {
      permissionQuery.addTerm(Field.USER_ID, userId);
    }

    BooleanQuery groupsQuery = BooleanQueryFactoryUtil.create(searchContext);
    BooleanQuery rolesQuery = BooleanQueryFactoryUtil.create(searchContext);

    for (Role role : roles) {
      String roleName = role.getName();

      if (roleName.equals(RoleConstants.ADMINISTRATOR)) {
        return query;
      }

      if (ResourcePermissionLocalServiceUtil.hasResourcePermission(
          companyId,
          className,
          ResourceConstants.SCOPE_COMPANY,
          String.valueOf(companyId),
          role.getRoleId(),
          ActionKeys.VIEW)) {

        return query;
      }

      if ((role.getType() == RoleConstants.TYPE_REGULAR)
          && ResourcePermissionLocalServiceUtil.hasResourcePermission(
              companyId,
              className,
              ResourceConstants.SCOPE_GROUP_TEMPLATE,
              String.valueOf(GroupConstants.DEFAULT_PARENT_GROUP_ID),
              role.getRoleId(),
              ActionKeys.VIEW)) {

        return query;
      }

      for (Group group : groups) {
        if (ResourcePermissionLocalServiceUtil.hasResourcePermission(
            companyId,
            className,
            ResourceConstants.SCOPE_GROUP,
            String.valueOf(group.getGroupId()),
            role.getRoleId(),
            ActionKeys.VIEW)) {

          groupsQuery.addTerm(Field.GROUP_ID, group.getGroupId());
        }

        if ((role.getType() != RoleConstants.TYPE_REGULAR)
            && ResourcePermissionLocalServiceUtil.hasResourcePermission(
                companyId,
                className,
                ResourceConstants.SCOPE_GROUP_TEMPLATE,
                String.valueOf(GroupConstants.DEFAULT_PARENT_GROUP_ID),
                role.getRoleId(),
                ActionKeys.VIEW)) {

          List<Role> groupRoles = groupIdsToRoles.get(group.getGroupId());

          if (groupRoles.contains(role)) {
            groupsQuery.addTerm(Field.GROUP_ID, group.getGroupId());
          }
        }

        if (group.isSite()
            && !roleName.equals(RoleConstants.SITE_MEMBER)
            && (role.getType() == RoleConstants.TYPE_SITE)) {

          rolesQuery.addTerm(
              Field.GROUP_ROLE_ID, group.getGroupId() + StringPool.DASH + role.getRoleId());
        }
      }

      rolesQuery.addTerm(Field.ROLE_ID, role.getRoleId());
    }

    for (Group group : groups) {
      addRequiredMemberRole(group, rolesQuery);
    }

    for (UserGroupRole userGroupRole : userGroupRoles) {
      rolesQuery.addTerm(
          Field.GROUP_ROLE_ID,
          userGroupRole.getGroupId() + StringPool.DASH + userGroupRole.getRoleId());
    }

    if (groupsQuery.hasClauses()) {
      permissionQuery.add(groupsQuery, BooleanClauseOccur.SHOULD);
    }

    if (rolesQuery.hasClauses()) {
      permissionQuery.add(rolesQuery, BooleanClauseOccur.SHOULD);
    }

    BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext);

    fullQuery.add(query, BooleanClauseOccur.MUST);
    fullQuery.add(permissionQuery, BooleanClauseOccur.MUST);

    return fullQuery;
  }
예제 #22
0
  protected void addImpossibleTerm(BooleanQuery contextQuery, String field) throws Exception {

    contextQuery.addTerm(field, "-1", false, BooleanClauseOccur.MUST);
  }