Example usage for com.liferay.portal.kernel.model Portlet isScopeable

List of usage examples for com.liferay.portal.kernel.model Portlet isScopeable

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.model Portlet isScopeable.

Prototype

public boolean isScopeable();

Source Link

Document

Returns true if the portlet supports scoping of data.

Usage

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

License:Open Source License

protected void testExportImportDisplayStyle(long displayStyleGroupId, String scopeType) throws Exception {

    Portlet portlet = PortletLocalServiceUtil.getPortletById(group.getCompanyId(), getPortletId());

    if (portlet == null) {
        return;/*from  w w  w  .ja va  2  s .  c om*/
    }

    if (scopeType.equals("layout") && !portlet.isScopeable()) {
        Assert.assertTrue("This test does not apply", true);

        return;
    }

    TemplateHandler templateHandler = portlet.getTemplateHandlerInstance();

    if ((templateHandler == null) || !templateHandler.isDisplayTemplateHandler()) {

        Assert.assertTrue("This test does not apply", true);

        return;
    }

    String className = templateHandler.getClassName();
    long resourceClassNameId = PortalUtil
            .getClassNameId("com.liferay.portlet.display.template.PortletDisplayTemplate");

    DDMTemplate ddmTemplate = DDMTemplateTestUtil.addTemplate(displayStyleGroupId,
            PortalUtil.getClassNameId(className), 0, resourceClassNameId);

    Map<String, String[]> preferenceMap = new HashMap<>();

    String displayStyle = PortletDisplayTemplateManager.DISPLAY_STYLE_PREFIX + ddmTemplate.getTemplateKey();

    preferenceMap.put("displayStyle", new String[] { displayStyle });

    preferenceMap.put("displayStyleGroupId", new String[] { String.valueOf(ddmTemplate.getGroupId()) });

    if (scopeType.equals("layout")) {
        preferenceMap.put("lfrScopeLayoutUuid", new String[] { this.layout.getUuid() });
    }

    preferenceMap.put("lfrScopeType", new String[] { scopeType });

    PortletPreferences portletPreferences = getImportedPortletPreferences(preferenceMap);

    String importedDisplayStyle = portletPreferences.getValue("displayStyle", StringPool.BLANK);

    Assert.assertEquals(displayStyle, importedDisplayStyle);

    long importedDisplayStyleGroupId = GetterUtil
            .getLong(portletPreferences.getValue("displayStyleGroupId", null));

    long expectedDisplayStyleGroupId = importedGroup.getGroupId();

    if (scopeType.equals("company")) {
        Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(importedGroup.getCompanyId());

        expectedDisplayStyleGroupId = companyGroup.getGroupId();
    } else if (displayStyleGroupId != group.getGroupId()) {
        expectedDisplayStyleGroupId = displayStyleGroupId;
    }

    Assert.assertEquals(expectedDisplayStyleGroupId, importedDisplayStyleGroupId);
}

From source file:com.liferay.site.internal.exportimport.data.handler.StagedGroupStagedModelDataHandler.java

License:Open Source License

protected void exportSitePortlets(PortletDataContext portletDataContext, StagedGroup group,
        Set<String> portletIds, long[] layoutIds) throws Exception {

    // Prepare XML

    Element rootElement = portletDataContext.getExportDataRootElement();

    Element portletsElement = rootElement.element("site-portlets");
    Element servicesElement = rootElement.element("site-services");

    String type = portletDataContext.getType();

    // Export portlets

    Map<String, String[]> parameterMap = portletDataContext.getParameterMap();

    boolean permissions = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PERMISSIONS);

    List<Layout> layouts = _layoutLocalService.getLayouts(group.getGroupId(),
            portletDataContext.isPrivateLayout());

    for (String portletId : portletIds) {

        // Default scope

        exportPortlet(portletDataContext, portletId, LayoutConstants.DEFAULT_PLID,
                portletDataContext.getGroupId(), StringPool.BLANK, StringPool.BLANK, type, portletsElement,
                servicesElement, permissions);

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

        if (!portlet.isScopeable()) {
            continue;
        }//  w  w w . j a v a  2  s .c o m

        // Scoped data

        for (Layout layout : layouts) {
            if (!ArrayUtil.contains(layoutIds, layout.getLayoutId()) || !layout.isTypePortlet()
                    || !layout.hasScopeGroup()) {

                continue;
            }

            LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

            if (!layoutTypePortlet.hasPortletId(portletId)) {
                continue;
            }

            Group scopeGroup = layout.getScopeGroup();

            exportPortlet(portletDataContext, portletId, layout.getPlid(), scopeGroup.getGroupId(),
                    StringPool.BLANK, layout.getUuid(), type, portletsElement, servicesElement, permissions);
        }
    }
}