@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 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));
  }
Exemplo n.º 3
0
  public int getPublicLayoutsPageCount() {
    try {
      return LayoutLocalServiceUtil.getLayoutsCount(this, false);
    } catch (Exception e) {
      _log.error(e, e);
    }

    return 0;
  }
  @Override
  public int getPrivateLayoutsPageCount() {
    try {
      return LayoutLocalServiceUtil.getLayoutsCount(this, true);
    } catch (Exception e) {
      _log.error(e, e);
    }

    return 0;
  }
  @Test
  public void testDeleteMissingLayouts() throws Exception {
    Layout layout1 = LayoutTestUtil.addLayout(group);
    Layout layout2 = LayoutTestUtil.addLayout(group);

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

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

    exportImportLayouts(layoutIds, getImportParameterMap());

    Assert.assertEquals(
        LayoutLocalServiceUtil.getLayoutsCount(group, false),
        LayoutLocalServiceUtil.getLayoutsCount(importedGroup, false));

    LayoutTestUtil.addLayout(importedGroup);

    Map<String, String[]> parameterMap = getImportParameterMap();

    parameterMap.put(
        PortletDataHandlerKeys.DELETE_MISSING_LAYOUTS, new String[] {Boolean.TRUE.toString()});

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

    exportImportLayouts(layoutIds, getImportParameterMap());

    Assert.assertEquals(
        LayoutLocalServiceUtil.getLayoutsCount(group, false),
        LayoutLocalServiceUtil.getLayoutsCount(importedGroup, false));

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

    Assert.assertNotNull(importedLayout1);

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

    Assert.assertNotNull(importedLayout2);
  }
  @Test
  public void testExportImportSelectedLayouts() throws Exception {
    Layout layout = LayoutTestUtil.addLayout(group);

    long[] layoutIds = new long[] {layout.getLayoutId()};

    exportImportLayouts(layoutIds, getImportParameterMap());

    Assert.assertEquals(
        layoutIds.length, LayoutLocalServiceUtil.getLayoutsCount(importedGroup, false));

    importedLayout =
        LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(
            layout.getUuid(), importedGroup.getGroupId(), false);

    Assert.assertNotNull(importedLayout);
  }
