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;
  }
  @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;
  }
示例#3
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());
  }
 /*
  * NOTE FOR DEVELOPERS:
  *
  * Never modify or reference this class directly. All methods that expect a layout model instance should use the {@link Layout} interface instead.
  */
 @Override
 public void persist() {
   if (this.isNew()) {
     LayoutLocalServiceUtil.addLayout(this);
   } else {
     LayoutLocalServiceUtil.updateLayout(this);
   }
 }
示例#5
0
  private Layout _getDefaultUserLayout(long companyId) throws PortalException, SystemException {

    Group group = GroupLocalServiceUtil.getGroup(companyId, GroupImpl.GUEST);

    long plid = LayoutLocalServiceUtil.getDefaultPlid(group.getGroupId(), false);

    return LayoutLocalServiceUtil.getLayout(plid);
  }
  protected void exportImportLayouts(long[] layoutIds, Map<String, String[]> parameterMap)
      throws Exception {

    larFile =
        LayoutLocalServiceUtil.exportLayoutsAsFile(
            group.getGroupId(), false, layoutIds, getExportParameterMap(), null, null);

    LayoutLocalServiceUtil.importLayouts(
        TestPropsValues.getUserId(), importedGroup.getGroupId(), false, parameterMap, larFile);
  }
  public void importResources() throws Exception {
    if (_privateLARInputStream != null) {
      LayoutLocalServiceUtil.importLayouts(
          userId, groupId, true, getParameterMap(), _privateLARInputStream);
    }

    if (_publicLARInputStream != null) {
      LayoutLocalServiceUtil.importLayouts(
          userId, groupId, false, getParameterMap(), _publicLARInputStream);
    }
  }
  protected void updateLayoutSetPrototype(long groupId, boolean privateLayout)
      throws PortalException {

    // Layout

    LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(groupId, privateLayout);

    LayoutSetPrototype layoutSetPrototype =
        LayoutSetPrototypeLocalServiceUtil.getLayoutSetPrototype(
            layoutSet.getLayoutSetPrototypeId());

    Group layoutSetPrototypeGroup = layoutSetPrototype.getGroup();

    List<Layout> layoutSetPrototypeLayouts =
        LayoutLocalServiceUtil.getLayouts(layoutSetPrototypeGroup.getGroupId(), true);

    String[] layoutSetPrototypeLayoutUuids = new String[layoutSetPrototypeLayouts.size()];

    for (int i = 0; i < layoutSetPrototypeLayouts.size(); i++) {
      Layout layout = layoutSetPrototypeLayouts.get(i);

      layoutSetPrototypeLayoutUuids[i] = layout.getUuid();
    }

    List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(groupId, privateLayout);

    for (Layout layout : layouts) {
      if (ArrayUtil.contains(
          layoutSetPrototypeLayoutUuids, layout.getSourcePrototypeLayoutUuid())) {

        layout.setLayoutPrototypeUuid(StringPool.BLANK);
        layout.setLayoutPrototypeLinkEnabled(false);
        layout.setSourcePrototypeLayoutUuid(StringPool.BLANK);

        LayoutLocalServiceUtil.updateLayout(layout);
      }
    }

    // Layout set

    UnicodeProperties settingsProperties = layoutSet.getSettingsProperties();

    settingsProperties.remove("last-merge-time");

    layoutSet.setSettingsProperties(settingsProperties);

    layoutSet.setLayoutSetPrototypeUuid(StringPool.BLANK);
    layoutSet.setLayoutSetPrototypeLinkEnabled(false);

    LayoutSetLocalServiceUtil.updateLayoutSet(layoutSet);

    LayoutSetLocalServiceUtil.updateLookAndFeel(
        layoutSet.getGroupId(), null, null, StringPool.BLANK, false);
  }
  @Test
  public void testExportImportLayouts() throws Exception {
    LayoutTestUtil.addLayout(group);

    List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(group.getGroupId(), false);

    exportImportLayouts(ExportImportHelperUtil.getLayoutIds(layouts), getImportParameterMap());

    Assert.assertEquals(
        LayoutLocalServiceUtil.getLayoutsCount(group, false),
        LayoutLocalServiceUtil.getLayoutsCount(importedGroup, false));
  }
  @Test
  public void testExportImportLayouts() throws Exception {
    LayoutTestUtil.addLayout(group.getGroupId(), ServiceTestUtil.randomString());

    long[] layoutIds = new long[0];

    exportImportLayouts(layoutIds, getImportParameterMap());

    Assert.assertEquals(
        LayoutLocalServiceUtil.getLayoutsCount(group, false),
        LayoutLocalServiceUtil.getLayoutsCount(importedGroup, false));
  }
  @Test
  public void testTypeLinkToLayout() throws Exception {
    initExport();

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

    Layout linkedLayout = LayoutTestUtil.addLayout(stagingGroup);

    List<LayoutFriendlyURL> linkedLayoutFriendlyURLs =
        LayoutFriendlyURLLocalServiceUtil.getLayoutFriendlyURLs(linkedLayout.getPlid());

    addDependentStagedModel(dependentStagedModelsMap, Layout.class, linkedLayout);

    addDependentLayoutFriendlyURLs(dependentStagedModelsMap, linkedLayout);

    Layout layout =
        LayoutTestUtil.addTypeLinkToLayoutLayout(
            stagingGroup.getGroupId(), linkedLayout.getLayoutId());

    List<LayoutFriendlyURL> layoutFriendlyURLs =
        LayoutFriendlyURLLocalServiceUtil.getLayoutFriendlyURLs(layout.getPlid());

    addDependentLayoutFriendlyURLs(dependentStagedModelsMap, layout);

    StagedModelDataHandlerUtil.exportStagedModel(portletDataContext, layout);

    validateExport(portletDataContext, layout, dependentStagedModelsMap);

    initImport();

    Layout exportedLayout = (Layout) readExportedStagedModel(layout);

    StagedModelDataHandlerUtil.importStagedModel(portletDataContext, exportedLayout);

    LayoutLocalServiceUtil.getLayoutByUuidAndGroupId(
        linkedLayout.getUuid(), liveGroup.getGroupId(), false);

    LayoutFriendlyURL linkedLayoutFriendlyURL = linkedLayoutFriendlyURLs.get(0);

    LayoutFriendlyURLLocalServiceUtil.getLayoutFriendlyURLByUuidAndGroupId(
        linkedLayoutFriendlyURL.getUuid(), liveGroup.getGroupId());

    LayoutLocalServiceUtil.getLayoutByUuidAndGroupId(
        layout.getUuid(), liveGroup.getGroupId(), false);

    LayoutFriendlyURL layoutFriendlyURL = layoutFriendlyURLs.get(0);

    LayoutFriendlyURLLocalServiceUtil.getLayoutFriendlyURLByUuidAndGroupId(
        layoutFriendlyURL.getUuid(), liveGroup.getGroupId());
  }
  @Test
  public void testFriendlyURLCollision() throws Exception {
    String defaultLanguageId = LocaleUtil.toLanguageId(LocaleUtil.getDefault());

    Layout layoutA = LayoutTestUtil.addLayout(group.getGroupId(), "layoutA");

    layoutA = LayoutLocalServiceUtil.updateFriendlyURL(layoutA.getPlid(), "/layoutA-de", "de");

    Layout layoutB = LayoutTestUtil.addLayout(group.getGroupId(), "layoutB");

    layoutB = LayoutLocalServiceUtil.updateFriendlyURL(layoutB.getPlid(), "/layoutB-de", "de");

    long[] layoutIds = {layoutA.getLayoutId(), layoutB.getLayoutId()};

    exportImportLayouts(layoutIds, getImportParameterMap());

    layoutA =
        LayoutLocalServiceUtil.updateFriendlyURL(layoutA.getPlid(), "/temp", defaultLanguageId);

    layoutA = LayoutLocalServiceUtil.updateFriendlyURL(layoutA.getPlid(), "/temp-de", "de");

    layoutB =
        LayoutLocalServiceUtil.updateFriendlyURL(layoutB.getPlid(), "/layoutA", defaultLanguageId);

    LayoutLocalServiceUtil.updateFriendlyURL(layoutB.getPlid(), "/layoutA-de", "de");

    layoutA =
        LayoutLocalServiceUtil.updateFriendlyURL(layoutA.getPlid(), "/layoutB", defaultLanguageId);

    LayoutLocalServiceUtil.updateFriendlyURL(layoutA.getPlid(), "/layoutB-de", "de");

    exportImportLayouts(layoutIds, getImportParameterMap());
  }
  protected File exportLayoutsAsFile(
      long sourceGroupId,
      boolean privateLayout,
      Map<Long, Boolean> layoutIdMap,
      Map<String, String[]> parameterMap,
      long remoteGroupId,
      Date startDate,
      Date endDate,
      HttpPrincipal httpPrincipal)
      throws PortalException {

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

    if (layoutIdMap != null) {
      for (Map.Entry<Long, Boolean> entry : layoutIdMap.entrySet()) {
        long plid = GetterUtil.getLong(String.valueOf(entry.getKey()));
        boolean includeChildren = entry.getValue();

        Layout layout = LayoutLocalServiceUtil.getLayout(plid);

        if (!layouts.contains(layout)) {
          layouts.add(layout);
        }

        List<Layout> parentLayouts =
            getMissingRemoteParentLayouts(httpPrincipal, layout, remoteGroupId);

        for (Layout parentLayout : parentLayouts) {
          if (!layouts.contains(parentLayout)) {
            layouts.add(parentLayout);
          }
        }

        if (includeChildren) {
          for (Layout childLayout : layout.getAllChildren()) {
            if (!layouts.contains(childLayout)) {
              layouts.add(childLayout);
            }
          }
        }
      }
    }

    long[] layoutIds = ExportImportHelperUtil.getLayoutIds(layouts);

    return LayoutLocalServiceUtil.exportLayoutsAsFile(
        sourceGroupId, privateLayout, layoutIds, parameterMap, startDate, endDate);
  }
