Example usage for com.liferay.portal.kernel.portlet PortletPreferencesFactoryUtil getStrictPortletSetup

List of usage examples for com.liferay.portal.kernel.portlet PortletPreferencesFactoryUtil getStrictPortletSetup

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.portlet PortletPreferencesFactoryUtil getStrictPortletSetup.

Prototype

public static PortletPreferences getStrictPortletSetup(Layout layout, String portletId) 

Source Link

Usage

From source file:com.liferay.exportimport.test.util.lar.BasePortletExportImportTestCase.java

License:Open Source License

@Test
public void testUpdateLastPublishDate() throws Exception {
    Date lastPublishDate = new Date(System.currentTimeMillis() - Time.HOUR);

    Date stagedModelCreationDate = new Date(lastPublishDate.getTime() + Time.MINUTE);

    StagedModel stagedModel = addStagedModel(group.getGroupId(), stagedModelCreationDate);

    if (stagedModel == null) {
        return;/*  w  w w  .j a  v a 2s. co  m*/
    }

    LayoutTestUtil.addPortletToLayout(TestPropsValues.getUserId(), layout, getPortletId(), "column-1",
            new HashMap<String, String[]>());

    PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup(layout,
            getPortletId());

    portletPreferences.setValue("last-publish-date", String.valueOf(lastPublishDate.getTime()));

    portletPreferences.store();

    Map<String, String[]> exportParameterMap = new LinkedHashMap<>();

    exportParameterMap.put(PortletDataHandlerKeys.UPDATE_LAST_PUBLISH_DATE,
            new String[] { String.valueOf(true) });
    exportParameterMap.put("range", new String[] { ExportImportDateUtil.RANGE_FROM_LAST_PUBLISH_DATE });

    Map<String, String[]> importParameterMap = new LinkedHashMap<>();

    portletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup(layout, getPortletId());

    Date oldLastPublishDate = ExportImportDateUtil.getLastPublishDate(portletPreferences);

    exportImportPortlet(getPortletId(), exportParameterMap, importParameterMap);

    portletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup(layout, getPortletId());

    Date newLastPublishDate = ExportImportDateUtil.getLastPublishDate(portletPreferences);

    Assert.assertTrue(newLastPublishDate.after(oldLastPublishDate));

    StagedModel importedStagedModel = getStagedModel(getStagedModelUuid(stagedModel),
            importedGroup.getGroupId());

    Assert.assertNotNull(importedStagedModel);
}

From source file:com.liferay.journal.subscriptions.test.JournalSubscriptionLocalizedContentTest.java

License:Open Source License

@Override
protected void setBaseModelSubscriptionBodyPreferences(String bodyPreferenceName) throws Exception {

    PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup(layout,
            getServiceName());/*  w ww  .  ja va  2s  .  c o m*/

    LocalizationUtil.setPreferencesValue(portletPreferences, bodyPreferenceName,
            LocaleUtil.toLanguageId(LocaleUtil.GERMANY), GERMAN_BODY);
    LocalizationUtil.setPreferencesValue(portletPreferences, bodyPreferenceName,
            LocaleUtil.toLanguageId(LocaleUtil.SPAIN), SPANISH_BODY);

    PortletPreferencesLocalServiceUtil.updatePreferences(group.getGroupId(), PortletKeys.PREFS_OWNER_TYPE_GROUP,
            PortletKeys.PREFS_PLID_SHARED, getServiceName(), portletPreferences);
}

From source file:com.liferay.journal.web.internal.portlet.JournalPortlet.java

