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;
  }
  protected void trashFileEntry() throws Exception {
    Group group = ServiceTestUtil.addGroup();

    ServiceContext serviceContext = ServiceTestUtil.getServiceContext();

    serviceContext.setScopeGroupId(group.getGroupId());

    BaseModel<?> parentBaseModel = getParentBaseModel(group, serviceContext);

    int initialBaseModelsCount = getBaseModelsNotInTrashCount(parentBaseModel);
    int initialTrashEntriesCount = getTrashEntriesCount(group.getGroupId());

    BaseModel<?> baseModel = addBaseModel(parentBaseModel, true, serviceContext);

    DLFileShortcut dlFileShortcut = (DLFileShortcut) baseModel;

    FileEntry fileEntry = DLAppServiceUtil.getFileEntry(dlFileShortcut.getToFileEntryId());

    Assert.assertEquals(initialBaseModelsCount + 1, getBaseModelsNotInTrashCount(parentBaseModel));
    Assert.assertEquals(initialTrashEntriesCount, getTrashEntriesCount(group.getGroupId()));

    DLAppServiceUtil.moveFileEntryToTrash(fileEntry.getFileEntryId());

    Assert.assertEquals(initialBaseModelsCount, getBaseModelsNotInTrashCount(parentBaseModel));
    Assert.assertEquals(initialTrashEntriesCount + 1, getTrashEntriesCount(group.getGroupId()));

    DLAppServiceUtil.restoreFileEntryFromTrash(fileEntry.getFileEntryId());

    Assert.assertEquals(initialBaseModelsCount + 1, getBaseModelsNotInTrashCount(parentBaseModel));
  }
  protected String[] getStaticPortletIds(String position) throws PortalException {

    Layout layout = getLayout();

    String selector1 = StringPool.BLANK;

    Group group = layout.getGroup();

    if (group.isUser()) {
      selector1 = LayoutTypePortletConstants.STATIC_PORTLET_USER_SELECTOR;
    } else if (group.isOrganization()) {
      selector1 = LayoutTypePortletConstants.STATIC_PORTLET_ORGANIZATION_SELECTOR;
    } else if (group.isRegularSite()) {
      selector1 = LayoutTypePortletConstants.STATIC_PORTLET_REGULAR_SITE_SELECTOR;
    }

    String selector2 = layout.getFriendlyURL();

    String[] portletIds = PropsUtil.getArray(position, new Filter(selector1, selector2));

    for (int i = 0; i < portletIds.length; i++) {
      portletIds[i] = JS.getSafeName(portletIds[i]);
    }

    return portletIds;
  }
Esempio n. 4
0
  public static long getGroupId(long companyId, String[] pathArray) throws WebDAVException {

    try {
      if (pathArray.length == 0) {
        return 0;
      }

      String name = pathArray[0];

      Group group = GroupLocalServiceUtil.fetchFriendlyURLGroup(companyId, StringPool.SLASH + name);

      if (group != null) {
        return group.getGroupId();
      }

      User user = UserLocalServiceUtil.fetchUserByScreenName(companyId, name);

      if (user != null) {
        group = user.getGroup();

        return group.getGroupId();
      }
    } catch (Exception e) {
      throw new WebDAVException(e);
    }

    return 0;
  }
