protected String getOldScopeName(ActionRequest actionRequest, Portlet portlet) throws Exception {

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

    Layout layout = themeDisplay.getLayout();

    PortletPreferences portletPreferences = actionRequest.getPreferences();

    String scopeType = GetterUtil.getString(portletPreferences.getValue("lfrScopeType", null));

    if (Validator.isNull(scopeType)) {
      return null;
    }

    String scopeName = null;

    if (scopeType.equals("company")) {
      scopeName = themeDisplay.translate("global");
    } else if (scopeType.equals("layout")) {
      String scopeLayoutUuid =
          GetterUtil.getString(portletPreferences.getValue("lfrScopeLayoutUuid", null));

      Layout scopeLayout =
          _layoutLocalService.fetchLayoutByUuidAndGroupId(
              scopeLayoutUuid, layout.getGroupId(), layout.isPrivateLayout());

      if (scopeLayout != null) {
        scopeName = scopeLayout.getName(themeDisplay.getLocale());
      }
    } else {
      throw new IllegalArgumentException("Scope type " + scopeType + " is invalid");
    }

    return scopeName;
  }
  protected Tuple getNewScope(ActionRequest actionRequest) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    Layout layout = themeDisplay.getLayout();

    String[] scopes = StringUtil.split(ParamUtil.getString(actionRequest, "scope"));

    String scopeType = scopes[0];

    long scopeGroupId = 0;
    String scopeName = null;

    if (Validator.isNull(scopeType)) {
      scopeGroupId = layout.getGroupId();
    } else if (scopeType.equals("company")) {
      scopeGroupId = themeDisplay.getCompanyGroupId();
      scopeName = themeDisplay.translate("global");
    } else if (scopeType.equals("layout")) {
      String scopeLayoutUuid = scopes[1];

      Layout scopeLayout =
          _layoutLocalService.getLayoutByUuidAndGroupId(
              scopeLayoutUuid, layout.getGroupId(), layout.isPrivateLayout());

      if (!scopeLayout.hasScopeGroup()) {
        Map<Locale, String> nameMap = new HashMap<>();

        String name = String.valueOf(scopeLayout.getPlid());

        nameMap.put(LocaleUtil.getDefault(), name);

        _groupLocalService.addGroup(
            themeDisplay.getUserId(),
            GroupConstants.DEFAULT_PARENT_GROUP_ID,
            Layout.class.getName(),
            scopeLayout.getPlid(),
            GroupConstants.DEFAULT_LIVE_GROUP_ID,
            nameMap,
            null,
            0,
            true,
            GroupConstants.DEFAULT_MEMBERSHIP_RESTRICTION,
            null,
            false,
            true,
            null);
      }

      scopeGroupId = scopeLayout.getGroupId();
      scopeName = scopeLayout.getName(themeDisplay.getLocale());
    } else {
      throw new IllegalArgumentException("Scope type " + scopeType + " is invalid");
    }

    return new Tuple(scopeGroupId, scopeName);
  }
  @Override
  protected void validateImportedStagedModel(
      StagedModel stagedModel, StagedModel importedStagedModel) throws Exception {

    Assert.assertTrue(
        stagedModel.getCreateDate() + " " + importedStagedModel.getCreateDate(),
        DateUtil.equals(stagedModel.getCreateDate(), importedStagedModel.getCreateDate()));
    Assert.assertEquals(stagedModel.getUuid(), importedStagedModel.getUuid());

    Layout layout = (Layout) stagedModel;
    Layout importedLayout = (Layout) importedStagedModel;

    Assert.assertEquals(layout.getName(), importedLayout.getName());
    Assert.assertEquals(layout.getTitle(), importedLayout.getTitle());
    Assert.assertEquals(layout.getDescription(), importedLayout.getDescription());
    Assert.assertEquals(layout.getKeywords(), importedLayout.getKeywords());
    Assert.assertEquals(layout.getRobots(), importedLayout.getRobots());
    Assert.assertEquals(layout.getType(), importedLayout.getType());
    Assert.assertEquals(layout.getFriendlyURL(), importedLayout.getFriendlyURL());
    Assert.assertEquals(layout.getCss(), importedLayout.getCss());
  }
Пример #4
0
  private static void _addLayoutBreadcrumbEntries(
      List<BreadcrumbEntry> breadcrumbEntries, ThemeDisplay themeDisplay, Layout layout)
      throws Exception {

    if (layout.getParentLayoutId() != LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {

      Layout parentLayout = LayoutLocalServiceUtil.getParentLayout(layout);

      _addLayoutBreadcrumbEntries(breadcrumbEntries, themeDisplay, parentLayout);
    }

    BreadcrumbEntry breadcrumbEntry = new BreadcrumbEntry();

    breadcrumbEntry.setBaseModel(layout);

    LayoutType layoutType = layout.getLayoutType();

    if (!layoutType.isBrowsable()) {
      breadcrumbEntry.setBrowsable(false);
    }

    String layoutName = layout.getName(themeDisplay.getLocale());

    if (layout.isTypeControlPanel()) {
      if (layoutName.equals(LayoutConstants.NAME_CONTROL_PANEL_DEFAULT)) {
        layoutName = LanguageUtil.get(themeDisplay.getLocale(), "control-panel");
      }
    }

    breadcrumbEntry.setTitle(layoutName);

    String layoutURL = PortalUtil.getLayoutFullURL(layout, themeDisplay);

    if (themeDisplay.isAddSessionIdToURL()) {
      layoutURL = PortalUtil.getURLWithSessionId(layoutURL, themeDisplay.getSessionId());
    }

    breadcrumbEntry.setURL(layoutURL);

    breadcrumbEntries.add(breadcrumbEntry);
  }