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.asset.publisher.internal.exportimport.portlet.preferences.processor.test.AssetPublisherExportImportPortletPreferencesProcessorTest.java

License:Open Source License

@Before
public void setUp() throws Exception {
    ServiceTestUtil.setUser(TestPropsValues.getUser());

    _group = GroupTestUtil.addGroup();/*from   w  w  w .j a  va  2  s.  c o m*/

    _layout = LayoutTestUtil.addLayout(_group.getGroupId());

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

    _portletDataContextExport = ExportImportTestUtil.getExportPortletDataContext(_group.getGroupId());

    _portletDataContextExport.setPlid(_layout.getPlid());
    _portletDataContextExport.setPortletId(AssetPublisherPortletKeys.ASSET_PUBLISHER);

    _portletDataContextImport = ExportImportTestUtil.getImportPortletDataContext(_group.getGroupId());

    _portletDataContextExport.setPlid(_layout.getPlid());
    _portletDataContextImport.setPortletId(AssetPublisherPortletKeys.ASSET_PUBLISHER);

    _exportImportPortletPreferencesProcessor = _serviceTracker.getService();

    _portletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup(_layout,
            AssetPublisherPortletKeys.ASSET_PUBLISHER);

    _portletPreferences.setValue("selectionStyle", "manual");
}

From source file:com.liferay.asset.publisher.web.internal.util.AssetPublisherWebUtil.java

License:Open Source License

public void addAndStoreSelection(PortletRequest portletRequest, String className, long classPK,
        int assetEntryOrder) throws Exception {

    String portletId = _portal.getPortletId(portletRequest);

    String rootPortletId = PortletIdCodec.decodePortletName(portletId);

    if (!rootPortletId.equals(AssetPublisherPortletKeys.ASSET_PUBLISHER)) {
        return;//from  ww w. j  a  v  a2  s. c om
    }

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

    Layout layout = _layoutLocalService.fetchLayout(themeDisplay.getPlid());

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

    if (portletPreferences instanceof StrictPortletPreferencesImpl) {
        return;
    }

    String selectionStyle = portletPreferences.getValue("selectionStyle", "dynamic");

    if (selectionStyle.equals("dynamic")) {
        return;
    }

    AssetEntry assetEntry = _assetEntryLocalService.getEntry(className, classPK);

    addSelection(portletPreferences, assetEntry.getEntryId(), assetEntryOrder, className);

    portletPreferences.store();
}

From source file:com.liferay.asset.publisher.web.util.AssetPublisherUtil.java

License:Open Source License

public static void addAndStoreSelection(PortletRequest portletRequest, String className, long classPK,
        int assetEntryOrder) throws Exception {

    String portletId = PortalUtil.getPortletId(portletRequest);

    String rootPortletId = PortletIdCodec.decodePortletName(portletId);

    if (!rootPortletId.equals(AssetPublisherPortletKeys.ASSET_PUBLISHER)) {
        return;/*  w ww  .ja va  2  s  .co  m*/
    }

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

    Layout layout = themeDisplay.getLayout();

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

    if (portletPreferences instanceof StrictPortletPreferencesImpl) {
        return;
    }

    String selectionStyle = portletPreferences.getValue("selectionStyle", "dynamic");

    if (selectionStyle.equals("dynamic")) {
        return;
    }

    AssetEntry assetEntry = _assetEntryLocalService.getEntry(className, classPK);

    addSelection(themeDisplay, portletPreferences, portletId, assetEntry.getEntryId(), assetEntryOrder,
            className);

    portletPreferences.store();
}

From source file:com.liferay.blogs.internal.exportimport.portlet.preferences.processor.test.BlogsAggregatorExportImportPortletPreferencesProcessorTest.java

License:Open Source License

