コード例 #1
0
  @Override
  @SystemEvent(action = SystemEventConstants.ACTION_SKIP, type = SystemEventConstants.TYPE_DELETE)
  public LayoutPrototype deleteLayoutPrototype(LayoutPrototype layoutPrototype)
      throws PortalException, SystemException {

    // Group

    if (layoutPersistence.countByLayoutPrototypeUuid(layoutPrototype.getUuid()) > 0) {

      throw new RequiredLayoutPrototypeException();
    }

    Group group = layoutPrototype.getGroup();

    groupLocalService.deleteGroup(group);

    // Resources

    resourceLocalService.deleteResource(
        layoutPrototype.getCompanyId(),
        LayoutPrototype.class.getName(),
        ResourceConstants.SCOPE_INDIVIDUAL,
        layoutPrototype.getLayoutPrototypeId());

    // Layout Prototype

    layoutPrototypePersistence.remove(layoutPrototype);

    // Permission cache

    PermissionCacheUtil.clearCache();

    return layoutPrototype;
  }
コード例 #2
0
  @Test
  @Transactional
  public void testExportImportLayoutSetPrototypeInvalidLARType() throws Exception {

    // Import LayoutSetPrototype to LayoutSet

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

    group = layoutSetPrototype.getGroup();
    importedGroup = GroupTestUtil.addGroup();

    long[] layoutIds = new long[0];

    try {
      exportImportLayouts(layoutIds, getImportParameterMap());

      Assert.fail();
    } catch (LARTypeException lte) {
    }

    // Import LayoutSetPrototype to LayoutPrototyope

    LayoutPrototype layoutPrototype =
        LayoutTestUtil.addLayoutPrototype(ServiceTestUtil.randomString());

    importedGroup = layoutPrototype.getGroup();

    try {
      exportImportLayouts(layoutIds, getImportParameterMap());

      Assert.fail();
    } catch (LARTypeException lte) {
    }
  }
コード例 #3
0
  @Test
  public void testFetchByPrimaryKeyExisting() throws Exception {
    LayoutPrototype newLayoutPrototype = addLayoutPrototype();

    LayoutPrototype existingLayoutPrototype =
        _persistence.fetchByPrimaryKey(newLayoutPrototype.getPrimaryKey());

    Assert.assertEquals(existingLayoutPrototype, newLayoutPrototype);
  }
コード例 #4
0
  @Test
  public void testCreate() throws Exception {
    long pk = ServiceTestUtil.nextLong();

    LayoutPrototype layoutPrototype = _persistence.create(pk);

    Assert.assertNotNull(layoutPrototype);

    Assert.assertEquals(layoutPrototype.getPrimaryKey(), pk);
  }
コード例 #5
0
  @Test
  public void testRemove() throws Exception {
    LayoutPrototype newLayoutPrototype = addLayoutPrototype();

    _persistence.remove(newLayoutPrototype);

    LayoutPrototype existingLayoutPrototype =
        _persistence.fetchByPrimaryKey(newLayoutPrototype.getPrimaryKey());

    Assert.assertNull(existingLayoutPrototype);
  }
コード例 #6
0
  @Override
  public void deleteNondefaultLayoutPrototypes(long companyId)
      throws PortalException, SystemException {

    long defaultUserId = userLocalService.getDefaultUserId(companyId);

    List<LayoutPrototype> layoutPrototypes = layoutPrototypePersistence.findByCompanyId(companyId);

    for (LayoutPrototype layoutPrototype : layoutPrototypes) {
      if (layoutPrototype.getUserId() != defaultUserId) {
        deleteLayoutPrototype(layoutPrototype);
      }
    }
  }
  protected LayoutPrototype getImportedLayoutPrototype(
      Map<String, List<StagedModel>> dependentStagedModelsMap, Group group) throws Exception {

    List<StagedModel> dependentLayoutPrototypeStagedModels =
        dependentStagedModelsMap.get(LayoutPrototype.class.getSimpleName());

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

    LayoutPrototype layoutPrototype = (LayoutPrototype) dependentLayoutPrototypeStagedModels.get(0);

    LayoutPrototype importedLayoutPrototype =
        LayoutPrototypeLocalServiceUtil.fetchLayoutPrototypeByUuidAndCompanyId(
            layoutPrototype.getUuid(), group.getCompanyId());

    Assert.assertNotNull(importedLayoutPrototype);

    return importedLayoutPrototype;
  }
