Search in sources :

Example 6 with Portlet

use of com.liferay.portal.kernel.model.Portlet in project liferay-imex by jpdacunha.

the class ExportRolePermissionsServiceImpl method getRolePermissions.

private RolePermissions getRolePermissions(long companyId, long roleId, boolean allActions) throws Exception {
    RolePermissions result = new RolePermissions();
    List<Portlet> portlets = portletLocalService.getPortlets(companyId, true, false);
    List<String> portletNames = new ArrayList<String>(portlets.size() + 1);
    for (Portlet portlet : portlets) {
        String portletName = portlet.getPortletId();
        portletNames.add(portletName);
    }
    portletNames.add(PortletKeys.PORTAL);
    for (String portletName : portletNames) {
        PortletPermissions portletPermissions = new PortletPermissions();
        List<String> modelResources = ResourceActionsUtil.getPortletModelResources(portletName);
        for (String modelResource : modelResources) {
            Resource r = getModelResource(companyId, roleId, modelResource, allActions);
            if (allActions || r.getActionList().size() > 0) {
                portletPermissions.getModelResourceList().add(r);
            }
        }
        Resource pr = getPortletResource(companyId, roleId, portletName, allActions);
        portletPermissions.setPortletResource(pr);
        if (allActions || portletPermissions.getModelResourceList().size() > 0 || pr.getActionList().size() > 0) {
            result.getPortletPermissionsList().add(portletPermissions);
        }
    }
    return result;
}
Also used : RolePermissions(com.liferay.imex.role.model.RolePermissions) Portlet(com.liferay.portal.kernel.model.Portlet) PortletPermissions(com.liferay.imex.role.model.PortletPermissions) ArrayList(java.util.ArrayList) Resource(com.liferay.imex.role.model.Resource)

Example 7 with Portlet

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

Example 8 with Portlet

use of com.liferay.portal.kernel.model.Portlet in project liferay-faces-bridge-ext by liferay.

the class PortalContextBridgeLiferayImpl method isLiferayNamespacingParameters.

private boolean isLiferayNamespacingParameters(PortletRequest portletRequest) {
    boolean liferayNamespacingParameters = false;
    String portletId = (String) portletRequest.getAttribute(WebKeys.PORTLET_ID);
    try {
        ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);
        Portlet portlet = PortletLocalServiceUtil.getPortletById(themeDisplay.getCompanyId(), portletId);
        liferayNamespacingParameters = portlet.isRequiresNamespacedParameters();
    } catch (SystemException e) {
        logger.error(e);
    }
    return liferayNamespacingParameters;
}
Also used : Portlet(com.liferay.portal.kernel.model.Portlet) SystemException(com.liferay.portal.kernel.exception.SystemException) ThemeDisplay(com.liferay.portal.kernel.theme.ThemeDisplay)

Example 9 with Portlet

use of com.liferay.portal.kernel.model.Portlet in project liferay-faces-bridge-ext by liferay.

the class LiferayURLGeneratorBaseImpl method generateURL.