@Test
public void testProcessOrganizationId() throws Exception {
    PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup(_layout,
            BlogsPortletKeys.BLOGS_AGGREGATOR);

    long organizationId = _organization.getOrganizationId();

    portletPreferences.setValue("organizationId", String.valueOf(organizationId));

    portletPreferences.store();/*from ww  w.j av a 2 s.co m*/

    ExportImportPortletPreferencesProcessor blogsAggregatorPortletPreferencesProcessor = _serviceTracker
            .getService();

    PortletPreferences exportedPortletPreferences = blogsAggregatorPortletPreferencesProcessor
            .processExportPortletPreferences(_portletDataContextExport, portletPreferences);

    String exportedOrganizationId = exportedPortletPreferences.getValue("organizationId", "");

    Assert.assertEquals(_organization.getUuid(), exportedOrganizationId);

    // Update organization to have a different primary key. We will swap
    // to the new one and verify it.

    OrganizationLocalServiceUtil.deleteOrganization(_organization.getOrganizationId());

    _organization = OrganizationTestUtil.addOrganization();

    _organization.setUuid(exportedOrganizationId);

    OrganizationLocalServiceUtil.updateOrganization(_organization);

    // Test the import

    PortletPreferences importedPortletPreferences = blogsAggregatorPortletPreferencesProcessor
            .processImportPortletPreferences(_portletDataContextImport, exportedPortletPreferences);

    String importedOrganizationId = importedPortletPreferences.getValue("organizationId", "");

    Assert.assertEquals(_organization.getOrganizationId(), GetterUtil.getLong(importedOrganizationId));
}

From source file:com.liferay.blogs.recent.bloggers.internal.exportimport.portlet.preferences.processor.test.RecentBloggersExportImportPortletPreferencesProcessorTest.java

License:Open Source License

@Test
public void testProcessOrganizationId() throws Exception {
    PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup(_layout,
            RecentBloggersPortletKeys.RECENT_BLOGGERS);

    long organizationId = _organization.getOrganizationId();

    portletPreferences.setValue("organizationId", String.valueOf(organizationId));

    portletPreferences.store();//w  ww  . j  a  va2 s  .c  o  m

    ExportImportPortletPreferencesProcessor blogsAggregatorPortletPreferencesProcessor = _serviceTracker
            .getService();

    PortletPreferences exportedPortletPreferences = blogsAggregatorPortletPreferencesProcessor
            .processExportPortletPreferences(_portletDataContextExport, portletPreferences);

    String exportedOrganizationId = exportedPortletPreferences.getValue("organizationId", "");

    Assert.assertEquals(_organization.getUuid(), exportedOrganizationId);

    // Update organization to have a different primary key. We will swap
    // to the new one and verify it.

    OrganizationLocalServiceUtil.deleteOrganization(_organization.getOrganizationId());

    _organization = OrganizationTestUtil.addOrganization();

    _organization.setUuid(exportedOrganizationId);

    OrganizationLocalServiceUtil.updateOrganization(_organization);

    // Test the import

    PortletPreferences importedPortletPreferences = blogsAggregatorPortletPreferencesProcessor
            .processImportPortletPreferences(_portletDataContextImport, exportedPortletPreferences);

    String importedOrganizationId = importedPortletPreferences.getValue("organizationId", "");

    Assert.assertEquals(_organization.getOrganizationId(), GetterUtil.getLong(importedOrganizationId));
}

From source file:com.liferay.dynamic.data.lists.web.internal.portlet.action.AddRecordSetMVCActionCommand.java

License:Open Source License

protected PortletPreferences getStrictPortletSetup(Layout layout, String portletId) throws PortalException {

    if (Validator.isNull(portletId)) {
        return null;
    }//from w ww  . j av a2  s. c  o m

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

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

    return portletPreferences;
}

From source file:com.liferay.exportimport.controller.PortletExportController.java

License:Open Source License

