コード例 #1
0
  protected List<Layout> getCandidateLayouts(long plid, boolean privateLayout, KBArticle kbArticle)
      throws Exception {

    List<Layout> candidateLayouts = new ArrayList<>();

    Group group = GroupLocalServiceUtil.getGroup(kbArticle.getGroupId());

    if (group.isLayout()) {
      Layout layout = LayoutLocalServiceUtil.getLayout(group.getClassPK());

      candidateLayouts.add(layout);

      group = layout.getGroup();
    }

    List<Layout> layouts =
        LayoutLocalServiceUtil.getLayouts(
            group.getGroupId(), privateLayout, LayoutConstants.TYPE_PORTLET);

    candidateLayouts.addAll(layouts);

    Layout layout = LayoutLocalServiceUtil.getLayout(plid);

    if ((layout.getGroupId() == kbArticle.getGroupId()) && layout.isTypePortlet()) {

      candidateLayouts.remove(layout);
      candidateLayouts.add(0, layout);
    }

    return candidateLayouts;
  }
コード例 #2
0
  protected int[] getRoleTypes(long companyId, Group group, String modelResource) {

    int[] types = RoleConstants.TYPES_REGULAR_AND_SITE;

    if (isPortalModelResource(modelResource)) {
      if (modelResource.equals(Organization.class.getName())
          || modelResource.equals(User.class.getName())) {

        types = RoleConstants.TYPES_ORGANIZATION_AND_REGULAR;
      } else {
        types = RoleConstants.TYPES_REGULAR;
      }
    } else {
      if (group != null) {
        if (group.isLayout()) {
          try {
            group = GroupServiceUtil.getGroup(group.getParentGroupId());
          } catch (Exception e) {
          }
        }

        if (group.isOrganization()) {
          types = RoleConstants.TYPES_ORGANIZATION_AND_REGULAR_AND_SITE;
        } else if (group.isUser()) {
          types = RoleConstants.TYPES_REGULAR;
        }
      }
    }

    return types;
  }
コード例 #3
0
  /**
   * Returns the default role for the group with the primary key.
   *
   * <p>If the group is a site, then the default role is {@link
   * com.liferay.portal.model.RoleConstants#SITE_MEMBER}. If the group is an organization, then the
   * default role is {@link com.liferay.portal.model.RoleConstants#ORGANIZATION_USER}. If the group
   * is a user or user group, then the default role is {@link
   * com.liferay.portal.model.RoleConstants#POWER_USER}. For all other group types, the default role
   * is {@link com.liferay.portal.model.RoleConstants#USER}.
   *
   * @param groupId the primary key of the group
   * @return the default role for the group with the primary key
   * @throws PortalException if a group with the primary key could not be found, or if a default
   *     role could not be found for the group
   * @throws SystemException if a system exception occurred
   */
  public Role getDefaultGroupRole(long groupId) throws PortalException, SystemException {

    Group group = groupPersistence.findByPrimaryKey(groupId);

    if (group.isLayout()) {
      Layout layout = layoutLocalService.getLayout(group.getClassPK());

      group = layout.getGroup();
    }

    if (group.isStagingGroup()) {
      group = group.getLiveGroup();
    }

    Role role = null;

    if (group.isCompany()) {
      role = getRole(group.getCompanyId(), RoleConstants.USER);
    } else if (group.isLayoutPrototype()
        || group.isLayoutSetPrototype()
        || group.isRegularSite()
        || group.isSite()) {

      role = getRole(group.getCompanyId(), RoleConstants.SITE_MEMBER);
    } else if (group.isOrganization()) {
      role = getRole(group.getCompanyId(), RoleConstants.ORGANIZATION_USER);
    } else if (group.isUser() || group.isUserGroup()) {
      role = getRole(group.getCompanyId(), RoleConstants.POWER_USER);
    } else {
      role = getRole(group.getCompanyId(), RoleConstants.USER);
    }

    return role;
  }
