@Test
  public void testExportImportLayoutsPriorities() throws Exception {
    Layout layout1 = LayoutTestUtil.addLayout(group);
    Layout layout2 = LayoutTestUtil.addLayout(group);
    Layout layout3 = LayoutTestUtil.addLayout(group);

    int priority = layout1.getPriority();

    layout1.setPriority(layout3.getPriority());
    layout3.setPriority(priority);

    layout1 = LayoutLocalServiceUtil.updateLayout(layout1);
    layout3 = LayoutLocalServiceUtil.updateLayout(layout3);

    long[] layoutIds = new long[] {layout1.getLayoutId(), layout2.getLayoutId()};

    exportImportLayouts(layoutIds, getImportParameterMap());

    Layout importedLayout1 =
        LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(
            layout1.getUuid(), importedGroup.getGroupId(), false);

    Assert.assertNotEquals(layout1.getPriority(), importedLayout1.getPriority());

    Layout importedLayout2 =
        LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(
            layout2.getUuid(), importedGroup.getGroupId(), false);

    Assert.assertNotEquals(layout2.getPriority(), importedLayout2.getPriority());

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

    layoutIds = ExportImportHelperUtil.getLayoutIds(layouts);

    exportImportLayouts(layoutIds, getImportParameterMap());

    importedLayout1 =
        LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(
            layout1.getUuid(), importedGroup.getGroupId(), false);

    Assert.assertEquals(layout1.getPriority(), importedLayout1.getPriority());

    importedLayout2 =
        LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(
            layout2.getUuid(), importedGroup.getGroupId(), false);

    Assert.assertEquals(layout2.getPriority(), importedLayout2.getPriority());

    Layout importedLayout3 =
        LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(
            layout3.getUuid(), importedGroup.getGroupId(), false);

    Assert.assertEquals(layout3.getPriority(), importedLayout3.getPriority());
  }
Exemplo n.º 2
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());
  }
  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;
  }