public void exportPortlet(PortletDataContext portletDataContext, long plid, Element parentElement,
        boolean exportPermissions, boolean exportPortletArchivedSetups, boolean exportPortletData,
        boolean exportPortletSetup, boolean exportPortletUserPreferences) throws Exception {

    long layoutId = LayoutConstants.DEFAULT_PARENT_LAYOUT_ID;

    Layout layout = _layoutLocalService.fetchLayout(plid);

    if (layout != null) {
        layoutId = layout.getLayoutId();
    }/* w  ww .  j  a  va 2 s  . c o  m*/

    Portlet portlet = _portletLocalService.getPortletById(portletDataContext.getCompanyId(),
            portletDataContext.getPortletId());

    if ((portlet == null) || portlet.isUndeployedPortlet()) {
        if (_log.isDebugEnabled()) {
            _log.debug("Do not export portlet " + portletDataContext.getPortletId()
                    + " because the portlet is not deployed");
        }

        return;
    }

    if (!portlet.isInstanceable() && !portlet.isPreferencesUniquePerLayout()
            && portletDataContext.hasNotUniquePerLayout(portletDataContext.getPortletId())) {

        return;
    }

    if (BackgroundTaskThreadLocal.hasBackgroundTask()) {
        PortletDataContext clonedPortletDataContext = _portletDataContextFactory
                .clonePortletDataContext(portletDataContext);

        ManifestSummary manifestSummary = clonedPortletDataContext.getManifestSummary();

        manifestSummary.resetCounters();

        PortletDataHandler portletDataHandler = portlet.getPortletDataHandlerInstance();

        portletDataHandler.prepareManifestSummary(clonedPortletDataContext);

        _portletDataHandlerStatusMessageSender.sendStatusMessage("portlet", portletDataContext.getPortletId(),
                manifestSummary);
    }

    Document document = SAXReaderUtil.createDocument();

    Element portletElement = document.addElement("portlet");

    portletElement.addAttribute("portlet-id", portletDataContext.getPortletId());
    portletElement.addAttribute("root-portlet-id", portletDataContext.getRootPortletId());
    portletElement.addAttribute("old-plid", String.valueOf(plid));
    portletElement.addAttribute("scope-group-id", String.valueOf(portletDataContext.getScopeGroupId()));
    portletElement.addAttribute("scope-layout-type", portletDataContext.getScopeType());
    portletElement.addAttribute("scope-layout-uuid", portletDataContext.getScopeLayoutUuid());
    portletElement.addAttribute("private-layout", String.valueOf(portletDataContext.isPrivateLayout()));

    // Data

    if (exportPortletData) {
        javax.portlet.PortletPreferences jxPortletPreferences = null;

        if (ExportImportThreadLocal.isInitialLayoutStagingInProcess()) {
            if (layout != null) {
                Group liveGroup = layout.getGroup();

                Group stagingGroup = liveGroup.getStagingGroup();

                layout.setGroupId(stagingGroup.getGroupId());

                jxPortletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup(layout,
                        portletDataContext.getPortletId());

                layout.setGroupId(liveGroup.getGroupId());
            } else {
                Group liveGroup = _groupLocalService.getGroup(portletDataContext.getGroupId());

                Group stagingGroup = liveGroup.getStagingGroup();

                jxPortletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup(
                        portletDataContext.getCompanyId(), stagingGroup.getGroupId(),
                        portletDataContext.getPortletId());
            }
        } else {
            if (layout != null) {
                jxPortletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup(layout,
                        portletDataContext.getPortletId());
            } else {
                jxPortletPreferences = PortletPreferencesFactoryUtil.getStrictPortletSetup(
                        portletDataContext.getCompanyId(), portletDataContext.getGroupId(),
                        portletDataContext.getPortletId());
            }
        }

        if (!portlet.isPreferencesUniquePerLayout()) {
            StringBundler sb = new StringBundler(5);

            sb.append(portletDataContext.getPortletId());
            sb.append(StringPool.AT);
            sb.append(portletDataContext.getScopeType());
            sb.append(StringPool.AT);
            sb.append(portletDataContext.getScopeLayoutUuid());

            String dataKey = sb.toString();

            if (!portletDataContext.hasNotUniquePerLayout(dataKey)) {
                portletDataContext.putNotUniquePerLayout(dataKey);

                exportPortletData(portletDataContext, portlet, layout, jxPortletPreferences, portletElement);
            }
        } else {
            exportPortletData(portletDataContext, portlet, layout, jxPortletPreferences, portletElement);
        }
    }

    // Portlet preferences

    if (exportPortletSetup) {

        // Company

        exportPortletPreferences(portletDataContext, portletDataContext.getCompanyId(),
                PortletKeys.PREFS_OWNER_TYPE_COMPANY, false, layout, plid, portlet.getRootPortletId(),
                portletElement);

        // Group

        exportPortletPreferences(portletDataContext, portletDataContext.getScopeGroupId(),
                PortletKeys.PREFS_OWNER_TYPE_GROUP, false, layout, PortletKeys.PREFS_PLID_SHARED,
                portlet.getRootPortletId(), portletElement);

        // Group embedded portlets

        exportPortletPreferences(portletDataContext, portletDataContext.getScopeGroupId(),
                PortletKeys.PREFS_OWNER_TYPE_LAYOUT, false, layout, PortletKeys.PREFS_PLID_SHARED,
                portlet.getPortletId(), portletElement);

        // Layout

        exportPortletPreferences(portletDataContext, PortletKeys.PREFS_OWNER_ID_DEFAULT,
                PortletKeys.PREFS_OWNER_TYPE_LAYOUT, false, layout, plid, portletDataContext.getPortletId(),
                portletElement);
    }

    // Portlet user preferences

    if (exportPortletUserPreferences) {
        List<PortletPreferences> portletPreferencesList = _portletPreferencesLocalService.getPortletPreferences(
                PortletKeys.PREFS_OWNER_TYPE_USER, plid, portletDataContext.getPortletId());

        for (PortletPreferences portletPreferences : portletPreferencesList) {

            boolean defaultUser = false;

            if (portletPreferences.getOwnerId() == PortletKeys.PREFS_OWNER_ID_DEFAULT) {

                defaultUser = true;
            }

            exportPortletPreferences(portletDataContext, portletPreferences.getOwnerId(),
                    PortletKeys.PREFS_OWNER_TYPE_USER, defaultUser, layout, plid,
                    portletDataContext.getPortletId(), portletElement);
        }

        try {
            PortletPreferences groupPortletPreferences = _portletPreferencesLocalService.getPortletPreferences(
                    portletDataContext.getScopeGroupId(), PortletKeys.PREFS_OWNER_TYPE_GROUP,
                    PortletKeys.PREFS_PLID_SHARED, portlet.getRootPortletId());

            exportPortletPreference(portletDataContext, portletDataContext.getScopeGroupId(),
                    PortletKeys.PREFS_OWNER_TYPE_GROUP, false, groupPortletPreferences,
                    portlet.getRootPortletId(), PortletKeys.PREFS_PLID_SHARED, portletElement);
        } catch (NoSuchPortletPreferencesException nsppe) {

            // LPS-52675

            if (_log.isDebugEnabled()) {
                _log.debug(nsppe, nsppe);
            }
        }
    }

    // Archived setups

    if (exportPortletArchivedSetups) {
        List<PortletItem> portletItems = _portletItemLocalService.getPortletItems(
                portletDataContext.getGroupId(), portletDataContext.getRootPortletId(),
                PortletPreferences.class.getName());

        for (PortletItem portletItem : portletItems) {
            exportPortletPreferences(portletDataContext, portletItem.getPortletItemId(),
                    PortletKeys.PREFS_OWNER_TYPE_ARCHIVED, false, null, plid, portletItem.getPortletId(),
                    portletElement);
        }
    }

    // Permissions

    if (exportPermissions) {
        _permissionExporter.exportPortletPermissions(portletDataContext, portletDataContext.getPortletId(),
                layout, portletElement);
    }

    // Zip

    StringBundler pathSB = new StringBundler(4);

    pathSB.append(ExportImportPathUtil.getPortletPath(portletDataContext));
    pathSB.append(StringPool.SLASH);
    pathSB.append(plid);
    pathSB.append("/portlet.xml");

    String path = pathSB.toString();

    Element element = parentElement.addElement("portlet");

    element.addAttribute("portlet-id", portletDataContext.getPortletId());
    element.addAttribute("layout-id", String.valueOf(layoutId));
    element.addAttribute("path", path);
    element.addAttribute("portlet-data", String.valueOf(exportPortletData));

    PortletDataHandler portletDataHandler = portlet.getPortletDataHandlerInstance();

    element.addAttribute("schema-version", portletDataHandler.getSchemaVersion());

    StringBundler configurationOptionsSB = new StringBundler(6);

    if (exportPortletSetup) {
        configurationOptionsSB.append("setup");
        configurationOptionsSB.append(StringPool.COMMA);
    }

    if (exportPortletArchivedSetups) {
        configurationOptionsSB.append("archived-setups");
        configurationOptionsSB.append(StringPool.COMMA);
    }

    if (exportPortletUserPreferences) {
        configurationOptionsSB.append("user-preferences");
        configurationOptionsSB.append(StringPool.COMMA);
    }

    if (configurationOptionsSB.index() > 0) {
        configurationOptionsSB.setIndex(configurationOptionsSB.index() - 1);
    }

    element.addAttribute("portlet-configuration", configurationOptionsSB.toString());

    try {
        portletDataContext.addZipEntry(path, document.formattedString());
    } catch (IOException ioe) {
        if (_log.isWarnEnabled()) {
            _log.warn(ioe.getMessage());
        }
    }
}

