Search in sources :

Example 61 with ThemeDisplay

use of com.liferay.portal.theme.ThemeDisplay in project sw360portal by sw360.

the class UserPortlet method createOrganizations.

public void createOrganizations(PortletRequest request, Iterable<String> departments) throws PortalException, SystemException {
    ImmutableSet<String> headDepartments = FluentIterable.from(departments).transform(department -> extractHeadDept(department)).toSet();
    Map<String, Long> organizationIds = new HashMap<>();
    ServiceContext serviceContext = ServiceContextFactory.getInstance(request);
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    long companyId = themeDisplay.getCompanyId();
    for (String headDepartment : headDepartments) {
        long organizationId;
        try {
            organizationId = OrganizationLocalServiceUtil.getOrganizationId(companyId, headDepartment);
        } catch (SystemException e) {
            organizationId = 0;
        }
        if (organizationId == 0) {
            // The organization does not yet exist
            Organization organization = createOrganization(serviceContext, headDepartment, OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID);
            organizationId = organization.getOrganizationId();
        }
        organizationIds.put(headDepartment, organizationId);
    }
    for (String department : departments) {
        long organizationId;
        try {
            organizationId = OrganizationLocalServiceUtil.getOrganizationId(companyId, department);
        } catch (SystemException e) {
            organizationId = 0;
        }
        if (organizationId == 0) {
            // The organization does not yet exist
            createOrganization(serviceContext, department, organizationIds.get(extractHeadDept(department)).intValue());
        }
    }
}
Also used : java.util(java.util) CSVRecord(org.apache.commons.csv.CSVRecord) PortletResponseUtil(com.liferay.portal.kernel.portlet.PortletResponseUtil) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) WebKeys(com.liferay.portal.kernel.util.WebKeys) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception) PortalException(com.liferay.portal.kernel.exception.PortalException) PortalUtil(com.liferay.portal.util.PortalUtil) SystemException(com.liferay.portal.kernel.exception.SystemException) Logger(org.apache.log4j.Logger) UserService(org.eclipse.sw360.datahandler.thrift.users.UserService) CSVFormat(org.apache.commons.csv.CSVFormat) FluentIterable(com.google.common.collect.FluentIterable) User(com.liferay.portal.model.User) CSVParser(org.apache.commons.csv.CSVParser) javax.portlet(javax.portlet) UserUtils(org.eclipse.sw360.portal.users.UserUtils) com.liferay.portal.service(com.liferay.portal.service) Sw360Portlet(org.eclipse.sw360.portal.portlets.Sw360Portlet) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) UserCSV(org.eclipse.sw360.portal.users.UserCSV) UserGroup(org.eclipse.sw360.datahandler.thrift.users.UserGroup) TException(org.apache.thrift.TException) UserUtils.getRoleConstantFromUserGroup(org.eclipse.sw360.portal.users.UserUtils.getRoleConstantFromUserGroup) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay) CommonUtils(org.eclipse.sw360.datahandler.common.CommonUtils) UploadPortletRequest(com.liferay.portal.kernel.upload.UploadPortletRequest) java.io(java.io) Predicate(com.google.common.base.Predicate) UserCacheHolder(org.eclipse.sw360.portal.users.UserCacheHolder) PortalConstants(org.eclipse.sw360.portal.common.PortalConstants) QueryUtil(com.liferay.portal.kernel.dao.orm.QueryUtil) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction) CSVPrinter(org.apache.commons.csv.CSVPrinter) com.liferay.portal.model(com.liferay.portal.model) SystemException(com.liferay.portal.kernel.exception.SystemException) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay)

Example 62 with ThemeDisplay

use of com.liferay.portal.theme.ThemeDisplay in project sw360portal by sw360.

the class ComponentPortlet method createDetailLinkTemplate.

private LiferayPortletURL createDetailLinkTemplate(PortletRequest request) {
    String portletId = (String) request.getAttribute(WebKeys.PORTLET_ID);
    ThemeDisplay tD = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    long plid = tD.getPlid();
    LiferayPortletURL componentUrl = PortletURLFactoryUtil.create(request, portletId, plid, PortletRequest.RENDER_PHASE);
    componentUrl.setParameter(PortalConstants.PAGENAME, PortalConstants.PAGENAME_DETAIL);
    return componentUrl;
}
Also used : LiferayPortletURL(com.liferay.portal.kernel.portlet.LiferayPortletURL) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay)

Example 63 with ThemeDisplay

use of com.liferay.portal.theme.ThemeDisplay in project sw360portal by sw360.

the class LifeRayUserSession method getEmailFromRequest.

/**
 * Get the email of the currently logged-in user
 *
 * @param request Java portlet render request
 */
public static String getEmailFromRequest(PortletRequest request) {
    String email = null;
    // Logged-in user can be fetched from Liferay's ThemeDisplay
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    if (themeDisplay.isSignedIn()) {
        com.liferay.portal.model.User user = themeDisplay.getUser();
        // Get email address from user
        if (user != null) {
            email = user.getEmailAddress();
        }
    }
    return email;
}
Also used : ThemeDisplay(com.liferay.portal.theme.ThemeDisplay)

Aggregations

ThemeDisplay (com.liferay.portal.theme.ThemeDisplay)63 PermissionChecker (com.liferay.portal.security.permission.PermissionChecker)10 ServiceContext (com.liferay.portal.service.ServiceContext)7 JSONObject (com.liferay.portal.kernel.json.JSONObject)6 PortletURL (javax.portlet.PortletURL)6 PortalException (com.liferay.portal.kernel.exception.PortalException)5 User (com.liferay.portal.model.User)5 Gadget (com.liferay.opensocial.model.Gadget)4 SystemException (com.liferay.portal.kernel.exception.SystemException)4 UploadPortletRequest (com.liferay.portal.kernel.upload.UploadPortletRequest)4 PortletConfig (javax.portlet.PortletConfig)4 KBArticle (com.liferay.knowledgebase.model.KBArticle)3 KBFolder (com.liferay.knowledgebase.model.KBFolder)3 Role (com.liferay.portal.model.Role)3 HashMap (java.util.HashMap)3 LiferayPortletURL (com.liferay.portal.kernel.portlet.LiferayPortletURL)2 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)2 Folder (com.liferay.portal.kernel.repository.model.Folder)2 Layout (com.liferay.portal.model.Layout)2 SocialActivity (com.liferay.portlet.social.model.SocialActivity)2