License:Open Source License

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

    UploadException uploadException = (UploadException) actionRequest.getAttribute(WebKeys.UPLOAD_EXCEPTION);

    if (uploadException != null) {
        Throwable cause = uploadException.getCause();

        if (uploadException.isExceededLiferayFileItemSizeLimit()) {
            throw new LiferayFileItemException(cause);
        }//from  ww  w  .java  2s. c o  m

        if (uploadException.isExceededFileSizeLimit() || uploadException.isExceededUploadRequestSizeLimit()) {

            throw new ArticleContentSizeException(cause);
        }

        throw new PortalException(cause);
    }

    UploadPortletRequest uploadPortletRequest = _portal.getUploadPortletRequest(actionRequest);

    if (_log.isDebugEnabled()) {
        _log.debug("Updating article " + MapUtil.toString(uploadPortletRequest.getParameterMap()));
    }

    String actionName = ParamUtil.getString(actionRequest, ActionRequest.ACTION_NAME);

    long groupId = ParamUtil.getLong(uploadPortletRequest, "groupId");
    long folderId = ParamUtil.getLong(uploadPortletRequest, "folderId");
    long classNameId = ParamUtil.getLong(uploadPortletRequest, "classNameId");
    long classPK = ParamUtil.getLong(uploadPortletRequest, "classPK");

    String articleId = ParamUtil.getString(uploadPortletRequest, "articleId");

    boolean autoArticleId = ParamUtil.getBoolean(uploadPortletRequest, "autoArticleId");
    double version = ParamUtil.getDouble(uploadPortletRequest, "version");

    Map<Locale, String> titleMap = LocalizationUtil.getLocalizationMap(actionRequest, "titleMapAsXML");
    Map<Locale, String> descriptionMap = LocalizationUtil.getLocalizationMap(actionRequest,
            "descriptionMapAsXML");

    ServiceContext serviceContext = ServiceContextFactory.getInstance(JournalArticle.class.getName(),
            uploadPortletRequest);

    String ddmStructureKey = ParamUtil.getString(uploadPortletRequest, "ddmStructureKey");

    DDMStructure ddmStructure = _ddmStructureLocalService.getStructure(_portal.getSiteGroupId(groupId),
            _portal.getClassNameId(JournalArticle.class), ddmStructureKey, true);

    Fields fields = DDMUtil.getFields(ddmStructure.getStructureId(), serviceContext);

    String content = _journalConverter.getContent(ddmStructure, fields);

    String ddmTemplateKey = ParamUtil.getString(uploadPortletRequest, "ddmTemplateKey");
    String layoutUuid = ParamUtil.getString(uploadPortletRequest, "layoutUuid");

    Layout targetLayout = JournalUtil.getArticleLayout(layoutUuid, groupId);

    if (targetLayout == null) {
        layoutUuid = null;
    }

    int displayDateMonth = ParamUtil.getInteger(uploadPortletRequest, "displayDateMonth");
    int displayDateDay = ParamUtil.getInteger(uploadPortletRequest, "displayDateDay");
    int displayDateYear = ParamUtil.getInteger(uploadPortletRequest, "displayDateYear");
    int displayDateHour = ParamUtil.getInteger(uploadPortletRequest, "displayDateHour");
    int displayDateMinute = ParamUtil.getInteger(uploadPortletRequest, "displayDateMinute");
    int displayDateAmPm = ParamUtil.getInteger(uploadPortletRequest, "displayDateAmPm");

    if (displayDateAmPm == Calendar.PM) {
        displayDateHour += 12;
    }

    int expirationDateMonth = ParamUtil.getInteger(uploadPortletRequest, "expirationDateMonth");
    int expirationDateDay = ParamUtil.getInteger(uploadPortletRequest, "expirationDateDay");
    int expirationDateYear = ParamUtil.getInteger(uploadPortletRequest, "expirationDateYear");
    int expirationDateHour = ParamUtil.getInteger(uploadPortletRequest, "expirationDateHour");
    int expirationDateMinute = ParamUtil.getInteger(uploadPortletRequest, "expirationDateMinute");
    int expirationDateAmPm = ParamUtil.getInteger(uploadPortletRequest, "expirationDateAmPm");
    boolean neverExpire = ParamUtil.getBoolean(uploadPortletRequest, "neverExpire");

    if (!PropsValues.SCHEDULER_ENABLED) {
        neverExpire = true;
    }

    if (expirationDateAmPm == Calendar.PM) {
        expirationDateHour += 12;
    }

    int reviewDateMonth = ParamUtil.getInteger(uploadPortletRequest, "reviewDateMonth");
    int reviewDateDay = ParamUtil.getInteger(uploadPortletRequest, "reviewDateDay");
    int reviewDateYear = ParamUtil.getInteger(uploadPortletRequest, "reviewDateYear");
    int reviewDateHour = ParamUtil.getInteger(uploadPortletRequest, "reviewDateHour");
    int reviewDateMinute = ParamUtil.getInteger(uploadPortletRequest, "reviewDateMinute");
    int reviewDateAmPm = ParamUtil.getInteger(uploadPortletRequest, "reviewDateAmPm");
    boolean neverReview = ParamUtil.getBoolean(uploadPortletRequest, "neverReview");

    if (!PropsValues.SCHEDULER_ENABLED) {
        neverReview = true;
    }

    if (reviewDateAmPm == Calendar.PM) {
        reviewDateHour += 12;
    }

    boolean indexable = ParamUtil.getBoolean(uploadPortletRequest, "indexable");

    boolean smallImage = ParamUtil.getBoolean(uploadPortletRequest, "smallImage");
    String smallImageURL = ParamUtil.getString(uploadPortletRequest, "smallImageURL");
    File smallFile = uploadPortletRequest.getFile("smallFile");

    String articleURL = ParamUtil.getString(uploadPortletRequest, "articleURL");

    JournalArticle article = null;
    String oldUrlTitle = StringPool.BLANK;

    if (actionName.equals("addArticle")) {

        // Add article

        article = _journalArticleService.addArticle(groupId, folderId, classNameId, classPK, articleId,
                autoArticleId, titleMap, descriptionMap, content, ddmStructureKey, ddmTemplateKey, layoutUuid,
                displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute,
                expirationDateMonth, expirationDateDay, expirationDateYear, expirationDateHour,
                expirationDateMinute, neverExpire, reviewDateMonth, reviewDateDay, reviewDateYear,
                reviewDateHour, reviewDateMinute, neverReview, indexable, smallImage, smallImageURL, smallFile,
                null, articleURL, serviceContext);
    } else {

        // Update article

        article = _journalArticleService.getArticle(groupId, articleId, version);

        String tempOldUrlTitle = article.getUrlTitle();

        if (actionName.equals("previewArticle") || actionName.equals("updateArticle")) {

            article = _journalArticleService.updateArticle(groupId, folderId, articleId, version, titleMap,
                    descriptionMap, content, ddmStructureKey, ddmTemplateKey, layoutUuid, displayDateMonth,
                    displayDateDay, displayDateYear, displayDateHour, displayDateMinute, expirationDateMonth,
                    expirationDateDay, expirationDateYear, expirationDateHour, expirationDateMinute,
                    neverExpire, reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour,
                    reviewDateMinute, neverReview, indexable, smallImage, smallImageURL, smallFile, null,
                    articleURL, serviceContext);
        }

        if (!tempOldUrlTitle.equals(article.getUrlTitle())) {
            oldUrlTitle = tempOldUrlTitle;
        }
    }

    // Recent articles

    JournalUtil.addRecentArticle(actionRequest, article);

    // Journal content

    String portletResource = ParamUtil.getString(actionRequest, "portletResource");

    long referringPlid = ParamUtil.getLong(actionRequest, "referringPlid");

    if (Validator.isNotNull(portletResource) && (referringPlid > 0)) {
        Layout layout = _layoutLocalService.getLayout(referringPlid);

        PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup(layout,
                portletResource);

        if (portletPreferences != null) {
            portletPreferences.setValue("groupId", String.valueOf(article.getGroupId()));
            portletPreferences.setValue("articleId", article.getArticleId());

            portletPreferences.store();

            updateContentSearch(actionRequest, portletResource, article.getArticleId());
        }
    }

    sendEditArticleRedirect(actionRequest, actionResponse, article, oldUrlTitle);

    long ddmStructureClassNameId = _portal.getClassNameId(DDMStructure.class);

    if (article.getClassNameId() == ddmStructureClassNameId) {
        String ddmPortletId = PortletProviderUtil.getPortletId(DDMStructure.class.getName(), Action.EDIT);

        MultiSessionMessages.add(actionRequest, ddmPortletId + "requestProcessed");
    }
}