public String generateURL(Map<String, String[]> additionalParameterMap, String cacheability, PortletMode portletMode, String resourceId, WindowState windowState) {
    String toStringValue;
    if (baseURL.contains(Portal.FRIENDLY_URL_SEPARATOR)) {
        toStringValue = baseURL;
    } else {
        StringBuilder url = new StringBuilder();
        // Build up a new URL string based on the one returned by Liferay, but discard everything after the
        // question mark because it's filled with all kinds of unnecessary stuff.
        url.append(prefix);
        // Possibly add the p_auth parameter.
        boolean firstParameter = true;
        String portalAuthToken = StringHelper.toString(additionalParameterMap.get(P_AUTH), parameterMap.get(P_AUTH));
        if (portalAuthToken != null) {
            appendParameterToURL(firstParameter, P_AUTH, portalAuthToken, url);
            firstParameter = false;
        }
        // Possibly add the p_l_id parameter.
        String plid = StringHelper.toString(additionalParameterMap.get(P_L_ID), parameterMap.get(P_L_ID));
        if (plid != null) {
            appendParameterToURL(firstParameter, P_L_ID, plid, url);
            firstParameter = false;
        }
        // Possibly add the p_p_auth parameter.
        String portletAuthToken = StringHelper.toString(additionalParameterMap.get(P_P_AUTH), parameterMap.get(P_P_AUTH));
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ExternalContext externalContext = facesContext.getExternalContext();
        if (portletAuthToken != null) {
            boolean addPortletAuthToken = true;
            final Product LIFERAY_PORTAL = ProductFactory.getProductInstance(externalContext, Product.Name.LIFERAY_PORTAL);
            final int LIFERAY_BUILD_NUMBER = LIFERAY_PORTAL.getBuildId();
            if ((LIFERAY_BUILD_NUMBER < 6102) || ((LIFERAY_BUILD_NUMBER > 6102) && (LIFERAY_BUILD_NUMBER < 6130))) {
                // Versions of Liferay Portal prior to 6.1.2-CE/6.1.30-EE suffered from LPS-36481 which caused
                // PortletURLImpl.addPortletAuthToken(StringBundle, Key) method to add the p_p_auth parameter to
                // URLs for portlets when add-default-resource=false. It is therefore necessary to check that
                // add-default-resource=true before adding the p_p_auth parameter to the URL.
                PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
                String portletId = (String) portletRequest.getAttribute(WebKeys.PORTLET_ID);
                ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);
                try {
                    Portlet portlet = PortletLocalServiceUtil.getPortletById(themeDisplay.getCompanyId(), portletId);
                    addPortletAuthToken = portlet.isAddDefaultResource();
                } catch (SystemException e) {
                    logger.error(e);
                }
            }
            if (addPortletAuthToken) {
                appendParameterToURL(firstParameter, P_P_AUTH, portletAuthToken, url);
                firstParameter = false;
            }
        }
        // Always add the p_p_id parameter
        String parameterValue = StringHelper.toString(additionalParameterMap.get(P_P_ID), responseNamespace);
        if (parameterValue.startsWith("_")) {
            parameterValue = parameterValue.substring(1);
        }
        if (parameterValue.endsWith("_")) {
            parameterValue = parameterValue.substring(0, parameterValue.length() - 1);
        }
        appendParameterToURL(firstParameter, P_P_ID, parameterValue, url);
        firstParameter = false;
        // Always add the p_p_lifecycle parameter.
        String portletLifecycleId = getPortletLifecycleId();
        appendParameterToURL(P_P_LIFECYCLE, portletLifecycleId, url);
        // Add the p_p_state parameter.
        Map<String, Object> applicationMap = externalContext.getApplicationMap();
        WindowState urlWindowState = initialWindowState;
        if (additionalParameterMap.get(P_P_STATE) != null) {
            urlWindowState = new WindowState(additionalParameterMap.get(P_P_STATE)[0]);
        }
        if (windowState != null) {
            urlWindowState = windowState;
        }
        if (urlWindowState == null) {
            parameterValue = (String) applicationMap.get(responseNamespace + P_P_STATE);
        } else {
            parameterValue = urlWindowState.toString();
        }
        appendParameterToURL(P_P_STATE, parameterValue, url);
        // Possibly add the p_p_state_rcv parameter.
        String stateRestoreCurrentView = StringHelper.toString(additionalParameterMap.get(P_P_STATE_RCV), parameterMap.get(P_P_STATE_RCV));
        if (stateRestoreCurrentView != null) {
            appendParameterToURL(P_P_STATE_RCV, stateRestoreCurrentView, url);
        }
        // Add the p_p_mode parameter.
        PortletMode urlPortletMode = initialPortletMode;
        if (additionalParameterMap.get(P_P_MODE) != null) {
            urlPortletMode = new PortletMode(additionalParameterMap.get(P_P_MODE)[0]);
        }
        if (portletMode != null) {
            urlPortletMode = portletMode;
        }
        if (urlPortletMode == null) {
            parameterValue = (String) applicationMap.get(responseNamespace + P_P_MODE);
        } else {
            parameterValue = urlPortletMode.toString();
        }
        appendParameterToURL(P_P_MODE, parameterValue, url);
        // Possibly add the p_p_cacheability parameter
        if (LIFECYCLE_RESOURCE_PHASE_ID.equals(portletLifecycleId)) {
            String urlCacheability = null;
            if (cacheability != null) {
                urlCacheability = cacheability;
            }
            if (urlCacheability == null) {
                urlCacheability = StringHelper.toString(additionalParameterMap.get(P_P_CACHEABILITY), parameterMap.get(P_P_CACHEABILITY));
            }
            if (urlCacheability != null) {
                appendParameterToURL(P_P_CACHEABILITY, urlCacheability, url);
            }
        }
        // Always add the p_p_col_id parameter
        parameterValue = (String) applicationMap.get(responseNamespace + P_P_COL_ID);
        appendParameterToURL(P_P_COL_ID, parameterValue, url);
        // Possibly add the p_p_col_count parameter.
        parameterValue = (String) applicationMap.get(responseNamespace + P_P_COL_COUNT);
        appendParameterToURL(P_P_COL_COUNT, parameterValue, url);
        // Add the p_p_col_pos parameter if it is greater than zero (same logic as Liferay's
        // PortletURLImpl.toString())
        parameterValue = (String) applicationMap.get(responseNamespace + P_P_COL_POS);
        if ((parameterValue != null) && (parameterValue.length() > 0)) {
            try {
                int colPos = Integer.parseInt(parameterValue);
                if (colPos > 0) {
                    appendParameterToURL(P_P_COL_POS, parameterValue, url);
                }
            } catch (NumberFormatException e) {
            // ignore
            }
        }
        // Possibly add the p_o_p_id parameter.
        String outerPortletId = StringHelper.toString(additionalParameterMap.get(P_O_P_ID), parameterMap.get(P_O_P_ID));
        if (outerPortletId != null) {
            appendParameterToURL(P_O_P_ID, outerPortletId, url);
        }
        // Possibly add the doAsUserId parameter.
        String doAsUserId = StringHelper.toString(additionalParameterMap.get(DO_AS_USER_ID), parameterMap.get(DO_AS_USER_ID));
        if (doAsUserId != null) {
            appendParameterToURL(DO_AS_USER_ID, doAsUserId, url);
        }
        // Possibly add the doAsUserLanguageId parameter.
        String doAsUserLanguageId = StringHelper.toString(additionalParameterMap.get(DO_AS_USER_LANGUAGE_ID), parameterMap.get(DO_AS_USER_LANGUAGE_ID));
        if (doAsUserLanguageId != null) {
            appendParameterToURL(DO_AS_USER_LANGUAGE_ID, doAsUserLanguageId, url);
        }
        // Possibly add the doAsGroupId parameter.
        String doAsGroupId = StringHelper.toString(additionalParameterMap.get(DO_AS_GROUP_ID), parameterMap.get(DO_AS_GROUP_ID));
        if (doAsGroupId != null) {
            appendParameterToURL(DO_AS_GROUP_ID, doAsGroupId, url);
        }
        // Possibly add the refererGroupId parameter.
        String refererGroupId = StringHelper.toString(additionalParameterMap.get(REFERER_GROUP_ID), parameterMap.get(REFERER_GROUP_ID));
        if (refererGroupId != null) {
            appendParameterToURL(REFERER_GROUP_ID, refererGroupId, url);
        }
        // Possibly add the refererPlid parameter.
        String refererPlid = StringHelper.toString(additionalParameterMap.get(REFERER_PLID), parameterMap.get(REFERER_PLID));
        if (refererPlid != null) {
            appendParameterToURL(REFERER_PLID, refererPlid, url);
        }
        // Possibly add the controlPanelCategory parameter.
        String controlPanelCategory = StringHelper.toString(additionalParameterMap.get(CONTROL_PANEL_CATEGORY), parameterMap.get(CONTROL_PANEL_CATEGORY));
        if (controlPanelCategory != null) {
            appendParameterToURL(CONTROL_PANEL_CATEGORY, controlPanelCategory, url);
        }
        // Add request parameters from the request parameter map.
        boolean namespaced = !responseNamespace.startsWith("wsrp");
        Set<Map.Entry<String, String[]>> mapEntries = additionalParameterMap.entrySet();
        if (mapEntries != null) {
            for (Map.Entry<String, String[]> mapEntry : mapEntries) {
                String[] parameterValues = mapEntry.getValue();
                if (parameterValues != null) {
                    String parameterName = mapEntry.getKey();
                    if (!LIFERAY_NON_NAMESPACED_PARAMS.contains(parameterName)) {
                        for (String curParameterValue : parameterValues) {
                            if (curParameterValue != null) {
                                appendParameterToURL(firstParameter, namespaced, parameterName, curParameterValue, url);
                            }
                        }
                    }
                }
            }
        }
        // Add WSRP URL parameters
        for (LiferayURLParameter wsrpParameter : wsrpParameters) {
            appendParameterToURL(wsrpParameter.getName(), wsrpParameter.getValue(), url);
        }
        // Possibly add the p_p_resource_id parameter.
        String urlResourceId = parameterMap.get(P_O_P_ID);
        if (resourceId != null) {
            urlResourceId = resourceId;
        }
        if (urlResourceId == null) {
            if (prefix.startsWith("wsrp")) {
                appendParameterToURL(P_P_RESOURCE_ID, "wsrp", url);
            }
        } else {
            appendParameterToURL(P_P_RESOURCE_ID, urlResourceId, url);
        }
        // Possibly add a Portlet URL Anchor
        if (portletURLAnchor != null) {
            url.append(portletURLAnchor);
        }
        toStringValue = url.toString();
    }
    return toStringValue;
}
Also used : WindowState(javax.portlet.WindowState) FacesContext(javax.faces.context.FacesContext) Portlet(com.liferay.portal.kernel.model.Portlet) Product(com.liferay.faces.util.product.Product) PortletMode(javax.portlet.PortletMode) PortletRequest(javax.portlet.PortletRequest) SystemException(com.liferay.portal.kernel.exception.SystemException) ExternalContext(javax.faces.context.ExternalContext) ThemeDisplay(com.liferay.portal.kernel.theme.ThemeDisplay) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with Portlet

