Example usage for com.liferay.portal.kernel.model.impl VirtualLayout getSourceGroupId

List of usage examples for com.liferay.portal.kernel.model.impl VirtualLayout getSourceGroupId

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.model.impl VirtualLayout getSourceGroupId.

Prototype

public long getSourceGroupId() 

Source Link

Usage

From source file:com.liferay.layout.internal.util.LayoutsTreeImpl.java

License:Open Source License

private LayoutTreeNodes _getLayoutTreeNodes(HttpServletRequest request, long groupId, boolean privateLayout,
        long parentLayoutId, boolean incomplete, long[] expandedLayoutIds, String treeId) throws Exception {

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

        sb.append("_getLayoutTreeNodes(groupId=");
        sb.append(groupId);/*from  w ww.ja v  a2s. co  m*/
        sb.append(", privateLayout=");
        sb.append(privateLayout);
        sb.append(", parentLayoutId=");
        sb.append(parentLayoutId);
        sb.append(", expandedLayoutIds=");
        sb.append(expandedLayoutIds);
        sb.append(", incomplete=");
        sb.append(incomplete);
        sb.append(", treeId=");
        sb.append(treeId);
        sb.append(StringPool.CLOSE_PARENTHESIS);

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

    List<LayoutTreeNode> layoutTreeNodes = new ArrayList<>();

    List<Layout> ancestorLayouts = _getAncestorLayouts(request);

    List<Layout> layouts = _layoutService.getLayouts(groupId, privateLayout, parentLayoutId, incomplete,
            QueryUtil.ALL_POS, QueryUtil.ALL_POS);

    for (Layout layout : _paginateLayouts(request, groupId, privateLayout, parentLayoutId, layouts, treeId)) {

        LayoutTreeNode layoutTreeNode = new LayoutTreeNode(layout);

        LayoutTreeNodes childLayoutTreeNodes = null;

        if (_isExpandableLayout(request, ancestorLayouts, expandedLayoutIds, layout)) {

            if (layout instanceof VirtualLayout) {
                VirtualLayout virtualLayout = (VirtualLayout) layout;

                childLayoutTreeNodes = _getLayoutTreeNodes(request, virtualLayout.getSourceGroupId(),
                        virtualLayout.isPrivateLayout(), virtualLayout.getLayoutId(), incomplete,
                        expandedLayoutIds, treeId);
            } else {
                childLayoutTreeNodes = _getLayoutTreeNodes(request, groupId, layout.isPrivateLayout(),
                        layout.getLayoutId(), incomplete, expandedLayoutIds, treeId);
            }
        } else {
            int childLayoutsCount = _layoutService.getLayoutsCount(groupId, privateLayout,
                    layout.getLayoutId());

            childLayoutTreeNodes = new LayoutTreeNodes(new ArrayList<LayoutTreeNode>(), childLayoutsCount);
        }

        layoutTreeNode.setChildLayoutTreeNodes(childLayoutTreeNodes);

        layoutTreeNodes.add(layoutTreeNode);
    }

    return new LayoutTreeNodes(layoutTreeNodes, layouts.size());
}

From source file:com.liferay.layout.internal.util.LayoutsTreeImpl.java

License:Open Source License

private JSONObject _toJSONObject(HttpServletRequest request, long groupId, LayoutTreeNodes layoutTreeNodes,
        LayoutSetBranch layoutSetBranch) throws Exception {

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

        sb.append("_toJSON(groupId=");
        sb.append(groupId);//  www .jav  a  2 s  .c  o m
        sb.append(", layoutTreeNodes=");
        sb.append(layoutTreeNodes);
        sb.append(StringPool.CLOSE_PARENTHESIS);

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

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

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    boolean hasManageLayoutsPermission = GroupPermissionUtil.contains(themeDisplay.getPermissionChecker(),
            groupId, ActionKeys.MANAGE_LAYOUTS);
    boolean mobile = BrowserSnifferUtil.isMobile(request);

    for (LayoutTreeNode layoutTreeNode : layoutTreeNodes) {
        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

        JSONObject childrenJSONObject = _toJSONObject(request, groupId,
                layoutTreeNode.getChildLayoutTreeNodes(), layoutSetBranch);

        jsonObject.put("children", childrenJSONObject);

        Layout layout = layoutTreeNode.getLayout();

        jsonObject.put("contentDisplayPage", layout.isContentDisplayPage());
        jsonObject.put("deleteable", _isDeleteable(layout, themeDisplay, layoutSetBranch));
        jsonObject.put("friendlyURL", layout.getFriendlyURL());

        if (layout instanceof VirtualLayout) {
            VirtualLayout virtualLayout = (VirtualLayout) layout;

            jsonObject.put("groupId", virtualLayout.getSourceGroupId());
        } else {
            jsonObject.put("groupId", layout.getGroupId());
        }

        jsonObject.put("hasChildren", layout.hasChildren());
        jsonObject.put("layoutId", layout.getLayoutId());
        jsonObject.put("name", layout.getName(themeDisplay.getLocale()));
        jsonObject.put("parentable", LayoutPermissionUtil.contains(themeDisplay.getPermissionChecker(), layout,
                ActionKeys.ADD_LAYOUT));
        jsonObject.put("parentLayoutId", layout.getParentLayoutId());
        jsonObject.put("plid", layout.getPlid());
        jsonObject.put("priority", layout.getPriority());
        jsonObject.put("privateLayout", layout.isPrivateLayout());
        jsonObject.put("regularURL", layout.getRegularURL(request));
        jsonObject.put("sortable", hasManageLayoutsPermission && !mobile && SitesUtil.isLayoutSortable(layout));
        jsonObject.put("type", layout.getType());
        jsonObject.put("updateable",
                LayoutPermissionUtil.contains(themeDisplay.getPermissionChecker(), layout, ActionKeys.UPDATE));
        jsonObject.put("uuid", layout.getUuid());

        LayoutRevision layoutRevision = LayoutStagingUtil.getLayoutRevision(layout);

        if (layoutRevision != null) {
            long layoutSetBranchId = layoutRevision.getLayoutSetBranchId();

            if (_staging.isIncomplete(layout, layoutSetBranchId)) {
                jsonObject.put("incomplete", true);
            }

            LayoutSetBranch boundLayoutSetBranch = _layoutSetBranchLocalService
                    .getLayoutSetBranch(layoutSetBranchId);

            LayoutBranch layoutBranch = layoutRevision.getLayoutBranch();

            if (!layoutBranch.isMaster()) {
                jsonObject.put("layoutBranchId", layoutBranch.getLayoutBranchId());
                jsonObject.put("layoutBranchName", layoutBranch.getName());
            }

            if (layoutRevision.isHead()) {
                jsonObject.put("layoutRevisionHead", true);
            }

            jsonObject.put("layoutRevisionId", layoutRevision.getLayoutRevisionId());
            jsonObject.put("layoutSetBranchId", layoutSetBranchId);
            jsonObject.put("layoutSetBranchName", boundLayoutSetBranch.getName());
        }

        jsonArray.put(jsonObject);
    }

    JSONObject responseJSONObject = JSONFactoryUtil.createJSONObject();

    responseJSONObject.put("layouts", jsonArray);
    responseJSONObject.put("total", layoutTreeNodes.getTotal());

    return responseJSONObject;
}