From source file:com.liferay.login.web.internal.portlet.action.LoginMVCActionCommand.java

License:Open Source License

protected void login(ThemeDisplay themeDisplay, ActionRequest actionRequest, ActionResponse actionResponse)
        throws Exception {

    HttpServletRequest request = _portal
            .getOriginalServletRequest(_portal.getHttpServletRequest(actionRequest));
    HttpServletResponse response = _portal.getHttpServletResponse(actionResponse);

    String login = ParamUtil.getString(actionRequest, "login");
    String password = actionRequest.getParameter("password");
    boolean rememberMe = ParamUtil.getBoolean(actionRequest, "rememberMe");

    if (!themeDisplay.isSignedIn()) {
        String portletId = _portal.getPortletId(actionRequest);

        PortletPreferences portletPreferences = PortletPreferencesFactoryUtil
                .getStrictPortletSetup(themeDisplay.getLayout(), portletId);

        String authType = portletPreferences.getValue("authType", null);

        _authenticatedSessionManager.login(request, response, login, password, rememberMe, authType);
    }//from  ww w.  ja v  a 2 s .c o m

    String redirect = ParamUtil.getString(actionRequest, "redirect");

    if (Validator.isNotNull(redirect)) {
        redirect = _portal.escapeRedirect(redirect);

        if (Validator.isNotNull(redirect) && !redirect.startsWith(Http.HTTP)) {

            redirect = getCompleteRedirectURL(request, redirect);
        }
    }

    String mainPath = themeDisplay.getPathMain();

    if (PropsValues.PORTAL_JAAS_ENABLE) {
        if (Validator.isNotNull(redirect)) {
            redirect = mainPath.concat("/portal/protected?redirect=").concat(URLCodec.encodeURL(redirect));
        } else {
            redirect = mainPath.concat("/portal/protected");
        }

        actionResponse.sendRedirect(redirect);
    } else {
        if (Validator.isNotNull(redirect)) {
            actionResponse.sendRedirect(redirect);
        } else {
            boolean doActionAfterLogin = ParamUtil.getBoolean(actionRequest, "doActionAfterLogin");

            if (doActionAfterLogin) {
                return;
            } else {
                actionResponse.sendRedirect(mainPath);
            }
        }
    }
}

