Example #1
1
  protected static List<CalendarBooking> filterCalendarBookings(
      List<CalendarBooking> calendarBookings, PermissionChecker permissionChecker, String actionId)
      throws PortalException, SystemException {

    calendarBookings = ListUtil.copy(calendarBookings);

    Iterator<CalendarBooking> itr = calendarBookings.iterator();

    while (itr.hasNext()) {
      CalendarBooking calendarBooking = itr.next();

      if (!CalendarPermission.contains(
          permissionChecker, calendarBooking.getCalendarId(), ACTION_VIEW_BOOKING_DETAILS)) {

        if (!CalendarPermission.contains(
            permissionChecker, calendarBooking.getCalendarId(), actionId)) {

          itr.remove();
        } else {
          filterCalendarBooking(calendarBooking, permissionChecker);
        }
      }
    }

    return calendarBookings;
  }
  protected List<Role> getGroupRoles(long groupId, String resourceName) throws PortalException {

    List<Role> roles = groupRolesMap.get(groupId);

    if (roles != null) {
      return roles;
    }

    Group group = GroupLocalServiceUtil.getGroup(groupId);

    roles =
        ListUtil.copy(
            ResourceActionsUtil.getRoles(group.getCompanyId(), group, resourceName, null));

    Map<Team, Role> teamRoleMap = RoleLocalServiceUtil.getTeamRoleMap(groupId);

    for (Map.Entry<Team, Role> entry : teamRoleMap.entrySet()) {
      Team team = entry.getKey();
      Role teamRole = entry.getValue();

      teamRole.setName(PermissionExporter.ROLE_TEAM_PREFIX + team.getName());
      teamRole.setDescription(team.getDescription());

      roles.add(teamRole);
    }

    groupRolesMap.put(groupId, roles);

    return roles;
  }
  public static List<AssetEntry> getAssetEntries(
      long[] groupIds,
      long[] classNameIds,
      long[] assetTagIds,
      long resourcePrimKey,
      int start,
      int end,
      String orderByColumn)
      throws PortalException {

    AssetEntryQuery assetEntryQuery = new AssetEntryQuery();

    assetEntryQuery.setAnyTagIds(assetTagIds);
    assetEntryQuery.setClassNameIds(classNameIds);
    assetEntryQuery.setEnd(end + 1);
    assetEntryQuery.setGroupIds(groupIds);
    assetEntryQuery.setOrderByCol1(orderByColumn);
    assetEntryQuery.setStart(start);

    List<AssetEntry> assetEntries =
        ListUtil.copy(AssetEntryServiceUtil.getEntries(assetEntryQuery));

    AssetEntry assetEntry = null;

    for (AssetEntry curAssetEntry : assetEntries) {
      if (curAssetEntry.getClassPK() == resourcePrimKey) {
        assetEntry = curAssetEntry;
      }
    }

    assetEntries.remove(assetEntry);

    return ListUtil.subList(assetEntries, 0, 10);
  }
  public List<KBArticle> getKBArticleAndAllDescendants(
      long resourcePrimKey, int status, OrderByComparator orderByComparator)
      throws SystemException {

    List<KBArticle> kbArticles = getKBArticles(new long[] {resourcePrimKey}, status, null);

    kbArticles = ListUtil.copy(kbArticles);

    Long[][] params = new Long[][] {new Long[] {resourcePrimKey}};

    while ((params = KnowledgeBaseUtil.getParams(params[0])) != null) {
      List<KBArticle> curKBArticles = null;

      if (status == WorkflowConstants.STATUS_ANY) {
        curKBArticles = kbArticlePersistence.findByP_L(ArrayUtil.toArray(params[1]), true);
      } else if (status == WorkflowConstants.STATUS_APPROVED) {
        curKBArticles = kbArticlePersistence.findByP_M(ArrayUtil.toArray(params[1]), true);
      } else {
        curKBArticles = kbArticlePersistence.findByP_S(ArrayUtil.toArray(params[1]), status);
      }

      kbArticles.addAll(curKBArticles);

      long[] resourcePrimKeys =
          StringUtil.split(ListUtil.toString(curKBArticles, "resourcePrimKey"), 0L);

      params[0] = ArrayUtil.append(params[0], ArrayUtil.toArray(resourcePrimKeys));
    }

    if (orderByComparator != null) {
      kbArticles = ListUtil.sort(kbArticles, orderByComparator);
    }

    return new UnmodifiableList<KBArticle>(kbArticles);
  }
  public List<Theme> getThemes(long companyId) {
    Map<String, Theme> themes = _getThemes(companyId);

    List<Theme> themesList = ListUtil.fromMapValues(themes);

    return ListUtil.sort(themesList);
  }
  protected List<DLFileEntry> doFindBy_G_U_R_F_M_NewRepository(
      long userId, String mimeType, QueryDefinition<DLFileEntry> queryDefinition) throws Exception {

    List<Long> repositoryIds = ListUtil.toList(new long[] {_newRepositoryFolder.getRepositoryId()});
    List<Long> folderIds = ListUtil.toList(new long[] {_newRepositoryFolder.getFolderId()});

    return doFindBy_G_U_R_F_M(userId, repositoryIds, folderIds, mimeType, queryDefinition);
  }
  private <T, V extends T> List<T> _subList(
      List<V> list, int start, int end, OrderByComparator<T> obc) {

    if (obc != null) {
      list = ListUtil.sort(list, obc);
    }

    return (List<T>) ListUtil.toList(ListUtil.subList(list, start, end));
  }
  public static String[] getCategories(List<App> apps, List<Bundle> bundles) {
    List<String> categories = new ArrayList<>();

    categories.addAll(getAppCategories(apps));
    categories.addAll(getBundleCategories(bundles));

    ListUtil.distinct(categories);
    ListUtil.sort(categories);

    categories.add(0, "all-categories");

    return ArrayUtil.toStringArray(categories);
  }
  public void addAssetCategories(Class<?> clazz, long classPK) throws SystemException {

    List<AssetCategory> assetCategories =
        AssetCategoryLocalServiceUtil.getCategories(clazz.getName(), classPK);

    _assetCategoryUuidsMap.put(
        getPrimaryKeyString(clazz, classPK),
        StringUtil.split(ListUtil.toString(assetCategories, AssetCategory.UUID_ACCESSOR)));
    _assetCategoryIdsMap.put(
        getPrimaryKeyString(clazz, classPK),
        StringUtil.split(
            ListUtil.toString(assetCategories, AssetCategory.CATEGORY_ID_ACCESSOR), 0L));
  }
