Search in sources :

Example 1 with PortletPreferences

use of com.liferay.portal.kernel.model.PortletPreferences 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);
            }
        }
    }
}
Also used : Portlet(com.liferay.portal.kernel.model.Portlet) LayoutTypePortlet(com.liferay.portal.kernel.model.LayoutTypePortlet) SystemException(com.liferay.portal.kernel.exception.SystemException) PortletPreferences(com.liferay.portal.kernel.model.PortletPreferences) PortalException(com.liferay.portal.kernel.exception.PortalException)

Aggregations

PortalException (com.liferay.portal.kernel.exception.PortalException)1 SystemException (com.liferay.portal.kernel.exception.SystemException)1 LayoutTypePortlet (com.liferay.portal.kernel.model.LayoutTypePortlet)1 Portlet (com.liferay.portal.kernel.model.Portlet)1 PortletPreferences (com.liferay.portal.kernel.model.PortletPreferences)1