Exemplo n.º 7
0
  public boolean isShowSite(PermissionChecker permissionChecker, boolean privateSite)
      throws PortalException, SystemException {

    if (!isControlPanel() && !isSite() && !isUser()) {
      return false;
    }

    boolean showSite = true;

    Layout defaultLayout = null;

    int siteLayoutsCount = LayoutLocalServiceUtil.getLayoutsCount(this, true);

    if (siteLayoutsCount == 0) {
      boolean hasPowerUserRole =
          RoleLocalServiceUtil.hasUserRole(
              permissionChecker.getUserId(),
              permissionChecker.getCompanyId(),
              RoleConstants.POWER_USER,
              true);

      if (isSite()) {
        if (privateSite) {
          showSite = PropsValues.MY_SITES_SHOW_PRIVATE_SITES_WITH_NO_LAYOUTS;
        } else {
          showSite = PropsValues.MY_SITES_SHOW_PUBLIC_SITES_WITH_NO_LAYOUTS;
        }
      } else if (isOrganization()) {
        showSite = false;
      } else if (isUser()) {
        if (privateSite) {
          showSite = PropsValues.MY_SITES_SHOW_USER_PRIVATE_SITES_WITH_NO_LAYOUTS;

          if (PropsValues.LAYOUT_USER_PRIVATE_LAYOUTS_POWER_USER_REQUIRED && !hasPowerUserRole) {

            showSite = false;
          }
        } else {
          showSite = PropsValues.MY_SITES_SHOW_USER_PUBLIC_SITES_WITH_NO_LAYOUTS;

          if (PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_POWER_USER_REQUIRED && !hasPowerUserRole) {

            showSite = false;
          }
        }
      }
    } else {
      defaultLayout =
          LayoutLocalServiceUtil.fetchFirstLayout(
              getGroupId(), privateSite, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);

      if ((defaultLayout != null)
          && !LayoutPermissionUtil.contains(
              permissionChecker, defaultLayout, true, ActionKeys.VIEW)) {

        showSite = false;
      } else if (isOrganization() && !isSite()) {
        _log.error("Group " + getGroupId() + " is an organization site that does not have pages");
      }
    }

    return showSite;
  }
  protected void runLayoutSetPrototype(
      boolean layoutSetLinkEnabled,
      boolean layoutLinkEnabled,
      boolean addPage,
      boolean deletePage,
      boolean useLayoutPrototype)
      throws Exception {

    LayoutSetPrototype layoutSetPrototype =
        ServiceTestUtil.addLayoutSetPrototype(ServiceTestUtil.randomString());

    Group layoutSetPrototypeGroup = layoutSetPrototype.getGroup();

    int layoutSetPrototypeLayoutsCount =
        LayoutLocalServiceUtil.getLayoutsCount(layoutSetPrototypeGroup, true);

    ServiceTestUtil.addLayout(
        layoutSetPrototypeGroup.getGroupId(), ServiceTestUtil.randomString(), true);
    ServiceTestUtil.addLayout(
        layoutSetPrototypeGroup.getGroupId(), ServiceTestUtil.randomString(), true);

    Group group = ServiceTestUtil.addGroup();

    SitesUtil.updateLayoutSetPrototypesLinks(
        group, layoutSetPrototype.getLayoutSetPrototypeId(), 0, layoutSetLinkEnabled, false);

    propagateChanges(group);

    int groupLayoutsCount = LayoutLocalServiceUtil.getLayoutsCount(group, false);

    Assert.assertEquals(groupLayoutsCount, layoutSetPrototypeLayoutsCount + 2);

    if (addPage) {
      Layout layout = null;

      if (useLayoutPrototype) {
        LayoutPrototype layoutPrototype =
            ServiceTestUtil.addLayoutPrototype(ServiceTestUtil.randomString());

        Layout layoutPrototypeLayout = layoutPrototype.getLayout();

        updateLayoutTemplateId(layoutPrototypeLayout, "2_2_columns");

        layout =
            addLayout(
                group.getGroupId(),
                ServiceTestUtil.randomString(),
                layoutPrototype,
                layoutLinkEnabled);

        if (layoutLinkEnabled) {
          layout = propagateChanges(layout);
        }

        updateLayoutTemplateId(layoutPrototypeLayout, "1_column");

        if (layoutLinkEnabled) {
          Assert.assertEquals(
              "2_2_columns",
              layout.getTypeSettingsProperty(LayoutTypePortletConstants.LAYOUT_TEMPLATE_ID));

          layout = propagateChanges(layout);
        }
      } else {

        // Database will store Date values without milliseconds. Wait
        // for more than one second to ensure that later queries can
        // correctly compare the Date values.

        Thread.sleep(2000);

        layout =
            ServiceTestUtil.addLayout(
                layoutSetPrototypeGroup.getGroupId(), ServiceTestUtil.randomString(), true);
      }

      if (!useLayoutPrototype) {
        groupLayoutsCount = LayoutLocalServiceUtil.getLayoutsCount(group, false);

        Assert.assertEquals(groupLayoutsCount, layoutSetPrototypeLayoutsCount + 2);
      }

      propagateChanges(group);

      groupLayoutsCount = LayoutLocalServiceUtil.getLayoutsCount(group, false);

      if (layoutSetLinkEnabled) {
        Assert.assertEquals(groupLayoutsCount, layoutSetPrototypeLayoutsCount + 3);

        if (useLayoutPrototype) {
          if (layoutLinkEnabled) {
            Assert.assertEquals(
                "1_column",
                layout.getTypeSettingsProperty(LayoutTypePortletConstants.LAYOUT_TEMPLATE_ID));
          } else {
            Assert.assertEquals(
                "2_2_columns",
                layout.getTypeSettingsProperty(LayoutTypePortletConstants.LAYOUT_TEMPLATE_ID));
          }
        }
      }

      if (deletePage) {
        LayoutLocalServiceUtil.deleteLayout(layout, true, ServiceTestUtil.getServiceContext());

        groupLayoutsCount = LayoutLocalServiceUtil.getLayoutsCount(group, false);

        if (layoutSetLinkEnabled) {
          if (!useLayoutPrototype) {
            Assert.assertEquals(groupLayoutsCount, layoutSetPrototypeLayoutsCount + 3);

            propagateChanges(group);
          }

          groupLayoutsCount = LayoutLocalServiceUtil.getLayoutsCount(group, false);
        }

        Assert.assertEquals(groupLayoutsCount, layoutSetPrototypeLayoutsCount + 2);
      }
    }
  }
