Example usage for com.liferay.portal.kernel.model LayoutConstants TYPE_PORTLET

List of usage examples for com.liferay.portal.kernel.model LayoutConstants TYPE_PORTLET

Introduction

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

Prototype

String TYPE_PORTLET

To view the source code for com.liferay.portal.kernel.model LayoutConstants TYPE_PORTLET.

Click Source Link

Usage

From source file:com.liferay.asset.publisher.portlet.test.DisplayPageFriendlyURLResolverTest.java

License:Open Source License

@Test
public void testJournalArticleFriendlyURL() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext();

    LayoutLocalServiceUtil.addLayout(TestPropsValues.getUserId(), _group.getGroupId(), false,
            LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, "Home", StringPool.BLANK, StringPool.BLANK,
            LayoutConstants.TYPE_PORTLET, false, StringPool.BLANK, serviceContext);

    Layout layout = LayoutLocalServiceUtil.addLayout(TestPropsValues.getUserId(), _group.getGroupId(), false,
            LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, "Test " + RandomTestUtil.nextInt(), StringPool.BLANK,
            StringPool.BLANK, LayoutConstants.TYPE_PORTLET, false, StringPool.BLANK, serviceContext);

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

    String portletId = layoutTypePortlet.addPortletId(TestPropsValues.getUserId(),
            AssetPublisherPortletKeys.ASSET_PUBLISHER, "column-1", 0);

    layoutTypePortlet.setTypeSettingsProperty(LayoutTypePortletConstants.DEFAULT_ASSET_PUBLISHER_PORTLET_ID,
            portletId);/* w  w  w  .ja  v a  2s  . co m*/

    layout = LayoutLocalServiceUtil.updateLayout(layout.getGroupId(), layout.isPrivateLayout(),
            layout.getLayoutId(), layout.getTypeSettings());

    Map<Locale, String> titleMap = new HashMap<>();

    titleMap.put(LocaleUtil.US, "Test Journal Article");

    Map<Locale, String> contentMap = new HashMap<>();

    contentMap.put(LocaleUtil.US, "This test content is in English.");

    JournalTestUtil.addArticle(_group.getGroupId(), JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            JournalArticleConstants.CLASSNAME_ID_DEFAULT, titleMap, titleMap, contentMap, layout.getUuid(),
            LocaleUtil.US, null, false, false, serviceContext);

    String actualURL = PortalUtil.getActualURL(_group.getGroupId(), false, Portal.PATH_MAIN,
            "/-/test-journal-article", new HashMap<String, String[]>(), getRequestContext());

    Assert.assertNotNull(actualURL);

    try {
        PortalUtil.getActualURL(_group.getGroupId(), false, Portal.PATH_MAIN,
                "/-/nonexistent-test-journal-article", new HashMap<String, String[]>(), getRequestContext());

        Assert.fail();
    } catch (NoSuchLayoutException nsle) {
    }
}

From source file:com.liferay.dynamic.data.mapping.form.web.internal.layout.type.controller.DDMFormPortletLayoutTypeController.java

License:Open Source License

@Override
public String getType() {
    return LayoutConstants.TYPE_PORTLET;
}

From source file:com.liferay.exportimport.resources.importer.internal.util.FileSystemImporter.java

License:Open Source License

