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.portlet.journal.search;
016    
017    import com.liferay.portal.kernel.dao.search.DisplayTerms;
018    import com.liferay.portal.kernel.util.ParamUtil;
019    import com.liferay.portal.kernel.util.StringPool;
020    import com.liferay.portal.theme.ThemeDisplay;
021    import com.liferay.portal.util.WebKeys;
022    
023    import java.util.ArrayList;
024    import java.util.Date;
025    import java.util.List;
026    
027    import javax.portlet.PortletRequest;
028    
029    /**
030     * @author Brian Wing Shun Chan
031     */
032    public class ArticleDisplayTerms extends DisplayTerms {
033    
034            public static final String ARTICLE_ID = "searchArticleId";
035    
036            public static final String CONTENT = "content";
037    
038            public static final String DDM_STRUCTURE_KEY = "ddmStructureKey";
039    
040            public static final String DDM_TEMPLATE_KEY = "ddmTemplateKey";
041    
042            public static final String DESCRIPTION = "description";
043    
044            public static final String DISPLAY_DATE_GT = "displayDateGT";
045    
046            public static final String DISPLAY_DATE_LT = "displayDateLT";
047    
048            public static final String FOLDER_ID = "folderId";
049    
050            public static final String GROUP_ID = "groupId";
051    
052            public static final String NAVIGATION = "navigation";
053    
054            public static final String STATUS = "status";
055    
056            public static final String TITLE = "title";
057    
058            public static final String VERSION = "version";
059    
060            public ArticleDisplayTerms(PortletRequest portletRequest) {
061                    super(portletRequest);
062    
063                    articleId = ParamUtil.getString(portletRequest, ARTICLE_ID);
064                    content = ParamUtil.getString(portletRequest, CONTENT);
065                    ddmStructureKey = ParamUtil.getString(
066                            portletRequest, DDM_STRUCTURE_KEY);
067                    ddmTemplateKey = ParamUtil.getString(portletRequest, DDM_TEMPLATE_KEY);
068                    description = ParamUtil.getString(portletRequest, DESCRIPTION);
069                    folderId = ParamUtil.getLong(portletRequest, FOLDER_ID);
070                    navigation = ParamUtil.getString(portletRequest, NAVIGATION);
071                    status = ParamUtil.getInteger(portletRequest, STATUS);
072                    title = ParamUtil.getString(portletRequest, TITLE);
073                    version = ParamUtil.getDouble(portletRequest, VERSION);
074    
075                    groupId = setGroupId(portletRequest);
076            }
077    
078            public String getArticleId() {
079                    return articleId;
080            }
081    
082            public String getContent() {
083                    return content;
084            }
085    
086            public String getDDMStructureKey() {
087                    return ddmStructureKey;
088            }
089    
090            public String getDDMTemplateKey() {
091                    return ddmTemplateKey;
092            }
093    
094            public String getDescription() {
095                    return description;
096            }
097    
098            public Date getDisplayDateGT() {
099                    return displayDateGT;
100            }
101    
102            public Date getDisplayDateLT() {
103                    return displayDateLT;
104            }
105    
106            public long getFolderId() {
107                    return folderId;
108            }
109    
110            public List<Long> getFolderIds() {
111                    if (folderIds != null) {
112                            return folderIds;
113                    }
114    
115                    List<Long> folderIds = new ArrayList<Long>();
116    
117                    folderIds.add(folderId);
118    
119                    return folderIds;
120            }
121    
122            public long getGroupId() {
123                    return groupId;
124            }
125    
126            public String getNavigation() {
127                    return navigation;
128            }
129    
130            public int getStatus() {
131                    return status;
132            }
133    
134            public String getTitle() {
135                    return title;
136            }
137    
138            public double getVersion() {
139                    return version;
140            }
141    
142            public String getVersionString() {
143                    if (version != 0) {
144                            return String.valueOf(version);
145                    }
146                    else {
147                            return StringPool.BLANK;
148                    }
149            }
150    
151            public boolean isNavigationRecent() {
152                    if (navigation.equals("recent")) {
153                            return true;
154                    }
155    
156                    return false;
157            }
158    
159            public void setDisplayDateGT(Date displayDateGT) {
160                    this.displayDateGT = displayDateGT;
161            }
162    
163            public void setDisplayDateLT(Date displayDateLT) {
164                    this.displayDateLT = displayDateLT;
165            }
166    
167            public void setFolderIds(List<Long> folderIds) {
168                    this.folderIds = folderIds;
169            }
170    
171            public long setGroupId(PortletRequest portletRequest) {
172                    groupId = ParamUtil.getLong(portletRequest, GROUP_ID);
173    
174                    if (groupId != 0) {
175                            return groupId;
176                    }
177    
178                    ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute(
179                            WebKeys.THEME_DISPLAY);
180    
181                    return themeDisplay.getScopeGroupId();
182            }
183    
184            public void setStatus(int status) {
185                    this.status = status;
186            }
187    
188            protected String articleId;
189            protected String content;
190            protected String ddmStructureKey;
191            protected String ddmTemplateKey;
192            protected String description;
193            protected Date displayDateGT;
194            protected Date displayDateLT;
195            protected long folderId;
196            protected List<Long> folderIds;
197            protected long groupId;
198            protected String navigation;
199            protected int status;
200            protected String title;
201            protected double version;
202    
203    }