Search in sources :

Example 1 with PageType

use of com.ableneo.liferay.portal.setup.domain.PageType in project liferay-db-setup-core by ableneo.

the class SetupPages method setupLiferayPage.

private static void setupLiferayPage(final Layout layout, final PageType page, final String defaultLayout, final String defaultLayoutContainedInThemeWithId, final long groupId, final boolean isPrivate, final long company, final long userId, final String pageTemplateName) throws PortalException {
    if (page.getTheme() != null) {
        setPageTheme(layout, page);
    }
    if (page.getLayout() != null) {
        setLayoutTemplate(layout, page, userId);
    }
    setPageTarget(page, layout);
    List<PagePortletType> portlets = page.getPagePortlet();
    if (portlets != null && !portlets.isEmpty()) {
        List<PortletWithRuntimeData> deferredAdd = new ArrayList<SetupPages.PortletWithRuntimeData>();
        for (PagePortletType portlet : portlets) {
            addRuntimeInfo(deferredAdd, portlet, page, layout, company, groupId);
        }
        portlets.clear();
        portlets.addAll(deferredAdd);
    }
    List<PageType> subPages = page.getPage();
    if (subPages != null && !subPages.isEmpty()) {
        if (pageTemplateName != null && !pageTemplateName.equals("")) {
            LOG.error(String.format("Page template %1$s may not have any sub-pages! Will ignore them!", pageTemplateName));
        } else {
            addPages(subPages, defaultLayout, defaultLayoutContainedInThemeWithId, groupId, isPrivate, layout.getLayoutId(), company, userId);
        }
    }
    if (page.getCustomFieldSetting() != null && !page.getCustomFieldSetting().isEmpty()) {
        setCustomFields(groupId, company, page, layout);
    }
    SetupPermissions.updatePermission(String.format("Page %1$s", page.getFriendlyUrl()), company, layout.getPlid(), Layout.class, page.getRolePermissions(), getDefaultPermissions(isPrivate));
}
Also used : ArrayList(java.util.ArrayList) PagePortletType(com.ableneo.liferay.portal.setup.domain.PagePortletType) PageType(com.ableneo.liferay.portal.setup.domain.PageType)

Example 2 with PageType

use of com.ableneo.liferay.portal.setup.domain.PageType in project liferay-db-setup-core by ableneo.

the class SetupPages method addPages.

/**
 * @param pages
 * @param groupId
 * @param isPrivate
 * @param parentLayoutId
 * @param company
 * @param userId
 *
 * @throws SystemException
 * @throws PortalException
 */
private static void addPages(final List<PageType> pages, String defaultLayout, String defaultLayoutContainedInThemeWithId, final long groupId, final boolean isPrivate, final long parentLayoutId, final long company, final long userId) throws PortalException {
    for (PageType page : pages) {
        Layout layout = null;
        try {
            layout = LayoutLocalServiceUtil.getFriendlyURLLayout(groupId, isPrivate, page.getFriendlyUrl());
            LOG.info(String.format("Setup: Page %1$s already exist, not creating...", page.getName()));
            if (layout != null && page.isDeleteExistingPages()) {
                LayoutLocalServiceUtil.deleteLayout(layout);
                if (page.getLinkToUrl() == null || page.getLinkToUrl().equals("")) {
                    layout = createPage(groupId, page, parentLayoutId, isPrivate);
                } else {
                    layout = createLinkPage(page, groupId, parentLayoutId, userId);
                }
            } else if (layout != null && (page.getLinkToUrl() != null && !page.getLinkToUrl().equals(""))) {
                updateLinkPage(page, groupId);
            } else {
                LOG.warn(String.format("Setup: unhandled 'else' while creatng page[%1$s]/layout[%2$s]", page.getName(), page.getLayout()));
            }
        } catch (NoSuchLayoutException e) {
            if (page.getLinkToUrl() == null || page.getLinkToUrl().equals("")) {
                layout = createPage(groupId, page, parentLayoutId, isPrivate);
            } else {
                layout = createLinkPage(page, groupId, parentLayoutId, userId);
            }
            LOG.info(String.format("Setup: Page %1$s created...", page.getName()));
        } catch (Exception ex) {
            LOG.error(ex);
        }
        // subtree
        if (page.getLayout() == null) {
            page.setLayout(defaultLayout);
            page.setLayoutThemeId(defaultLayoutContainedInThemeWithId);
        } else {
            defaultLayout = page.getLayout();
            defaultLayoutContainedInThemeWithId = page.getLayoutThemeId();
        }
        setupLiferayPage(layout, page, defaultLayout, defaultLayoutContainedInThemeWithId, groupId, isPrivate, company, userId, null);
    }
}
Also used : Layout(com.liferay.portal.kernel.model.Layout) NoSuchLayoutException(com.liferay.portal.kernel.exception.NoSuchLayoutException) PageType(com.ableneo.liferay.portal.setup.domain.PageType) 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)

