Example usage for com.liferay.portal.kernel.theme ThemeDisplay getUserId

List of usage examples for com.liferay.portal.kernel.theme ThemeDisplay getUserId

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.theme ThemeDisplay getUserId.

Prototype

public long getUserId() 

Source Link

Document

Returns the ID of the user for which the current request is being handled.

Usage

From source file:com.liferay.exportimport.web.internal.portlet.action.ImportLayoutsMVCActionCommand.java

License:Open Source License

protected void importData(ActionRequest actionRequest, String fileName, InputStream inputStream)
        throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long groupId = ParamUtil.getLong(actionRequest, "groupId");
    boolean privateLayout = ParamUtil.getBoolean(actionRequest, "privateLayout");

    Map<String, Serializable> importLayoutSettingsMap = ExportImportConfigurationSettingsMapFactory
            .buildImportLayoutSettingsMap(themeDisplay.getUserId(), groupId, privateLayout, null,
                    actionRequest.getParameterMap(), themeDisplay.getLocale(), themeDisplay.getTimeZone());

    ExportImportConfiguration exportImportConfiguration = _exportImportConfigurationLocalService
            .addDraftExportImportConfiguration(themeDisplay.getUserId(),
                    ExportImportConfigurationConstants.TYPE_IMPORT_LAYOUT, importLayoutSettingsMap);

    _exportImportService.importLayoutsInBackground(exportImportConfiguration, inputStream);
}

From source file:com.liferay.exportimport.web.internal.portlet.action.ImportLayoutsMVCActionCommand.java

License:Open Source License

protected MissingReferences validateFile(ActionRequest actionRequest, InputStream inputStream)
        throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long groupId = ParamUtil.getLong(actionRequest, "groupId");
    boolean privateLayout = ParamUtil.getBoolean(actionRequest, "privateLayout");

    Map<String, Serializable> importLayoutSettingsMap = ExportImportConfigurationSettingsMapFactory
            .buildImportLayoutSettingsMap(themeDisplay.getUserId(), groupId, privateLayout, null,
                    actionRequest.getParameterMap(), themeDisplay.getLocale(), themeDisplay.getTimeZone());

    ExportImportConfiguration exportImportConfiguration = _exportImportConfigurationLocalService
            .addDraftExportImportConfiguration(themeDisplay.getUserId(),
                    ExportImportConfigurationConstants.TYPE_IMPORT_LAYOUT, importLayoutSettingsMap);

    return _exportImportService.validateImportLayoutsFile(exportImportConfiguration, inputStream);
}

From source file:com.liferay.faces.bridge.demos.bean.RuntimeBacking.java

License:Open Source License

@PostConstruct
public void postConstruct() {

    FacesContext facesContext = FacesContext.getCurrentInstance();
    Map<String, Object> requestAttributeMap = facesContext.getExternalContext().getRequestMap();
    ThemeDisplay themeDisplay = (ThemeDisplay) requestAttributeMap.get(WebKeys.THEME_DISPLAY);

    try {/*from ww  w. j av a 2s.c  o  m*/
        long companyId = themeDisplay.getCompanyId();
        long userId = themeDisplay.getUserId();
        long groupId = themeDisplay.getScopeGroupId();
        long folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
        Locale locale = themeDisplay.getLocale();

        StringBuilder content1 = new StringBuilder(9);
        content1.append("<?xml version=\"1.0\"?>");
        content1.append("<root available-locales=\"en_US\" default-locale=\"en_US\">");
        content1.append(
                "<dynamic-element name=\"content\" type=\"text_area\" index-type=\"keyword\" instance-id=\"zeun\">");
        content1.append("<dynamic-content language-id=\"en_US\"><![CDATA[");
        content1.append(
                "<p>Liferay Portal is an enterprise web platform for building business solutions that deliver ");
        content1.append("immediate results and long-term value.</p>");
        content1.append("]]></dynamic-content>");
        content1.append("</dynamic-element>");
        content1.append("</root>");

        JournalArticle article1 = WebContentUtil.getArticle(companyId, userId, groupId, folderId, locale,
                "Liferay Portal", content1.toString());
        this.preferencesArticle1 = getPreferences(article1.getGroupId(), article1.getArticleId());

        StringBuilder content2 = new StringBuilder(9);
        content2.append("<?xml version=\"1.0\"?>");
        content2.append("<root available-locales=\"en_US\" default-locale=\"en_US\">");
        content2.append(
                "<dynamic-element name=\"content\" type=\"text_area\" index-type=\"keyword\" instance-id=\"yujh\">");
        content2.append("<dynamic-content language-id=\"en_US\"><![CDATA[");
        content2.append(
                "<p>Liferay Faces is an umbrella project that provides support for the JavaServer Faces (JSF) ");
        content2.append("standard within Liferay Portal.</p>");
        content2.append("]]></dynamic-content>");
        content2.append("</dynamic-element>");
        content2.append("</root>");

        JournalArticle article2 = WebContentUtil.getArticle(companyId, userId, groupId, folderId, locale,
                "Liferay Faces", content2.toString());
        this.preferencesArticle2 = getPreferences(article2.getGroupId(), article2.getArticleId());
    } catch (Exception e) {
        logger.error(e);
    }
}