From source file:com.liferay.exportimport.controller.test.PortletImportControllerTest.java

License:Open Source License

@Test
public void testUdatePortletPreferencesPlid1NotNullNotNull() throws Exception {

    Date lastPublishDate1 = new Date(System.currentTimeMillis() - 1);
    Date lastPublishDate2 = new Date(System.currentTimeMillis());

    PortletPreferencesImpl portletPreferencesImpl1 = setLastPublishDate(group, lastPublishDate1, layout);

    Assert.assertEquals(PortletKeys.PREFS_OWNER_ID_DEFAULT, portletPreferencesImpl1.getOwnerId());
    Assert.assertEquals(PortletKeys.PREFS_OWNER_TYPE_LAYOUT, portletPreferencesImpl1.getOwnerType());
    Assert.assertEquals(layout.getPlid(), portletPreferencesImpl1.getPlid());

    PortletPreferencesImpl portletPreferencesImpl2 = setLastPublishDate(importedGroup, lastPublishDate2,
            importedGroupLayout);//from   w w  w  .  j av a  2  s. c  o  m

    Assert.assertEquals(PortletKeys.PREFS_OWNER_ID_DEFAULT, portletPreferencesImpl2.getOwnerId());
    Assert.assertEquals(PortletKeys.PREFS_OWNER_TYPE_LAYOUT, portletPreferencesImpl2.getOwnerType());
    Assert.assertEquals(importedGroupLayout.getPlid(), portletPreferencesImpl2.getPlid());

    exportLayouts(new long[] { layout.getLayoutId() }, getExportParameterMap());

    importLayouts(getImportParameterMap());

    PortletPreferences portletPreferences = PortletPreferencesFactoryUtil
            .getStrictPortletSetup(importedGroupLayout, BookmarksPortletKeys.BOOKMARKS);

    Assert.assertEquals(Long.valueOf(lastPublishDate2.getTime()),
            Long.valueOf(portletPreferences.getValue("last-publish-date", null)));
}