Example 3 with PageType

use of com.ableneo.liferay.portal.setup.domain.PageType in project liferay-db-setup-core by ableneo.

the class SetupPages method setupPageTemplates.

/**
 * Set the page templates up. As this is heavily based on page (layout).
 *
 * @param pageTemplates The page template definitions that are imported.
 */
public static void setupPageTemplates(final PageTemplates pageTemplates) {
    try {
        for (PageTemplate pageTemplate : pageTemplates.getPageTemplate()) {
            String name = pageTemplate.getName();
            if (name != null) {
                LayoutPrototype lp;
                DynamicQuery dq = LayoutPrototypeLocalServiceUtil.dynamicQuery().add(PropertyFactoryUtil.forName("name").like("%" + name + "%"));
                List<LayoutPrototype> listLayoutPrototype = LayoutPrototypeLocalServiceUtil.dynamicQuery(dq);
                long groupId = SetupConfigurationThreadLocal.getRunInGroupId();
                long userid = SetupConfigurationThreadLocal.getRunAsUserId();
                long company = SetupConfigurationThreadLocal.getRunInCompanyId();
                if (listLayoutPrototype != null && !listLayoutPrototype.isEmpty()) {
                    lp = listLayoutPrototype.get(0);
                } else {
                    Map<Locale, String> titleMap = TranslationMapUtil.getTranslationMap(pageTemplate.getTitleTranslation(), groupId, name, String.format(" Page template  %1$s", name));
                    Map<Locale, String> nameMap = TranslationMapUtil.getTranslationMap(pageTemplate.getTitleTranslation(), groupId, name, String.format(" Page template  %1$s", name));
                    lp = LayoutPrototypeLocalServiceUtil.addLayoutPrototype(userid, company, titleMap, nameMap, true, new ServiceContext());
                }
                if (lp != null) {
                    Layout layout = lp.getLayout();
                    if (pageTemplate.getPage() != null) {
                        PageType page = pageTemplate.getPage();
                        if (page.getFriendlyUrl() != null && !page.getFriendlyUrl().equals("")) {
                            LOG.error(String.format("The page of page template %1$s may not have a friendly URL! Will ignore it!", name));
                        }
                        setupLiferayPage(layout, page, null, null, groupId, false, company, userid, name);
                    }
                } else {
                    LOG.error(String.format("Could not create or find the page template %1$s", name));
                }
            }
        }
    } catch (PortalException | SystemException e) {
        LOG.error("Problem during creating page templates ", e);
    }
}
Also used : Locale(java.util.Locale) PageTemplate(com.ableneo.liferay.portal.setup.domain.PageTemplate) DynamicQuery(com.liferay.portal.kernel.dao.orm.DynamicQuery) ServiceContext(com.liferay.portal.kernel.service.ServiceContext) SystemException(com.liferay.portal.kernel.exception.SystemException) Layout(com.liferay.portal.kernel.model.Layout) LayoutPrototype(com.liferay.portal.kernel.model.LayoutPrototype) PortalException(com.liferay.portal.kernel.exception.PortalException) PageType(com.ableneo.liferay.portal.setup.domain.PageType)

Aggregations

PageType (com.ableneo.liferay.portal.setup.domain.PageType)3 PortalException (com.liferay.portal.kernel.exception.PortalException)2 SystemException (com.liferay.portal.kernel.exception.SystemException)2 Layout (com.liferay.portal.kernel.model.Layout)2 PagePortletType (com.ableneo.liferay.portal.setup.domain.PagePortletType)1 PageTemplate (com.ableneo.liferay.portal.setup.domain.PageTemplate)1 DynamicQuery (com.liferay.portal.kernel.dao.orm.DynamicQuery)1 NoSuchLayoutException (com.liferay.portal.kernel.exception.NoSuchLayoutException)1 LayoutPrototype (com.liferay.portal.kernel.model.LayoutPrototype)1 ServiceContext (com.liferay.portal.kernel.service.ServiceContext)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1 ReadOnlyException (javax.portlet.ReadOnlyException)1