use of com.liferay.portal.kernel.model.Portlet in project liferay-faces-bridge-ext by liferay.

the class ScriptsEncoderLiferayImpl method scriptDataAppendScripts.

private void scriptDataAppendScripts(ScriptData scriptData, Map<String, Object> requestMap, List<Script> scripts) throws IOException {
    String portletId = "";
    Object portletObject = requestMap.get(WebKeys.RENDER_PORTLET);
    if ((portletObject != null) && (portletObject instanceof Portlet)) {
        Portlet portlet = (Portlet) portletObject;
        portletId = portlet.getPortletId();
    }
    for (Script script : scripts) {
        Script.ModulesType modulesType = script.getModulesType();
        if (Script.ModulesType.ALLOY.equals(modulesType)) {
            StringBuilder modulesStringBuilder = new StringBuilder();
            String[] modules = script.getModules();
            if (modules != null) {
                boolean firstModule = true;
                for (String module : modules) {
                    if (!firstModule) {
                        modulesStringBuilder.append(",");
                    }
                    modulesStringBuilder.append(module);
                    firstModule = false;
                }
            }
            scriptDataAppendScript(scriptData, portletId, script.getSourceCode(), modulesStringBuilder.toString());
        } else {
            scriptDataAppendScript(scriptData, portletId, script.getSourceCode(), null);
        }
    }
}
Also used : Script(com.liferay.faces.util.client.Script) Portlet(com.liferay.portal.kernel.model.Portlet)