示例#14
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;
  }
  protected void deleteMissingLayouts(
      long groupId,
      boolean privateLayout,
      Set<Long> newLayoutIds,
      List<Layout> previousLayouts,
      ServiceContext serviceContext)
      throws Exception {

    // Layouts

    if (_log.isDebugEnabled()) {
      if (newLayoutIds.size() > 0) {
        _log.debug("Delete missing layouts");
      }
    }

    for (Layout layout : previousLayouts) {
      if (!newLayoutIds.contains(layout.getLayoutId())) {
        try {
          LayoutLocalServiceUtil.deleteLayout(layout, false, serviceContext);
        } catch (NoSuchLayoutException nsle) {
        }
      }
    }

    // Layout set

    LayoutSetLocalServiceUtil.updatePageCount(groupId, privateLayout);
  }
  protected void exportImportLayouts(boolean privateLayout) throws Exception {
    List<Layout> layouts =
        LayoutLocalServiceUtil.getLayouts(_stagingGroup.getGroupId(), privateLayout);

    User user = TestPropsValues.getUser();

    Map<String, Serializable> publishLayoutLocalSettingsMap =
        ExportImportConfigurationSettingsMapFactory.buildPublishLayoutLocalSettingsMap(
            user,
            _stagingGroup.getGroupId(),
            _liveGroup.getGroupId(),
            privateLayout,
            ExportImportHelperUtil.getLayoutIds(layouts),
            new HashMap<String, String[]>());

    ExportImportConfiguration exportImportConfiguration =
        ExportImportConfigurationLocalServiceUtil.addDraftExportImportConfiguration(
            user.getUserId(),
            ExportImportConfigurationConstants.TYPE_PUBLISH_LAYOUT_LOCAL,
            publishLayoutLocalSettingsMap);

    File larFile = ExportImportLocalServiceUtil.exportLayoutsAsFile(exportImportConfiguration);

    ExportImportLocalServiceUtil.importLayouts(exportImportConfiguration, larFile);
  }