Example #10
0
  public static List<WikiNode> orderNodes(List<WikiNode> nodes, String[] visibleNodeNames) {

    if ((visibleNodeNames == null) || (visibleNodeNames.length == 0)) {
      return nodes;
    }

    nodes = ListUtil.copy(nodes);

    List<WikiNode> orderedNodes = new ArrayList<WikiNode>(nodes.size());

    for (String visibleNodeName : visibleNodeNames) {
      for (WikiNode node : nodes) {
        if (node.getName().equals(visibleNodeName)) {
          orderedNodes.add(node);

          nodes.remove(node);

          break;
        }
      }
    }

    orderedNodes.addAll(nodes);

    return orderedNodes;
  }
Example #11
0
  public static List<OpenSearch> getOpenSearchInstances(String primarySearch) {

    List<OpenSearch> openSearchInstances =
        ListUtil.filter(
            OpenSearchRegistryUtil.getOpenSearchInstances(),
            new PredicateFilter<OpenSearch>() {

              @Override
              public boolean filter(OpenSearch openSearch) {
                return openSearch.isEnabled();
              }
            });

    if (Validator.isNotNull(primarySearch)) {
      for (int i = 0; i < openSearchInstances.size(); i++) {
        OpenSearch openSearch = openSearchInstances.get(i);

        if (primarySearch.equals(openSearch.getClassName())) {
          if (i != 0) {
            openSearchInstances.remove(i);

            openSearchInstances.add(0, openSearch);
          }

          break;
        }
      }
    }

    return openSearchInstances;
  }
  @Override
  public List<?> list(boolean copy, boolean unmodifiable) throws ORMException {

    try {
      List<?> list =
          sessionImpl.list(
              queryString,
              positionalParameterMap,
              namedParameterMap,
              strictName,
              firstResult,
              maxResults,
              flushModeType,
              lockModeType,
              sqlQuery,
              entityClass);

      if ((entityClass == null) && !list.isEmpty()) {
        list = _transformList(list);
      }

      if (unmodifiable) {
        list = new UnmodifiableList<Object>(list);
      } else if (copy) {
        list = ListUtil.copy(list);
      }

      return list;
    } catch (Exception e) {
      throw ExceptionTranslator.translate(e);
    }
  }
  public FileEntry moveFileEntryFromTrash(
      long userId, FileEntry fileEntry, long newFolderId, ServiceContext serviceContext)
      throws PortalException, SystemException {

    // File entry

    List<DLFileVersion> dlFileVersions =
        dlFileVersionLocalService.getFileVersions(
            fileEntry.getFileEntryId(), WorkflowConstants.STATUS_ANY);

    dlFileVersions = ListUtil.sort(dlFileVersions, new FileVersionVersionComparator());

    FileVersion fileVersion = new LiferayFileVersion(dlFileVersions.get(0));

    dlFileEntryLocalService.updateStatus(
        userId,
        fileVersion.getFileVersionId(),
        fileVersion.getStatus(),
        new HashMap<String, Serializable>(),
        serviceContext);

    // File rank

    dlFileRankLocalService.enableFileRanks(fileEntry.getFileEntryId());

    // App helper

    return dlAppService.moveFileEntry(fileEntry.getFileEntryId(), newFolderId, serviceContext);
  }
  @Override
  public void removeAndStoreSelection(
      List<String> assetEntryUuids, PortletPreferences portletPreferences) throws Exception {

    if (assetEntryUuids.size() == 0) {
      return;
    }

    String[] assetEntryXmls = portletPreferences.getValues("assetEntryXml", new String[0]);

    List<String> assetEntryXmlsList = ListUtil.fromArray(assetEntryXmls);

    Iterator<String> itr = assetEntryXmlsList.iterator();

    while (itr.hasNext()) {
      String assetEntryXml = itr.next();

      Document document = SAXReaderUtil.read(assetEntryXml);

      Element rootElement = document.getRootElement();

      String assetEntryUuid = rootElement.elementText("asset-entry-uuid");

      if (assetEntryUuids.contains(assetEntryUuid)) {
        itr.remove();
      }
    }

    portletPreferences.setValues(
        "assetEntryXml", assetEntryXmlsList.toArray(new String[assetEntryXmlsList.size()]));

    portletPreferences.store();
  }