Aggregations

Portlet (com.liferay.portal.kernel.model.Portlet)10 PortletRequest (javax.portlet.PortletRequest)5 Layout (com.liferay.portal.kernel.model.Layout)4 LiferayPortletURL (com.liferay.portal.kernel.portlet.LiferayPortletURL)4 PortletURLFactoryUtil (com.liferay.portal.kernel.portlet.PortletURLFactoryUtil)4 LayoutLocalServiceUtil (com.liferay.portal.kernel.service.LayoutLocalServiceUtil)4 PortletLocalServiceUtil (com.liferay.portal.kernel.service.PortletLocalServiceUtil)4 LogManager (org.apache.logging.log4j.LogManager)4 Logger (org.apache.logging.log4j.Logger)4 User (org.eclipse.sw360.datahandler.thrift.users.User)4 PortalConstants (org.eclipse.sw360.portal.common.PortalConstants)4 UserCacheHolder (org.eclipse.sw360.portal.users.UserCacheHolder)4 SystemException (com.liferay.portal.kernel.exception.SystemException)3 ResourceRequest (javax.portlet.ResourceRequest)3 CommonUtils (org.eclipse.sw360.datahandler.common.CommonUtils)3 SW360Utils (org.eclipse.sw360.datahandler.common.SW360Utils)3 CustomFieldHelper (org.eclipse.sw360.portal.common.CustomFieldHelper)3 PortletUtils (org.eclipse.sw360.portal.common.PortletUtils)3 com.google.common.collect (com.google.common.collect)2 ThemeDisplay (com.liferay.portal.kernel.theme.ThemeDisplay)2