From source file:com.liferay.exportimport.controller.test.PortletImportControllerTest.java

License:Open Source License

@Test
public void testUdatePortletPreferencesPlid1NotNullNull() throws Exception {
    Date lastPublishDate = new Date(System.currentTimeMillis());

    PortletPreferencesImpl portletPreferencesImpl = setLastPublishDate(group, lastPublishDate, layout);

    Assert.assertEquals(PortletKeys.PREFS_OWNER_ID_DEFAULT, portletPreferencesImpl.getOwnerId());
    Assert.assertEquals(PortletKeys.PREFS_OWNER_TYPE_LAYOUT, portletPreferencesImpl.getOwnerType());
    Assert.assertEquals(layout.getPlid(), portletPreferencesImpl.getPlid());

    exportLayouts(new long[] { layout.getLayoutId() }, getExportParameterMap());

    importLayouts(getImportParameterMap());

    PortletPreferences portletPreferences = PortletPreferencesFactoryUtil
            .getStrictPortletSetup(importedGroupLayout, BookmarksPortletKeys.BOOKMARKS);

    Assert.assertNull(portletPreferences.getValue("last-publish-date", null));
}

From source file:com.liferay.exportimport.controller.test.PortletImportControllerTest.java

License:Open Source License

@Test
public void testUdatePortletPreferencesPlid1NullNotNull() throws Exception {
    Date lastPublishDate = new Date(System.currentTimeMillis());

    PortletPreferencesImpl portletPreferencesImpl = setLastPublishDate(importedGroup, lastPublishDate,
            importedGroupLayout);/* w w w. j av  a2 s .com*/

    Assert.assertEquals(PortletKeys.PREFS_OWNER_ID_DEFAULT, portletPreferencesImpl.getOwnerId());
    Assert.assertEquals(PortletKeys.PREFS_OWNER_TYPE_LAYOUT, portletPreferencesImpl.getOwnerType());
    Assert.assertEquals(importedGroupLayout.getPlid(), portletPreferencesImpl.getPlid());

    exportLayouts(new long[] { layout.getLayoutId() }, getExportParameterMap());

    importLayouts(getImportParameterMap());

    PortletPreferences portletPreferences = PortletPreferencesFactoryUtil
            .getStrictPortletSetup(importedGroupLayout, BookmarksPortletKeys.BOOKMARKS);

    Assert.assertEquals(Long.valueOf(lastPublishDate.getTime()),
            Long.valueOf(portletPreferences.getValue("last-publish-date", null)));
}