Esempio n. 5
0
  public static Layout addLayout(
      Group group,
      boolean privateLayout,
      long parentLayoutId,
      String name,
      String friendlyURL,
      String layoutTemplateId)
      throws Exception {

    ServiceContext serviceContext = new ServiceContext();

    Layout layout =
        LayoutLocalServiceUtil.addLayout(
            group.getCreatorUserId(),
            group.getGroupId(),
            privateLayout,
            parentLayoutId,
            name,
            StringPool.BLANK,
            StringPool.BLANK,
            LayoutConstants.TYPE_PORTLET,
            false,
            friendlyURL,
            serviceContext);

    LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

    layoutTypePortlet.setLayoutTemplateId(0, layoutTemplateId, false);

    return LayoutLocalServiceUtil.updateLayout(
        layout.getGroupId(),
        layout.isPrivateLayout(),
        layout.getLayoutId(),
        layout.getTypeSettings());
  }
  @Override
  protected void doUpgrade() throws Exception {
    List<User> users = UserLocalServiceUtil.getUsers(QueryUtil.ALL_POS, QueryUtil.ALL_POS);

    for (User user : users) {
      try {
        if (user.isDefaultUser()) {
          continue;
        }

        Group group = user.getGroup();

        LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(group.getGroupId(), false);

        String themeId = layoutSet.getThemeId();

        if (!themeId.equals("so_WAR_sotheme")) {
          return;
        }

        Role role =
            RoleLocalServiceUtil.getRole(user.getCompanyId(), RoleConstants.SOCIAL_OFFICE_USER);

        UserLocalServiceUtil.addRoleUsers(role.getRoleId(), new long[] {user.getUserId()});

        updateUserGroup(group);
        updateSocialRelations(user);
      } catch (Exception e) {
      }
    }
  }
  protected void initNewLayoutPermissions(
      long companyId,
      long groupId,
      long userId,
      Layout layout,
      Layout importedLayout,
      boolean privateLayout)
      throws Exception {

    boolean addGroupPermissions = true;

    Group group = importedLayout.getGroup();

    if (privateLayout && group.isUser()) {
      addGroupPermissions = false;
    }

    boolean addGuestPermissions = false;

    if (!privateLayout || layout.isTypeControlPanel()) {
      addGuestPermissions = true;
    }

    _resourceLocalService.addResources(
        companyId,
        groupId,
        userId,
        Layout.class.getName(),
        importedLayout.getPlid(),
        false,
        addGroupPermissions,
        addGuestPermissions);
  }
  @Test
  public void testLocalizedSiteAddFileEntryType() throws Exception {
    Group group = GroupTestUtil.addGroup();

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId());

    Locale locale = LocaleThreadLocal.getSiteDefaultLocale();

    try {
      LocaleThreadLocal.setSiteDefaultLocale(LocaleUtil.SPAIN);

      String name = RandomTestUtil.randomString();
      String description = RandomTestUtil.randomString();
      DDMStructure ddmStructure =
          DDMStructureTestUtil.addStructure(
              DLFileEntry.class.getName(), new Locale[] {LocaleUtil.SPAIN}, LocaleUtil.SPAIN);

      DLFileEntryType dlFileEntryType =
          DLFileEntryTypeLocalServiceUtil.addFileEntryType(
              TestPropsValues.getUserId(),
              group.getGroupId(),
              name,
              description,
              new long[] {ddmStructure.getStructureId()},
              serviceContext);

      Assert.assertEquals(name, dlFileEntryType.getName(LocaleUtil.US, true));
      Assert.assertEquals(description, dlFileEntryType.getDescription(LocaleUtil.US, true));
    } finally {
      LocaleThreadLocal.setSiteDefaultLocale(locale);
    }
  }
  protected PortletDataContext createPortletDataContext(long companyId, long groupId) {

    PortletDataContext portletDataContext = new PortletDataContextImpl();

    try {
      Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(companyId);

      portletDataContext.setCompanyGroupId(companyGroup.getGroupId());
    } catch (Exception e) {
      throw new IllegalStateException(e);
    }

    portletDataContext.setCompanyId(companyId);
    portletDataContext.setGroupId(groupId);
    portletDataContext.setScopeGroupId(groupId);

    try {
      Group userPersonalSiteGroup = GroupLocalServiceUtil.getUserPersonalSiteGroup(companyId);

      portletDataContext.setUserPersonalSiteGroupId(userPersonalSiteGroup.getGroupId());
    } catch (Exception e) {
      throw new IllegalStateException(e);
    }

    return portletDataContext;
  }
  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;
  }
  @Before
  public void setUp() throws Exception {
    Group group = GroupTestUtil.addGroup();

    companyId = group.getCompanyId();
    groupId = group.getGroupId();
  }
  protected Map<String, List<StagedModel>> addCompanyDependencies() throws Exception {

    Map<String, List<StagedModel>> dependentStagedModelsMap = new HashMap<>();

    Company company = CompanyLocalServiceUtil.fetchCompany(stagingGroup.getCompanyId());

    Group companyGroup = company.getGroup();

    DDMStructure ddmStructure =
        DDMStructureTestUtil.addStructure(
            companyGroup.getGroupId(), DLFileEntryType.class.getName());

    addDependentStagedModel(dependentStagedModelsMap, DDMStructure.class, ddmStructure);

    DLFileEntryType dlFileEntryType =
        DLAppTestUtil.addDLFileEntryType(companyGroup.getGroupId(), ddmStructure.getStructureId());

    addDependentStagedModel(dependentStagedModelsMap, DLFileEntryType.class, dlFileEntryType);

    Folder folder =
        DLAppTestUtil.addFolder(
            stagingGroup.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);

    addDependentStagedModel(dependentStagedModelsMap, DLFolder.class, folder);

    return dependentStagedModelsMap;
  }
  @Override
  protected void validateImport(
      Map<String, List<StagedModel>> dependentStagedModelsMap, Group group) throws Exception {

    List<StagedModel> ddmStructureDependentStagedModels =
        dependentStagedModelsMap.get(DDMStructure.class.getSimpleName());

    Assert.assertEquals(1, ddmStructureDependentStagedModels.size());

    DDMStructure ddmStructure = (DDMStructure) ddmStructureDependentStagedModels.get(0);

    DDMStructureLocalServiceUtil.getDDMStructureByUuidAndGroupId(
        ddmStructure.getUuid(), group.getGroupId());

    List<StagedModel> dlFileEntryTypesDependentStagedModels =
        dependentStagedModelsMap.get(DLFileEntryType.class.getSimpleName());

    Assert.assertEquals(1, dlFileEntryTypesDependentStagedModels.size());

    DLFileEntryType dlFileEntryType =
        (DLFileEntryType) dlFileEntryTypesDependentStagedModels.get(0);

    DLFileEntryTypeLocalServiceUtil.getDLFileEntryTypeByUuidAndGroupId(
        dlFileEntryType.getUuid(), group.getGroupId());

    List<StagedModel> folderDependentStagedModels =
        dependentStagedModelsMap.get(DLFolder.class.getSimpleName());

    Assert.assertEquals(1, folderDependentStagedModels.size());

    Folder parentFolder = (Folder) folderDependentStagedModels.get(0);

    DLFolderLocalServiceUtil.getDLFolderByUuidAndGroupId(
        parentFolder.getUuid(), group.getGroupId());
  }
  protected void validateCompanyDependenciesImport(
      Map<String, List<StagedModel>> dependentStagedModelsMap, Group group) throws Exception {

    List<StagedModel> ddmStructureDependentStagedModels =
        dependentStagedModelsMap.get(DDMStructure.class.getSimpleName());

    Assert.assertEquals(1, ddmStructureDependentStagedModels.size());

    DDMStructure ddmStructure = (DDMStructure) ddmStructureDependentStagedModels.get(0);

    Assert.assertNull(
        "Company DDM structure dependency should not be imported",
        DDMStructureLocalServiceUtil.fetchDDMStructureByUuidAndGroupId(
            ddmStructure.getUuid(), group.getGroupId()));

    List<StagedModel> dlFileEntryTypesDependentStagedModels =
        dependentStagedModelsMap.get(DLFileEntryType.class.getSimpleName());

    Assert.assertEquals(1, dlFileEntryTypesDependentStagedModels.size());

    DLFileEntryType dlFileEntryType =
        (DLFileEntryType) dlFileEntryTypesDependentStagedModels.get(0);

    Assert.assertNull(
        "Company DL file entry should not be imported",
        DLFileEntryTypeLocalServiceUtil.fetchDLFileEntryTypeByUuidAndGroupId(
            dlFileEntryType.getUuid(), group.getGroupId()));
  }
  /**
   * 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);
  }
Esempio n. 16
0
  /** @deprecated As of 6.2.0, replaced by {@link #getUserName(long, ServiceContext)} */
  protected String getUserName(long userId, ThemeDisplay themeDisplay) {
    try {
      if (userId <= 0) {
        return StringPool.BLANK;
      }

      User user = UserLocalServiceUtil.getUserById(userId);

      if (user.getUserId() == themeDisplay.getUserId()) {
        return HtmlUtil.escape(user.getFirstName());
      }

      String userName = user.getFullName();

      Group group = user.getGroup();

      if (group.getGroupId() == themeDisplay.getScopeGroupId()) {
        return HtmlUtil.escape(userName);
      }

      String userDisplayURL = user.getDisplayURL(themeDisplay);

      userName =
          "******"user\" href=\"" + userDisplayURL + "\">" + HtmlUtil.escape(userName) + "</a>";

      return userName;
    } catch (Exception e) {
      return StringPool.BLANK;
    }
  }
  /**
   * Updates the group's type settings.
   *
   * @param groupId the primary key of the group
   * @param typeSettings the group's new type settings (optionally <code>null</code>)
   * @return the group
   * @throws PortalException if a portal exception occurred
   */
  @Override
  public Group updateGroup(long groupId, String typeSettings) throws PortalException {

    Group group = groupPersistence.findByPrimaryKey(groupId);

    GroupPermissionUtil.check(getPermissionChecker(), group, ActionKeys.UPDATE);

    if (group.isSite()) {
      Group oldGroup = group;

      UnicodeProperties oldTypeSettingsProperties = oldGroup.getTypeSettingsProperties();

      group = groupLocalService.updateGroup(groupId, typeSettings);

      RatingsDataTransformerUtil.transformGroupRatingsData(
          groupId, oldTypeSettingsProperties, group.getTypeSettingsProperties());

      SiteMembershipPolicyUtil.verifyPolicy(
          group, oldGroup, null, null, null, oldTypeSettingsProperties);

      return group;
    } else {
      return groupLocalService.updateGroup(groupId, typeSettings);
    }
  }
  private void _getFolders(CommandArgument commandArgument, Document document, Node rootNode)
      throws Exception {

    Element foldersElement = document.createElement("Folders");

    rootNode.appendChild(foldersElement);

    if (commandArgument.getCurrentFolder().equals(StringPool.SLASH)) {
      getRootFolders(commandArgument, document, foldersElement);
    } else {
      Group group = commandArgument.getCurrentGroup();

      Folder folder = _getFolder(group.getGroupId(), commandArgument.getCurrentFolder());

      List<Folder> folders = DLAppServiceUtil.getFolders(group.getGroupId(), folder.getFolderId());

      for (Folder curFolder : folders) {
        Element folderElement = document.createElement("Folder");

        foldersElement.appendChild(folderElement);

        folderElement.setAttribute("name", curFolder.getName());
      }
    }
  }
  protected void fixImportTypeSettings(Layout layout) throws Exception {
    Object[] friendlyURLInfo = extractFriendlyURLInfo(layout);

    if (friendlyURLInfo == null) {
      return;
    }

    String friendlyURL = (String) friendlyURLInfo[0];

    if (!friendlyURL.equals(_SAME_GROUP_FRIENDLY_URL)) {
      return;
    }

    Group group = layout.getGroup();

    UnicodeProperties typeSettings = layout.getTypeSettingsProperties();

    String url = (String) friendlyURLInfo[1];

    int x = (Integer) friendlyURLInfo[2];
    int y = (Integer) friendlyURLInfo[3];

    typeSettings.setProperty(
        "url", url.substring(0, x) + group.getFriendlyURL() + url.substring(y));
  }
  protected String fileUpload(
      CommandArgument commandArgument, String fileName, File file, String extension) {

    try {
      Group group = commandArgument.getCurrentGroup();

      Folder folder = _getFolder(group.getGroupId(), commandArgument.getCurrentFolder());

      long folderId = folder.getFolderId();
      String title = fileName;
      String description = StringPool.BLANK;
      String changeLog = StringPool.BLANK;

      ServiceContext serviceContext = new ServiceContext();

      serviceContext.setAddCommunityPermissions(true);
      serviceContext.setAddGuestPermissions(true);

      DLAppServiceUtil.addFileEntry(
          group.getGroupId(), folderId, title, description, changeLog, file, serviceContext);
    } catch (Exception e) {
      throw new FCKException(e);
    }

    return "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;
  }
  /** @deprecated As of 7.0.0, with no direct replacement */
  @Deprecated
  @Override
  public SyncDLObjectUpdate getAllSyncDLObjects(long repositoryId, long folderId)
      throws PortalException {

    try {
      SyncUtil.checkSyncEnabled(repositoryId);

      long lastAccessTime = System.currentTimeMillis();

      long companyId = 0;

      Repository repository = repositoryLocalService.fetchRepository(repositoryId);

      if (repository != null) {
        companyId = repository.getCompanyId();
      } else {
        Group group = groupLocalService.getGroup(repositoryId);

        companyId = group.getCompanyId();
      }

      List<SyncDLObject> syncDLObjects =
          syncDLObjectPersistence.findByC_M_R(companyId, 0, repositoryId);

      return new SyncDLObjectUpdate(syncDLObjects, lastAccessTime);
    } catch (PortalException pe) {
      throw new PortalException(SyncUtil.buildExceptionMessage(pe), pe);
    }
  }
  @Override
  public String getURLViewInContext(
      LiferayPortletRequest liferayPortletRequest,
      LiferayPortletResponse liferayPortletResponse,
      String noSuchEntryRedirect)
      throws Exception {

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

    Layout layout = themeDisplay.getLayout();

    if (Validator.isNotNull(_article.getLayoutUuid())) {
      layout =
          LayoutLocalServiceUtil.getLayoutByUuidAndCompanyId(
              _article.getLayoutUuid(), _article.getCompanyId());
    }

    String portletId = (String) liferayPortletRequest.getAttribute(WebKeys.PORTLET_ID);

    PortletPreferences portletSetup =
        PortletPreferencesFactoryUtil.getLayoutPortletSetup(layout, portletId);

    String linkToLayoutUuid =
        GetterUtil.getString(portletSetup.getValue("portletSetupLinkToLayoutUuid", null));

    if (Validator.isNotNull(_article.getLayoutUuid()) && Validator.isNull(linkToLayoutUuid)) {

      Group group = themeDisplay.getScopeGroup();

      if (group.getGroupId() != _article.getGroupId()) {
        group = GroupLocalServiceUtil.getGroup(_article.getGroupId());
      }

      String groupFriendlyURL =
          PortalUtil.getGroupFriendlyURL(group, layout.isPrivateLayout(), themeDisplay);

      return PortalUtil.addPreservedParameters(
          themeDisplay,
          groupFriendlyURL
              .concat(JournalArticleConstants.CANONICAL_URL_SEPARATOR)
              .concat(_article.getUrlTitle()));
    }

    List<Long> hitLayoutIds =
        JournalContentSearchLocalServiceUtil.getLayoutIds(
            _article.getGroupId(), layout.isPrivateLayout(), _article.getArticleId());

    if (!hitLayoutIds.isEmpty()) {
      Long hitLayoutId = hitLayoutIds.get(0);

      Layout hitLayout =
          LayoutLocalServiceUtil.getLayout(
              _article.getGroupId(), layout.isPrivateLayout(), hitLayoutId.longValue());

      return PortalUtil.getLayoutURL(hitLayout, themeDisplay);
    }

    return noSuchEntryRedirect;
  }
