Search in sources :

Example 1 with LayoutPrototype

use of com.liferay.portal.kernel.model.LayoutPrototype 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

PageTemplate (com.ableneo.liferay.portal.setup.domain.PageTemplate)1 PageType (com.ableneo.liferay.portal.setup.domain.PageType)1 DynamicQuery (com.liferay.portal.kernel.dao.orm.DynamicQuery)1 PortalException (com.liferay.portal.kernel.exception.PortalException)1 SystemException (com.liferay.portal.kernel.exception.SystemException)1 Layout (com.liferay.portal.kernel.model.Layout)1 LayoutPrototype (com.liferay.portal.kernel.model.LayoutPrototype)1 ServiceContext (com.liferay.portal.kernel.service.ServiceContext)1 Locale (java.util.Locale)1