List of usage examples for com.liferay.portal.kernel.model Layout getLayoutType
public LayoutType getLayoutType();
From source file:com.liferay.arquillian.portal.bundle.servlet.PortalURLServlet.java
License:Open Source License
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String portletId = request.getParameter("portlet-id"); response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<h1> Portlet ID: " + portletId + "</h1>"); Company company = _companyLocalService.getCompanies().get(0); Group guestGroup = null;/*from www .ja va 2s. c o m*/ if (_layouts == null) { _layouts = new ArrayList<>(); } try { guestGroup = _groupLocalService.getGroup(company.getCompanyId(), "Guest"); User defaultUser = _userLocalService.getDefaultUser(company.getCompanyId()); UUID uuid = UUID.randomUUID(); Layout layout = _layoutLocalService.addLayout(defaultUser.getUserId(), guestGroup.getGroupId(), false, 0, uuid.toString(), null, null, "portlet", false, "/" + uuid.toString(), new ServiceContext()); _layouts.add(layout); LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType(); layoutTypePortlet.setLayoutTemplateId(defaultUser.getUserId(), "1_column"); String portletIdAdded = layoutTypePortlet.addPortletId(defaultUser.getUserId(), portletId, false); long ownerId = 0; int ownerType = 3; PortletPreferences prefs = _portletPreferencesLocalService.getPreferences(company.getCompanyId(), ownerId, ownerType, layout.getPlid(), portletIdAdded); _portletPreferencesLocalService.updatePreferences(ownerId, ownerType, layout.getPlid(), portletIdAdded, prefs); _layoutLocalService.updateLayout(layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings()); response.sendRedirect("/" + uuid.toString()); } catch (PortalException pe) { _logger.log(Level.SEVERE, pe.getMessage(), pe); } }
From source file:com.liferay.arquillian.portal.servlet.PortalURLServlet.java
License:Open Source License
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String portletId = request.getParameter("portlet-id"); response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<h1> Portlet ID: " + portletId + "</h1>"); Company company = _companyLocalService.getCompanies().get(0); Group guestGroup = null;// w w w . j av a 2s. c om if (_layouts == null) { _layouts = new ArrayList<>(); } try { guestGroup = _groupLocalService.getGroup(company.getCompanyId(), "Guest"); User defaultUser = _userLocalService.getDefaultUser(company.getCompanyId()); UUID uuid = UUID.randomUUID(); Layout layout = _layoutLocalService.addLayout(defaultUser.getUserId(), guestGroup.getGroupId(), false, 0, uuid.toString(), null, null, "portlet", false, "/" + uuid.toString(), new ServiceContext()); _layouts.add(layout); LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType(); layoutTypePortlet.setLayoutTemplateId(defaultUser.getUserId(), "1_column"); String portletIdAdded = layoutTypePortlet.addPortletId(defaultUser.getUserId(), portletId, false); long ownerId = 0; int ownerType = 3; PortletPreferences prefs = _portletPreferencesLocalService.getPreferences(company.getCompanyId(), ownerId, ownerType, layout.getPlid(), portletIdAdded); _portletPreferencesLocalService.updatePreferences(ownerId, ownerType, layout.getPlid(), portletIdAdded, prefs); _layoutLocalService.updateLayout(layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings()); response.sendRedirect("/" + uuid.toString()); } catch (PortalException e) { _logger.log(Level.SEVERE, e.getMessage(), e); } }
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 www.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.exportimport.controller.PortletExportController.java
License:Open Source License
protected void exportPortletPreferences(PortletDataContext portletDataContext, long ownerId, int ownerType, boolean defaultUser, Layout layout, long plid, String portletId, Element parentElement) throws Exception { PortletPreferences portletPreferences = null; try {/* w w w .j ava 2 s .com*/ portletPreferences = getPortletPreferences(ownerId, ownerType, plid, portletId); } catch (NoSuchPortletPreferencesException nsppe) { // LPS-52675 if (_log.isDebugEnabled()) { _log.debug(nsppe, nsppe); } return; } LayoutTypePortlet layoutTypePortlet = null; if (layout != null) { layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType(); } if ((layoutTypePortlet == null) || layoutTypePortlet.hasPortletId(portletId)) { exportPortletPreference(portletDataContext, ownerId, ownerType, defaultUser, portletPreferences, portletId, plid, parentElement); } }
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();//from w ww . j ava 2 s. co 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(); } }
From source file:com.liferay.exportimport.resources.importer.internal.util.FileSystemImporter.java
License:Open Source License
protected void addLayout(boolean privateLayout, long parentLayoutId, JSONObject layoutJSONObject) throws Exception { if (targetClassName.equals(LayoutSetPrototype.class.getName())) { privateLayout = true;/*from ww w. ja va 2 s .c o m*/ } Map<Locale, String> nameMap = getMap(layoutJSONObject, "name"); Map<Locale, String> titleMap = getMap(layoutJSONObject, "title"); String type = layoutJSONObject.getString("type"); if (Validator.isNull(type)) { type = LayoutConstants.TYPE_PORTLET; } String typeSettings = layoutJSONObject.getString("typeSettings"); boolean hidden = layoutJSONObject.getBoolean("hidden"); String themeId = layoutJSONObject.getString("themeId"); String layoutCss = layoutJSONObject.getString("layoutCss"); String colorSchemeId = layoutJSONObject.getString("colorSchemeId"); Map<Locale, String> friendlyURLMap = new HashMap<>(); String friendlyURL = layoutJSONObject.getString("friendlyURL"); if (Validator.isNotNull(friendlyURL) && !friendlyURL.startsWith(StringPool.SLASH)) { friendlyURL = StringPool.SLASH + friendlyURL; } friendlyURLMap.put(LocaleUtil.getDefault(), friendlyURL); ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(companyId); serviceContext.setScopeGroupId(groupId); serviceContext.setUserId(userId); ServiceContextThreadLocal.pushServiceContext(serviceContext); try { String layoutPrototypeName = layoutJSONObject.getString("layoutPrototypeName"); String layoutPrototypeUuid = null; if (Validator.isNotNull(layoutPrototypeName)) { LayoutPrototype layoutPrototype = getLayoutPrototype(companyId, layoutPrototypeName); layoutPrototypeUuid = layoutPrototype.getUuid(); } else { layoutPrototypeUuid = layoutJSONObject.getString("layoutPrototypeUuid"); } if (Validator.isNotNull(layoutPrototypeUuid)) { boolean layoutPrototypeLinkEnabled = GetterUtil .getBoolean(layoutJSONObject.getString("layoutPrototypeLinkEnabled")); serviceContext.setAttribute("layoutPrototypeLinkEnabled", layoutPrototypeLinkEnabled); serviceContext.setAttribute("layoutPrototypeUuid", layoutPrototypeUuid); } Layout layout = layoutLocalService.fetchLayoutByFriendlyURL(groupId, privateLayout, friendlyURL); if (layout != null) { if (!developerModeEnabled) { if (_log.isInfoEnabled()) { _log.info("Layout with friendly URL " + friendlyURL + " already exists"); } return; } if (!updateModeEnabled) { layoutLocalService.deleteLayout(layout); } } if (!updateModeEnabled || (layout == null)) { layout = layoutLocalService.addLayout(userId, groupId, privateLayout, parentLayoutId, nameMap, titleMap, null, null, null, type, typeSettings, hidden, friendlyURLMap, serviceContext); } else { resetLayoutColumns(layout); layout = layoutLocalService.updateLayout(groupId, privateLayout, layout.getLayoutId(), parentLayoutId, nameMap, titleMap, layout.getDescriptionMap(), layout.getKeywordsMap(), layout.getRobotsMap(), type, hidden, friendlyURLMap, layout.getIconImage(), null, serviceContext); } if (Validator.isNotNull(themeId) || Validator.isNotNull(colorSchemeId)) { // If the theme ID or the color scheme ID are not null, then the // layout has a custom look and feel and should be updated in // the database layoutLocalService.updateLookAndFeel(groupId, privateLayout, layout.getLayoutId(), themeId, colorSchemeId, layoutCss); } 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, LayoutTypePortletConstants.COLUMN_PREFIX, columnsJSONArray); layoutLocalService.updateLayout(groupId, layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings()); JSONArray layoutsJSONArray = layoutJSONObject.getJSONArray("layouts"); addLayouts(privateLayout, layout.getLayoutId(), layoutsJSONArray); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Unable to import layout " + layoutJSONObject, e); } throw e; } finally { ServiceContextThreadLocal.popServiceContext(); } }
From source file:com.liferay.exportimport.resources.importer.internal.util.FileSystemImporter.java
License:Open Source License
protected void addLayoutColumnPortlet(Layout layout, String columnId, JSONObject portletJSONObject) throws Exception { LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType(); String rootPortletId = portletJSONObject.getString("portletId"); if (Validator.isNull(rootPortletId)) { throw new ImporterException("portletId is not specified"); }//from ww w . jav a 2 s . c om PortletPreferencesTranslator portletPreferencesTranslator = portletPreferencesTranslators .get(rootPortletId); String portletId = layoutTypePortlet.addPortletId(userId, rootPortletId, columnId, -1, false); if (portletId == null) { return; } JSONObject portletPreferencesJSONObject = portletJSONObject.getJSONObject("portletPreferences"); if ((portletPreferencesJSONObject == null) || (portletPreferencesJSONObject.length() == 0)) { return; } if (portletPreferencesTranslator != null) { PortletPreferencesIds portletPreferencesIds = PortletPreferencesFactoryUtil .getPortletPreferencesIds(layout.getGroupId(), 0, layout, portletId, false); PortletPreferences portletSetup = PortletPreferencesLocalServiceUtil .getPreferences(portletPreferencesIds); Iterator<String> iterator = portletPreferencesJSONObject.keys(); while (iterator.hasNext()) { String key = iterator.next(); portletPreferencesTranslator.translate(portletPreferencesJSONObject, key, portletSetup); } portletSetup.store(); } if (rootPortletId.equals(PortletKeys.NESTED_PORTLETS)) { JSONArray columnsJSONArray = portletPreferencesJSONObject.getJSONArray("columns"); StringBundler sb = new StringBundler(4); sb.append(StringPool.UNDERLINE); sb.append(portletId); sb.append(StringPool.DOUBLE_UNDERLINE); sb.append(LayoutTypePortletConstants.COLUMN_PREFIX); addLayoutColumns(layout, sb.toString(), columnsJSONArray); } }
From source file:com.liferay.exportimport.resources.importer.test.ResourcesImporterTest.java
License:Open Source License
protected void validateLayouts(Group importedGroup) throws Exception { long privateLayoutsCount = LayoutLocalServiceUtil.getLayoutsCount(importedGroup, true); Assert.assertEquals(1, privateLayoutsCount); long publicLayoutsCount = LayoutLocalServiceUtil.getLayoutsCount(importedGroup, false); Assert.assertEquals(9, publicLayoutsCount); Layout layout = LayoutLocalServiceUtil.getFriendlyURLLayout(importedGroup.getGroupId(), false, "/home"); Map<Locale, String> nameMap = layout.getNameMap(); Assert.assertTrue(nameMap.containsValue("Bienvenue")); Assert.assertTrue(layout.isTypePortlet()); LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType(); List<Portlet> portlets = layoutTypePortlet.getAllPortlets(); Assert.assertEquals(portlets.toString(), 7, portlets.size()); UnicodeProperties layoutTypeSettingsProperties = layout.getTypeSettingsProperties(); String nestedColumnIds = layoutTypeSettingsProperties.get(LayoutTypePortletConstants.NESTED_COLUMN_IDS); Assert.assertTrue((nestedColumnIds != null) && nestedColumnIds.contains("column-1") && nestedColumnIds.contains("column-2")); layout = LayoutLocalServiceUtil.getFriendlyURLLayout(importedGroup.getGroupId(), false, "/layout-prototypes-page-1"); Assert.assertTrue(layout.isLayoutPrototypeLinkActive()); Assert.assertEquals("371647ba-3649-4039-bfe6-ae32cf404737", layout.getLayoutPrototypeUuid()); layout = LayoutLocalServiceUtil.getFriendlyURLLayout(importedGroup.getGroupId(), false, "/layout-prototypes-page-2"); Assert.assertFalse(layout.isLayoutPrototypeLinkActive()); Assert.assertEquals("c98067d0-fc10-9556-7364-238d39693bc4", layout.getLayoutPrototypeUuid()); layout = LayoutLocalServiceUtil.getFriendlyURLLayout(importedGroup.getGroupId(), false, "/url-page"); Assert.assertTrue(layout.isTypeURL()); layout = LayoutLocalServiceUtil.getFriendlyURLLayout(importedGroup.getGroupId(), false, "/hidden-page"); Assert.assertTrue(layout.isHidden()); }
From source file:com.liferay.grow.layout.helper.service.impl.LayoutHelperServiceImpl.java
License:Open Source License
@Override public void updateProfilePages() { if (_log.isInfoEnabled()) { _log.info("Updating Profile Pages..."); }/* w ww . ja v a2 s . co m*/ List<User> users = _userLocalService.getUsers(QueryUtil.ALL_POS, QueryUtil.ALL_POS); for (User user : users) { try { if (user.isDefaultUser()) { continue; } List<Layout> layouts = _layoutLocalService.getLayouts(user.getGroupId(), false); if (layouts.size() != 1) { if (_log.isInfoEnabled()) { _log.info("User: " + user.getScreenName() + " has " + layouts.size() + " public layout"); } } if (layouts.isEmpty()) { continue; } Layout layout = layouts.get(0); LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType(); // Update Theme layout.setThemeId("frontenduserprofilegrow_WAR_growthemeuserprofile"); layout.setColorSchemeId("01"); UnicodeProperties properties = layoutTypePortlet.getTypeSettingsProperties(); properties.put("layoutUpdateable", Boolean.TRUE.toString()); properties.put("sitemap-changefreq", "daily"); properties.put("sitemap-include", "1"); // Remove OWXPSubscribePortlet String owxpSubscribePortletId = "com_liferay_owxp_subscribe_portlet_OWXPSubscribePortlet"; List<String> portletIds = layoutTypePortlet.getPortletIds(); for (String portletId : portletIds) { if (portletId.startsWith(owxpSubscribePortletId)) { layoutTypePortlet.removePortletId(user.getUserId(), portletId); break; } } _layoutLocalService.updateLayout(layout); // Remove the Guest role's View permission from the Profile // Pages Role guestRole = _roleLocalService.getRole(layout.getCompanyId(), RoleConstants.GUEST); _resourcePermissionLocalService.setResourcePermissions(layout.getCompanyId(), Layout.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(layout.getPlid()), guestRole.getRoleId(), new String[0]); } catch (Exception e) { _log.error("Cannot remove View permission for " + user.getScreenName(), e); } } if (_log.isInfoEnabled()) { _log.info("Profile Pages have been updated"); } }
From source file:com.liferay.journal.service.impl.JournalContentSearchLocalServiceImpl.java
License:Open Source License
@Override public void checkContentSearches(long companyId) throws PortalException { if (_log.isInfoEnabled()) { _log.info("Checking journal content search for " + companyId); }//from w w w .j a va 2s .c om List<Layout> layouts = new ArrayList<>(); List<Group> groups = groupLocalService.search(companyId, null, null, null, QueryUtil.ALL_POS, QueryUtil.ALL_POS); for (Group group : groups) { // Private layouts deleteOwnerContentSearches(group.getGroupId(), true); layouts.addAll(layoutLocalService.getLayouts(group.getGroupId(), true)); // Public layouts deleteOwnerContentSearches(group.getGroupId(), false); layouts.addAll(layoutLocalService.getLayouts(group.getGroupId(), false)); } for (Layout layout : layouts) { LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType(); List<String> portletIds = layoutTypePortlet.getPortletIds(); for (String portletId : portletIds) { String rootPortletId = PortletConstants.getRootPortletId(portletId); DisplayInformationProvider displayInformationProvider = _serviceTrackerMap .getService(rootPortletId); if (displayInformationProvider == null) { continue; } PortletPreferences portletPreferences = portletPreferencesLocalService.getPreferences( layout.getCompanyId(), PortletKeys.PREFS_OWNER_ID_DEFAULT, PortletKeys.PREFS_OWNER_TYPE_LAYOUT, layout.getPlid(), portletId); String classPK = displayInformationProvider.getClassPK(portletPreferences); updateContentSearch(layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), portletId, classPK); } } }