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);
}
}
Aggregations