List of usage examples for com.liferay.portal.kernel.model LayoutConstants DEFAULT_PARENT_LAYOUT_ID
long DEFAULT_PARENT_LAYOUT_ID
To view the source code for com.liferay.portal.kernel.model LayoutConstants DEFAULT_PARENT_LAYOUT_ID.
Click Source Link
From source file:com.liferay.asset.publisher.portlet.test.DisplayPageFriendlyURLResolverTest.java
License:Open Source License
@Test public void testJournalArticleFriendlyURL() throws Exception { ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(); LayoutLocalServiceUtil.addLayout(TestPropsValues.getUserId(), _group.getGroupId(), false, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, "Home", StringPool.BLANK, StringPool.BLANK, LayoutConstants.TYPE_PORTLET, false, StringPool.BLANK, serviceContext); Layout layout = LayoutLocalServiceUtil.addLayout(TestPropsValues.getUserId(), _group.getGroupId(), false, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, "Test " + RandomTestUtil.nextInt(), StringPool.BLANK, StringPool.BLANK, LayoutConstants.TYPE_PORTLET, false, StringPool.BLANK, serviceContext); LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType(); String portletId = layoutTypePortlet.addPortletId(TestPropsValues.getUserId(), AssetPublisherPortletKeys.ASSET_PUBLISHER, "column-1", 0); layoutTypePortlet.setTypeSettingsProperty(LayoutTypePortletConstants.DEFAULT_ASSET_PUBLISHER_PORTLET_ID, portletId);//from w ww .ja v a 2 s . c o m layout = LayoutLocalServiceUtil.updateLayout(layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings()); Map<Locale, String> titleMap = new HashMap<>(); titleMap.put(LocaleUtil.US, "Test Journal Article"); Map<Locale, String> contentMap = new HashMap<>(); contentMap.put(LocaleUtil.US, "This test content is in English."); JournalTestUtil.addArticle(_group.getGroupId(), JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID, JournalArticleConstants.CLASSNAME_ID_DEFAULT, titleMap, titleMap, contentMap, layout.getUuid(), LocaleUtil.US, null, false, false, serviceContext); String actualURL = PortalUtil.getActualURL(_group.getGroupId(), false, Portal.PATH_MAIN, "/-/test-journal-article", new HashMap<String, String[]>(), getRequestContext()); Assert.assertNotNull(actualURL); try { PortalUtil.getActualURL(_group.getGroupId(), false, Portal.PATH_MAIN, "/-/nonexistent-test-journal-article", new HashMap<String, String[]>(), getRequestContext()); Assert.fail(); } catch (NoSuchLayoutException nsle) { } }
From source file:com.liferay.dynamic.data.lists.internal.instance.lifecycle.AddDefaultSharedFormLayoutPortalInstanceLifecycleListener.java
License:Open Source License
protected void addPrivateLayout(long companyId, long groupId) throws PortalException { ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGuestPermissions(true); serviceContext.setAddGroupPermissions(true); serviceContext.setAttribute("layout.instanceable.allowed", Boolean.TRUE); serviceContext.setAttribute("layoutUpdateable", Boolean.FALSE); serviceContext.setScopeGroupId(groupId); long defaultUserId = _userLocalService.getDefaultUserId(companyId); serviceContext.setUserId(defaultUserId); Layout layout = _layoutLocalService.addLayout(defaultUserId, groupId, true, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, "Shared", StringPool.BLANK, StringPool.BLANK, LayoutConstants.TYPE_SHARED_PORTLET, true, "/shared", serviceContext); updateUserLayoutViewPermissionPermission(companyId, layout); }
From source file:com.liferay.dynamic.data.lists.internal.instance.lifecycle.AddDefaultSharedFormLayoutPortalInstanceLifecycleListener.java
License:Open Source License
protected void addPublicLayout(long companyId, long groupId) throws PortalException { ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGuestPermissions(true); serviceContext.setAddGroupPermissions(true); serviceContext.setAttribute("layout.instanceable.allowed", Boolean.TRUE); serviceContext.setAttribute("layoutUpdateable", Boolean.FALSE); serviceContext.setScopeGroupId(groupId); long defaultUserId = _userLocalService.getDefaultUserId(companyId); serviceContext.setUserId(defaultUserId); _layoutLocalService.addLayout(defaultUserId, groupId, false, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, "Shared", StringPool.BLANK, StringPool.BLANK, LayoutConstants.TYPE_SHARED_PORTLET, true, "/shared", serviceContext);//from w w w . j a va 2 s .com }
From source file:com.liferay.dynamic.data.mapping.form.web.internal.instance.lifecycle.AddDefaultSharedFormLayoutPortalInstanceLifecycleListener.java
License:Open Source License
protected Layout addPrivateLayout(long companyId, long groupId) throws PortalException { ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGuestPermissions(true); serviceContext.setAddGroupPermissions(true); serviceContext.setAttribute("layout.instanceable.allowed", Boolean.TRUE); serviceContext.setAttribute("layoutUpdateable", Boolean.FALSE); serviceContext.setScopeGroupId(groupId); long defaultUserId = _userLocalService.getDefaultUserId(companyId); serviceContext.setUserId(defaultUserId); Layout layout = _layoutLocalService.addLayout(defaultUserId, groupId, true, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, "Shared", StringPool.BLANK, StringPool.BLANK, DDMFormPortletLayoutTypeConstants.LAYOUT_TYPE, true, "/shared", serviceContext); updateUserLayoutViewPermissionPermission(companyId, layout); return layout; }
From source file:com.liferay.dynamic.data.mapping.form.web.internal.instance.lifecycle.AddDefaultSharedFormLayoutPortalInstanceLifecycleListener.java
License:Open Source License
protected Layout addPublicLayout(long companyId, long groupId) throws PortalException { ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGuestPermissions(true); serviceContext.setAddGroupPermissions(true); serviceContext.setAttribute("layout.instanceable.allowed", Boolean.TRUE); serviceContext.setAttribute("layoutUpdateable", Boolean.FALSE); serviceContext.setScopeGroupId(groupId); long defaultUserId = _userLocalService.getDefaultUserId(companyId); serviceContext.setUserId(defaultUserId); return _layoutLocalService.addLayout(defaultUserId, groupId, false, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, "Shared", StringPool.BLANK, StringPool.BLANK, DDMFormPortletLayoutTypeConstants.LAYOUT_TYPE, true, "/shared", serviceContext); }
From source file:com.liferay.exportimport.controller.PortletExportController.java
License:Open Source License
public void exportPortlet(PortletDataContext portletDataContext, long plid, Element parentElement, boolean exportPermissions, boolean exportPortletArchivedSetups, boolean exportPortletData, boolean exportPortletSetup, boolean exportPortletUserPreferences) throws Exception { long layoutId = LayoutConstants.DEFAULT_PARENT_LAYOUT_ID; Layout layout = _layoutLocalService.fetchLayout(plid); if (layout != null) { layoutId = layout.getLayoutId(); }/*from w ww. jav a2s. co m*/ Portlet portlet = _portletLocalService.getPortletById(portletDataContext.getCompanyId(), portletDataContext.getPortletId()); if ((portlet == null) || portlet.isUndeployedPortlet()) { if (_log.isDebugEnabled()) { _log.debug("Do not export portlet " + portletDataContext.getPortletId() + " because the portlet is not deployed"); } return; } if (!portlet.isInstanceable() && !portlet.isPreferencesUniquePerLayout() && portletDataContext.hasNotUniquePerLayout(portletDataContext.getPortletId())) { return; } if (BackgroundTaskThreadLocal.hasBackgroundTask()) { PortletDataContext clonedPortletDataContext = _portletDataContextFactory .clonePortletDataContext(portletDataContext); ManifestSummary manifestSummary = clonedPortletDataContext.getManifestSummary(); manifestSummary.resetCounters(); PortletDataHandler portletDataHandler = portlet.getPortletDataHandlerInstance(); portletDataHandler.prepareManifestSummary(clonedPortletDataContext); _portletDataHandlerStatusMessageSender.sendStatusMessage("portlet", portletDataContext.getPortletId(), manifestSummary); } Document document = SAXReaderUtil.createDocument(); Element portletElement = document.addElement("portlet"); portletElement.addAttribute("portlet-id", portletDataContext.getPortletId()); portletElement.addAttribute("root-portlet-id", portletDataContext.getRootPortletId()); portletElement.addAttribute("old-plid", String.valueOf(plid)); portletElement.addAttribute("scope-group-id", String.valueOf(portletDataContext.getScopeGroupId())); portletElement.addAttribute("scope-layout-type", portletDataContext.getScopeType()); portletElement.addAttribute("scope-layout-uuid", portletDataContext.getScopeLayoutUuid()); portletElement.addAttribute("private-layout", String.valueOf(portletDataContext.isPrivateLayout())); // Data if (exportPortletData) { javax.portlet.PortletPreferences jxPortletPreferences = null; if (ExportImportThreadLocal.isInitialLayoutStagingInProcess()) { if (layout != null) { Group liveGroup = layout.getGroup(); Group stagingGroup = liveGroup.getStagingGroup(); layout.setGroupId(stagingGroup.getGroupId()); jxPortletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup(layout, portletDataContext.getPortletId()); layout.setGroupId(liveGroup.getGroupId()); } else { Group liveGroup = _groupLocalService.getGroup(portletDataContext.getGroupId()); Group stagingGroup = liveGroup.getStagingGroup(); jxPortletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup( portletDataContext.getCompanyId(), stagingGroup.getGroupId(), portletDataContext.getPortletId()); } } else { if (layout != null) { jxPortletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup(layout, portletDataContext.getPortletId()); } else { jxPortletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup( portletDataContext.getCompanyId(), portletDataContext.getGroupId(), portletDataContext.getPortletId()); } } if (!portlet.isPreferencesUniquePerLayout()) { StringBundler sb = new StringBundler(5); sb.append(portletDataContext.getPortletId()); sb.append(StringPool.AT); sb.append(portletDataContext.getScopeType()); sb.append(StringPool.AT); sb.append(portletDataContext.getScopeLayoutUuid()); String dataKey = sb.toString(); if (!portletDataContext.hasNotUniquePerLayout(dataKey)) { portletDataContext.putNotUniquePerLayout(dataKey); exportPortletData(portletDataContext, portlet, layout, jxPortletPreferences, portletElement); } } else { exportPortletData(portletDataContext, portlet, layout, jxPortletPreferences, portletElement); } } // Portlet preferences if (exportPortletSetup) { // Company exportPortletPreferences(portletDataContext, portletDataContext.getCompanyId(), PortletKeys.PREFS_OWNER_TYPE_COMPANY, false, layout, plid, portlet.getRootPortletId(), portletElement); // Group exportPortletPreferences(portletDataContext, portletDataContext.getScopeGroupId(), PortletKeys.PREFS_OWNER_TYPE_GROUP, false, layout, PortletKeys.PREFS_PLID_SHARED, portlet.getRootPortletId(), portletElement); // Group embedded portlets exportPortletPreferences(portletDataContext, portletDataContext.getScopeGroupId(), PortletKeys.PREFS_OWNER_TYPE_LAYOUT, false, layout, PortletKeys.PREFS_PLID_SHARED, portlet.getPortletId(), portletElement); // Layout exportPortletPreferences(portletDataContext, PortletKeys.PREFS_OWNER_ID_DEFAULT, PortletKeys.PREFS_OWNER_TYPE_LAYOUT, false, layout, plid, portletDataContext.getPortletId(), portletElement); } // Portlet user preferences if (exportPortletUserPreferences) { List<PortletPreferences> portletPreferencesList = _portletPreferencesLocalService.getPortletPreferences( PortletKeys.PREFS_OWNER_TYPE_USER, plid, portletDataContext.getPortletId()); for (PortletPreferences portletPreferences : portletPreferencesList) { boolean defaultUser = false; if (portletPreferences.getOwnerId() == PortletKeys.PREFS_OWNER_ID_DEFAULT) { defaultUser = true; } exportPortletPreferences(portletDataContext, portletPreferences.getOwnerId(), PortletKeys.PREFS_OWNER_TYPE_USER, defaultUser, layout, plid, portletDataContext.getPortletId(), portletElement); } try { PortletPreferences groupPortletPreferences = _portletPreferencesLocalService.getPortletPreferences( portletDataContext.getScopeGroupId(), PortletKeys.PREFS_OWNER_TYPE_GROUP, PortletKeys.PREFS_PLID_SHARED, portlet.getRootPortletId()); exportPortletPreference(portletDataContext, portletDataContext.getScopeGroupId(), PortletKeys.PREFS_OWNER_TYPE_GROUP, false, groupPortletPreferences, portlet.getRootPortletId(), PortletKeys.PREFS_PLID_SHARED, portletElement); } catch (NoSuchPortletPreferencesException nsppe) { // LPS-52675 if (_log.isDebugEnabled()) { _log.debug(nsppe, nsppe); } } } // Archived setups if (exportPortletArchivedSetups) { List<PortletItem> portletItems = _portletItemLocalService.getPortletItems( portletDataContext.getGroupId(), portletDataContext.getRootPortletId(), PortletPreferences.class.getName()); for (PortletItem portletItem : portletItems) { exportPortletPreferences(portletDataContext, portletItem.getPortletItemId(), PortletKeys.PREFS_OWNER_TYPE_ARCHIVED, false, null, plid, portletItem.getPortletId(), portletElement); } } // Permissions if (exportPermissions) { _permissionExporter.exportPortletPermissions(portletDataContext, portletDataContext.getPortletId(), layout, portletElement); } // Zip StringBundler pathSB = new StringBundler(4); pathSB.append(ExportImportPathUtil.getPortletPath(portletDataContext)); pathSB.append(StringPool.SLASH); pathSB.append(plid); pathSB.append("/portlet.xml"); String path = pathSB.toString(); Element element = parentElement.addElement("portlet"); element.addAttribute("portlet-id", portletDataContext.getPortletId()); element.addAttribute("layout-id", String.valueOf(layoutId)); element.addAttribute("path", path); element.addAttribute("portlet-data", String.valueOf(exportPortletData)); PortletDataHandler portletDataHandler = portlet.getPortletDataHandlerInstance(); element.addAttribute("schema-version", portletDataHandler.getSchemaVersion()); StringBundler configurationOptionsSB = new StringBundler(6); if (exportPortletSetup) { configurationOptionsSB.append("setup"); configurationOptionsSB.append(StringPool.COMMA); } if (exportPortletArchivedSetups) { configurationOptionsSB.append("archived-setups"); configurationOptionsSB.append(StringPool.COMMA); } if (exportPortletUserPreferences) { configurationOptionsSB.append("user-preferences"); configurationOptionsSB.append(StringPool.COMMA); } if (configurationOptionsSB.index() > 0) { configurationOptionsSB.setIndex(configurationOptionsSB.index() - 1); } element.addAttribute("portlet-configuration", configurationOptionsSB.toString()); try { portletDataContext.addZipEntry(path, document.formattedString()); } catch (IOException ioe) { if (_log.isWarnEnabled()) { _log.warn(ioe.getMessage()); } } }
From source file:com.liferay.exportimport.lar.ExportImportHelperImpl.java
License:Open Source License
@Override public Map<Long, Boolean> getAllLayoutIdsMap(long groupId, boolean privateLayout) { List<Layout> layouts = _layoutLocalService.getLayouts(groupId, privateLayout, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID); Map<Long, Boolean> layoutIdMap = new HashMap<>(); for (Layout layout : layouts) { layoutIdMap.put(layout.getPlid(), true); }//from w ww . j a va2s . c o m return layoutIdMap; }
From source file:com.liferay.exportimport.lar.ExportImportHelperImpl.java
License:Open Source License
@Override public long[] getLayoutIds(Map<Long, Boolean> layoutIdMap, long targetGroupId) throws PortalException { if (MapUtil.isEmpty(layoutIdMap)) { return new long[0]; }//from ww w. ja v a 2 s.c o m List<Layout> layouts = new ArrayList<>(); for (Map.Entry<Long, Boolean> entry : layoutIdMap.entrySet()) { long plid = GetterUtil.getLong(String.valueOf(entry.getKey())); Layout layout = new LayoutImpl(); if (plid == 0) { layout.setPlid(LayoutConstants.DEFAULT_PLID); layout.setLayoutId(LayoutConstants.DEFAULT_PLID); layout.setParentLayoutId(LayoutConstants.DEFAULT_PARENT_LAYOUT_ID); } else { layout = _layoutLocalService.getLayout(plid); } if (!layouts.contains(layout)) { layouts.add(layout); } if (layout.getPlid() == LayoutConstants.DEFAULT_PLID) { continue; } List<Layout> parentLayouts = Collections.emptyList(); if (targetGroupId != GroupConstants.DEFAULT_LIVE_GROUP_ID) { parentLayouts = getMissingParentLayouts(layout, targetGroupId); } for (Layout parentLayout : parentLayouts) { if (!layouts.contains(parentLayout)) { layouts.add(parentLayout); } } boolean includeChildren = entry.getValue(); if (includeChildren) { for (Layout childLayout : layout.getAllChildren()) { if (!layouts.contains(childLayout)) { layouts.add(childLayout); } } } } return getLayoutIds(layouts); }
From source file:com.liferay.exportimport.lar.ExportImportHelperImpl.java
License:Open Source License
@Override public String getSelectedLayoutsJSON(long groupId, boolean privateLayout, String selectedNodes) { JSONArray jsonArray = JSONFactoryUtil.createJSONArray(); List<Layout> layouts = _layoutLocalService.getLayouts(groupId, privateLayout, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID); long[] selectedPlids = StringUtil.split(selectedNodes, 0L); for (Layout layout : layouts) { populateLayoutsJSON(jsonArray, layout, selectedPlids); }/*from w w w .j a va 2s . c o m*/ if (ArrayUtil.contains(selectedPlids, 0)) { JSONObject layoutJSONObject = JSONFactoryUtil.createJSONObject(); layoutJSONObject.put("includeChildren", true); layoutJSONObject.put("plid", 0); jsonArray.put(layoutJSONObject); } return jsonArray.toString(); }
From source file:com.liferay.exportimport.resources.importer.internal.util.BaseImporter.java
License:Open Source License
@Override public void afterPropertiesSet() throws Exception { User user = UserLocalServiceUtil.getDefaultUser(companyId); userId = user.getUserId();// w ww. ja v a 2 s. c o m if (isCompanyGroup()) { return; } Group group = null; if (targetClassName.equals(LayoutSetPrototype.class.getName())) { LayoutSetPrototype layoutSetPrototype = getLayoutSetPrototype(companyId, targetValue); if (layoutSetPrototype != null) { existing = true; } else { layoutSetPrototype = LayoutSetPrototypeLocalServiceUtil.addLayoutSetPrototype(userId, companyId, getTargetValueMap(), new HashMap<Locale, String>(), true, true, new ServiceContext()); } group = layoutSetPrototype.getGroup(); targetClassPK = layoutSetPrototype.getLayoutSetPrototypeId(); } else if (targetClassName.equals(Group.class.getName())) { if (targetValue.equals(GroupConstants.GLOBAL)) { group = GroupLocalServiceUtil.getCompanyGroup(companyId); } else if (targetValue.equals(GroupConstants.GUEST)) { group = GroupLocalServiceUtil.getGroup(companyId, GroupConstants.GUEST); List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(group.getGroupId(), false, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, false, 0, 1); if (!layouts.isEmpty()) { Layout layout = layouts.get(0); LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType(); List<String> portletIds = layoutTypePortlet.getPortletIds(); if (portletIds.size() != 2) { existing = true; } for (String portletId : portletIds) { if (!portletId.equals("47") && !portletId.equals("58")) { existing = true; } } } } else { group = GroupLocalServiceUtil.fetchGroup(companyId, targetValue); if (group != null) { int privateLayoutPageCount = group.getPrivateLayoutsPageCount(); int publicLayoutPageCount = group.getPublicLayoutsPageCount(); if ((privateLayoutPageCount != 0) || (publicLayoutPageCount != 0)) { existing = true; } } else { group = GroupLocalServiceUtil.addGroup(userId, GroupConstants.DEFAULT_PARENT_GROUP_ID, StringPool.BLANK, GroupConstants.DEFAULT_PARENT_GROUP_ID, GroupConstants.DEFAULT_LIVE_GROUP_ID, getMap(targetValue), null, GroupConstants.TYPE_SITE_OPEN, true, GroupConstants.DEFAULT_MEMBERSHIP_RESTRICTION, null, true, true, new ServiceContext()); } } targetClassPK = group.getGroupId(); } if (group != null) { groupId = group.getGroupId(); } }