Exemplo n.º 9
0
  public int getPublicLayoutsPageCount() throws PortalException, SystemException {

    return LayoutLocalServiceUtil.getLayoutsCount(this, false);
  }
Exemplo n.º 10
0
  @Override
  public int getPrivateLayoutsPageCount() throws PortalException, SystemException {

    return LayoutLocalServiceUtil.getLayoutsCount(this, true);
  }
Exemplo n.º 11
0
  protected void enableLocalStaging(boolean stageJournal, boolean stagePolls) throws Exception {

    Group group = ServiceTestUtil.addGroup();

    ServiceTestUtil.addLayout(group.getGroupId(), "Page1");
    ServiceTestUtil.addLayout(group.getGroupId(), "Page2");

    int initialPagesCount = LayoutLocalServiceUtil.getLayoutsCount(group, false);

    // Create content

    JournalArticle journalArticle = addJournalArticle(group.getGroupId(), "Title", "content");

    PollsQuestion pollsQuestion = addPollsQuestion(group.getGroupId(), "Question", "Description");

    ServiceContext serviceContext = ServiceTestUtil.getServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);
    serviceContext.setScopeGroupId(group.getGroupId());

    Map<String, String[]> parameters = StagingUtil.getStagingParameters();

    parameters.put(PortletDataHandlerKeys.PORTLET_DATA_ALL, new String[] {String.valueOf(false)});

    parameters.put(
        PortletDataHandlerKeys.PORTLET_DATA + "_" + PortletKeys.JOURNAL,
        new String[] {String.valueOf(stageJournal)});

    parameters.put(
        PortletDataHandlerKeys.PORTLET_DATA + "_" + PortletKeys.POLLS,
        new String[] {String.valueOf(stagePolls)});

    for (String parameterName : parameters.keySet()) {
      serviceContext.setAttribute(parameterName, parameters.get(parameterName)[0]);
    }

    serviceContext.setAttribute(
        StagingConstants.STAGED_PORTLET + PortletKeys.JOURNAL, stageJournal);

    serviceContext.setAttribute(StagingConstants.STAGED_PORTLET + PortletKeys.POLLS, stagePolls);

    // Enable staging

    StagingUtil.enableLocalStaging(
        TestPropsValues.getUserId(), group, group, false, false, serviceContext);

    Group stagingGroup = group.getStagingGroup();

    Assert.assertNotNull(stagingGroup);

    Assert.assertEquals(
        LayoutLocalServiceUtil.getLayoutsCount(stagingGroup, false), initialPagesCount);

    // Update content in staging

    JournalArticle stagingJournalArticle =
        JournalArticleLocalServiceUtil.getArticleByUrlTitle(
            stagingGroup.getGroupId(), journalArticle.getUrlTitle());

    stagingJournalArticle =
        updateJournalArticle(stagingJournalArticle, "Title2", stagingJournalArticle.getContent());

    PollsQuestion stagingQuestion =
        PollsQuestionLocalServiceUtil.getPollsQuestionByUuidAndGroupId(
            pollsQuestion.getUuid(), stagingGroup.getGroupId());

    stagingQuestion = updatePollsQuestion(stagingQuestion, "Question2", "Description2");

    // Publish to live

    StagingUtil.publishLayouts(
        TestPropsValues.getUserId(),
        stagingGroup.getGroupId(),
        group.getGroupId(),
        false,
        parameters,
        null,
        null);

    // Retrieve content from live after publishing

    journalArticle = JournalArticleLocalServiceUtil.getArticle(journalArticle.getId());
    pollsQuestion = PollsQuestionLocalServiceUtil.getQuestion(pollsQuestion.getQuestionId());

    if (stagePolls) {
      for (Locale locale : _locales) {
        Assert.assertEquals(pollsQuestion.getTitle(locale), stagingQuestion.getTitle(locale));
      }
    } else {
      for (Locale locale : _locales) {
        Assert.assertFalse(pollsQuestion.getTitle(locale).equals(stagingQuestion.getTitle(locale)));
      }
    }

    if (stageJournal) {
      for (Locale locale : _locales) {
        Assert.assertEquals(
            journalArticle.getTitle(locale), stagingJournalArticle.getTitle(locale));
      }
    } else {
      for (Locale locale : _locales) {
        Assert.assertFalse(
            journalArticle.getTitle(locale).equals(stagingJournalArticle.getTitle(locale)));
      }
    }
  }