コード例 #4
0
  public long getDDMTemplateGroupId(ThemeDisplay themeDisplay) {
    try {
      Group scopeGroup = themeDisplay.getScopeGroup();

      if (scopeGroup.isLayout()) {
        scopeGroup = scopeGroup.getParentGroup();
      }

      if (scopeGroup.isStagingGroup()) {
        Group liveGroup = scopeGroup.getLiveGroup();

        if (!liveGroup.isStagedPortlet(PortletKeys.PORTLET_DISPLAY_TEMPLATES)) {

          return liveGroup.getGroupId();
        }
      }

      return scopeGroup.getGroupId();
    } catch (Exception e) {
      if (_log.isWarnEnabled()) {
        _log.warn(e, e);
      }
    }

    return themeDisplay.getScopeGroupId();
  }
コード例 #5
0
  @Override
  public String getScopeId(Group group, long scopeGroupId) throws PortalException, SystemException {

    String key = null;

    if (group.isLayout()) {
      Layout layout = LayoutLocalServiceUtil.getLayout(group.getClassPK());

      key = SCOPE_ID_LAYOUT_UUID_PREFIX + layout.getUuid();
    } else if (group.isLayoutPrototype() || (group.getGroupId() == scopeGroupId)) {

      key = SCOPE_ID_GROUP_PREFIX + GroupConstants.DEFAULT;
    } else {
      Group scopeGroup = GroupLocalServiceUtil.getGroup(scopeGroupId);

      if (scopeGroup.hasAncestor(group.getGroupId())) {
        key = SCOPE_ID_PARENT_GROUP_PREFIX + group.getGroupId();
      } else if (group.hasAncestor(scopeGroup.getGroupId())) {
        key = SCOPE_ID_CHILD_GROUP_PREFIX + group.getGroupId();
      } else {
        key = SCOPE_ID_GROUP_PREFIX + group.getGroupId();
      }
    }

    return key;
  }
コード例 #6
0
  @Override
  public long getDDMTemplateGroupId(long groupId) {
    try {
      Group group = GroupLocalServiceUtil.getGroup(groupId);

      if (group.isLayout()) {
        group = group.getParentGroup();
      }

      if (group.isStagingGroup()) {
        Group liveGroup = group.getLiveGroup();

        if (!liveGroup.isStagedPortlet(PortletKeys.PORTLET_DISPLAY_TEMPLATE)) {

          return liveGroup.getGroupId();
        }
      }

      return group.getGroupId();
    } catch (Exception e) {
      if (_log.isWarnEnabled()) {
        _log.warn(e, e);
      }
    }

    return groupId;
  }
コード例 #7
0
  protected boolean hasLayoutGroup(long[] groupIds) throws SystemException {
    for (long groupId : groupIds) {
      Group group = GroupLocalServiceUtil.fetchGroup(groupId);

      if ((group != null) && group.isLayout()) {
        return true;
      }
    }

    return false;
  }
コード例 #8
0
  public static long[] getGroupIds(long groupId) throws PortalException, SystemException {

    Group scopeGroup = GroupLocalServiceUtil.getGroup(groupId);

    Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(scopeGroup.getCompanyId());

    if (scopeGroup.isLayout()) {
      return new long[] {scopeGroup.getParentGroupId(), companyGroup.getGroupId()};
    } else {
      return new long[] {groupId, companyGroup.getGroupId()};
    }
  }
コード例 #9
0
ファイル: TrashImpl.java プロジェクト: Brokk88/liferay-portal
  public int getMaxAge(Group group) throws PortalException, SystemException {
    if (group.isLayout()) {
      group = group.getParentGroup();
    }

    int trashEntriesMaxAge =
        PrefsPropsUtil.getInteger(
            group.getCompanyId(),
            PropsKeys.TRASH_ENTRIES_MAX_AGE,
            GetterUtil.getInteger(PropsUtil.get(PropsKeys.TRASH_ENTRIES_MAX_AGE)));

    UnicodeProperties typeSettingsProperties = group.getTypeSettingsProperties();

    return GetterUtil.getInteger(
        typeSettingsProperties.getProperty("trashEntriesMaxAge"), trashEntriesMaxAge);
  }