Exemplo n.º 4
0
 /*
  * 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);
   }
 }
  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);
  }
  protected void addLayout(long parentLayoutId, JSONObject layoutJSONObject) throws Exception {

    String name = layoutJSONObject.getString("name");
    String title = layoutJSONObject.getString("title");
    boolean hidden = layoutJSONObject.getBoolean("hidden");

    String friendlyURL = layoutJSONObject.getString("friendlyURL");

    if (Validator.isNotNull(friendlyURL) && !friendlyURL.startsWith(StringPool.SLASH)) {

      friendlyURL = StringPool.SLASH + friendlyURL;
    }

    Layout layout =
        LayoutLocalServiceUtil.addLayout(
            userId,
            groupId,
            privateLayout,
            parentLayoutId,
            name,
            title,
            StringPool.BLANK,
            LayoutConstants.TYPE_PORTLET,
            hidden,
            friendlyURL,
            serviceContext);

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

    String layoutTemplateId =
        layoutJSONObject.getString("layoutTemplateId", _defaultLayoutTemplateId);

    if (Validator.isNotNull(layoutTemplateId)) {
      layoutTypePortlet.setLayoutTemplateId(userId, layoutTemplateId, false);
    }

    JSONArray columnsJSONArray = layoutJSONObject.getJSONArray("columns");

    addLayoutColumns(layout, columnsJSONArray);

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

    JSONArray layoutsJSONArray = layoutJSONObject.getJSONArray("layouts");

    addLayouts(layout.getLayoutId(), layoutsJSONArray);
  }
  protected void addLayout(Class<?> clazz, Layout layout) throws Exception {
    List<Layout> layouts = _layouts.get(clazz.getSimpleName());

    if (layouts == null) {
      layouts = new ArrayList<>();

      _layouts.put(clazz.getSimpleName(), layouts);
    }

    layouts.add(layout);

    UnicodeProperties typeSettings = layout.getTypeSettingsProperties();

    typeSettings.setProperty(
        LayoutSetPrototypeStagedModelDataHandlerTest.class.getName(), Boolean.TRUE.toString());

    LayoutLocalServiceUtil.updateLayout(layout);
  }
Exemplo n.º 8
0
  protected void setupPage(long userId, long groupId, PortalPage portalPage) throws Exception {
    String portalPageName = portalPage.getName();
    String[] portletIds = portalPage.getPortletIds();
    Layout portalPageLayout = getPortalPageLayout(userId, groupId, portalPageName);
    LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) portalPageLayout.getLayoutType();

    layoutTypePortlet.setLayoutTemplateId(userId, "2_columns_i", false);

    int columnNumber = 1;

    for (String portletId : portletIds) {

      if (portletId.endsWith("_INSTANCE_")) {
        portletId = portletId + "ABCD";
      }

      addPortlet(layoutTypePortlet, userId, columnNumber, portletId);
      columnNumber++;
    }

    LayoutLocalServiceUtil.updateLayout(portalPageLayout);

    logger.info("Setup page: " + portalPageName);
  }
Exemplo n.º 9
0
  public static void addPortlets(Group group, Layout layout, String name, String keyPrefix)
      throws Exception {

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

    LayoutTemplate layoutTemplate = layoutTypePortlet.getLayoutTemplate();

    List<String> columns = layoutTemplate.getColumns();

    for (String column : columns) {
      String[] portletIds = null;

      if (Validator.isNull(name)) {
        portletIds = PortletProps.getArray(keyPrefix + column);
      } else {
        Filter filter = new Filter(name);

        portletIds = PortletProps.getArray(keyPrefix + column, filter);
      }

      layoutTypePortlet.addPortletIds(0, portletIds, column, false);
    }

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

    List<String> portletIds = layoutTypePortlet.getPortletIds();

    for (String portletId : portletIds) {
      addResources(layout, portletId);

      if (portletId.startsWith("1_WAR_eventsdisplayportlet")) {
        updatePortletTitle(layout, portletId, "Events");
      } else if (portletId.startsWith("1_WAR_soannouncementsportlet")) {
        updatePortletTitle(layout, portletId, "Announcements");
      } else if (portletId.startsWith("1_WAR_wysiwygportlet")) {
        updatePortletTitle(layout, portletId, "Welcome");
      } else if (portletId.contains("_WAR_contactsportlet")) {
        configureProfile(layout, portletId);
        removePortletBorder(layout, portletId);
      } else if (portletId.startsWith(PortletKeys.ASSET_PUBLISHER)) {
        configureAssetPublisher(layout);
        updatePortletTitle(layout, portletId, "Related Content");
      } else if (portletId.startsWith(PortletKeys.BLOGS_AGGREGATOR)) {
        configureBlogsAggregator(layout);
        updatePortletTitle(layout, portletId, "Recent Blogs");
      } else if (portletId.startsWith(PortletKeys.BREADCRUMB)) {
        removePortletBorder(layout, portletId);
      } else if (portletId.startsWith(PortletKeys.MESSAGE_BOARDS)) {
        configureMessageBoards(layout);
        removePortletBorder(layout, portletId);
      } else if (portletId.equals(PortletKeys.DOCUMENT_LIBRARY)
          || portletId.equals(PortletKeys.BLOGS)
          || portletId.equals(PortletKeys.WIKI)
          || portletId.equals("1_WAR_calendarportlet")
          || portletId.contains("_WAR_microblogsportlet")
          || portletId.equals("1_WAR_privatemessagingportlet")
          || portletId.contains("1_WAR_tasksportlet")) {

        removePortletBorder(layout, portletId);
      }
    }
  }
  protected void updateRolePermissions(ActionRequest actionRequest) throws Exception {

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

    String portletResource = ParamUtil.getString(actionRequest, "portletResource");
    String modelResource = ParamUtil.getString(actionRequest, "modelResource");
    long[] roleIds =
        StringUtil.split(ParamUtil.getString(actionRequest, "rolesSearchContainerPrimaryKeys"), 0L);

    String selResource = PortletConstants.getRootPortletId(portletResource);

    if (Validator.isNotNull(modelResource)) {
      selResource = modelResource;
    }

    long resourceGroupId =
        ParamUtil.getLong(actionRequest, "resourceGroupId", themeDisplay.getScopeGroupId());
    String resourcePrimKey = ParamUtil.getString(actionRequest, "resourcePrimKey");

    Map<Long, String[]> roleIdsToActionIds = new HashMap<Long, String[]>();

    if (ResourceBlockLocalServiceUtil.isSupported(selResource)) {
      for (long roleId : roleIds) {
        List<String> actionIds = getActionIdsList(actionRequest, roleId, true);

        roleIdsToActionIds.put(roleId, actionIds.toArray(new String[actionIds.size()]));
      }

      ResourceBlockServiceUtil.setIndividualScopePermissions(
          themeDisplay.getCompanyId(),
          resourceGroupId,
          selResource,
          GetterUtil.getLong(resourcePrimKey),
          roleIdsToActionIds);
    } else {
      for (long roleId : roleIds) {
        String[] actionIds = getActionIds(actionRequest, roleId, false);

        roleIdsToActionIds.put(roleId, actionIds);
      }

      ResourcePermissionServiceUtil.setIndividualResourcePermissions(
          resourceGroupId,
          themeDisplay.getCompanyId(),
          selResource,
          resourcePrimKey,
          roleIdsToActionIds);
    }

    int pos = resourcePrimKey.indexOf(PortletConstants.LAYOUT_SEPARATOR);

    if (pos != -1) {
      long plid = GetterUtil.getLong(resourcePrimKey.substring(0, pos));

      Layout layout = LayoutLocalServiceUtil.fetchLayout(plid);

      if (layout != null) {
        layout.setModifiedDate(new Date());

        LayoutLocalServiceUtil.updateLayout(layout);

        CacheUtil.clearCache(layout.getCompanyId());
      }
    }

    if (PropsValues.PERMISSIONS_PROPAGATION_ENABLED) {
      Portlet portlet =
          PortletLocalServiceUtil.getPortletById(themeDisplay.getCompanyId(), portletResource);

      PermissionPropagator permissionPropagator = portlet.getPermissionPropagatorInstance();

      if (permissionPropagator != null) {
        permissionPropagator.propagateRolePermissions(
            actionRequest, modelResource, resourcePrimKey, roleIds);
      }
    }
  }