Example usage for com.liferay.portal.kernel.model LayoutPrototype getLayout

List of usage examples for com.liferay.portal.kernel.model LayoutPrototype getLayout

Introduction

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

Prototype

public Layout getLayout() throws com.liferay.portal.kernel.exception.PortalException;

Source Link

Usage

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

License:Open Source License

protected void addLayoutPrototype(InputStream inputStream) throws Exception {

    String content = StringUtil.read(inputStream);

    if (Validator.isNull(content)) {
        return;/*from w  w w  .j  a  v a  2s . c om*/
    }

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject(content);

    JSONObject layoutTemplateJSONObject = jsonObject.getJSONObject("layoutTemplate");

    Map<Locale, String> nameMap = getMap(layoutTemplateJSONObject.getString("name"));

    String name = nameMap.get(Locale.getDefault());

    Map<Locale, String> descriptionMap = getMap(layoutTemplateJSONObject, "description");

    String uuid = layoutTemplateJSONObject.getString("uuid");

    LayoutPrototype layoutPrototype = getLayoutPrototype(companyId, name);

    if (layoutPrototype != null) {
        if (!developerModeEnabled) {
            if (_log.isInfoEnabled()) {
                _log.info(StringBundler.concat("Layout prototype with name ", name,
                        " already exists for company ", String.valueOf(companyId)));
            }

            return;
        }

        if (!updateModeEnabled) {
            layoutPrototypeLocalService.deleteLayoutPrototype(layoutPrototype);
        }
    }

    ServiceContext serviceContext = new ServiceContext();

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

    if (Validator.isNotNull(uuid)) {
        serviceContext.setUuid(uuid);
    }

    try {
        if (!updateModeEnabled || (layoutPrototype == null)) {
            layoutPrototype = layoutPrototypeLocalService.addLayoutPrototype(userId, companyId, getMap(name),
                    descriptionMap, true, serviceContext);
        } else {
            layoutPrototype = layoutPrototypeLocalService.updateLayoutPrototype(
                    layoutPrototype.getLayoutPrototypeId(), getMap(name), descriptionMap,
                    layoutPrototype.isActive(), serviceContext);
        }
    } catch (Exception e) {
        if (_log.isWarnEnabled()) {
            _log.warn("Unable to import layout prototype " + name, e);
        }

        throw e;
    }

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

    Layout layout = layoutPrototype.getLayout();

    addLayoutColumns(layout, LayoutTypePortletConstants.COLUMN_PREFIX, columnsJSONArray);

    layoutLocalService.updateLayout(layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(),
            layout.getTypeSettings());
}