コード例 #10
0
  public Hits search(
      long companyId,
      long userId,
      String portletId,
      long groupId,
      long[] repositoryIds,
      String keywords,
      int start,
      int end) {

    try {
      SearchContext searchContext = new SearchContext();

      searchContext.setCompanyId(companyId);
      searchContext.setEnd(end);
      searchContext.setEntryClassNames(new String[] {DLFileEntryConstants.getClassName()});
      searchContext.setGroupIds(new long[] {groupId});

      Indexer indexer = IndexerRegistryUtil.getIndexer(DLFileEntryConstants.getClassName());

      searchContext.setSearchEngineId(indexer.getSearchEngineId());

      searchContext.setStart(start);
      searchContext.setUserId(userId);

      BooleanQuery contextQuery = BooleanQueryFactoryUtil.create(searchContext);

      contextQuery.addRequiredTerm(Field.PORTLET_ID, portletId);

      if (groupId > 0) {
        Group group = groupLocalService.getGroup(groupId);

        if (group.isLayout()) {
          contextQuery.addRequiredTerm(Field.SCOPE_GROUP_ID, groupId);

          groupId = group.getParentGroupId();
        }

        contextQuery.addRequiredTerm(Field.GROUP_ID, groupId);
      }

      if (ArrayUtil.isNotEmpty(repositoryIds)) {
        BooleanQuery repositoryIdsQuery = BooleanQueryFactoryUtil.create(searchContext);

        for (long repositoryId : repositoryIds) {
          try {
            if (userId > 0) {
              PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();

              DLFolderPermission.check(permissionChecker, groupId, repositoryId, ActionKeys.VIEW);
            }

            if (repositoryId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

              repositoryId = groupId;
            }

            TermQuery termQuery =
                TermQueryFactoryUtil.create(searchContext, "repositoryId", repositoryId);

            repositoryIdsQuery.add(termQuery, BooleanClauseOccur.SHOULD);
          } catch (Exception e) {
          }
        }

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

      BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext);

      searchQuery.addTerms(_KEYWORDS_FIELDS, keywords);

      BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext);

      fullQuery.add(contextQuery, BooleanClauseOccur.MUST);

      List<BooleanClause> clauses = searchQuery.clauses();

      if (!clauses.isEmpty()) {
        fullQuery.add(searchQuery, BooleanClauseOccur.MUST);
      }

      return SearchEngineUtil.search(searchContext, fullQuery);
    } catch (Exception e) {
      throw new SystemException(e);
    }
  }
  /**
   * Records an activity with the given time in the database.
   *
   * <p>This method records a social activity done on an asset, identified by its class name and
   * class primary key, in the database. Additional information (such as the original message ID for
   * a reply to a forum post) is passed in via the <code>extraData</code> in JSON format. For
   * activities affecting another user, a mirror activity is generated that describes the action
   * from the user's point of view. The target user's ID is passed in via the <code>receiverUserId
   * </code>.
   *
   * <p>Example for a mirrored activity:<br>
   * When a user replies to a message boards post, the reply action is stored in the database with
   * the <code>receiverUserId</code> being the ID of the author of the original message. The <code>
   * extraData</code> contains the ID of the original message in JSON format. A mirror activity is
   * generated with the values of the <code>userId</code> and the <code>receiverUserId</code>
   * swapped. This mirror activity basically describes a "replied to" event.
   *
   * <p>Mirror activities are most often used in relation to friend requests and activities.
   *
   * @param userId the primary key of the acting user
   * @param groupId the primary key of the group
   * @param createDate the activity's date
   * @param className the target asset's class name
   * @param classPK the primary key of the target asset
   * @param type the activity's type
   * @param extraData any extra data regarding the activity
   * @param receiverUserId the primary key of the receiving user
   * @throws PortalException if the user or group could not be found
   */
  @Override
  public void addActivity(
      long userId,
      long groupId,
      Date createDate,
      String className,
      long classPK,
      int type,
      String extraData,
      long receiverUserId)
      throws PortalException {

    if (ExportImportThreadLocal.isImportInProcess()) {
      return;
    }

    User user = userPersistence.findByPrimaryKey(userId);
    long classNameId = classNameLocalService.getClassNameId(className);

    if (groupId > 0) {
      Group group = groupLocalService.getGroup(groupId);

      if (group.isLayout()) {
        Layout layout = layoutLocalService.getLayout(group.getClassPK());

        groupId = layout.getGroupId();
      }
    }

    final SocialActivity activity = socialActivityPersistence.create(0);

    activity.setGroupId(groupId);
    activity.setCompanyId(user.getCompanyId());
    activity.setUserId(user.getUserId());
    activity.setCreateDate(createDate.getTime());
    activity.setMirrorActivityId(0);
    activity.setClassNameId(classNameId);
    activity.setClassPK(classPK);

    SocialActivityHierarchyEntry activityHierarchyEntry =
        SocialActivityHierarchyEntryThreadLocal.peek();

    if (activityHierarchyEntry != null) {
      activity.setParentClassNameId(activityHierarchyEntry.getClassNameId());
      activity.setParentClassPK(activityHierarchyEntry.getClassPK());
    }

    activity.setType(type);
    activity.setExtraData(extraData);
    activity.setReceiverUserId(receiverUserId);

    AssetEntry assetEntry = assetEntryPersistence.fetchByC_C(classNameId, classPK);

    activity.setAssetEntry(assetEntry);

    SocialActivity mirrorActivity = null;

    if ((receiverUserId > 0) && (userId != receiverUserId)) {
      mirrorActivity = socialActivityPersistence.create(0);

      mirrorActivity.setGroupId(groupId);
      mirrorActivity.setCompanyId(user.getCompanyId());
      mirrorActivity.setUserId(receiverUserId);
      mirrorActivity.setCreateDate(createDate.getTime());
      mirrorActivity.setClassNameId(classNameId);
      mirrorActivity.setClassPK(classPK);

      if (activityHierarchyEntry != null) {
        mirrorActivity.setParentClassNameId(activityHierarchyEntry.getClassNameId());
        mirrorActivity.setParentClassPK(activityHierarchyEntry.getClassPK());
      }

      mirrorActivity.setType(type);
      mirrorActivity.setExtraData(extraData);
      mirrorActivity.setReceiverUserId(user.getUserId());
      mirrorActivity.setAssetEntry(assetEntry);
    }

    final SocialActivity finalMirrorActivity = mirrorActivity;

    Callable<Void> callable =
        new Callable<Void>() {

          @Override
          public Void call() throws Exception {
            socialActivityLocalService.addActivity(activity, finalMirrorActivity);

            return null;
          }
        };

    TransactionCommitCallbackUtil.registerCallback(callable);
  }