示例#17
0
  protected List<Layout> getPrototypeLinkedLayouts(long groupId, boolean privateLayout)
      throws SystemException {

    Class<?> clazz = getClass();

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

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

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

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

    dynamicQuery.add(layoutPrototypeUuidProperty.isNotNull());

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

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

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

    dynamicQuery.add(sourcePrototypeLayoutUuidProperty.isNotNull());

    return LayoutLocalServiceUtil.dynamicQuery(dynamicQuery);
  }
  protected String addJournalContentPortletToLayout(
      long userId, Layout layout, JournalArticle journalArticle, String columnId) throws Exception {

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

    String journalPortletId =
        layoutTypePortlet.addPortletId(userId, PortletKeys.JOURNAL_CONTENT, columnId, -1);

    LayoutLocalServiceUtil.updateLayout(
        layout.getGroupId(),
        layout.isPrivateLayout(),
        layout.getLayoutId(),
        layout.getTypeSettings());

    javax.portlet.PortletPreferences prefs =
        getPortletPreferences(layout.getCompanyId(), layout.getPlid(), journalPortletId);

    prefs.setValue("articleId", journalArticle.getArticleId());
    prefs.setValue("groupId", String.valueOf(journalArticle.getGroupId()));
    prefs.setValue("showAvailableLocales", Boolean.TRUE.toString());

    updatePortletPreferences(layout.getPlid(), journalPortletId, prefs);

    return journalPortletId;
  }
  @Test
  public void testExportImportPortletData() throws Exception {

    // Check data after site creation

    String content = _layoutSetPrototypeJournalArticle.getContent();

    JournalArticle journalArticle =
        JournalArticleLocalServiceUtil.getArticleByUrlTitle(
            _group.getGroupId(), _layoutSetPrototypeJournalArticle.getUrlTitle());

    Assert.assertEquals(content, journalArticle.getContent());

    // Update site template data

    updateArticle(_layoutSetPrototypeJournalArticle, "New Test Content");

    // Check data after layout reset

    Layout layout =
        LayoutLocalServiceUtil.getFriendlyURLLayout(
            _group.getGroupId(), false, _layoutSetPrototypeLayout.getFriendlyURL());

    SitesUtil.resetPrototype(layout);

    Assert.assertEquals(content, journalArticle.getContent());
  }
  @Override
  protected void doExportStagedModel(
      PortletDataContext portletDataContext,
      Element[] elements,
      MDRRuleGroupInstance ruleGroupInstance)
      throws Exception {

    Element ruleGroupsElement = elements[0];

    MDRRuleGroup ruleGroup =
        MDRRuleGroupLocalServiceUtil.getRuleGroup(ruleGroupInstance.getRuleGroupId());

    StagedModelDataHandlerUtil.exportStagedModel(portletDataContext, ruleGroupsElement, ruleGroup);

    Element ruleGroupInstancesElement = elements[1];

    Element ruleGroupInstanceElement = ruleGroupInstancesElement.addElement("rule-group-instance");

    String className = ruleGroupInstance.getClassName();

    if (className.equals(Layout.class.getName())) {
      Layout layout = LayoutLocalServiceUtil.getLayout(ruleGroupInstance.getClassPK());

      ruleGroupInstanceElement.addAttribute("layout-uuid", layout.getUuid());
    }

    portletDataContext.addClassedModel(
        ruleGroupInstanceElement,
        StagedModelPathUtil.getPath(ruleGroupInstance),
        ruleGroupInstance,
        MDRPortletDataHandler.NAMESPACE);
  }
  private LiferayPortletURL createLiferayPortletURL(
      PortletRequest request, String toPage, String portletId) {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    //		String portletId = (String) request.getAttribute(WebKeys.PORTLET_ID);
    LiferayPortletURL renderURL = null;
    String localHost = themeDisplay.getPortalURL();
    List<Layout> layouts = null;
    try {
      layouts = LayoutLocalServiceUtil.getLayouts(themeDisplay.getLayout().getGroupId(), false);

      for (Layout layout : layouts) {

        String nodeNameRemoved =
            PortalUtil.getLayoutFriendlyURL(layout, themeDisplay).replace(localHost, "");

        // Viene ricercato l'URL esatto per la pagina successiva
        if (nodeNameRemoved.indexOf(toPage) > 0) {

          renderURL =
              PortletURLFactoryUtil.create(
                  request, portletId, layout.getPlid(), PortletRequest.RENDER_PHASE);
          renderURL.setWindowState(WindowState.NORMAL);
          renderURL.setPortletMode(PortletMode.VIEW);

          break;
        }
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
    return renderURL;
  }
  @Override
  protected StagedModel addStagedModel(
      Group group, Map<String, List<StagedModel>> dependentStagedModelsMap) throws Exception {

    _layoutSetPrototype = LayoutTestUtil.addLayoutSetPrototype(RandomTestUtil.randomString());

    List<Layout> layouts =
        LayoutLocalServiceUtil.getLayouts(
            _layoutSetPrototype.getGroupId(), true, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);

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

    Layout layout = layouts.get(0);

    addLayout(LayoutSetPrototype.class, layout);
    addLayoutFriendlyURLs(LayoutSetPrototype.class, layout.getPlid());

    LayoutPrototype layoutPrototype = addLayoutPrototype(dependentStagedModelsMap);

    Layout prototypedLayout =
        LayoutTestUtil.addLayout(_layoutSetPrototype.getGroupId(), true, layoutPrototype, true);

    addLayout(LayoutSetPrototype.class, prototypedLayout);
    addLayoutFriendlyURLs(LayoutSetPrototype.class, prototypedLayout.getPlid());

    return _layoutSetPrototype;
  }
示例#23
0
  protected Layout getPortalPageLayout(long userId, long groupId, String portalPageName)
      throws Exception {
    Layout portalPageLayout = null;
    boolean privateLayout = true;
    List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(groupId, privateLayout);

    for (Layout layout : layouts) {

      if (layout.getName(Locale.US).equals(portalPageName)) {
        portalPageLayout = layout;
      }
    }

    if (portalPageLayout == null) {
      long parentLayoutId = LayoutConstants.DEFAULT_PARENT_LAYOUT_ID;
      String type = LayoutConstants.TYPE_PORTLET;
      boolean hidden = false;
      String friendlyURL = "/" + portalPageName.toLowerCase();
      portalPageLayout =
          ServiceUtil.addLayout(
              userId,
              groupId,
              privateLayout,
              parentLayoutId,
              portalPageName,
              portalPageName,
              portalPageName,
              type,
              hidden,
              friendlyURL);
    }

    return portalPageLayout;
  }
  protected void validatePrototypedLayouts(Class<?> clazz, long groupId) throws Exception {

    List<Layout> layouts = getLayouts(clazz);

    for (Layout layout : layouts) {
      Layout importedLayout =
          LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(
              layout.getUuid(), groupId, layout.getPrivateLayout());

      Assert.assertNotNull(importedLayout);
      Assert.assertEquals(
          layout.getTypeSettingsProperty(
              LayoutSetPrototypeStagedModelDataHandlerTest.class.getName()),
          importedLayout.getTypeSettingsProperty(
              LayoutSetPrototypeStagedModelDataHandlerTest.class.getName()));
    }

    List<LayoutFriendlyURL> layoutFriendlyURLs = getLayoutFriendlyURLs(clazz);

    for (LayoutFriendlyURL layoutFriendlyURL : layoutFriendlyURLs) {
      LayoutFriendlyURL importedLayoutFriendlyURL =
          LayoutFriendlyURLLocalServiceUtil.fetchLayoutFriendlyURLByUuidAndGroupId(
              layoutFriendlyURL.getUuid(), groupId);

      Assert.assertNotNull(importedLayoutFriendlyURL);
      Assert.assertEquals(
          layoutFriendlyURL.getFriendlyURL(), importedLayoutFriendlyURL.getFriendlyURL());
    }
  }
  protected String getJournalURL(ThemeDisplay themeDisplay, long groupId, Document result)
      throws Exception {

    Layout layout = themeDisplay.getLayout();

    String articleId = result.get(Field.ENTRY_CLASS_PK);
    String version = result.get("version");

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

    if (hitLayoutIds.size() > 0) {
      Long hitLayoutId = hitLayoutIds.get(0);

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

      return PortalUtil.getLayoutURL(hitLayout, themeDisplay);
    } else {
      StringBundler sb = new StringBundler(7);

      sb.append(themeDisplay.getPathMain());
      sb.append("/journal/view_article_content?groupId=");
      sb.append(groupId);
      sb.append("&articleId=");
      sb.append(articleId);
      sb.append("&version=");
      sb.append(version);

      return sb.toString();
    }
  }
  protected PortletDataContext getPortletDataContext(
      ExportImportConfiguration exportImportConfiguration, File file) throws PortalException {

    Map<String, Serializable> settingsMap = exportImportConfiguration.getSettingsMap();

    Map<String, String[]> parameterMap = (Map<String, String[]>) settingsMap.get("parameterMap");
    String portletId = MapUtil.getString(settingsMap, "portletId");
    long targetPlid = MapUtil.getLong(settingsMap, "targetPlid");
    long targetGroupId = MapUtil.getLong(settingsMap, "targetGroupId");
    long userId = MapUtil.getLong(settingsMap, "userId");

    Layout layout = LayoutLocalServiceUtil.getLayout(targetPlid);

    String userIdStrategyString =
        MapUtil.getString(parameterMap, PortletDataHandlerKeys.USER_ID_STRATEGY);

    UserIdStrategy userIdStrategy =
        ExportImportHelperUtil.getUserIdStrategy(userId, userIdStrategyString);

    ZipReader zipReader = ZipReaderFactoryUtil.getZipReader(file);

    PortletDataContext portletDataContext =
        PortletDataContextFactoryUtil.createImportPortletDataContext(
            layout.getCompanyId(), targetGroupId, parameterMap, userIdStrategy, zipReader);

    portletDataContext.setOldPlid(targetPlid);
    portletDataContext.setPlid(targetPlid);
    portletDataContext.setPortletId(portletId);
    portletDataContext.setPrivateLayout(layout.isPrivateLayout());

    return portletDataContext;
  }
  /** @see com.liferay.portal.lar.ExportImportHelperImpl#getMissingParentLayouts( Layout, long) */
  protected List<Layout> getMissingRemoteParentLayouts(
      HttpPrincipal httpPrincipal, Layout layout, long remoteGroupId) throws PortalException {

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

    long parentLayoutId = layout.getParentLayoutId();

    while (parentLayoutId > 0) {
      Layout parentLayout =
          LayoutLocalServiceUtil.getLayout(
              layout.getGroupId(), layout.isPrivateLayout(), parentLayoutId);

      try {
        LayoutServiceHttp.getLayoutByUuidAndGroupId(
            httpPrincipal, parentLayout.getUuid(), remoteGroupId, parentLayout.getPrivateLayout());

        // If one parent is found, all others are assumed to exist

        break;
      } catch (NoSuchLayoutException nsle) {
        missingRemoteParentLayouts.add(parentLayout);

        parentLayoutId = parentLayout.getParentLayoutId();
      }
    }

    return missingRemoteParentLayouts;
  }
  public boolean contains(PermissionChecker permissionChecker, long plid, String actionId)
      throws PortalException, SystemException {

    Layout layout = LayoutLocalServiceUtil.getLayout(plid);

    return contains(permissionChecker, layout, actionId);
  }
示例#29
0
  public static String getCreateAccountHREF(HttpServletRequest request, ThemeDisplay themeDisplay)
      throws Exception {

    if (Validator.isNull(PropsValues.COMPANY_SECURITY_STRANGERS_URL)) {
      PortletURL createAccountURL =
          new PortletURLImpl(
              request, PortletKeys.LOGIN, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE);

      createAccountURL.setWindowState(WindowState.MAXIMIZED);
      createAccountURL.setPortletMode(PortletMode.VIEW);

      createAccountURL.setParameter("saveLastPath", "0");
      createAccountURL.setParameter("struts_action", "/login/create_account");

      return createAccountURL.toString();
    }

    try {
      Layout layout =
          LayoutLocalServiceUtil.getFriendlyURLLayout(
              themeDisplay.getScopeGroupId(), false, PropsValues.COMPANY_SECURITY_STRANGERS_URL);

      return PortalUtil.getLayoutURL(layout, themeDisplay);
    } catch (NoSuchLayoutException nsle) {
    }

    return StringPool.BLANK;
  }
  @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;
  }