protected void addLayout(boolean privateLayout, long parentLayoutId, JSONObject layoutJSONObject)
        throws Exception {

    if (targetClassName.equals(LayoutSetPrototype.class.getName())) {
        privateLayout = true;// ww w  .j  av  a 2s. c  o  m
    }

    Map<Locale, String> nameMap = getMap(layoutJSONObject, "name");
    Map<Locale, String> titleMap = getMap(layoutJSONObject, "title");

    String type = layoutJSONObject.getString("type");

    if (Validator.isNull(type)) {
        type = LayoutConstants.TYPE_PORTLET;
    }

    String typeSettings = layoutJSONObject.getString("typeSettings");

    boolean hidden = layoutJSONObject.getBoolean("hidden");

    String themeId = layoutJSONObject.getString("themeId");

    String layoutCss = layoutJSONObject.getString("layoutCss");

    String colorSchemeId = layoutJSONObject.getString("colorSchemeId");

    Map<Locale, String> friendlyURLMap = new HashMap<>();

    String friendlyURL = layoutJSONObject.getString("friendlyURL");

    if (Validator.isNotNull(friendlyURL) && !friendlyURL.startsWith(StringPool.SLASH)) {

        friendlyURL = StringPool.SLASH + friendlyURL;
    }

    friendlyURLMap.put(LocaleUtil.getDefault(), friendlyURL);

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setCompanyId(companyId);
    serviceContext.setScopeGroupId(groupId);
    serviceContext.setUserId(userId);

    ServiceContextThreadLocal.pushServiceContext(serviceContext);

    try {
        String layoutPrototypeName = layoutJSONObject.getString("layoutPrototypeName");

        String layoutPrototypeUuid = null;

        if (Validator.isNotNull(layoutPrototypeName)) {
            LayoutPrototype layoutPrototype = getLayoutPrototype(companyId, layoutPrototypeName);

            layoutPrototypeUuid = layoutPrototype.getUuid();
        } else {
            layoutPrototypeUuid = layoutJSONObject.getString("layoutPrototypeUuid");
        }

        if (Validator.isNotNull(layoutPrototypeUuid)) {
            boolean layoutPrototypeLinkEnabled = GetterUtil
                    .getBoolean(layoutJSONObject.getString("layoutPrototypeLinkEnabled"));

            serviceContext.setAttribute("layoutPrototypeLinkEnabled", layoutPrototypeLinkEnabled);

            serviceContext.setAttribute("layoutPrototypeUuid", layoutPrototypeUuid);
        }

        Layout layout = layoutLocalService.fetchLayoutByFriendlyURL(groupId, privateLayout, friendlyURL);

        if (layout != null) {
            if (!developerModeEnabled) {
                if (_log.isInfoEnabled()) {
                    _log.info("Layout with friendly URL " + friendlyURL + " already exists");
                }

                return;
            }

            if (!updateModeEnabled) {
                layoutLocalService.deleteLayout(layout);
            }
        }

        if (!updateModeEnabled || (layout == null)) {
            layout = layoutLocalService.addLayout(userId, groupId, privateLayout, parentLayoutId, nameMap,
                    titleMap, null, null, null, type, typeSettings, hidden, friendlyURLMap, serviceContext);
        } else {
            resetLayoutColumns(layout);

            layout = layoutLocalService.updateLayout(groupId, privateLayout, layout.getLayoutId(),
                    parentLayoutId, nameMap, titleMap, layout.getDescriptionMap(), layout.getKeywordsMap(),
                    layout.getRobotsMap(), type, hidden, friendlyURLMap, layout.getIconImage(), null,
                    serviceContext);
        }

        if (Validator.isNotNull(themeId) || Validator.isNotNull(colorSchemeId)) {

            // If the theme ID or the color scheme ID are not null, then the
            // layout has a custom look and feel and should be updated in
            // the database

            layoutLocalService.updateLookAndFeel(groupId, privateLayout, layout.getLayoutId(), themeId,
                    colorSchemeId, layoutCss);
        }

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

        String layoutTemplateId = layoutJSONObject.getString("layoutTemplateId", _defaultLayoutTemplateId);

        if (Validator.isNotNull(layoutTemplateId)) {
            layoutTypePortlet.setLayoutTemplateId(userId, layoutTemplateId, false);
        }

        JSONArray columnsJSONArray = layoutJSONObject.getJSONArray("columns");

        addLayoutColumns(layout, LayoutTypePortletConstants.COLUMN_PREFIX, columnsJSONArray);

        layoutLocalService.updateLayout(groupId, layout.isPrivateLayout(), layout.getLayoutId(),
                layout.getTypeSettings());

        JSONArray layoutsJSONArray = layoutJSONObject.getJSONArray("layouts");

        addLayouts(privateLayout, layout.getLayoutId(), layoutsJSONArray);
    } catch (Exception e) {
        if (_log.isWarnEnabled()) {
            _log.warn("Unable to import layout " + layoutJSONObject, e);
        }

        throw e;
    } finally {
        ServiceContextThreadLocal.popServiceContext();
    }
}

From source file:com.liferay.layout.admin.web.internal.exportimport.data.handler.LayoutStagedModelDataHandler.java

License:Open Source License