コード例 #12
0
  /**
   * Records an activity with the given time in the database.
   *
   * <p>This method records a social activity done on an asset, identified by its class name and
   * class primary key, in the database. Additional information (such as the original message ID for
   * a reply to a forum post) is passed in via the <code>extraData</code> in JSON format. For
   * activities affecting another user, a mirror activity is generated that describes the action
   * from the user's point of view. The target user's ID is passed in via the <code>receiverUserId
   * </code>.
   *
   * <p>Example for a mirrored activity:<br>
   * When a user replies to a message boards post, the reply action is stored in the database with
   * the <code>receiverUserId</code> being the ID of the author of the original message. The <code>
   * extraData</code> contains the ID of the original message in JSON format. A mirror activity is
   * generated with the values of the <code>userId</code> and the <code>receiverUserId</code>
   * swapped. This mirror activity basically describes a "replied to" event.
   *
   * <p>Mirror activities are most often used in relation to friend requests and activities.
   *
   * @param userId the primary key of the acting user
   * @param groupId the primary key of the group
   * @param createDate the activity's date
   * @param className the target asset's class name
   * @param classPK the primary key of the target asset
   * @param type the activity's type
   * @param extraData any extra data regarding the activity
   * @param receiverUserId the primary key of the receiving user
   * @throws PortalException if the user or group could not be found
   * @throws SystemException if a system exception occurred
   */
  public void addActivity(
      long userId,
      long groupId,
      Date createDate,
      String className,
      long classPK,
      int type,
      String extraData,
      long receiverUserId)
      throws PortalException, SystemException {

    if (ImportExportThreadLocal.isImportInProcess()) {
      return;
    }

    User user = userPersistence.findByPrimaryKey(userId);
    long classNameId = PortalUtil.getClassNameId(className);

    if (groupId > 0) {
      Group group = groupLocalService.getGroup(groupId);

      if (group.isLayout()) {
        Layout layout = layoutLocalService.getLayout(group.getClassPK());

        groupId = layout.getGroupId();
      }
    }

    SocialActivity activity = socialActivityPersistence.create(0);

    activity.setGroupId(groupId);
    activity.setCompanyId(user.getCompanyId());
    activity.setUserId(user.getUserId());
    activity.setCreateDate(createDate.getTime());
    activity.setMirrorActivityId(0);
    activity.setClassNameId(classNameId);
    activity.setClassPK(classPK);
    activity.setType(type);
    activity.setExtraData(extraData);
    activity.setReceiverUserId(receiverUserId);

    AssetEntry assetEntry = assetEntryPersistence.fetchByC_C(classNameId, classPK);

    activity.setAssetEntry(assetEntry);

    SocialActivity mirrorActivity = null;

    if ((receiverUserId > 0) && (userId != receiverUserId)) {
      mirrorActivity = socialActivityPersistence.create(0);

      mirrorActivity.setGroupId(groupId);
      mirrorActivity.setCompanyId(user.getCompanyId());
      mirrorActivity.setUserId(receiverUserId);
      mirrorActivity.setCreateDate(createDate.getTime());
      mirrorActivity.setClassNameId(classNameId);
      mirrorActivity.setClassPK(classPK);
      mirrorActivity.setType(type);
      mirrorActivity.setExtraData(extraData);
      mirrorActivity.setReceiverUserId(user.getUserId());
      mirrorActivity.setAssetEntry(assetEntry);
    }

    socialActivityLocalService.addActivity(activity, mirrorActivity);
  }