Esempio n. 24
0
  protected void importAssetVocabulary(
      PortletDataContext portletDataContext,
      Map<Long, Long> assetVocabularyPKs,
      Element assetVocabularyElement,
      AssetVocabulary assetVocabulary)
      throws Exception {

    long userId = portletDataContext.getUserId(assetVocabulary.getUserUuid());
    long groupId = portletDataContext.getScopeGroupId();

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);
    serviceContext.setCreateDate(assetVocabulary.getCreateDate());
    serviceContext.setModifiedDate(assetVocabulary.getModifiedDate());
    serviceContext.setScopeGroupId(portletDataContext.getScopeGroupId());

    AssetVocabulary importedAssetVocabulary = null;

    AssetVocabulary existingAssetVocabulary =
        AssetVocabularyUtil.fetchByG_N(groupId, assetVocabulary.getName());

    if (existingAssetVocabulary == null) {
      Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(portletDataContext.getCompanyId());

      existingAssetVocabulary =
          AssetVocabularyUtil.fetchByG_N(companyGroup.getGroupId(), assetVocabulary.getName());
    }

    if (existingAssetVocabulary == null) {
      serviceContext.setUuid(assetVocabulary.getUuid());

      importedAssetVocabulary =
          AssetVocabularyLocalServiceUtil.addVocabulary(
              userId,
              assetVocabulary.getTitle(),
              getAssetVocabularyTitleMap(assetVocabulary),
              assetVocabulary.getDescriptionMap(),
              assetVocabulary.getSettings(),
              serviceContext);
    } else {
      importedAssetVocabulary =
          AssetVocabularyLocalServiceUtil.updateVocabulary(
              existingAssetVocabulary.getVocabularyId(),
              assetVocabulary.getTitle(),
              getAssetVocabularyTitleMap(assetVocabulary),
              assetVocabulary.getDescriptionMap(),
              assetVocabulary.getSettings(),
              serviceContext);
    }

    assetVocabularyPKs.put(
        assetVocabulary.getVocabularyId(), importedAssetVocabulary.getVocabularyId());

    portletDataContext.importPermissions(
        AssetVocabulary.class,
        assetVocabulary.getVocabularyId(),
        importedAssetVocabulary.getVocabularyId());
  }