@Override
protected void doExportStagedModel(PortletDataContext portletDataContext, Layout layout) throws Exception {

    Element layoutElement = portletDataContext.getExportDataElement(layout);

    populateElementLayoutMetadata(layoutElement, layout);

    layoutElement.addAttribute(Constants.ACTION, Constants.ADD);

    portletDataContext.setPlid(layout.getPlid());

    long parentLayoutId = layout.getParentLayoutId();

    if (parentLayoutId != LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {
        Layout parentLayout = _layoutLocalService.fetchLayout(layout.getGroupId(), layout.isPrivateLayout(),
                parentLayoutId);/*from ww w.j a v a 2 s .  c  om*/

        if (parentLayout != null) {
            StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, layout, parentLayout,
                    PortletDataContext.REFERENCE_TYPE_PARENT);

            layoutElement.addAttribute("parent-layout-uuid", parentLayout.getUuid());
        }
    }

    List<LayoutFriendlyURL> layoutFriendlyURLs = _layoutFriendlyURLLocalService
            .getLayoutFriendlyURLs(layout.getPlid());

    for (LayoutFriendlyURL layoutFriendlyURL : layoutFriendlyURLs) {
        StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, layout, layoutFriendlyURL,
                PortletDataContext.REFERENCE_TYPE_DEPENDENCY);
    }

    if (layout.isIconImage()) {
        exportLayoutIconImage(portletDataContext, layout, layoutElement);
    }

    if (Objects.equals(layout.getType(), LayoutConstants.TYPE_LINK_TO_LAYOUT)) {

        exportLinkedLayout(portletDataContext, layout, layoutElement);
    } else if (Objects.equals(layout.getType(), LayoutConstants.TYPE_PORTLET)) {

        exportLayoutPortlets(portletDataContext, layout, layoutElement);
    }

    fixExportTypeSettings(layout);

    exportTheme(portletDataContext, layout);

    portletDataContext.addClassedModel(layoutElement, ExportImportPathUtil.getModelPath(layout),
            LayoutStagingUtil.mergeLayoutRevisionIntoLayout(layout));
}

From source file:com.liferay.layout.admin.web.internal.exportimport.data.handler.LayoutStagedModelDataHandler.java