Example #15
0
  protected List<Layout> addUserGroupLayouts(
      Group group, LayoutSet layoutSet, List<Layout> layouts, long parentLayoutId)
      throws Exception {

    layouts = ListUtil.copy(layouts);

    List<UserGroup> userUserGroups =
        UserGroupLocalServiceUtil.getUserUserGroups(group.getClassPK());

    for (UserGroup userGroup : userUserGroups) {
      Group userGroupGroup = userGroup.getGroup();

      List<Layout> userGroupLayouts =
          LayoutLocalServiceUtil.getLayouts(
              userGroupGroup.getGroupId(), layoutSet.isPrivateLayout(), parentLayoutId);

      for (Layout userGroupLayout : userGroupLayouts) {
        Layout virtualLayout = new VirtualLayout(userGroupLayout, group);

        layouts.add(virtualLayout);
      }
    }

    return layouts;
  }
  /**
   * Returns a range of all the site groups for which the user has control panel access.
   *
   * @param portlets the portlets to manage
   * @param max the upper bound of the range of groups to consider (not inclusive)
   * @return the range of site groups for which the user has Control Panel access
   * @throws PortalException if a portal exception occurred
   */
  @Override
  public List<Group> getManageableSiteGroups(Collection<Portlet> portlets, int max)
      throws PortalException {

    PermissionChecker permissionChecker = getPermissionChecker();

    if (permissionChecker.isCompanyAdmin()) {
      LinkedHashMap<String, Object> params = new LinkedHashMap<>();

      params.put("site", Boolean.TRUE);

      return ListUtil.unique(
          groupLocalService.search(
              permissionChecker.getCompanyId(), null, null, null, params, true, 0, max));
    }

    Set<Group> groups = new LinkedHashSet<>();

    List<Group> userSitesGroups = getUserSitesGroups(null, max);

    Iterator<Group> itr = userSitesGroups.iterator();

    while (itr.hasNext()) {
      Group group = itr.next();

      if (group.isSite()
          && PortletPermissionUtil.hasControlPanelAccessPermission(
              permissionChecker, group.getGroupId(), portlets)) {

        groups.add(group);
      }
    }

    return new ArrayList<>(groups);
  }
  public void unregisterListener(ModelListener listener) {
    List<ModelListener> listeners = ListUtil.fromArray(_listeners);

    listeners.remove(listener);

    _listeners = listeners.toArray(new ModelListener[listeners.size()]);
  }
  @Override
  public TreeView getTreeView() throws PortalException {
    _nodeId = 1;

    _list = new ArrayList<>();

    TreeNodeView rootNodeView = null;

    if (_rootNodeName != null) {
      rootNodeView = new TreeNodeView(_nodeId);

      rootNodeView.setLeaf(false);
      rootNodeView.setName(_rootNodeName);

      _list.add(rootNodeView);
    }

    PortletCategory portletCategory =
        (PortletCategory) WebAppPool.get(_user.getCompanyId(), WebKeys.PORTLET_CATEGORY);

    List<PortletCategory> portletCategories =
        ListUtil.fromCollection(portletCategory.getCategories());

    iteratePortletCategories(rootNodeView, portletCategories, _nodeId, 0);

    return new TreeView(_list, _depth);
  }
  public List<PluginPackage> getSortedPluginPackages() {
    List<PluginPackage> pluginPackages = new ArrayList<PluginPackage>();

    pluginPackages.addAll(_pluginPackages.values());

    return ListUtil.sort(pluginPackages, new PluginPackageNameAndContextComparator());
  }