Esempio n. 25
0
  @Override
  public String getPortalURL(long groupId) throws PortalException, SystemException {

    String portalURL = PortalUtil.getPortalURL(getVirtualHostname(), Http.HTTP_PORT, false);

    if (groupId <= 0) {
      return portalURL;
    }

    Group group = GroupLocalServiceUtil.getGroup(groupId);

    if (group.hasPublicLayouts()) {
      LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(groupId, false);

      if (Validator.isNotNull(layoutSet.getVirtualHostname())) {
        portalURL = PortalUtil.getPortalURL(layoutSet.getVirtualHostname(), Http.HTTP_PORT, false);
      }
    } else if (group.hasPrivateLayouts()) {
      LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(groupId, true);

      if (Validator.isNotNull(layoutSet.getVirtualHostname())) {
        portalURL = PortalUtil.getPortalURL(layoutSet.getVirtualHostname(), Http.HTTP_PORT, false);
      }
    }

    return portalURL;
  }
  /**
   * Returns the WebDAV URL to access the structure.
   *
   * @param themeDisplay the theme display needed to build the URL. It can set HTTPS access, the
   *     server name, the server port, the path context, and the scope group.
   * @param webDAVToken the WebDAV token for the URL
   * @return the WebDAV URL
   */
  @Override
  public String getWebDavURL(ThemeDisplay themeDisplay, String webDAVToken) {
    StringBundler sb = new StringBundler(11);

    boolean secure = false;

    if (themeDisplay.isSecure() || PropsValues.WEBDAV_SERVLET_HTTPS_REQUIRED) {

      secure = true;
    }

    String portalURL =
        PortalUtil.getPortalURL(themeDisplay.getServerName(), themeDisplay.getServerPort(), secure);

    sb.append(portalURL);

    sb.append(themeDisplay.getPathContext());
    sb.append(StringPool.SLASH);
    sb.append("webdav");

    Group group = themeDisplay.getScopeGroup();

    sb.append(group.getFriendlyURL());

    sb.append(StringPool.SLASH);
    sb.append(webDAVToken);
    sb.append(StringPool.SLASH);
    sb.append("Structures");
    sb.append(StringPool.SLASH);
    sb.append(getStructureId());

    return sb.toString();
  }
