Search in sources :

Example 1 with LayoutTemplate

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

the class SetupPages method setLayoutTemplate.

public static void setLayoutTemplate(final Layout layout, final PageType page, final long userid) {
    if (layout.getLayoutType() instanceof LayoutTypePortlet) {
        LayoutTypePortlet portletLayout = (LayoutTypePortlet) layout.getLayoutType();
        if (page.isClearPage()) {
            if (page.getPagePortlet() != null && !page.getPagePortlet().isEmpty() && page.getLinkToUrl() != null && !page.getLinkToUrl().equals("")) {
                LOG.error("This is a link page! It cannot be cleared. If you intend to use this page for portlets, please delete this page, or remove the link from the page!");
            } else {
                removeAllPortlets(userid, portletLayout, layout);
            }
        }
        String themeId = null;
        try {
            if (!Validator.isBlank(page.getLayoutThemeId())) {
                themeId = page.getLayoutThemeId();
            }
            LayoutTemplate layoutTemplate = LayoutTemplateLocalServiceUtil.getLayoutTemplate(page.getLayout(), false, themeId);
            if (layoutTemplate != null) {
                LOG.info(String.format("Setting layout to %1$s for page %2$s", page.getLayout(), page.getName()));
                if (themeId != null) {
                    LOG.info(String.format(LAYOUT_WAS_LOOKED_UP_IN_THEME, themeId));
                }
                portletLayout.setLayoutTemplateId(UserLocalServiceUtil.getDefaultUserId(layout.getCompanyId()), layoutTemplate.getLayoutTemplateId());
                LayoutLocalServiceUtil.updateLayout(layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings());
            } else {
                LOG.error(String.format("Layout template %1$s not found !", page.getLayout()));
                if (themeId != null) {
                    LOG.error(String.format(LAYOUT_WAS_LOOKED_UP_IN_THEME, themeId));
                }
            }
        } catch (Exception e) {
            LOG.error(String.format("Error by setting layout template : %1$s", page.getLayout()), e);
            if (themeId != null) {
                LOG.error(String.format(LAYOUT_WAS_LOOKED_UP_IN_THEME, themeId));
            }
        }
    }
}
Also used : LayoutTemplate(com.liferay.portal.kernel.model.LayoutTemplate) LayoutTypePortlet(com.liferay.portal.kernel.model.LayoutTypePortlet) ReadOnlyException(javax.portlet.ReadOnlyException) NoSuchLayoutException(com.liferay.portal.kernel.exception.NoSuchLayoutException) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException)

Aggregations

NoSuchLayoutException (com.liferay.portal.kernel.exception.NoSuchLayoutException)1 PortalException (com.liferay.portal.kernel.exception.PortalException)1 SystemException (com.liferay.portal.kernel.exception.SystemException)1 LayoutTemplate (com.liferay.portal.kernel.model.LayoutTemplate)1 LayoutTypePortlet (com.liferay.portal.kernel.model.LayoutTypePortlet)1 ReadOnlyException (javax.portlet.ReadOnlyException)1