From source file:com.liferay.faces.portal.context.internal.LiferayPortletHelperImpl.java

License:Open Source License

@Override
public ServiceContext getServiceContext() {

    ServiceContext serviceContext = new ServiceContext();
    ThemeDisplay themeDisplay = getThemeDisplay();
    serviceContext.setCompanyId(themeDisplay.getCompanyId());
    serviceContext.setLanguageId(themeDisplay.getLanguageId());
    serviceContext.setPathMain(PortalUtil.getPathMain());
    serviceContext.setPlid(themeDisplay.getPlid());
    serviceContext.setPortalURL(PortalUtil.getPortalURL(getPortletRequest()));
    serviceContext.setScopeGroupId(themeDisplay.getScopeGroupId());
    serviceContext.setUserId(themeDisplay.getUserId());

    try {/*from ww w  .j  a  v  a  2s  .  com*/
        serviceContext.setLayoutFullURL(PortalUtil.getLayoutFullURL(themeDisplay));
        serviceContext.setLayoutURL(PortalUtil.getLayoutURL(themeDisplay));
        serviceContext.setUserDisplayURL(themeDisplay.getUser().getDisplayURL(themeDisplay));
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }

    return serviceContext;
}

From source file:com.liferay.iframe.web.internal.util.IFrameUtil.java

License:Open Source License

public static boolean isPasswordTokenEnabled(PortletRequest portletRequest) throws PortalException {

    if (!PropsValues.SESSION_STORE_PASSWORD) {
        return false;
    }//  w w  w. j a  v a  2s . c  om

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    Layout layout = themeDisplay.getLayout();

    String roleName = PropsValues.IFRAME_PASSWORD_PASSWORD_TOKEN_ROLE;

    if (layout.isPrivateLayout() && layout.getGroup().isUser()
            && (themeDisplay.getRealUserId() == layout.getGroup().getClassPK())) {

        return true;
    }

    if (Validator.isNull(roleName)) {
        return false;
    }

    try {
        Role role = RoleLocalServiceUtil.getRole(themeDisplay.getCompanyId(), roleName);

        if (UserLocalServiceUtil.hasRoleUser(role.getRoleId(), themeDisplay.getUserId())) {

            return true;
        }
    } catch (Exception e) {
        if (_log.isWarnEnabled()) {
            _log.warn("Error getting role " + roleName + ". The password token " + "will be disabled.");
        }
    }

    return false;
}

From source file:com.liferay.image.uploader.web.internal.portlet.action.UploadImageMVCActionCommand.java

License:Open Source License

protected FileEntry addTempImageFileEntry(PortletRequest portletRequest) throws Exception {

    UploadPortletRequest uploadPortletRequest = _portal.getUploadPortletRequest(portletRequest);

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    String contentType = uploadPortletRequest.getContentType("fileName");

    String fileName = uploadPortletRequest.getFileName("fileName");

    File file = uploadPortletRequest.getFile("fileName");

    String mimeType = MimeTypesUtil.getContentType(file, fileName);

    if (!StringUtil.equalsIgnoreCase(ContentTypes.APPLICATION_OCTET_STREAM, mimeType)) {

        contentType = mimeType;/*  ww w . j av  a  2 s. c o  m*/
    }

    if (!MimeTypesUtil.isWebImage(contentType)) {
        throw new ImageTypeException();
    }

    try {
        TempFileEntryUtil.deleteTempFileEntry(themeDisplay.getScopeGroupId(), themeDisplay.getUserId(),
                UploadImageUtil.getTempImageFolderName(), fileName);
    } catch (Exception e) {
    }

    return TempFileEntryUtil.addTempFileEntry(themeDisplay.getScopeGroupId(), themeDisplay.getUserId(),
            UploadImageUtil.getTempImageFolderName(), fileName, file, contentType);
}

From source file:com.liferay.image.uploader.web.internal.portlet.action.UploadImageMVCActionCommand.java

License:Open Source License