License:Open Source License

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, Layout layout) throws Exception {

    final long groupId = portletDataContext.getGroupId();
    long userId = portletDataContext.getUserId(layout.getUserUuid());

    Element layoutElement = portletDataContext.getImportDataStagedModelElement(layout);

    long layoutId = GetterUtil.getLong(layoutElement.attributeValue("layout-id"));

    long oldLayoutId = layoutId;

    final boolean privateLayout = portletDataContext.isPrivateLayout();

    Map<Long, Layout> layouts = (Map<Long, Layout>) portletDataContext
            .getNewPrimaryKeysMap(Layout.class + ".layout");

    Layout existingLayout = null;/* ww  w.  j  av a  2s  . c  o m*/
    Layout importedLayout = null;

    String friendlyURL = layout.getFriendlyURL();

    String layoutsImportMode = MapUtil.getString(portletDataContext.getParameterMap(),
            PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE,
            PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_MERGE_BY_LAYOUT_UUID);

    if (layoutsImportMode.equals(PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_ADD_AS_NEW)) {

        layoutId = _layoutLocalService.getNextLayoutId(groupId, privateLayout);

        friendlyURL = StringPool.SLASH + layoutId;
    } else if (layoutsImportMode.equals(PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_MERGE_BY_LAYOUT_NAME)) {

        Locale locale = LocaleUtil.getSiteDefault();

        String localizedName = layout.getName(locale);

        List<Layout> previousLayouts = _layoutLocalService.getLayouts(groupId, privateLayout);

        for (Layout curLayout : previousLayouts) {
            if (localizedName.equals(curLayout.getName(locale))
                    || friendlyURL.equals(curLayout.getFriendlyURL())) {

                existingLayout = curLayout;

                break;
            }
        }

        if (existingLayout == null) {
            layoutId = _layoutLocalService.getNextLayoutId(groupId, privateLayout);
        }
    } else if (layoutsImportMode.equals(PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_CREATED_FROM_PROTOTYPE)) {

        existingLayout = _layoutLocalService.fetchLayoutByUuidAndGroupId(layout.getUuid(), groupId,
                privateLayout);

        if (SitesUtil.isLayoutModifiedSinceLastMerge(existingLayout)) {
            layouts.put(oldLayoutId, existingLayout);

            return;
        }

        LayoutFriendlyURL layoutFriendlyURL = _layoutFriendlyURLLocalService
                .fetchFirstLayoutFriendlyURL(groupId, privateLayout, friendlyURL);

        if ((layoutFriendlyURL != null) && (existingLayout == null)) {
            Layout mergeFailFriendlyURLLayout = _layoutLocalService.getLayout(layoutFriendlyURL.getPlid());

            SitesUtil.addMergeFailFriendlyURLLayout(mergeFailFriendlyURLLayout);

            if (!_log.isWarnEnabled()) {
                return;
            }

            StringBundler sb = new StringBundler(6);

            sb.append("Layout with layout ID ");
            sb.append(layout.getLayoutId());
            sb.append(" cannot be propagated because the friendly URL ");
            sb.append("conflicts with the friendly URL of layout with ");
            sb.append("layout ID ");
            sb.append(mergeFailFriendlyURLLayout.getLayoutId());

            _log.warn(sb.toString());

            return;
        }
    } else {

        // The default behavior of import mode is
        // PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_MERGE_BY_LAYOUT_UUID

        existingLayout = _layoutLocalService.fetchLayoutByUuidAndGroupId(layout.getUuid(), groupId,
                privateLayout);

        if (existingLayout == null) {
            existingLayout = _layoutLocalService.fetchLayoutByFriendlyURL(groupId, privateLayout, friendlyURL);
        }

        if (existingLayout == null) {
            layoutId = _layoutLocalService.getNextLayoutId(groupId, privateLayout);
        }
    }

    if (_log.isDebugEnabled()) {
        StringBundler sb = new StringBundler(7);

        sb.append("Layout with {groupId=");
        sb.append(groupId);
        sb.append(",privateLayout=");
        sb.append(privateLayout);
        sb.append(",layoutId=");
        sb.append(layoutId);

        if (existingLayout == null) {
            sb.append("} does not exist");

            _log.debug(sb.toString());
        } else {
            sb.append("} exists");

            _log.debug(sb.toString());
        }
    }

    if (existingLayout == null) {
        long plid = _counterLocalService.increment();

        importedLayout = _layoutLocalService.createLayout(plid);

        if (layoutsImportMode.equals(PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_CREATED_FROM_PROTOTYPE)) {

            importedLayout.setSourcePrototypeLayoutUuid(layout.getUuid());

            layoutId = _layoutLocalService.getNextLayoutId(groupId, privateLayout);
        } else {
            importedLayout.setCreateDate(layout.getCreateDate());
            importedLayout.setModifiedDate(layout.getModifiedDate());
            importedLayout.setLayoutPrototypeUuid(layout.getLayoutPrototypeUuid());
            importedLayout.setLayoutPrototypeLinkEnabled(layout.isLayoutPrototypeLinkEnabled());
            importedLayout.setSourcePrototypeLayoutUuid(layout.getSourcePrototypeLayoutUuid());
        }

        importedLayout.setUuid(layout.getUuid());
        importedLayout.setGroupId(groupId);
        importedLayout.setUserId(userId);
        importedLayout.setPrivateLayout(privateLayout);
        importedLayout.setLayoutId(layoutId);

        initNewLayoutPermissions(portletDataContext.getCompanyId(), groupId, userId, layout, importedLayout,
                privateLayout);

        LayoutSet layoutSet = _layoutSetLocalService.getLayoutSet(groupId, privateLayout);

        importedLayout.setLayoutSet(layoutSet);
    } else {
        importedLayout = existingLayout;
    }

    portletDataContext.setPlid(importedLayout.getPlid());
    portletDataContext.setOldPlid(layout.getPlid());

    long parentLayoutId = layout.getParentLayoutId();

    String parentLayoutUuid = GetterUtil.getString(layoutElement.attributeValue("parent-layout-uuid"));

    Element parentLayoutElement = portletDataContext.getReferenceDataElement(layout, Layout.class,
            layout.getGroupId(), parentLayoutUuid);

    if ((parentLayoutId != LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) && (parentLayoutElement != null)) {

        StagedModelDataHandlerUtil.importStagedModel(portletDataContext, parentLayoutElement);

        Layout importedParentLayout = layouts.get(parentLayoutId);

        parentLayoutId = importedParentLayout.getLayoutId();
    }

    if (_log.isDebugEnabled()) {
        StringBundler sb = new StringBundler(4);

        sb.append("Importing layout with layout ID ");
        sb.append(layoutId);
        sb.append(" and parent layout ID ");
        sb.append(parentLayoutId);

        _log.debug(sb.toString());
    }

    importedLayout.setCompanyId(portletDataContext.getCompanyId());

    if (layout.getLayoutPrototypeUuid() != null) {
        importedLayout.setModifiedDate(new Date());
    }

    importedLayout.setParentLayoutId(parentLayoutId);
    importedLayout.setName(layout.getName());
    importedLayout.setTitle(layout.getTitle());
    importedLayout.setDescription(layout.getDescription());
    importedLayout.setKeywords(layout.getKeywords());
    importedLayout.setRobots(layout.getRobots());
    importedLayout.setType(layout.getType());

    String portletsMergeMode = MapUtil.getString(portletDataContext.getParameterMap(),
            PortletDataHandlerKeys.PORTLETS_MERGE_MODE, PortletDataHandlerKeys.PORTLETS_MERGE_MODE_REPLACE);

    if (Objects.equals(layout.getType(), LayoutConstants.TYPE_PORTLET)
            && Validator.isNotNull(layout.getTypeSettings())
            && !portletsMergeMode.equals(PortletDataHandlerKeys.PORTLETS_MERGE_MODE_REPLACE)) {

        mergePortlets(importedLayout, layout.getTypeSettings(), portletsMergeMode);
    } else if (Objects.equals(layout.getType(), LayoutConstants.TYPE_LINK_TO_LAYOUT)) {

        importLinkedLayout(portletDataContext, layout, importedLayout, layoutElement);

        updateTypeSettings(importedLayout, layout);
    } else {
        updateTypeSettings(importedLayout, layout);
    }

    importedLayout.setHidden(layout.isHidden());
    importedLayout.setFriendlyURL(getUniqueFriendlyURL(portletDataContext, importedLayout, friendlyURL));

    if (layout.getIconImageId() > 0) {
        importLayoutIconImage(portletDataContext, importedLayout, layoutElement);
    } else if (importedLayout.getIconImageId() > 0) {
        _imageLocalService.deleteImage(importedLayout.getIconImageId());

        importedLayout.setIconImageId(0);
    }

    if (existingLayout == null) {
        try {
            final long finalParentLayoutId = parentLayoutId;

            int priority = TransactionInvokerUtil.invoke(_transactionConfig, new Callable<Integer>() {

                @Override
                public Integer call() throws Exception {
                    return _layoutLocalServiceHelper.getNextPriority(groupId, privateLayout,
                            finalParentLayoutId, null, -1);
                }

            });

            importedLayout.setPriority(priority);
        } catch (Throwable t) {
            ReflectionUtil.throwException(t);
        }
    }

    importedLayout.setLayoutPrototypeUuid(layout.getLayoutPrototypeUuid());
    importedLayout.setLayoutPrototypeLinkEnabled(layout.isLayoutPrototypeLinkEnabled());

    ServiceContext serviceContext = portletDataContext.createServiceContext(layout);

    importedLayout.setExpandoBridgeAttributes(serviceContext);

    _staging.updateLastImportSettings(layoutElement, importedLayout, portletDataContext);

    fixImportTypeSettings(importedLayout);

    importTheme(portletDataContext, layout, importedLayout);

    _layoutLocalService.updateLayout(importedLayout);

    _layoutSetLocalService.updatePageCount(groupId, privateLayout);

    Map<Long, Long> layoutPlids = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Layout.class);

    layoutPlids.put(layout.getPlid(), importedLayout.getPlid());

    layouts.put(oldLayoutId, importedLayout);

    if (Objects.equals(layout.getType(), LayoutConstants.TYPE_PORTLET)
            && Validator.isNotNull(layout.getTypeSettings())) {

        importLayoutPortlets(portletDataContext, importedLayout, layoutElement);
    }

    importAssets(portletDataContext, layout, importedLayout);

    importLayoutFriendlyURLs(portletDataContext, layout, importedLayout);

    portletDataContext.importClassedModel(layout, importedLayout);
}

