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