コード例 #8
0
  @Test
  public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
    LayoutPrototype newLayoutPrototype = addLayoutPrototype();

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

    dynamicQuery.add(
        RestrictionsFactoryUtil.eq("layoutPrototypeId", newLayoutPrototype.getLayoutPrototypeId()));

    List<LayoutPrototype> result = _persistence.findWithDynamicQuery(dynamicQuery);

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

    LayoutPrototype existingLayoutPrototype = result.get(0);

    Assert.assertEquals(existingLayoutPrototype, newLayoutPrototype);
  }
  protected void validateLayouts(
      LayoutSetPrototype importedLayoutSetPrototype,
      LayoutPrototype importedLayoutPrototype,
      Layout layoutSetPrototypeLayout)
      throws Exception {

    validatePrototypedLayouts(LayoutSetPrototype.class, importedLayoutSetPrototype.getGroupId());
    validatePrototypedLayouts(LayoutPrototype.class, importedLayoutPrototype.getGroupId());

    Assert.assertNotNull(layoutSetPrototypeLayout.getLayoutPrototypeUuid());

    Layout importedLayout =
        LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(
            layoutSetPrototypeLayout.getUuid(), importedLayoutSetPrototype.getGroupId(), true);

    Assert.assertNotNull(importedLayout);
    Assert.assertEquals(importedLayoutSetPrototype.getGroupId(), importedLayout.getGroupId());
    Assert.assertEquals(importedLayoutPrototype.getUuid(), importedLayout.getLayoutPrototypeUuid());
  }
コード例 #10
0
  @Override
  public List<LayoutPrototype> search(long companyId, Boolean active, OrderByComparator obc)
      throws PortalException, SystemException {

    List<LayoutPrototype> filteredLayoutPrototypes = new ArrayList<LayoutPrototype>();

    List<LayoutPrototype> layoutPrototypes =
        layoutPrototypeLocalService.search(
            companyId, active, QueryUtil.ALL_POS, QueryUtil.ALL_POS, obc);

    for (LayoutPrototype layoutPrototype : layoutPrototypes) {
      if (LayoutPrototypePermissionUtil.contains(
          getPermissionChecker(), layoutPrototype.getLayoutPrototypeId(), ActionKeys.VIEW)) {

        filteredLayoutPrototypes.add(layoutPrototype);
      }
    }

    return filteredLayoutPrototypes;
  }
コード例 #11
0
  @Test
  public void testExportImportLayoutSetPrototypeInvalidLARType() throws Exception {

    // Import a layout set prototype to a layout set

    LayoutSetPrototype layoutSetPrototype =
        LayoutTestUtil.addLayoutSetPrototype(RandomTestUtil.randomString());

    try {
      group = layoutSetPrototype.getGroup();
      importedGroup = GroupTestUtil.addGroup();

      long[] layoutIds = new long[0];

      try {
        exportImportLayouts(layoutIds, getImportParameterMap());

        Assert.fail();
      } catch (LARTypeException lte) {
      }

      // Import a layout set prototype to a layout prototyope

      LayoutPrototype layoutPrototype =
          LayoutTestUtil.addLayoutPrototype(RandomTestUtil.randomString());

      importedGroup = layoutPrototype.getGroup();

      try {
        exportImportLayouts(layoutIds, getImportParameterMap());

        Assert.fail();
      } catch (LARTypeException lte) {
      }
    } finally {
      LayoutSetPrototypeLocalServiceUtil.deleteLayoutSetPrototype(layoutSetPrototype);

      group = null;
    }
  }
コード例 #12
0
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    LayoutPrototype newLayoutPrototype = addLayoutPrototype();

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

    dynamicQuery.setProjection(ProjectionFactoryUtil.property("layoutPrototypeId"));

    Object newLayoutPrototypeId = newLayoutPrototype.getLayoutPrototypeId();

    dynamicQuery.add(
        RestrictionsFactoryUtil.in("layoutPrototypeId", new Object[] {newLayoutPrototypeId}));

    List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);

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

    Object existingLayoutPrototypeId = result.get(0);

    Assert.assertEquals(existingLayoutPrototypeId, newLayoutPrototypeId);
  }