From source file:com.liferay.polls.web.internal.portlet.action.EditQuestionMVCActionCommand.java

License:Open Source License

protected void addAndStoreSelection(PortletRequest portletRequest, PollsQuestion question) throws Exception {

    String referringPortletResource = ParamUtil.getString(portletRequest, "referringPortletResource");

    if (Validator.isNull(referringPortletResource)) {
        return;//w ww.j a va 2s .co m
    }

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

    PortletPreferences portletPreferences = PortletPreferencesFactoryUtil
            .getStrictPortletSetup(themeDisplay.getLayout(), themeDisplay.getPpid());

    portletPreferences.setValue("questionId", String.valueOf(question.getQuestionId()));

    portletPreferences.store();

    SessionMessages.add(portletRequest,
            portal.getPortletId(portletRequest) + SessionMessages.KEY_SUFFIX_REFRESH_PORTLET,
            referringPortletResource);
}

From source file:com.liferay.quick.note.web.internal.portlet.action.SaveMVCActionCommand.java

License:Open Source License

@Override
public boolean processAction(ActionRequest actionRequest, ActionResponse actionResponse)
        throws PortletException {

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

    try {/*from  www. ja  v a  2 s. c o  m*/
        PortletPermissionUtil.check(themeDisplay.getPermissionChecker(), themeDisplay.getLayout(),
                themeDisplay.getPpid(), ActionKeys.CONFIGURATION);

        PortletPreferences portletPreferences = PortletPreferencesFactoryUtil
                .getStrictPortletSetup(themeDisplay.getLayout(), themeDisplay.getPpid());

        if (portletPreferences instanceof StrictPortletPreferencesImpl) {
            throw new PortletPreferencesException.MustBeStrict(themeDisplay.getPpid());
        }

        String color = ParamUtil.getString(actionRequest, "color");
        String data = ParamUtil.getString(actionRequest, "data");

        if (Validator.isNotNull(color)) {
            portletPreferences.setValue("color", color);
        }

        if (Validator.isNotNull(data)) {
            portletPreferences.setValue("data", data);
        }

        portletPreferences.store();
    } catch (Exception e) {
        throw new PortletException(e);
    }

    return true;
}