Search in sources :

Example 11 with Layout

use of com.liferay.portal.kernel.model.Layout in project liferay-db-setup-core by ableneo.

the class SetupPages method createLinkPage.

private static Layout createLinkPage(final PageType 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(String.format("Could not create link page %1$s with link to url %2$s", p.getFriendlyUrl(), p.getLinkToUrl()), e);
    }
    return layout;
}
Also used : SystemException(com.liferay.portal.kernel.exception.SystemException) Layout(com.liferay.portal.kernel.model.Layout) UnicodeProperties(com.liferay.portal.kernel.util.UnicodeProperties) ServiceContext(com.liferay.portal.kernel.service.ServiceContext) PortalException(com.liferay.portal.kernel.exception.PortalException)

Aggregations

Layout (com.liferay.portal.kernel.model.Layout)11 PortalException (com.liferay.portal.kernel.exception.PortalException)4 SystemException (com.liferay.portal.kernel.exception.SystemException)4 Portlet (com.liferay.portal.kernel.model.Portlet)4 LiferayPortletURL (com.liferay.portal.kernel.portlet.LiferayPortletURL)4 PortletURLFactoryUtil (com.liferay.portal.kernel.portlet.PortletURLFactoryUtil)4 LayoutLocalServiceUtil (com.liferay.portal.kernel.service.LayoutLocalServiceUtil)4 PortletLocalServiceUtil (com.liferay.portal.kernel.service.PortletLocalServiceUtil)4 PortletRequest (javax.portlet.PortletRequest)4 LogManager (org.apache.logging.log4j.LogManager)4 Logger (org.apache.logging.log4j.Logger)4 User (org.eclipse.sw360.datahandler.thrift.users.User)4 PortalConstants (org.eclipse.sw360.portal.common.PortalConstants)4 UserCacheHolder (org.eclipse.sw360.portal.users.UserCacheHolder)4 ResourceRequest (javax.portlet.ResourceRequest)3 CommonUtils (org.eclipse.sw360.datahandler.common.CommonUtils)3 SW360Utils (org.eclipse.sw360.datahandler.common.SW360Utils)3 CustomFieldHelper (org.eclipse.sw360.portal.common.CustomFieldHelper)3 PortletUtils (org.eclipse.sw360.portal.common.PortletUtils)3 com.google.common.collect (com.google.common.collect)2