From source file:com.liferay.layout.admin.web.internal.portlet.action.AddLayoutMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    UploadPortletRequest uploadPortletRequest = _portal.getUploadPortletRequest(actionRequest);

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

    long groupId = ParamUtil.getLong(actionRequest, "groupId");
    long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
    long stagingGroupId = ParamUtil.getLong(actionRequest, "stagingGroupId");
    boolean privateLayout = ParamUtil.getBoolean(actionRequest, "privateLayout");
    long parentLayoutId = ParamUtil.getLong(uploadPortletRequest, "parentLayoutId");
    Map<Locale, String> nameMap = LocalizationUtil.getLocalizationMap(actionRequest, "name");
    Map<Locale, String> titleMap = LocalizationUtil.getLocalizationMap(actionRequest, "title");
    Map<Locale, String> descriptionMap = LocalizationUtil.getLocalizationMap(actionRequest, "description");
    Map<Locale, String> keywordsMap = LocalizationUtil.getLocalizationMap(actionRequest, "keywords");
    Map<Locale, String> robotsMap = LocalizationUtil.getLocalizationMap(actionRequest, "robots");
    String type = ParamUtil.getString(uploadPortletRequest, "type");
    boolean hidden = ParamUtil.getBoolean(uploadPortletRequest, "hidden");
    Map<Locale, String> friendlyURLMap = LocalizationUtil.getLocalizationMap(actionRequest, "friendlyURL");

    long layoutPrototypeId = ParamUtil.getLong(uploadPortletRequest, "layoutPrototypeId");

    ServiceContext serviceContext = ServiceContextFactory.getInstance(Layout.class.getName(), actionRequest);

    Layout layout = null;// w  ww .  java 2 s.  c  o m

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

    UnicodeProperties typeSettingsProperties = PropertiesParamUtil.getProperties(actionRequest,
            "TypeSettingsProperties--");

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

    if (Validator.isNotNull(linkToLayoutUuid)) {
        Layout linkToLayout = _layoutLocalService.getLayoutByUuidAndGroupId(linkToLayoutUuid, groupId,
                privateLayout);

        typeSettingsProperties.put("linkToLayoutId", String.valueOf(linkToLayout.getLayoutId()));
    }

    if (inheritFromParentLayoutId && (parentLayoutId > 0)) {
        Layout parentLayout = _layoutLocalService.getLayout(groupId, privateLayout, parentLayoutId);

        layout = _layoutService.addLayout(groupId, privateLayout, parentLayoutId, nameMap, titleMap,
                parentLayout.getDescriptionMap(), parentLayout.getKeywordsMap(), parentLayout.getRobotsMap(),
                parentLayout.getType(), parentLayout.getTypeSettings(), hidden, friendlyURLMap, serviceContext);

        inheritMobileRuleGroups(layout, serviceContext);

        if (parentLayout.isTypePortlet()) {
            com.liferay.portlet.sites.action.ActionUtil.copyPreferences(actionRequest, layout, parentLayout);

            SitesUtil.copyLookAndFeel(layout, parentLayout);
        }
    } else if (layoutPrototypeId > 0) {
        LayoutPrototype layoutPrototype = _layoutPrototypeService.getLayoutPrototype(layoutPrototypeId);

        boolean layoutPrototypeLinkEnabled = ParamUtil.getBoolean(uploadPortletRequest,
                "layoutPrototypeLinkEnabled" + layoutPrototype.getUuid());

        serviceContext.setAttribute("layoutPrototypeLinkEnabled", layoutPrototypeLinkEnabled);

        serviceContext.setAttribute("layoutPrototypeUuid", layoutPrototype.getUuid());

        layout = _layoutService.addLayout(groupId, privateLayout, parentLayoutId, nameMap, titleMap,
                descriptionMap, keywordsMap, robotsMap, LayoutConstants.TYPE_PORTLET,
                typeSettingsProperties.toString(), hidden, friendlyURLMap, serviceContext);

        // Force propagation from page template to page. See LPS-48430.

        SitesUtil.mergeLayoutPrototypeLayout(layout.getGroup(), layout);
    } else {
        long copyLayoutId = ParamUtil.getLong(uploadPortletRequest, "copyLayoutId");

        Layout copyLayout = null;

        String layoutTemplateId = ParamUtil.getString(uploadPortletRequest, "layoutTemplateId",
                PropsValues.DEFAULT_LAYOUT_TEMPLATE_ID);

        if (copyLayoutId > 0) {
            copyLayout = _layoutLocalService.fetchLayout(groupId, privateLayout, copyLayoutId);

            if ((copyLayout != null) && copyLayout.isTypePortlet()) {
                LayoutTypePortlet copyLayoutTypePortlet = (LayoutTypePortlet) copyLayout.getLayoutType();

                layoutTemplateId = copyLayoutTypePortlet.getLayoutTemplateId();

                typeSettingsProperties = copyLayout.getTypeSettingsProperties();
            }
        }

        layout = _layoutService.addLayout(groupId, privateLayout, parentLayoutId, nameMap, titleMap,
                descriptionMap, keywordsMap, robotsMap, type, typeSettingsProperties.toString(), hidden,
                friendlyURLMap, serviceContext);

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

        layoutTypePortlet.setLayoutTemplateId(themeDisplay.getUserId(), layoutTemplateId);

        _layoutService.updateLayout(groupId, privateLayout, layout.getLayoutId(), layout.getTypeSettings());

        if ((copyLayout != null) && copyLayout.isTypePortlet()) {
            com.liferay.portlet.sites.action.ActionUtil.copyPreferences(actionRequest, layout, copyLayout);

            SitesUtil.copyLookAndFeel(layout, copyLayout);
        }
    }

    _actionUtil.updateLookAndFeel(actionRequest, themeDisplay.getCompanyId(), liveGroupId, stagingGroupId,
            privateLayout, layout.getLayoutId(), layout.getTypeSettingsProperties());

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

    MultiSessionMessages.add(actionRequest, portletResource + "layoutAdded", layout);

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

    if (Validator.isNull(redirect)) {
        redirect = _portal.getLayoutFullURL(layout, themeDisplay);

        if (layout.isTypeURL()) {
            redirect = _portal.getGroupFriendlyURL(layout.getLayoutSet(), themeDisplay);
        }
    }

    actionRequest.setAttribute(WebKeys.REDIRECT, redirect);
}