Esempio n. 27
0
  protected Group addScopeGroup() throws Exception {
    Group group = GroupTestUtil.addGroup();

    Layout layout = LayoutTestUtil.addLayout(group.getGroupId(), ServiceTestUtil.randomString());

    String name = ServiceTestUtil.randomString();

    ServiceContext serviceContext = ServiceTestUtil.getServiceContext(group.getGroupId());

    Group scopeGroup =
        GroupLocalServiceUtil.addGroup(
            TestPropsValues.getUserId(),
            group.getParentGroupId(),
            Layout.class.getName(),
            layout.getPlid(),
            GroupConstants.DEFAULT_LIVE_GROUP_ID,
            name,
            ServiceTestUtil.randomString(),
            GroupConstants.TYPE_SITE_OPEN,
            true,
            GroupConstants.DEFAULT_MEMBERSHIP_RESTRICTION,
            StringPool.SLASH + FriendlyURLNormalizerUtil.normalize(name),
            false,
            true,
            serviceContext);

    return scopeGroup;
  }
  @Override
  public boolean isShow() {
    try {
      Layout layout = getLayout();

      if (layout == null) {
        return false;
      }

      Group group = layout.getGroup();

      if (group.isLayoutPrototype()) {
        return false;
      }

      if (LayoutPermissionUtil.contains(
          themeDisplay.getPermissionChecker(), getLayout(), ActionKeys.PERMISSIONS)) {

        return true;
      }
    } catch (Exception e) {
    }

    return false;
  }
  public void deleteGroupKBArticles(long groupId) throws PortalException, SystemException {

    // KB articles

    List<KBArticle> kbArticles =
        getSiblingKBArticles(
            groupId,
            KBArticleConstants.DEFAULT_PARENT_RESOURCE_PRIM_KEY,
            WorkflowConstants.STATUS_ANY,
            QueryUtil.ALL_POS,
            QueryUtil.ALL_POS,
            new KBArticlePriorityComparator());

    for (KBArticle kbArticle : kbArticles) {
      deleteKBArticle(kbArticle);
    }

    // Subscriptions

    Group group = groupLocalService.getGroup(groupId);

    List<Subscription> subscriptions =
        subscriptionLocalService.getSubscriptions(
            group.getCompanyId(), KBArticle.class.getName(), groupId);

    for (Subscription subscription : subscriptions) {
      unsubscribeGroupKBArticles(subscription.getUserId(), groupId);
    }
  }
  protected void assertLinksToLayouts(String content, Layout layout, long groupId) {

    StringBundler sb = new StringBundler();

    sb.append(StringPool.OPEN_BRACKET);
    sb.append(layout.getLayoutId());
    sb.append(CharPool.AT);

    Group group = GroupLocalServiceUtil.fetchGroup(groupId);

    if (layout.isPrivateLayout()) {
      if (group == null) {
        sb.append("private");
      } else if (group.isUser()) {
        sb.append("private-user");
      } else {
        sb.append("private-group");
      }
    } else {
      sb.append("public");
    }

    sb.append(CharPool.AT);
    sb.append(layout.getPlid());

    if (group != null) {
      sb.append(CharPool.AT);
      sb.append(String.valueOf(groupId));
    }

    sb.append(StringPool.CLOSE_BRACKET);

    Assert.assertTrue(content.contains(sb.toString()));
  }