protected FileEntry saveTempImageFileEntry(ActionRequest actionRequest) throws Exception {

    try {//from  w  w w.j av  a 2s  .  c om
        FileEntry tempFileEntry = UploadImageUtil.getTempImageFileEntry(actionRequest);

        try (InputStream tempImageStream = tempFileEntry.getContentStream()) {

            ImageBag imageBag = ImageToolUtil.read(tempImageStream);

            RenderedImage renderedImage = imageBag.getRenderedImage();

            String cropRegionJSON = ParamUtil.getString(actionRequest, "cropRegion");

            if (Validator.isNotNull(cropRegionJSON)) {
                JSONObject jsonObject = JSONFactoryUtil.createJSONObject(cropRegionJSON);

                int height = jsonObject.getInt("height");
                int width = jsonObject.getInt("width");
                int x = jsonObject.getInt("x");
                int y = jsonObject.getInt("y");

                if ((x == 0) && (y == 0) && (renderedImage.getHeight() == height)
                        && (renderedImage.getWidth() == width)) {

                    return tempFileEntry;
                }

                if ((height + y) > renderedImage.getHeight()) {
                    height = renderedImage.getHeight() - y;
                }

                if ((width + x) > renderedImage.getWidth()) {
                    width = renderedImage.getWidth() - x;
                }

                renderedImage = ImageToolUtil.crop(renderedImage, height, width, x, y);
            }

            byte[] bytes = ImageToolUtil.getBytes(renderedImage, imageBag.getType());

            ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

            File file = FileUtil.createTempFile(bytes);

            try {
                TempFileEntryUtil.deleteTempFileEntry(themeDisplay.getScopeGroupId(), themeDisplay.getUserId(),
                        UploadImageUtil.getTempImageFolderName(), getTempImageFileName(actionRequest));
            } catch (Exception e) {
            }

            return TempFileEntryUtil.addTempFileEntry(themeDisplay.getScopeGroupId(), themeDisplay.getUserId(),
                    UploadImageUtil.getTempImageFolderName(), getTempImageFileName(actionRequest), file,
                    tempFileEntry.getMimeType());
        }
    } catch (NoSuchFileEntryException nsfee) {
        throw new UploadException(nsfee);
    } catch (NoSuchRepositoryException nsre) {
        throw new UploadException(nsre);
    }
}

From source file:com.liferay.image.uploader.web.internal.util.UploadImageUtil.java

License:Open Source License

public static FileEntry getTempImageFileEntry(PortletRequest portletRequest) throws PortalException {

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    return TempFileEntryUtil.getTempFileEntry(themeDisplay.getScopeGroupId(), themeDisplay.getUserId(),
            getTempImageFolderName(), getTempImageFileName(portletRequest));
}

From source file:com.liferay.invitation.invite.members.web.internal.portlet.InviteMembersPortlet.java

License:Open Source License

public void updateMemberRequest(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long memberRequestId = ParamUtil.getLong(actionRequest, "memberRequestId");
    int status = ParamUtil.getInteger(actionRequest, "status");

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    try {/* w  ww.jav a  2s . co  m*/
        _memberRequestLocalService.updateMemberRequest(themeDisplay.getUserId(), memberRequestId, status);

        jsonObject.put("success", Boolean.TRUE);
    } catch (Exception e) {
        jsonObject.put("success", Boolean.FALSE);
    }

    writeJSON(actionRequest, actionResponse, jsonObject);
}

From source file:com.liferay.invitation.invite.members.web.internal.portlet.InviteMembersPortlet.java

License:Open Source License

protected void doSendInvite(ActionRequest actionRequest) throws Exception {
    long groupId = ParamUtil.getLong(actionRequest, "groupId");
    long[] receiverUserIds = getLongArray(actionRequest, "receiverUserIds");
    String[] receiverEmailAddresses = getStringArray(actionRequest, "receiverEmailAddresses");
    long invitedRoleId = ParamUtil.getLong(actionRequest, "invitedRoleId");
    long invitedTeamId = ParamUtil.getLong(actionRequest, "invitedTeamId");

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    if (!_userLocalService.hasGroupUser(groupId, themeDisplay.getUserId())) {

        return;/*from w w w. j a v  a 2s  .  c o  m*/
    }

    ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

    Group group = _groupLocalService.getGroup(groupId);

    PortletURL portletURL = PortletProviderUtil.getPortletURL(actionRequest, group,
            UserNotificationEvent.class.getName(), PortletProvider.Action.VIEW);

    serviceContext.setAttribute("redirectURL", portletURL.toString());

    HttpServletRequest request = _portal.getHttpServletRequest(actionRequest);

    String createAccountURL = _portal.getCreateAccountURL(request, themeDisplay);

    serviceContext.setAttribute("createAccountURL", createAccountURL);

    serviceContext.setAttribute("loginURL", themeDisplay.getURLSignIn());

    _memberRequestLocalService.addMemberRequests(themeDisplay.getUserId(), groupId, receiverUserIds,
            invitedRoleId, invitedTeamId, serviceContext);

    _memberRequestLocalService.addMemberRequests(themeDisplay.getUserId(), groupId, receiverEmailAddresses,
            invitedRoleId, invitedTeamId, serviceContext);
}