コード例 #13
0
  @Override
  public LayoutPrototype updateLayoutPrototype(
      long layoutPrototypeId,
      Map<Locale, String> nameMap,
      String description,
      boolean active,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Layout prototype

    LayoutPrototype layoutPrototype =
        layoutPrototypePersistence.findByPrimaryKey(layoutPrototypeId);

    layoutPrototype.setModifiedDate(serviceContext.getModifiedDate(new Date()));
    layoutPrototype.setNameMap(nameMap);
    layoutPrototype.setDescription(description);
    layoutPrototype.setActive(active);

    layoutPrototypePersistence.update(layoutPrototype);

    // Group

    Group group =
        groupLocalService.getLayoutPrototypeGroup(
            layoutPrototype.getCompanyId(), layoutPrototypeId);

    group.setName(layoutPrototype.getName(LocaleUtil.getDefault()));

    groupPersistence.update(group);

    // Layout

    Layout layout = layoutPrototype.getLayout();

    layout.setModifiedDate(layoutPrototype.getModifiedDate());
    layout.setNameMap(nameMap);

    layoutPersistence.update(layout);

    return layoutPrototype;
  }
コード例 #14
0
  protected void populateElementLayoutMetadata(Element layoutElement, Layout layout)
      throws Exception {

    LayoutStagingHandler layoutStagingHandler = LayoutStagingUtil.getLayoutStagingHandler(layout);

    if (layoutStagingHandler != null) {
      LayoutRevision layoutRevision = layoutStagingHandler.getLayoutRevision();

      if (layoutRevision != null) {
        layoutElement.addAttribute(
            "layout-revision-id", String.valueOf(layoutRevision.getLayoutRevisionId()));
        layoutElement.addAttribute(
            "layout-branch-id", String.valueOf(layoutRevision.getLayoutBranchId()));

        LayoutBranch layoutBranch = layoutRevision.getLayoutBranch();

        layoutElement.addAttribute("layout-branch-name", String.valueOf(layoutBranch.getName()));
      }
    }

    layoutElement.addAttribute("layout-uuid", layout.getUuid());
    layoutElement.addAttribute("layout-id", String.valueOf(layout.getLayoutId()));
    layoutElement.addAttribute("layout-priority", String.valueOf(layout.getPriority()));

    String layoutPrototypeUuid = layout.getLayoutPrototypeUuid();

    if (Validator.isNotNull(layoutPrototypeUuid)) {
      LayoutPrototype layoutPrototype =
          _layoutPrototypeLocalService.getLayoutPrototypeByUuidAndCompanyId(
              layoutPrototypeUuid, layout.getCompanyId());

      layoutElement.addAttribute("layout-prototype-uuid", layoutPrototypeUuid);
      layoutElement.addAttribute(
          "layout-prototype-name", layoutPrototype.getName(LocaleUtil.getDefault()));
    }
  }
コード例 #15
0
  public static Layout getSourcePrototypeLayout(Layout layout) {
    if (Validator.isNull(layout.getUuid())) {
      return null;
    }

    try {
      Group group = null;

      if (Validator.isNotNull(layout.getLayoutPrototypeUuid())) {
        LayoutPrototype layoutPrototype =
            LayoutPrototypeLocalServiceUtil.getLayoutPrototypeByUuid(
                layout.getLayoutPrototypeUuid());

        group = layoutPrototype.getGroup();
      } else {
        LayoutSet layoutSet = layout.getLayoutSet();

        if (Validator.isNull(layoutSet.getLayoutSetPrototypeUuid())) {
          return null;
        }

        LayoutSetPrototype layoutSetPrototype =
            LayoutSetPrototypeLocalServiceUtil.getLayoutSetPrototypeByUuid(
                layoutSet.getLayoutSetPrototypeUuid());

        group = layoutSetPrototype.getGroup();
      }

      return LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(
          layout.getSourcePrototypeLayoutUuid(), group.getGroupId());
    } catch (Exception e) {
      _log.error(e, e);
    }

    return null;
  }
  protected void exportLayouts(
      PortletDataContext portletDataContext,
      LayoutPrototype layoutPrototype,
      Element layoutPrototypeElement)
      throws Exception {

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

    for (Layout layout : layouts) {
      StagedModelDataHandlerUtil.exportStagedModel(portletDataContext, layout);

      portletDataContext.addReferenceElement(
          layoutPrototype,
          layoutPrototypeElement,
          layout,
          PortletDataContext.REFERENCE_TYPE_EMBEDDED,
          false);
    }
  }
コード例 #17
0
 @Override
 public Long get(LayoutPrototype layoutPrototype) {
   return layoutPrototype.getLayoutPrototypeId();
 }
