Example usage for com.liferay.portal.kernel.model LayoutTypePortlet setLayoutTemplateId

List of usage examples for com.liferay.portal.kernel.model LayoutTypePortlet setLayoutTemplateId

Introduction

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

Prototype

public void setLayoutTemplateId(long userId, String newLayoutTemplateId, boolean checkPermission);

Source Link

Usage

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;/*from w  w  w  .jav a 2  s  . c  om*/
    }

    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.service.test.LayoutServiceTest.java

License:Open Source License

@Test
public void testUpdateLayoutLookAndFeel() throws Exception {
    Layout layout = LayoutTestUtil.addLayout(_group);

    long userId = layout.getUserId();

    layout = LayoutLocalServiceUtil.updateLookAndFeel(_group.getGroupId(), false, layout.getLayoutId(),
            "test_WAR_testtheme", "01", StringPool.BLANK);

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

    layoutTypePortlet.setLayoutTemplateId(userId, "1_column", false);

    layout = LayoutLocalServiceUtil.updateLayout(layout);
}

From source file:com.liferay.mobile.device.rules.rule.group.action.LayoutTemplateModificationActionHandler.java

License:Open Source License

@Override
public void applyAction(MDRAction mdrAction, HttpServletRequest request, HttpServletResponse response) {

    UnicodeProperties mdrActionTypeSettingsProperties = mdrAction.getTypeSettingsProperties();

    String layoutTemplateId = GetterUtil
            .getString(mdrActionTypeSettingsProperties.getProperty("layoutTemplateId"));

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

    Layout layout = themeDisplay.getLayout();

    if (layout.isTypePortlet()) {
        LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

        layoutTypePortlet.setLayoutTemplateId(0, layoutTemplateId, false);
    }//w ww .  j ava2 s  .c o m
}