001    /**
002     * Copyright (c) 2000-2010 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.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.security.permission.ActionKeys;
020    import com.liferay.portal.service.ServiceContext;
021    import com.liferay.portal.theme.ThemeDisplay;
022    import com.liferay.portlet.journal.model.JournalArticle;
023    import com.liferay.portlet.journal.model.JournalArticleConstants;
024    import com.liferay.portlet.journal.service.base.JournalArticleServiceBaseImpl;
025    import com.liferay.portlet.journal.service.permission.JournalArticlePermission;
026    import com.liferay.portlet.journal.service.permission.JournalPermission;
027    
028    import java.io.File;
029    
030    import java.util.Map;
031    
032    /**
033     * @author Brian Wing Shun Chan
034     * @author Raymond Augé
035     */
036    public class JournalArticleServiceImpl extends JournalArticleServiceBaseImpl {
037    
038            public JournalArticle addArticle(
039                            long groupId, String articleId, boolean autoArticleId, String title,
040                            String description, String content, String type, String structureId,
041                            String templateId, int displayDateMonth, int displayDateDay,
042                            int displayDateYear, int displayDateHour, int displayDateMinute,
043                            int expirationDateMonth, int expirationDateDay,
044                            int expirationDateYear, int expirationDateHour,
045                            int expirationDateMinute, boolean neverExpire, int reviewDateMonth,
046                            int reviewDateDay, int reviewDateYear, int reviewDateHour,
047                            int reviewDateMinute, boolean neverReview, boolean indexable,
048                            boolean smallImage, String smallImageURL, File smallFile,
049                            Map<String, byte[]> images, String articleURL,
050                            ServiceContext serviceContext)
051                    throws PortalException, SystemException {
052    
053                    JournalPermission.check(
054                            getPermissionChecker(), groupId, ActionKeys.ADD_ARTICLE);
055    
056                    return journalArticleLocalService.addArticle(
057                            getUserId(), groupId, articleId, autoArticleId,
058                            JournalArticleConstants.DEFAULT_VERSION, title, description,
059                            content, type, structureId, templateId, displayDateMonth,
060                            displayDateDay, displayDateYear, displayDateHour, displayDateMinute,
061                            expirationDateMonth, expirationDateDay, expirationDateYear,
062                            expirationDateHour, expirationDateMinute, neverExpire,
063                            reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour,
064                            reviewDateMinute, neverReview, indexable, smallImage, smallImageURL,
065                            smallFile, images, articleURL, serviceContext);
066            }
067    
068            public JournalArticle addArticle(
069                            long groupId, String articleId, boolean autoArticleId, String title,
070                            String description, String content, String type, String structureId,
071                            String templateId, int displayDateMonth, int displayDateDay,
072                            int displayDateYear, int displayDateHour, int displayDateMinute,
073                            int expirationDateMonth, int expirationDateDay,
074                            int expirationDateYear, int expirationDateHour,
075                            int expirationDateMinute, boolean neverExpire, int reviewDateMonth,
076                            int reviewDateDay, int reviewDateYear, int reviewDateHour,
077                            int reviewDateMinute, boolean neverReview, boolean indexable,
078                            String articleURL, ServiceContext serviceContext)
079                    throws PortalException, SystemException {
080    
081                    JournalPermission.check(
082                            getPermissionChecker(), groupId, ActionKeys.ADD_ARTICLE);
083    
084                    return journalArticleLocalService.addArticle(
085                            getUserId(), groupId, articleId, autoArticleId,
086                            JournalArticleConstants.DEFAULT_VERSION, title, description,
087                            content, type, structureId, templateId, displayDateMonth,
088                            displayDateDay, displayDateYear, displayDateHour, displayDateMinute,
089                            expirationDateMonth, expirationDateDay, expirationDateYear,
090                            expirationDateHour, expirationDateMinute, neverExpire,
091                            reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour,
092                            reviewDateMinute, neverReview, indexable, false, null, null, null,
093                            articleURL, serviceContext);
094            }
095    
096            public JournalArticle copyArticle(
097                            long groupId, String oldArticleId, String newArticleId,
098                            boolean autoArticleId, double version)
099                    throws PortalException, SystemException {
100    
101                    JournalPermission.check(
102                            getPermissionChecker(), groupId, ActionKeys.ADD_ARTICLE);
103    
104                    return journalArticleLocalService.copyArticle(
105                            getUserId(), groupId, oldArticleId, newArticleId, autoArticleId,
106                            version);
107            }
108    
109            public void deleteArticle(
110                            long groupId, String articleId, double version, String articleURL,
111                            ServiceContext serviceContext)
112                    throws PortalException, SystemException {
113    
114                    JournalArticlePermission.check(
115                            getPermissionChecker(), groupId, articleId, ActionKeys.DELETE);
116    
117                    journalArticleLocalService.deleteArticle(
118                            groupId, articleId, version, articleURL, serviceContext);
119            }
120    
121            public void deleteArticle(
122                            long groupId, String articleId, String articleURL,
123                            ServiceContext serviceContext)
124                    throws PortalException, SystemException {
125    
126                    JournalArticlePermission.check(
127                            getPermissionChecker(), groupId, articleId, ActionKeys.DELETE);
128    
129                    journalArticleLocalService.deleteArticle(
130                            groupId, articleId, serviceContext);
131            }
132    
133            public JournalArticle expireArticle(
134                            long groupId, String articleId, double version, String articleURL,
135                            ServiceContext serviceContext)
136                    throws PortalException, SystemException {
137    
138                    JournalArticlePermission.check(
139                            getPermissionChecker(), groupId, articleId, ActionKeys.EXPIRE);
140    
141                    return journalArticleLocalService.expireArticle(
142                            getUserId(), groupId, articleId, version, articleURL,
143                            serviceContext);
144            }
145    
146            public JournalArticle getArticle(long groupId, String articleId)
147                    throws PortalException, SystemException {
148    
149                    JournalArticlePermission.check(
150                            getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
151    
152                    return journalArticleLocalService.getArticle(groupId, articleId);
153            }
154    
155            public JournalArticle getArticle(
156                            long groupId, String articleId, double version)
157                    throws PortalException, SystemException {
158    
159                    JournalArticlePermission.check(
160                            getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
161    
162                    return journalArticleLocalService.getArticle(
163                            groupId, articleId, version);
164            }
165    
166            public JournalArticle getArticleByUrlTitle(long groupId, String urlTitle)
167                    throws PortalException, SystemException {
168    
169                    JournalArticle article =
170                            journalArticleLocalService.getArticleByUrlTitle(groupId, urlTitle);
171    
172                    JournalArticlePermission.check(
173                            getPermissionChecker(), article, ActionKeys.VIEW);
174    
175                    return article;
176            }
177    
178            public String getArticleContent(
179                            long groupId, String articleId, double version, String languageId,
180                            ThemeDisplay themeDisplay)
181                    throws PortalException, SystemException {
182    
183                    JournalArticlePermission.check(
184                            getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
185    
186                    return journalArticleLocalService.getArticleContent(
187                            groupId, articleId, version, null, languageId, themeDisplay);
188            }
189    
190            public String getArticleContent(
191                            long groupId, String articleId, String languageId,
192                            ThemeDisplay themeDisplay)
193                    throws PortalException, SystemException {
194    
195                    JournalArticlePermission.check(
196                            getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
197    
198                    return journalArticleLocalService.getArticleContent(
199                            groupId, articleId, null, languageId, themeDisplay);
200            }
201    
202            public JournalArticle getLatestArticle(
203                            long groupId, String articleId, int status)
204                    throws PortalException, SystemException {
205    
206                    JournalArticlePermission.check(
207                            getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
208    
209                    return journalArticleLocalService.getLatestArticle(
210                            groupId, articleId, status);
211            }
212    
213            public void removeArticleLocale(long companyId, String languageId)
214                    throws PortalException, SystemException {
215    
216                    for (JournalArticle article :
217                                    journalArticlePersistence.findByCompanyId(companyId)) {
218    
219                            removeArticleLocale(
220                                    article.getGroupId(), article.getArticleId(),
221                                    article.getVersion(), languageId);
222                    }
223            }
224    
225            public JournalArticle removeArticleLocale(
226                            long groupId, String articleId, double version, String languageId)
227                    throws PortalException, SystemException {
228    
229                    JournalArticlePermission.check(
230                            getPermissionChecker(), groupId, articleId, ActionKeys.UPDATE);
231    
232                    return journalArticleLocalService.removeArticleLocale(
233                            groupId, articleId, version, languageId);
234            }
235    
236            public JournalArticle updateArticle(
237                            long groupId, String articleId, double version, String content)
238                    throws PortalException, SystemException {
239    
240                    JournalArticlePermission.check(
241                            getPermissionChecker(), groupId, articleId, ActionKeys.UPDATE);
242    
243                    return journalArticleLocalService.updateArticle(
244                            getUserId(), groupId, articleId, version, content);
245            }
246    
247            public JournalArticle updateArticle(
248                            long groupId, String articleId, double version,
249                            String title, String description, String content, String type,
250                            String structureId, String templateId, int displayDateMonth,
251                            int displayDateDay, int displayDateYear, int displayDateHour,
252                            int displayDateMinute, int expirationDateMonth,
253                            int expirationDateDay, int expirationDateYear,
254                            int expirationDateHour, int expirationDateMinute,
255                            boolean neverExpire, int reviewDateMonth, int reviewDateDay,
256                            int reviewDateYear, int reviewDateHour, int reviewDateMinute,
257                            boolean neverReview, boolean indexable, boolean smallImage,
258                            String smallImageURL, File smallFile, Map<String, byte[]> images,
259                            String articleURL, ServiceContext serviceContext)
260                    throws PortalException, SystemException {
261    
262                    JournalArticlePermission.check(
263                            getPermissionChecker(), groupId, articleId, ActionKeys.UPDATE);
264    
265                    return journalArticleLocalService.updateArticle(
266                            getUserId(), groupId, articleId, version, title, description,
267                            content, type, structureId, templateId, displayDateMonth,
268                            displayDateDay, displayDateYear, displayDateHour, displayDateMinute,
269                            expirationDateMonth, expirationDateDay, expirationDateYear,
270                            expirationDateHour, expirationDateMinute, neverExpire,
271                            reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour,
272                            reviewDateMinute, neverReview, indexable, smallImage, smallImageURL,
273                            smallFile, images, articleURL, serviceContext);
274            }
275    
276            public JournalArticle updateContent(
277                            long groupId, String articleId, double version, String content)
278                    throws PortalException, SystemException {
279    
280                    JournalArticlePermission.check(
281                            getPermissionChecker(), groupId, articleId, ActionKeys.UPDATE);
282    
283                    return journalArticleLocalService.updateContent(
284                            groupId, articleId, version, content);
285            }
286    
287    }