コード例 #18
0
  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);
      }
    }
  }
  @Override
  protected void doImportStagedModel(
      PortletDataContext portletDataContext, LayoutPrototype layoutPrototype) throws Exception {

    long userId = portletDataContext.getUserId(layoutPrototype.getUserUuid());

    ServiceContext serviceContext =
        portletDataContext.createServiceContext(
            layoutPrototype, LayoutPrototypePortletDataHandler.NAMESPACE);

    serviceContext.setAttribute("addDefaultLayout", false);

    LayoutPrototype importedLayoutPrototype = null;

    if (portletDataContext.isDataStrategyMirror()) {
      LayoutPrototype existingLayoutPrototype =
          LayoutPrototypeLocalServiceUtil.fetchLayoutPrototypeByUuidAndCompanyId(
              layoutPrototype.getUuid(), portletDataContext.getCompanyId());

      if (existingLayoutPrototype == null) {
        serviceContext.setUuid(layoutPrototype.getUuid());

        importedLayoutPrototype =
            LayoutPrototypeLocalServiceUtil.addLayoutPrototype(
                userId,
                portletDataContext.getCompanyId(),
                layoutPrototype.getNameMap(),
                layoutPrototype.getDescription(),
                layoutPrototype.isActive(),
                serviceContext);
      } else {
        importedLayoutPrototype =
            LayoutPrototypeLocalServiceUtil.updateLayoutPrototype(
                existingLayoutPrototype.getLayoutPrototypeId(),
                layoutPrototype.getNameMap(),
                layoutPrototype.getDescription(),
                layoutPrototype.isActive(),
                serviceContext);
      }
    } else {
      importedLayoutPrototype =
          LayoutPrototypeLocalServiceUtil.addLayoutPrototype(
              userId,
              portletDataContext.getCompanyId(),
              layoutPrototype.getNameMap(),
              layoutPrototype.getDescription(),
              layoutPrototype.isActive(),
              serviceContext);
    }

    importLayouts(portletDataContext, layoutPrototype, importedLayoutPrototype.getGroupId());

    portletDataContext.importClassedModel(
        layoutPrototype, importedLayoutPrototype, LayoutPrototypePortletDataHandler.NAMESPACE);
  }
コード例 #20
0
  @Override
  public LayoutPrototype addLayoutPrototype(
      long userId,
      long companyId,
      Map<Locale, String> nameMap,
      String description,
      boolean active,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Layout prototype

    User user = userPersistence.findByPrimaryKey(userId);
    Date now = new Date();

    long layoutPrototypeId = counterLocalService.increment();

    LayoutPrototype layoutPrototype = layoutPrototypePersistence.create(layoutPrototypeId);

    layoutPrototype.setUuid(serviceContext.getUuid());
    layoutPrototype.setCompanyId(companyId);
    layoutPrototype.setUserId(userId);
    layoutPrototype.setUserName(user.getFullName());
    layoutPrototype.setCreateDate(serviceContext.getCreateDate(now));
    layoutPrototype.setModifiedDate(serviceContext.getModifiedDate(now));
    layoutPrototype.setNameMap(nameMap);
    layoutPrototype.setDescription(description);
    layoutPrototype.setActive(active);

    layoutPrototypePersistence.update(layoutPrototype);

    // Resources

    if (userId > 0) {
      resourceLocalService.addResources(
          companyId,
          0,
          userId,
          LayoutPrototype.class.getName(),
          layoutPrototype.getLayoutPrototypeId(),
          false,
          false,
          false);
    }

    // Group

    String friendlyURL = "/template-" + layoutPrototype.getLayoutPrototypeId();

    Group group =
        groupLocalService.addGroup(
            userId,
            GroupConstants.DEFAULT_PARENT_GROUP_ID,
            LayoutPrototype.class.getName(),
            layoutPrototype.getLayoutPrototypeId(),
            GroupConstants.DEFAULT_LIVE_GROUP_ID,
            layoutPrototype.getName(LocaleUtil.getDefault()),
            null,
            0,
            true,
            GroupConstants.DEFAULT_MEMBERSHIP_RESTRICTION,
            friendlyURL,
            false,
            true,
            null);

    if (GetterUtil.getBoolean(serviceContext.getAttribute("addDefaultLayout"), true)) {

      layoutLocalService.addLayout(
          userId,
          group.getGroupId(),
          true,
          LayoutConstants.DEFAULT_PARENT_LAYOUT_ID,
          layoutPrototype.getName(LocaleUtil.getDefault()),
          null,
          null,
          LayoutConstants.TYPE_PORTLET,
          false,
          "/layout",
          serviceContext);
    }

    return layoutPrototype;
  }
