001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.dao.search;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.json.JSONArray;
019    import com.liferay.portal.kernel.json.JSONFactoryUtil;
020    import com.liferay.portal.kernel.json.JSONObject;
021    import com.liferay.portal.kernel.util.StringPool;
022    
023    import java.util.ArrayList;
024    import java.util.List;
025    
026    /**
027     * @author Chema Balsas
028     */
029    public class RowMover {
030    
031            public RowMover() {
032            }
033    
034            public void addRowMoverDropTarget(RowMoverDropTarget rowMoverDropTarget) {
035                    _rowMoverDropTargets.add(rowMoverDropTarget);
036            }
037    
038            public List<RowMoverDropTarget> getRowMoverDropTargets() {
039                    return _rowMoverDropTargets;
040            }
041    
042            public String getRowSelector() {
043                    return _rowSelector;
044            }
045    
046            public void setRowMoverDropTargets(
047                    List<RowMoverDropTarget> rowMoverDropTargets) {
048    
049                    _rowMoverDropTargets = rowMoverDropTargets;
050            }
051    
052            public void setRowSelector(String rowSelector) {
053                    _rowSelector = rowSelector;
054            }
055    
056            public String toJSON() throws PortalException {
057                    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
058    
059                    JSONArray rowMoverDropTargetsJSONArray =
060                            JSONFactoryUtil.createJSONArray();
061    
062                    for (RowMoverDropTarget rowMoverDropTarget : _rowMoverDropTargets) {
063                            String rowMoverDropTargetJSON = JSONFactoryUtil.looseSerialize(
064                                    rowMoverDropTarget);
065    
066                            JSONObject rowMoverDropTargetJSONObject =
067                                    JSONFactoryUtil.createJSONObject(rowMoverDropTargetJSON);
068    
069                            rowMoverDropTargetsJSONArray.put(rowMoverDropTargetJSONObject);
070                    }
071    
072                    jsonObject.put("dropTargets", rowMoverDropTargetsJSONArray);
073    
074                    jsonObject.put("rowSelector", _rowSelector);
075    
076                    return jsonObject.toString();
077            }
078    
079            private List<RowMoverDropTarget> _rowMoverDropTargets = new ArrayList<>();
080            private String _rowSelector = StringPool.BLANK;
081    
082    }