From source file:com.liferay.layout.admin.web.internal.portlet.action.CopyApplicationsMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

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

    Layout layout = _layoutLocalService.getLayout(groupId, privateLayout, layoutId);

    String layoutType = layout.getType();

    if (!layoutType.equals(LayoutConstants.TYPE_PORTLET)) {
        return;/*from  w  ww.j ava  2 s .  c  om*/
    }

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

    if ((copyLayoutId == 0) || (copyLayoutId == layout.getLayoutId())) {
        return;
    }

    Layout copyLayout = _layoutLocalService.fetchLayout(groupId, privateLayout, copyLayoutId);

    if ((copyLayout == null) || !copyLayout.isTypePortlet()) {
        return;
    }

    UnicodeProperties sourceLayoutTypeSettingsProperties = copyLayout.getTypeSettingsProperties();

    ActionUtil.removePortletIds(actionRequest, layout);

    ActionUtil.copyPreferences(actionRequest, layout, copyLayout);

    SitesUtil.copyLookAndFeel(layout, copyLayout);

    _layoutService.updateLayout(groupId, privateLayout, layoutId,
            sourceLayoutTypeSettingsProperties.toString());
}

From source file:com.liferay.layout.admin.web.internal.portlet.action.EditLayoutMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    UploadPortletRequest uploadPortletRequest = _portal.getUploadPortletRequest(actionRequest);

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

    long groupId = ParamUtil.getLong(actionRequest, "groupId");
    long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
    long stagingGroupId = ParamUtil.getLong(actionRequest, "stagingGroupId");
    boolean privateLayout = ParamUtil.getBoolean(actionRequest, "privateLayout");
    long layoutId = ParamUtil.getLong(actionRequest, "layoutId");
    Map<Locale, String> nameMap = LocalizationUtil.getLocalizationMap(actionRequest, "name");
    Map<Locale, String> titleMap = LocalizationUtil.getLocalizationMap(actionRequest, "title");
    Map<Locale, String> descriptionMap = LocalizationUtil.getLocalizationMap(actionRequest, "description");
    Map<Locale, String> keywordsMap = LocalizationUtil.getLocalizationMap(actionRequest, "keywords");
    Map<Locale, String> robotsMap = LocalizationUtil.getLocalizationMap(actionRequest, "robots");
    String type = ParamUtil.getString(uploadPortletRequest, "type");
    boolean hidden = ParamUtil.getBoolean(uploadPortletRequest, "hidden");
    Map<Locale, String> friendlyURLMap = LocalizationUtil.getLocalizationMap(actionRequest, "friendlyURL");
    boolean deleteLogo = ParamUtil.getBoolean(actionRequest, "deleteLogo");

    byte[] iconBytes = null;

    long fileEntryId = ParamUtil.getLong(uploadPortletRequest, "fileEntryId");

    if (fileEntryId > 0) {
        FileEntry fileEntry = _dlAppLocalService.getFileEntry(fileEntryId);

        iconBytes = FileUtil.getBytes(fileEntry.getContentStream());
    }// ww  w .j  av a  2  s  .  c o m

    ServiceContext serviceContext = ServiceContextFactory.getInstance(Layout.class.getName(), actionRequest);

    Layout layout = _layoutLocalService.getLayout(groupId, privateLayout, layoutId);

    String currentType = layout.getType();

    layout = _layoutService.updateLayout(groupId, privateLayout, layoutId, layout.getParentLayoutId(), nameMap,
            titleMap, descriptionMap, keywordsMap, robotsMap, type, hidden, friendlyURLMap, !deleteLogo,
            iconBytes, serviceContext);

    themeDisplay.clearLayoutFriendlyURL(layout);

    UnicodeProperties layoutTypeSettingsProperties = layout.getTypeSettingsProperties();

    UnicodeProperties formTypeSettingsProperties = PropertiesParamUtil.getProperties(actionRequest,
            "TypeSettingsProperties--");

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

    if (Validator.isNotNull(linkToLayoutUuid)) {
        Layout linkToLayout = _layoutLocalService.getLayoutByUuidAndGroupId(linkToLayoutUuid, groupId,
                privateLayout);

        formTypeSettingsProperties.put("linkToLayoutId", String.valueOf(linkToLayout.getLayoutId()));
    }

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

    if (type.equals(LayoutConstants.TYPE_PORTLET)) {
        String layoutTemplateId = ParamUtil.getString(uploadPortletRequest, "layoutTemplateId",
                PropsValues.DEFAULT_LAYOUT_TEMPLATE_ID);

        layoutTypePortlet.setLayoutTemplateId(themeDisplay.getUserId(), layoutTemplateId);

        layoutTypeSettingsProperties.putAll(formTypeSettingsProperties);

        boolean layoutCustomizable = GetterUtil
                .getBoolean(layoutTypeSettingsProperties.get(LayoutConstants.CUSTOMIZABLE_LAYOUT));

        if (!layoutCustomizable) {
            layoutTypePortlet.removeCustomization(layoutTypeSettingsProperties);
        }

        layout = _layoutService.updateLayout(groupId, privateLayout, layoutId,
                layoutTypeSettingsProperties.toString());

        if (!currentType.equals(LayoutConstants.TYPE_PORTLET)) {
            _portletPreferencesLocalService.deletePortletPreferences(0, PortletKeys.PREFS_OWNER_TYPE_LAYOUT,
                    layout.getPlid());
        }
    } else {
        layoutTypeSettingsProperties.putAll(formTypeSettingsProperties);

        layoutTypeSettingsProperties.putAll(layout.getTypeSettingsProperties());

        layout = _layoutService.updateLayout(groupId, privateLayout, layoutId,
                layoutTypeSettingsProperties.toString());
    }

    HttpServletResponse response = _portal.getHttpServletResponse(actionResponse);

    EventsProcessorUtil.process(PropsKeys.LAYOUT_CONFIGURATION_ACTION_UPDATE,
            layoutTypePortlet.getConfigurationActionUpdate(), uploadPortletRequest, response);

    _actionUtil.updateLookAndFeel(actionRequest, themeDisplay.getCompanyId(), liveGroupId, stagingGroupId,
            privateLayout, layout.getLayoutId(), layout.getTypeSettingsProperties());

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

    if (Validator.isNull(redirect)) {
        redirect = _portal.getLayoutFullURL(layout, themeDisplay);
    }

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

    MultiSessionMessages.add(actionRequest, portletResource + "layoutUpdated", layout);

    actionRequest.setAttribute(WebKeys.REDIRECT, redirect);
}

From source file:com.liferay.layout.service.test.LayoutImplTest.java

License:Open Source License

@Test
public void testIsSupportsEmbeddedPortletsWithTypePortlet() {
    _layout.setType(LayoutConstants.TYPE_PORTLET);

    Assert.assertTrue(_layout.isSupportsEmbeddedPortlets());
}

From source file:com.liferay.layout.service.test.LayoutImplTest.java

License:Open Source License

@Test
public void testIsTypePortletReturnsFalse() throws Exception {
    Registry registry = RegistryUtil.getRegistry();

    for (String type : _TYPES) {
        if (type.equals(LayoutConstants.TYPE_PORTLET)) {
            continue;
        }/*from  w w w.  j  a v  a2  s.c o  m*/

        LayoutTypeController layoutTypeController = new LayoutTypeControllerImpl(type);

        Map<String, Object> properties = new HashMap<>();

        properties.put("layout.type", type);

        ServiceRegistration<LayoutTypeController> serviceRegistration = registry
                .registerService(LayoutTypeController.class, layoutTypeController, properties);

        try {
            _layout.setType(type);

            Assert.assertFalse(_layout.isTypePortlet());
        } finally {
            serviceRegistration.unregister();
        }
    }
}