コード例 #21
0
  @Override
  public String getDescriptiveName(Locale locale) throws PortalException {
    Group curGroup = this;

    String name = getName(locale);

    if (Validator.isNull(name)) {
      Locale siteDefaultLocale = PortalUtil.getSiteDefaultLocale(getGroupId());

      name = getName(siteDefaultLocale);
    }

    if (isCompany() && !isCompanyStagingGroup()) {
      name = LanguageUtil.get(locale, "global");
    } else if (isControlPanel()) {
      name = LanguageUtil.get(locale, "control-panel");
    } else if (isGuest()) {
      Company company = CompanyLocalServiceUtil.getCompany(getCompanyId());

      Account account = company.getAccount();

      name = account.getName();
    } else if (isLayout()) {
      Layout layout = LayoutLocalServiceUtil.getLayout(getClassPK());

      name = layout.getName(locale);
    } else if (isLayoutPrototype()) {
      LayoutPrototype layoutPrototype =
          LayoutPrototypeLocalServiceUtil.getLayoutPrototype(getClassPK());

      name = layoutPrototype.getName(locale);
    } else if (isLayoutSetPrototype()) {
      LayoutSetPrototype layoutSetPrototype =
          LayoutSetPrototypeLocalServiceUtil.getLayoutSetPrototype(getClassPK());

      name = layoutSetPrototype.getName(locale);
    } else if (isOrganization()) {
      long organizationId = getOrganizationId();

      Organization organization = OrganizationLocalServiceUtil.getOrganization(organizationId);

      name = organization.getName();

      curGroup = organization.getGroup();
    } else if (isUser()) {
      long userId = getClassPK();

      User user = UserLocalServiceUtil.getUser(userId);

      name = user.getFullName();
    } else if (isUserGroup()) {
      long userGroupId = getClassPK();

      UserGroup userGroup = UserGroupLocalServiceUtil.getUserGroup(userGroupId);

      name = userGroup.getName();
    } else if (isUserPersonalSite()) {
      name = LanguageUtil.get(locale, "user-personal-site");
    }

    if (curGroup.isStaged() && !curGroup.isStagedRemotely() && curGroup.isStagingGroup()) {

      Group liveGroup = getLiveGroup();

      name = liveGroup.getDescriptiveName(locale);
    }

    return name;
  }
コード例 #22
0
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = ServiceTestUtil.nextLong();

    LayoutPrototype newLayoutPrototype = _persistence.create(pk);

    newLayoutPrototype.setMvccVersion(ServiceTestUtil.nextLong());

    newLayoutPrototype.setUuid(ServiceTestUtil.randomString());

    newLayoutPrototype.setCompanyId(ServiceTestUtil.nextLong());

    newLayoutPrototype.setUserId(ServiceTestUtil.nextLong());

    newLayoutPrototype.setUserName(ServiceTestUtil.randomString());

    newLayoutPrototype.setCreateDate(ServiceTestUtil.nextDate());

    newLayoutPrototype.setModifiedDate(ServiceTestUtil.nextDate());

    newLayoutPrototype.setName(ServiceTestUtil.randomString());

    newLayoutPrototype.setDescription(ServiceTestUtil.randomString());

    newLayoutPrototype.setSettings(ServiceTestUtil.randomString());

    newLayoutPrototype.setActive(ServiceTestUtil.randomBoolean());

    _persistence.update(newLayoutPrototype);

    LayoutPrototype existingLayoutPrototype =
        _persistence.findByPrimaryKey(newLayoutPrototype.getPrimaryKey());

    Assert.assertEquals(
        existingLayoutPrototype.getMvccVersion(), newLayoutPrototype.getMvccVersion());
    Assert.assertEquals(existingLayoutPrototype.getUuid(), newLayoutPrototype.getUuid());
    Assert.assertEquals(
        existingLayoutPrototype.getLayoutPrototypeId(), newLayoutPrototype.getLayoutPrototypeId());
    Assert.assertEquals(existingLayoutPrototype.getCompanyId(), newLayoutPrototype.getCompanyId());
    Assert.assertEquals(existingLayoutPrototype.getUserId(), newLayoutPrototype.getUserId());
    Assert.assertEquals(existingLayoutPrototype.getUserName(), newLayoutPrototype.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingLayoutPrototype.getCreateDate()),
        Time.getShortTimestamp(newLayoutPrototype.getCreateDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingLayoutPrototype.getModifiedDate()),
        Time.getShortTimestamp(newLayoutPrototype.getModifiedDate()));
    Assert.assertEquals(existingLayoutPrototype.getName(), newLayoutPrototype.getName());
    Assert.assertEquals(
        existingLayoutPrototype.getDescription(), newLayoutPrototype.getDescription());
    Assert.assertEquals(existingLayoutPrototype.getSettings(), newLayoutPrototype.getSettings());
    Assert.assertEquals(existingLayoutPrototype.getActive(), newLayoutPrototype.getActive());
  }
