use of com.liferay.portal.kernel.model.LayoutTypePortlet 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));
}
}
}
}
use of com.liferay.portal.kernel.model.LayoutTypePortlet in project liferay-db-setup-core by ableneo.
the class SetupPages method insertPortletIntoPage.
private static void insertPortletIntoPage(final PageType page, final Layout layout, final PagePortletType portlet, final long companyId, final long groupId) throws PortalException {
long plid = layout.getPlid();
long ownerId = PortletKeys.PREFS_OWNER_ID_DEFAULT;
int ownerType = PortletKeys.PREFS_OWNER_TYPE_LAYOUT;
long runAsUserId = SetupConfigurationThreadLocal.getRunAsUserId();
LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();
String portletId = portlet.getPortletId();
String column = portlet.getColumn();
String portletIdInc = "";
try {
int columnPos = portlet.getColumnPosition();
portletIdInc = layoutTypePortlet.addPortletId(runAsUserId, portletId, column, columnPos, false);
if (portletIdInc == null) {
portletIdInc = portletId;
}
} catch (SystemException e) {
LOG.error("Add wrappedPortlet error ", e);
}
javax.portlet.PortletPreferences preferences = PortletPreferencesLocalServiceUtil.getPreferences(companyId, ownerId, ownerType, plid, portletIdInc);
List<PortletPreference> prefsList = portlet.getPortletPreference();
for (PortletPreference p : prefsList) {
try {
preferences.setValue(p.getKey(), resolvePortletPrefValue(p.getKey(), p.getValue(), portlet, companyId, groupId));
} catch (ReadOnlyException e) {
LOG.error("Portlet preferences (" + p.getKey() + ", " + p.getValue() + ") of " + "wrappedPortlet " + portlet.getPortletId() + " caused an excpetion! ");
}
}
PortletPreferencesLocalServiceUtil.updatePreferences(ownerId, ownerType, plid, portletIdInc, preferences);
if (Validator.isNotNull(column) && Validator.isNotNull(portletIdInc)) {
layoutTypePortlet.movePortletId(runAsUserId, portletIdInc, column, portlet.getColumnPosition());
}
LayoutLocalServiceUtil.updateLayout(layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings());
if (portlet.getRolePermissions() != null) {
LOG.info(" i portlet rights");
updatePortletDisplayPermissions(portlet, portletIdInc, layout, page, companyId, groupId, portlet.getRolePermissions(), getDefaultPortletPermissions(layout.isPrivateLayout()));
}
LOG.info(" i portlet added.");
}
use of com.liferay.portal.kernel.model.LayoutTypePortlet in project liferay-db-setup-core by ableneo.
the class SetupPages method removeAllPortlets.
private static void removeAllPortlets(final long runasUser, final LayoutTypePortlet layoutTypePortlet, final Layout layout) {
List<Portlet> portlets = null;
try {
portlets = layoutTypePortlet.getAllPortlets();
} catch (SystemException e1) {
LOG.error(e1);
}
if (portlets != null) {
for (Portlet portlet : portlets) {
String portletId = portlet.getPortletId();
try {
if (layoutTypePortlet.hasPortletId(portletId)) {
LOG.debug(String.format("Removing wrappedPortlet %1$s", portletId));
layoutTypePortlet.removePortletId(runasUser, portletId);
String rootPortletId = PortletIdCodec.decodePortletName(portletId);
LOG.debug(String.format("Root portletId: %1$s", rootPortletId));
ResourceLocalServiceUtil.deleteResource(layout.getCompanyId(), rootPortletId, ResourceConstants.SCOPE_INDIVIDUAL, PortletPermissionUtil.getPrimaryKey(layout.getPlid(), portletId));
LayoutLocalServiceUtil.updateLayout(layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings());
List<PortletPreferences> list = PortletPreferencesLocalServiceUtil.getPortletPreferences(PortletKeys.PREFS_OWNER_TYPE_LAYOUT, layout.getPlid(), portletId);
for (PortletPreferences p : list) {
PortletPreferencesLocalServiceUtil.deletePortletPreferences(p);
}
}
} catch (PortalException | SystemException e) {
LOG.error(e);
}
}
}
}
Aggregations