protected LayoutFriendlyURL getUniqueLayoutFriendlyURL( PortletDataContext portletDataContext, LayoutFriendlyURL layoutFriendlyURL, LayoutFriendlyURL existingLayoutFriendlyURL) throws Exception { String friendlyURL = layoutFriendlyURL.getFriendlyURL(); for (int i = 1; ; i++) { LayoutFriendlyURL duplicateLayoutFriendlyURL = LayoutFriendlyURLLocalServiceUtil.fetchLayoutFriendlyURL( portletDataContext.getScopeGroupId(), layoutFriendlyURL.isPrivateLayout(), layoutFriendlyURL.getFriendlyURL(), layoutFriendlyURL.getLanguageId()); if ((duplicateLayoutFriendlyURL == null) || ((existingLayoutFriendlyURL != null) && (existingLayoutFriendlyURL.getLayoutFriendlyURLId() == duplicateLayoutFriendlyURL.getLayoutFriendlyURLId()))) { break; } layoutFriendlyURL.setFriendlyURL(friendlyURL + i); } return layoutFriendlyURL; }
protected void validatePrototypedLayouts(Class<?> clazz, long groupId) throws Exception { List<Layout> layouts = getLayouts(clazz); for (Layout layout : layouts) { Layout importedLayout = LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId( layout.getUuid(), groupId, layout.getPrivateLayout()); Assert.assertNotNull(importedLayout); Assert.assertEquals( layout.getTypeSettingsProperty( LayoutSetPrototypeStagedModelDataHandlerTest.class.getName()), importedLayout.getTypeSettingsProperty( LayoutSetPrototypeStagedModelDataHandlerTest.class.getName())); } List<LayoutFriendlyURL> layoutFriendlyURLs = getLayoutFriendlyURLs(clazz); for (LayoutFriendlyURL layoutFriendlyURL : layoutFriendlyURLs) { LayoutFriendlyURL importedLayoutFriendlyURL = LayoutFriendlyURLLocalServiceUtil.fetchLayoutFriendlyURLByUuidAndGroupId( layoutFriendlyURL.getUuid(), groupId); Assert.assertNotNull(importedLayoutFriendlyURL); Assert.assertEquals( layoutFriendlyURL.getFriendlyURL(), importedLayoutFriendlyURL.getFriendlyURL()); } }
@Override public Map<Locale, String> getFriendlyURLMap() throws SystemException { Map<Locale, String> friendlyURLMap = new HashMap<Locale, String>(); List<LayoutFriendlyURL> layoutFriendlyURLs = LayoutFriendlyURLLocalServiceUtil.getLayoutFriendlyURLs(getPlid()); for (LayoutFriendlyURL layoutFriendlyURL : layoutFriendlyURLs) { friendlyURLMap.put( LocaleUtil.fromLanguageId(layoutFriendlyURL.getLanguageId()), layoutFriendlyURL.getFriendlyURL()); } return friendlyURLMap; }
@Override public String getFriendlyURL(Locale locale) { Layout layout = this; String friendlyURL = layout.getFriendlyURL(); try { LayoutFriendlyURL layoutFriendlyURL = LayoutFriendlyURLLocalServiceUtil.getLayoutFriendlyURL( layout.getPlid(), LocaleUtil.toLanguageId(locale)); friendlyURL = layoutFriendlyURL.getFriendlyURL(); } catch (Exception e) { } return friendlyURL; }
@Override protected void doImportStagedModel( PortletDataContext portletDataContext, LayoutFriendlyURL layoutFriendlyURL) throws Exception { long userId = portletDataContext.getUserId(layoutFriendlyURL.getUserUuid()); Map<Long, Long> plids = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Layout.class); long plid = MapUtil.getLong(plids, layoutFriendlyURL.getPlid(), layoutFriendlyURL.getPlid()); ServiceContext serviceContext = portletDataContext.createServiceContext(layoutFriendlyURL); LayoutFriendlyURL importedLayoutFriendlyURL = null; if (portletDataContext.isDataStrategyMirror()) { LayoutFriendlyURL existingLayoutFriendlyURL = fetchExistingLayoutFriendlyURL(portletDataContext, layoutFriendlyURL, plid); layoutFriendlyURL = getUniqueLayoutFriendlyURL( portletDataContext, layoutFriendlyURL, existingLayoutFriendlyURL); if (existingLayoutFriendlyURL == null) { serviceContext.setUuid(layoutFriendlyURL.getUuid()); importedLayoutFriendlyURL = LayoutFriendlyURLLocalServiceUtil.addLayoutFriendlyURL( userId, portletDataContext.getCompanyId(), portletDataContext.getScopeGroupId(), plid, portletDataContext.isPrivateLayout(), layoutFriendlyURL.getFriendlyURL(), layoutFriendlyURL.getLanguageId(), serviceContext); } else { importedLayoutFriendlyURL = LayoutFriendlyURLLocalServiceUtil.updateLayoutFriendlyURL( userId, portletDataContext.getCompanyId(), portletDataContext.getScopeGroupId(), plid, portletDataContext.isPrivateLayout(), layoutFriendlyURL.getFriendlyURL(), layoutFriendlyURL.getLanguageId(), serviceContext); } } else { layoutFriendlyURL = getUniqueLayoutFriendlyURL(portletDataContext, layoutFriendlyURL, null); importedLayoutFriendlyURL = LayoutFriendlyURLLocalServiceUtil.addLayoutFriendlyURL( userId, portletDataContext.getCompanyId(), portletDataContext.getScopeGroupId(), plid, portletDataContext.isPrivateLayout(), layoutFriendlyURL.getFriendlyURL(), layoutFriendlyURL.getLanguageId(), serviceContext); } portletDataContext.importClassedModel(layoutFriendlyURL, importedLayoutFriendlyURL); }