コード例 #23
0
  protected File doExportLayoutsAsFile(
      long groupId,
      boolean privateLayout,
      long[] layoutIds,
      Map<String, String[]> parameterMap,
      Date startDate,
      Date endDate)
      throws Exception {

    boolean exportCategories = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.CATEGORIES);
    boolean exportIgnoreLastPublishDate =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.IGNORE_LAST_PUBLISH_DATE);
    boolean exportPermissions =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PERMISSIONS);
    boolean exportPortletDataAll =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PORTLET_DATA_ALL);
    boolean exportTheme = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.THEME);
    boolean exportThemeSettings =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.THEME_REFERENCE);
    boolean exportLogo = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.LOGO);
    boolean exportLayoutSetSettings =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.LAYOUT_SET_SETTINGS);
    boolean updateLastPublishDate =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.UPDATE_LAST_PUBLISH_DATE);

    if (_log.isDebugEnabled()) {
      _log.debug("Export permissions " + exportPermissions);
      _log.debug("Export theme " + exportTheme);
    }

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

    long companyId = layoutSet.getCompanyId();
    long defaultUserId = UserLocalServiceUtil.getDefaultUserId(companyId);

    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();

    if (serviceContext == null) {
      serviceContext = new ServiceContext();

      serviceContext.setCompanyId(companyId);
      serviceContext.setSignedIn(false);
      serviceContext.setUserId(defaultUserId);

      ServiceContextThreadLocal.pushServiceContext(serviceContext);
    }

    serviceContext.setAttribute("exporting", Boolean.TRUE);

    long layoutSetBranchId = MapUtil.getLong(parameterMap, "layoutSetBranchId");

    serviceContext.setAttribute("layoutSetBranchId", layoutSetBranchId);

    long lastPublishDate = System.currentTimeMillis();

    if (endDate != null) {
      lastPublishDate = endDate.getTime();
    }

    if (exportIgnoreLastPublishDate) {
      endDate = null;
      startDate = null;
    }

    StopWatch stopWatch = null;

    if (_log.isInfoEnabled()) {
      stopWatch = new StopWatch();

      stopWatch.start();
    }

    LayoutCache layoutCache = new LayoutCache();

    ZipWriter zipWriter = ZipWriterFactoryUtil.getZipWriter();

    PortletDataContext portletDataContext =
        PortletDataContextFactoryUtil.createExportPortletDataContext(
            companyId, groupId, parameterMap, startDate, endDate, zipWriter);

    portletDataContext.setPortetDataContextListener(
        new PortletDataContextListenerImpl(portletDataContext));

    Document document = SAXReaderUtil.createDocument();

    Element rootElement = document.addElement("root");

    portletDataContext.setExportDataRootElement(rootElement);

    Element headerElement = rootElement.addElement("header");

    headerElement.addAttribute(
        "available-locales",
        StringUtil.merge(LanguageUtil.getAvailableLocales(portletDataContext.getScopeGroupId())));
    headerElement.addAttribute("build-number", String.valueOf(ReleaseInfo.getBuildNumber()));
    headerElement.addAttribute("export-date", Time.getRFC822());

    if (portletDataContext.hasDateRange()) {
      headerElement.addAttribute("start-date", String.valueOf(portletDataContext.getStartDate()));
      headerElement.addAttribute("end-date", String.valueOf(portletDataContext.getEndDate()));
    }

    headerElement.addAttribute("company-id", String.valueOf(portletDataContext.getCompanyId()));
    headerElement.addAttribute(
        "company-group-id", String.valueOf(portletDataContext.getCompanyGroupId()));
    headerElement.addAttribute("group-id", String.valueOf(groupId));
    headerElement.addAttribute(
        "user-personal-site-group-id",
        String.valueOf(portletDataContext.getUserPersonalSiteGroupId()));
    headerElement.addAttribute("private-layout", String.valueOf(privateLayout));

    Group group = layoutSet.getGroup();

    String type = "layout-set";

    if (group.isLayoutPrototype()) {
      type = "layout-prototype";

      LayoutPrototype layoutPrototype =
          LayoutPrototypeLocalServiceUtil.getLayoutPrototype(group.getClassPK());

      headerElement.addAttribute("type-uuid", layoutPrototype.getUuid());
    } else if (group.isLayoutSetPrototype()) {
      type = "layout-set-prototype";

      LayoutSetPrototype layoutSetPrototype =
          LayoutSetPrototypeLocalServiceUtil.getLayoutSetPrototype(group.getClassPK());

      headerElement.addAttribute("type-uuid", layoutSetPrototype.getUuid());
    }

    headerElement.addAttribute("type", type);

    if (exportTheme || exportThemeSettings) {
      headerElement.addAttribute("theme-id", layoutSet.getThemeId());
      headerElement.addAttribute("color-scheme-id", layoutSet.getColorSchemeId());
    }

    if (exportLogo) {
      Image image = ImageLocalServiceUtil.getImage(layoutSet.getLogoId());

      if ((image != null) && (image.getTextObj() != null)) {
        String logoPath = ExportImportPathUtil.getRootPath(portletDataContext);

        logoPath += "/logo";

        headerElement.addAttribute("logo-path", logoPath);

        portletDataContext.addZipEntry(logoPath, image.getTextObj());
      }
    }

    if (exportLayoutSetSettings) {
      Element settingsElement = headerElement.addElement("settings");

      settingsElement.addCDATA(layoutSet.getSettings());
    }

    Element cssElement = headerElement.addElement("css");

    cssElement.addCDATA(layoutSet.getCss());

    Map<String, Object[]> portletIds = new LinkedHashMap<String, Object[]>();

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

    List<Portlet> portlets = getDataSiteLevelPortlets(companyId);

    long plid = LayoutConstants.DEFAULT_PLID;

    if (!layouts.isEmpty()) {
      Layout firstLayout = layouts.get(0);

      plid = firstLayout.getPlid();
    }

    if (group.isStagingGroup()) {
      group = group.getLiveGroup();
    }

    for (Portlet portlet : portlets) {
      String portletId = portlet.getRootPortletId();

      if (!group.isStagedPortlet(portletId)) {
        continue;
      }

      String key = PortletPermissionUtil.getPrimaryKey(0, portletId);

      if (portletIds.get(key) == null) {
        portletIds.put(
            key, new Object[] {portletId, plid, groupId, StringPool.BLANK, StringPool.BLANK});
      }
    }

    Element missingReferencesElement = rootElement.addElement("missing-references");

    portletDataContext.setMissingReferencesElement(missingReferencesElement);

    portletDataContext.addDeletionSystemEventStagedModelTypes(new StagedModelType(Layout.class));

    Element layoutsElement = portletDataContext.getExportDataGroupElement(Layout.class);

    String layoutSetPrototypeUuid = layoutSet.getLayoutSetPrototypeUuid();

    if (Validator.isNotNull(layoutSetPrototypeUuid)) {
      LayoutSetPrototype layoutSetPrototype =
          LayoutSetPrototypeLocalServiceUtil.getLayoutSetPrototypeByUuidAndCompanyId(
              layoutSetPrototypeUuid, companyId);

      layoutsElement.addAttribute("layout-set-prototype-uuid", layoutSetPrototypeUuid);

      layoutsElement.addAttribute(
          "layout-set-prototype-name", layoutSetPrototype.getName(LocaleUtil.getDefault()));
    }

    for (Layout layout : layouts) {
      exportLayout(portletDataContext, portlets, layoutIds, portletIds, layout);
    }

    long previousScopeGroupId = portletDataContext.getScopeGroupId();

    Element portletsElement = rootElement.addElement("portlets");

    for (Map.Entry<String, Object[]> portletIdsEntry : portletIds.entrySet()) {

      Object[] portletObjects = portletIdsEntry.getValue();

      String portletId = null;
      plid = LayoutConstants.DEFAULT_PLID;
      long scopeGroupId = 0;
      String scopeType = StringPool.BLANK;
      String scopeLayoutUuid = null;

      if (portletObjects.length == 4) {
        portletId = (String) portletIdsEntry.getValue()[0];
        plid = (Long) portletIdsEntry.getValue()[1];
        scopeGroupId = (Long) portletIdsEntry.getValue()[2];
        scopeLayoutUuid = (String) portletIdsEntry.getValue()[3];
      } else {
        portletId = (String) portletIdsEntry.getValue()[0];
        plid = (Long) portletIdsEntry.getValue()[1];
        scopeGroupId = (Long) portletIdsEntry.getValue()[2];
        scopeType = (String) portletIdsEntry.getValue()[3];
        scopeLayoutUuid = (String) portletIdsEntry.getValue()[4];
      }

      Layout layout = LayoutLocalServiceUtil.fetchLayout(plid);

      if (layout == null) {
        if (!group.isCompany() && (plid <= LayoutConstants.DEFAULT_PLID)) {

          continue;
        }

        if (_log.isWarnEnabled()) {
          _log.warn("Assuming global scope because no layout was found");
        }

        layout = new LayoutImpl();

        layout.setGroupId(groupId);
        layout.setCompanyId(companyId);
      }

      portletDataContext.setPlid(plid);
      portletDataContext.setOldPlid(plid);
      portletDataContext.setScopeGroupId(scopeGroupId);
      portletDataContext.setScopeType(scopeType);
      portletDataContext.setScopeLayoutUuid(scopeLayoutUuid);

      boolean[] exportPortletControls =
          getExportPortletControls(companyId, portletId, parameterMap, type);

      _portletExporter.exportPortlet(
          portletDataContext,
          layoutCache,
          portletId,
          layout,
          portletsElement,
          defaultUserId,
          exportPermissions,
          exportPortletControls[0],
          exportPortletControls[1],
          exportPortletControls[2],
          exportPortletControls[3]);
    }

    portletDataContext.setScopeGroupId(previousScopeGroupId);

    exportAssetCategories(
        portletDataContext, exportPortletDataAll, exportCategories, group.isCompany());

    _portletExporter.exportAssetLinks(portletDataContext);
    _portletExporter.exportAssetTags(portletDataContext);
    _portletExporter.exportComments(portletDataContext);
    _portletExporter.exportExpandoTables(portletDataContext);
    _portletExporter.exportLocks(portletDataContext);

    _deletionSystemEventExporter.exportDeletionSystemEvents(portletDataContext);

    if (exportPermissions) {
      _permissionExporter.exportPortletDataPermissions(portletDataContext);
    }

    _portletExporter.exportRatingsEntries(portletDataContext, rootElement);

    if (exportTheme && !portletDataContext.isPerformDirectBinaryImport()) {
      exportTheme(layoutSet, zipWriter);
    }

    ExportImportHelperUtil.writeManifestSummary(document, portletDataContext.getManifestSummary());

    if (_log.isInfoEnabled()) {
      if (stopWatch != null) {
        _log.info("Exporting layouts takes " + stopWatch.getTime() + " ms");
      } else {
        _log.info("Exporting layouts is finished");
      }
    }

    portletDataContext.addZipEntry("/manifest.xml", document.formattedString());

    try {
      return zipWriter.getFile();
    } finally {
      if (updateLastPublishDate) {
        updateLastPublishDate(layoutSet, lastPublishDate);
      }
    }
  }
コード例 #24
0
  protected LayoutPrototype addLayoutPrototype() throws Exception {
    long pk = ServiceTestUtil.nextLong();

    LayoutPrototype layoutPrototype = _persistence.create(pk);

    layoutPrototype.setMvccVersion(ServiceTestUtil.nextLong());

    layoutPrototype.setUuid(ServiceTestUtil.randomString());

    layoutPrototype.setCompanyId(ServiceTestUtil.nextLong());

    layoutPrototype.setUserId(ServiceTestUtil.nextLong());

    layoutPrototype.setUserName(ServiceTestUtil.randomString());

    layoutPrototype.setCreateDate(ServiceTestUtil.nextDate());

    layoutPrototype.setModifiedDate(ServiceTestUtil.nextDate());

    layoutPrototype.setName(ServiceTestUtil.randomString());

    layoutPrototype.setDescription(ServiceTestUtil.randomString());

    layoutPrototype.setSettings(ServiceTestUtil.randomString());

    layoutPrototype.setActive(ServiceTestUtil.randomBoolean());

    _persistence.update(layoutPrototype);

    return layoutPrototype;
  }