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