Example #20
0
  protected List<String> getFieldNames(
      String fieldNamespace, String fieldName, ServiceContext serviceContext) {

    String[] fieldsDisplayValues =
        StringUtil.split(
            (String) serviceContext.getAttribute(fieldNamespace + FIELDS_DISPLAY_NAME));

    List<String> privateFieldNames = ListUtil.fromArray(new String[] {FIELDS_DISPLAY_NAME});

    List<String> fieldNames = new ArrayList<>();

    if ((fieldsDisplayValues.length == 0) || privateFieldNames.contains(fieldName)) {

      fieldNames.add(fieldNamespace + fieldName);
    } else {
      for (String namespacedFieldName : fieldsDisplayValues) {
        String fieldNameValue = StringUtil.extractFirst(namespacedFieldName, INSTANCE_SEPARATOR);

        if (fieldNameValue.equals(fieldName)) {
          fieldNames.add(fieldNamespace + namespacedFieldName);
        }
      }
    }

    return fieldNames;
  }
  protected void checkPopulatedServiceContext(
      ServiceContext serviceContext, WikiPage page, boolean hasExpandoValues) throws Exception {

    long[] assetCategoryIds =
        AssetCategoryLocalServiceUtil.getCategoryIds(
            WikiPage.class.getName(), page.getResourcePrimKey());

    Assert.assertArrayEquals(serviceContext.getAssetCategoryIds(), assetCategoryIds);

    AssetEntry assetEntry =
        AssetEntryLocalServiceUtil.getEntry(WikiPage.class.getName(), page.getResourcePrimKey());

    List<AssetLink> assetLinks = AssetLinkLocalServiceUtil.getLinks(assetEntry.getEntryId());

    long[] assetLinkEntryIds = ListUtil.toLongArray(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR);

    Assert.assertArrayEquals(serviceContext.getAssetLinkEntryIds(), assetLinkEntryIds);

    String[] assetTagNames =
        AssetTagLocalServiceUtil.getTagNames(WikiPage.class.getName(), page.getResourcePrimKey());

    Assert.assertArrayEquals(serviceContext.getAssetTagNames(), assetTagNames);

    if (hasExpandoValues) {
      ExpandoBridge expandoBridge = page.getExpandoBridge();

      AssertUtils.assertEquals(
          expandoBridge.getAttributes(), serviceContext.getExpandoBridgeAttributes());
    }
  }
  protected int doCountBy_G_U_R_F_M_BothRepositories(
      long userId, String mimeType, QueryDefinition<DLFileEntry> queryDefinition) throws Exception {

    List<Long> repositoryIds =
        ListUtil.toList(
            new long[] {
              _defaultRepositoryFolder.getRepositoryId(), _newRepositoryFolder.getRepositoryId()
            });
    List<Long> folderIds =
        ListUtil.toList(
            new long[] {
              _defaultRepositoryFolder.getFolderId(), _newRepositoryFolder.getFolderId()
            });

    return doCountBy_G_U_R_F_M(userId, repositoryIds, folderIds, mimeType, queryDefinition);
  }
  protected long getFolderId(String type) throws SystemException {
    Locale[] locales = LanguageUtil.getAvailableLocales();

    List<String> words = new ArrayList<String>();

    for (Locale locale : locales) {
      String translation = LanguageUtil.get(locale, type).toLowerCase();

      words.addAll(ListUtil.toList(translation.split(StringPool.SPACE)));
    }

    List<Folder> folders = FolderLocalServiceUtil.getFolders(account.getAccountId());

    for (String word : words) {
      for (Folder folder : folders) {
        String folderName = folder.getDisplayName().toLowerCase();

        if (folderName.contains(word)) {
          return folder.getFolderId();
        }
      }
    }

    return 0;
  }
  protected static boolean isExcluded(
      List<String> exclusions, String absolutePath, int lineCount, String javaTermName) {

    if (ListUtil.isEmpty(exclusions)) {
      return false;
    }

    String absolutePathWithJavaTermName = null;

    if (Validator.isNotNull(javaTermName)) {
      absolutePathWithJavaTermName = absolutePath + StringPool.AT + javaTermName;
    }

    String absolutePathWithLineCount = null;

    if (lineCount > 0) {
      absolutePathWithLineCount = absolutePath + StringPool.AT + lineCount;
    }

    for (String exclusion : exclusions) {
      if (absolutePath.endsWith(exclusion)
          || ((absolutePathWithJavaTermName != null)
              && absolutePathWithJavaTermName.endsWith(exclusion))
          || ((absolutePathWithLineCount != null)
              && absolutePathWithLineCount.endsWith(exclusion))) {

        return true;
      }
    }

    return false;
  }
  public static void updateLanguage(HttpServletRequest request, HttpServletResponse response) {

    String languageId =
        ParamUtil.getString(request, "companyLocale", PropsValues.COMPANY_DEFAULT_LOCALE);

    Locale locale = LocaleUtil.fromLanguageId(languageId);

    List<Locale> availableLocales = ListUtil.fromArray(LanguageUtil.getAvailableLocales());

    if (!availableLocales.contains(locale)) {
      return;
    }

    HttpSession session = request.getSession();

    session.setAttribute(Globals.LOCALE_KEY, locale);
    session.setAttribute(WebKeys.SETUP_WIZARD_DEFAULT_LOCALE, languageId);

    LanguageUtil.updateCookie(request, response, locale);

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    themeDisplay.setLanguageId(languageId);
    themeDisplay.setLocale(locale);
  }
  public static com.liferay.portlet.documentlibrary.model.DLFolderSoap updateFolder(
      long folderId,
      java.lang.String name,
      java.lang.String description,
      long defaultFileEntryTypeId,
      Long[] fileEntryTypeIds,
      boolean overrideFileEntryTypes,
      com.liferay.portal.service.ServiceContext serviceContext)
      throws RemoteException {
    try {
      com.liferay.portlet.documentlibrary.model.DLFolder returnValue =
          DLFolderServiceUtil.updateFolder(
              folderId,
              name,
              description,
              defaultFileEntryTypeId,
              ListUtil.toList(fileEntryTypeIds),
              overrideFileEntryTypes,
              serviceContext);

      return com.liferay.portlet.documentlibrary.model.DLFolderSoap.toSoapModel(returnValue);
    } catch (Exception e) {
      _log.error(e, e);

      throw new RemoteException(e.getMessage());
    }
  }
  public List<KeyValuePair> getAvailableVocabularyNames() throws PortalException {

    List<KeyValuePair> availableVocabularNames = new ArrayList<>();

    long[] assetVocabularyIds = getAssetVocabularyIds();

    Arrays.sort(assetVocabularyIds);

    Set<Long> availableAssetVocabularyIdsSet = SetUtil.fromArray(getAvailableAssetVocabularyIds());

    for (long assetVocabularyId : availableAssetVocabularyIdsSet) {
      if (Arrays.binarySearch(assetVocabularyIds, assetVocabularyId) < 0) {

        AssetVocabulary assetVocabulary =
            AssetVocabularyLocalServiceUtil.fetchAssetVocabulary(assetVocabularyId);

        assetVocabulary = assetVocabulary.toEscapedModel();

        availableVocabularNames.add(
            new KeyValuePair(String.valueOf(assetVocabularyId), getTitle(assetVocabulary)));
      }
    }

    return ListUtil.sort(availableVocabularNames, new KeyValuePairComparator(false, true));
  }
  public List<KBArticle> getKBArticles(
      long[] resourcePrimKeys, int status, OrderByComparator orderByComparator)
      throws SystemException {

    List<KBArticle> kbArticles = new ArrayList<KBArticle>();

    Long[][] params = new Long[][] {ArrayUtil.toArray(resourcePrimKeys)};

    while ((params = KnowledgeBaseUtil.getParams(params[0])) != null) {
      List<KBArticle> curKBArticles = null;

      if (status == WorkflowConstants.STATUS_ANY) {
        curKBArticles = kbArticlePersistence.findByR_L(ArrayUtil.toArray(params[1]), true);
      } else if (status == WorkflowConstants.STATUS_APPROVED) {
        curKBArticles = kbArticlePersistence.findByR_M(ArrayUtil.toArray(params[1]), true);
      } else {
        curKBArticles = kbArticlePersistence.findByR_S(ArrayUtil.toArray(params[1]), status);
      }

      kbArticles.addAll(curKBArticles);
    }

    if (orderByComparator != null) {
      kbArticles = ListUtil.sort(kbArticles, orderByComparator);
    } else {
      kbArticles = KnowledgeBaseUtil.sort(resourcePrimKeys, kbArticles);
    }

    return new UnmodifiableList<KBArticle>(kbArticles);
  }
Example #29
0
  public static String getAssetKeywords(String className, long classPK) {
    List<AssetTag> tags = AssetTagLocalServiceUtil.getTags(className, classPK);
    List<AssetCategory> categories =
        AssetCategoryLocalServiceUtil.getCategories(className, classPK);

    StringBuffer sb = new StringBuffer();

    sb.append(ListUtil.toString(tags, AssetTag.NAME_ACCESSOR));

    if (!tags.isEmpty()) {
      sb.append(StringPool.COMMA);
    }

    sb.append(ListUtil.toString(categories, AssetCategory.NAME_ACCESSOR));

    return sb.toString();
  }
  @Override
  public List<String> getConfigLocations() {
    List<String> configLocations = ListUtil.fromArray(PropsUtil.getArray(PropsKeys.SPRING_CONFIGS));

    configLocations.remove("META-INF/model-listener-spring.xml");

    return configLocations;
  }