private static void updateLinkPage(final Page page, final long groupId) { try { Layout layout = LayoutLocalServiceUtil.getFriendlyURLLayout(groupId, false, page.getFriendlyURL()); if (layout.getLayoutType().getTypeSettingsProperties().get("url") == null) { LOG.error("Could not update link page " + page.getFriendlyURL() + " with link to url" + " " + page.getLinkToURL() + " because page is not a link type page! " + " Maybe it has been imported before as non link type page. Please " + "delete it and rerun!"); } else { UnicodeProperties props = layout.getTypeSettingsProperties(); props.put("url", page.getLinkToURL()); layout.setTypeSettingsProperties(props); layout.setHidden(page.isHidden()); LayoutLocalServiceUtil.updateLayout(layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings()); } } catch (PortalException | SystemException e) { LOG.error("Could not update link page " + page.getFriendlyURL() + " with link to url " + page.getLinkToURL(), e); } }
private ExpandoColumn getNavigationColumn(boolean publicLayouts, long companyId) throws PortalException, SystemException { long tableId = getGroupExpandoTable(companyId).getTableId(); String name = publicLayouts ? CustomNavigationKeys.PUBLIC_GROUP_IDS : CustomNavigationKeys.PRIVATE_GROUP_IDS; ExpandoColumn column = expandoColumnLocalService.getColumn(tableId, name); if(column == null) { column = expandoColumnLocalService.addColumn( tableId, name, ExpandoColumnConstants.STRING_ARRAY); // Add Unicode Properties UnicodeProperties properties = new UnicodeProperties(); properties.setProperty( ExpandoColumnConstants.INDEX_TYPE, Boolean.FALSE.toString()); column.setTypeSettingsProperties(properties); column.setDefaultData("unconfigured"); expandoColumnLocalService.updateExpandoColumn(column); } return column; }
/** * Returns a list of search URLs to be put in the request attributes * * @param themeDisplay The theme display * @param layout The current page * @return A list of search URLs to be put in the request attributes */ private List<SearchUrl> generateSearchUrl(HttpServletRequest request, ThemeDisplay themeDisplay, Layout layout) { LayoutTypePortlet layoutType = (LayoutTypePortlet) layout.getLayoutType(); UnicodeProperties props = layoutType.getTypeSettingsProperties(); return layoutType.getPortlets().stream() .filter(portlet -> portlet.getPortletName().equals(FlashlightSearchPortletKeys.PORTLET_NAME)) .map(portletInstance -> { String columnId = StringPool.BLANK; for(Entry<String, String> entry : props.entrySet()) { if(entry.getValue().equals(portletInstance.getPortletId())) { columnId = entry.getKey(); break; } } String portletUrl; try { portletUrl = this.portal.getLayoutFriendlyURL(layout, themeDisplay); } catch (PortalException e) { portletUrl = StringPool.BLANK; LOG.error(e); } SearchUrlRequestParameter[] params = new SearchUrlRequestParameter[] { new SearchUrlRequestParameter(PARAM_PORTLET_ID, portletInstance.getPortletId()), new SearchUrlRequestParameter(PARAM_PORTLET_LIFECYCLE, LIFECYCLE_RENDER), new SearchUrlRequestParameter(PARAM_PORTLET_MODE, PortletMode.VIEW.toString()), new SearchUrlRequestParameter(PARAM_PORTLET_COLUMN_ID, columnId), new SearchUrlRequestParameter(PARAM_PORTLET_COLUMN_COUNT, Integer.toString(layoutType.getNumOfColumns())) }; String portletNamespace = this.portal.getPortletNamespace(portletInstance.getPortletId()); return new SearchUrl(layout, portletUrl, params, portletNamespace); }) .collect(Collectors.toList()); }
private static Layout createLinkPage(final Page p, final long groupId, final long parentLayoutId, final long userId) { // all values are usually retrieved via special methods from our code // for better readability I have added the real values here String title = "my title"; ServiceContext serviceContext = new ServiceContext(); String layoutType = LayoutConstants.TYPE_URL; boolean hidden = p.isHidden(); String friendlyURL = p.getFriendlyURL(); // add the layout Layout layout = null; try { layout = LayoutLocalServiceUtil.addLayout(userId, groupId, false, parentLayoutId, title, title, StringPool.BLANK, layoutType, hidden, friendlyURL, serviceContext); String linkToPageUrl = p.getLinkToURL(); // set the value of the "link to page" UnicodeProperties props = layout.getTypeSettingsProperties(); props.put("url", linkToPageUrl); layout.setTypeSettingsProperties(props); LayoutLocalServiceUtil.updateLayout(layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings()); } catch (PortalException | SystemException e) { LOG.error("Could not create link page " + p.getFriendlyURL() + " with link to url " + p.getLinkToURL(), e); } return layout; }
private static void setPageTarget(final Page page, final Layout layout) { UnicodeProperties props = layout.getTypeSettingsProperties(); props.put("target", page.getTarget()); layout.setTypeSettingsProperties(props); try { LayoutLocalServiceUtil.updateLayout(layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings()); } catch (PortalException e) { LOG.error("Can not set target attribute value '" + page.getTarget() + "' to page with layoutId:" + layout.getLayoutId() + ".", e); } }
public static Layout createLayout(long adminId, long companyId, long groupId, E_ContextPath path, String actualPath) { Layout result = null; boolean privateLayout = false; String description = null; String type = path.getType(); long parentLayoutId = path.isHidden() ? homeLayoutId : LayoutConstants.DEFAULT_PARENT_LAYOUT_ID; ServiceContext ctx = new ServiceContext(); if (actualPath == null) actualPath = path.getPath(); try { result = LayoutLocalServiceUtil.addLayout(adminId, groupId, privateLayout, parentLayoutId, path.getName(), path.getTitle(), description, type, path.isHidden(), actualPath, ctx); // layout.setLayoutPrototypeLinkEnabled(false); if (!type.equals(LayoutConstants.TYPE_URL)) { Theme theme = getTheme(companyId, path.getThemeId()); if (theme != null) { result.setThemeId(path.getThemeId()); result = LayoutLocalServiceUtil.updateLookAndFeel(groupId, false, result.getLayoutId(), path.getThemeId(), "01", "", false); } else m_objLog.warn("Did not find theme: " + path.getThemeId() + " for url " + path.getPath()); LayoutTemplate template = getLayoutTemplate(path.getTemplateId()); LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) result .getLayoutType(); if (template != null) { layoutTypePortlet.setLayoutTemplateId(0, path.getTemplateId(), false); m_objLog.debug("Set layout template: " + template.getLayoutTemplateId() + " for url " + path.getPath()); } else m_objLog.warn("Did not find layout template: " + path.getTemplateId() + " for url " + path.getPath()); } else { // set the value of the "link to page" UnicodeProperties props = result.getTypeSettingsProperties(); props.put( "url", path.getTitle() ); result.setTypeSettingsProperties( props ); LayoutLocalServiceUtil.updateLayout( result ); // } m_objLog.debug("Added layout for url " + actualPath + ", group: " + groupId + ", company: " + companyId + ", user: " + adminId); updatePermissions(result, path); } catch (Throwable t) { m_objLog.error(t); } return result; }
protected void fixTypeSettings(Layout layout) throws Exception { if (!layout.isTypeURL()) { return; } UnicodeProperties typeSettings = layout.getTypeSettingsProperties(); String url = GetterUtil.getString(typeSettings.getProperty("url")); String friendlyURLPrivateGroupPath = PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_GROUP_SERVLET_MAPPING; String friendlyURLPrivateUserPath = PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_USER_SERVLET_MAPPING; String friendlyURLPublicPath = PropsValues.LAYOUT_FRIENDLY_URL_PUBLIC_SERVLET_MAPPING; if (!url.startsWith(friendlyURLPrivateGroupPath) && !url.startsWith(friendlyURLPrivateUserPath) && !url.startsWith(friendlyURLPublicPath)) { return; } int x = url.indexOf(CharPool.SLASH, 1); if (x == -1) { return; } int y = url.indexOf(CharPool.SLASH, x + 1); if (y == -1) { return; } String friendlyURL = url.substring(x, y); if (!friendlyURL.equals(LayoutExporter.SAME_GROUP_FRIENDLY_URL)) { return; } Group group = layout.getGroup(); typeSettings.setProperty( "url", url.substring(0, x) + group.getFriendlyURL() + url.substring(y)); }
protected void importJournalArticle( PortletDataContext portletDataContext, Layout layout, Element layoutElement) throws Exception { UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties(); String articleId = typeSettingsProperties.getProperty( "article-id", StringPool.BLANK); if (Validator.isNull(articleId)) { return; } JournalPortletDataHandlerImpl.importReferencedData( portletDataContext, layoutElement); Element structureElement = layoutElement.element("structure"); if (structureElement != null) { JournalPortletDataHandlerImpl.importStructure( portletDataContext, structureElement); } Element templateElement = layoutElement.element("template"); if (templateElement != null) { JournalPortletDataHandlerImpl.importTemplate( portletDataContext, templateElement); } Element articleElement = layoutElement.element("article"); if (articleElement != null) { JournalPortletDataHandlerImpl.importArticle( portletDataContext, articleElement); } Map<String, String> articleIds = (Map<String, String>)portletDataContext.getNewPrimaryKeysMap( JournalArticle.class + ".articleId"); articleId = MapUtil.getString(articleIds, articleId, articleId); typeSettingsProperties.setProperty("article-id", articleId); JournalContentSearchLocalServiceUtil.updateContentSearch( portletDataContext.getScopeGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), StringPool.BLANK, articleId, true); }
@Indexable(type = IndexableType.REINDEX) public Song moveSongToTrash(long userId, Song song) throws PortalException { ServiceContext serviceContext = new ServiceContext(); // Entry User user = userPersistence.findByPrimaryKey(userId); Date now = new Date(); int oldStatus = song.getStatus(); song.setModifiedDate(serviceContext.getModifiedDate(now)); song.setStatus(WorkflowConstants.STATUS_IN_TRASH); song.setStatusByUserId(user.getUserId()); song.setStatusByUserName(user.getFullName()); song.setStatusDate(serviceContext.getModifiedDate(now)); // Asset assetEntryLocalService.updateVisible( Song.class.getName(), song.getSongId(), false); // Trash UnicodeProperties typeSettingsProperties = new UnicodeProperties(); typeSettingsProperties.put("title", song.getName()); TrashEntry trashEntry = trashEntryLocalService.addTrashEntry( userId, song.getGroupId(), Song.class.getName(), song.getSongId(), song.getUuid(), null, oldStatus, null, typeSettingsProperties); song.setName(TrashUtil.getTrashTitle(trashEntry.getEntryId())); songPersistence.update(song); return song; }
@Indexable(type = IndexableType.REINDEX) public Song moveSongToTrash(long userId, Song song) throws PortalException, SystemException { ServiceContext serviceContext = new ServiceContext(); // Entry User user = userPersistence.findByPrimaryKey(userId); Date now = new Date(); int oldStatus = song.getStatus(); song.setModifiedDate(serviceContext.getModifiedDate(now)); song.setStatus(WorkflowConstants.STATUS_IN_TRASH); song.setStatusByUserId(user.getUserId()); song.setStatusByUserName(user.getFullName()); song.setStatusDate(serviceContext.getModifiedDate(now)); // Asset assetEntryLocalService.updateVisible( Song.class.getName(), song.getSongId(), false); // Trash UnicodeProperties typeSettingsProperties = new UnicodeProperties(); typeSettingsProperties.put("title", song.getName()); TrashEntry trashEntry = trashEntryLocalService.addTrashEntry( userId, song.getGroupId(), Song.class.getName(), song.getSongId(), song.getUuid(), null, oldStatus, null, typeSettingsProperties); song.setName(TrashUtil.getTrashTitle(trashEntry.getEntryId())); songPersistence.update(song); return song; }