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