コード例 #13
0
  protected PortletPreferences getPortletSetup(
      long siteGroupId,
      Layout layout,
      String portletId,
      String defaultPreferences,
      boolean strictMode) {

    String originalPortletId = portletId;

    Portlet portlet = PortletLocalServiceUtil.getPortletById(layout.getCompanyId(), portletId);

    boolean uniquePerLayout = false;
    boolean uniquePerGroup = false;

    if (portlet.isPreferencesCompanyWide()) {
      portletId = PortletConstants.getRootPortletId(portletId);
    } else {
      if (portlet.isPreferencesUniquePerLayout()) {
        uniquePerLayout = true;

        if (portlet.isPreferencesOwnedByGroup()) {
          uniquePerGroup = true;
        }
      } else {
        if (portlet.isPreferencesOwnedByGroup()) {
          uniquePerGroup = true;
          portletId = PortletConstants.getRootPortletId(portletId);
        }
      }
    }

    long ownerId = PortletKeys.PREFS_OWNER_ID_DEFAULT;
    int ownerType = PortletKeys.PREFS_OWNER_TYPE_LAYOUT;
    long plid = layout.getPlid();

    Group group = GroupLocalServiceUtil.fetchGroup(siteGroupId);

    if ((group != null) && group.isLayout()) {
      plid = group.getClassPK();
    }

    if (PortletConstants.hasUserId(originalPortletId)) {
      ownerId = PortletConstants.getUserId(originalPortletId);
      ownerType = PortletKeys.PREFS_OWNER_TYPE_USER;
    } else if (!uniquePerLayout) {
      plid = PortletKeys.PREFS_PLID_SHARED;

      if (uniquePerGroup) {
        if (siteGroupId > LayoutConstants.DEFAULT_PLID) {
          ownerId = siteGroupId;
        } else {
          ownerId = layout.getGroupId();
        }

        ownerType = PortletKeys.PREFS_OWNER_TYPE_GROUP;
      } else {
        ownerId = layout.getCompanyId();
        ownerType = PortletKeys.PREFS_OWNER_TYPE_COMPANY;
      }
    }

    if (strictMode) {
      return PortletPreferencesLocalServiceUtil.getStrictPreferences(
          layout.getCompanyId(), ownerId, ownerType, plid, portletId);
    }

    return PortletPreferencesLocalServiceUtil.getPreferences(
        layout.getCompanyId(), ownerId, ownerType, plid, portletId, defaultPreferences);
  }