1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.journal.service.impl;
16  
17  import com.liferay.portal.kernel.exception.PortalException;
18  import com.liferay.portal.kernel.exception.SystemException;
19  import com.liferay.portal.security.permission.ActionKeys;
20  import com.liferay.portal.service.ServiceContext;
21  import com.liferay.portal.theme.ThemeDisplay;
22  import com.liferay.portlet.journal.model.JournalArticle;
23  import com.liferay.portlet.journal.service.base.JournalArticleServiceBaseImpl;
24  import com.liferay.portlet.journal.service.permission.JournalArticlePermission;
25  import com.liferay.portlet.journal.service.permission.JournalPermission;
26  
27  import java.io.File;
28  
29  import java.util.Map;
30  
31  /**
32   * <a href="JournalArticleServiceImpl.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Brian Wing Shun Chan
35   * @author Raymond Augé
36   */
37  public class JournalArticleServiceImpl extends JournalArticleServiceBaseImpl {
38  
39      public JournalArticle addArticle(
40              long groupId, String articleId, boolean autoArticleId, String title,
41              String description, String content, String type, String structureId,
42              String templateId, int displayDateMonth, int displayDateDay,
43              int displayDateYear, int displayDateHour, int displayDateMinute,
44              int expirationDateMonth, int expirationDateDay,
45              int expirationDateYear, int expirationDateHour,
46              int expirationDateMinute, boolean neverExpire, int reviewDateMonth,
47              int reviewDateDay, int reviewDateYear, int reviewDateHour,
48              int reviewDateMinute, boolean neverReview, boolean indexable,
49              boolean smallImage, String smallImageURL, File smallFile,
50              Map<String, byte[]> images, String articleURL,
51              ServiceContext serviceContext)
52          throws PortalException, SystemException {
53  
54          JournalPermission.check(
55              getPermissionChecker(), groupId, ActionKeys.ADD_ARTICLE);
56  
57          return journalArticleLocalService.addArticle(
58              getUserId(), groupId, articleId, autoArticleId, title, description,
59              content, type, structureId, templateId, displayDateMonth,
60              displayDateDay, displayDateYear, displayDateHour, displayDateMinute,
61              expirationDateMonth, expirationDateDay, expirationDateYear,
62              expirationDateHour, expirationDateMinute, neverExpire,
63              reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour,
64              reviewDateMinute, neverReview, indexable, smallImage, smallImageURL,
65              smallFile, images, articleURL, serviceContext);
66      }
67  
68      public JournalArticle addArticle(
69              long groupId, String articleId, boolean autoArticleId, String title,
70              String description, String content, String type, String structureId,
71              String templateId, int displayDateMonth, int displayDateDay,
72              int displayDateYear, int displayDateHour, int displayDateMinute,
73              int expirationDateMonth, int expirationDateDay,
74              int expirationDateYear, int expirationDateHour,
75              int expirationDateMinute, boolean neverExpire, int reviewDateMonth,
76              int reviewDateDay, int reviewDateYear, int reviewDateHour,
77              int reviewDateMinute, boolean neverReview, boolean indexable,
78              String articleURL, ServiceContext serviceContext)
79          throws PortalException, SystemException {
80  
81          JournalPermission.check(
82              getPermissionChecker(), groupId, ActionKeys.ADD_ARTICLE);
83  
84          return journalArticleLocalService.addArticle(
85              getUserId(), groupId, articleId, autoArticleId, title, description,
86              content, type, structureId, templateId, displayDateMonth,
87              displayDateDay, displayDateYear, displayDateHour, displayDateMinute,
88              expirationDateMonth, expirationDateDay, expirationDateYear,
89              expirationDateHour, expirationDateMinute, neverExpire,
90              reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour,
91              reviewDateMinute, neverReview, indexable, false, null, null, null,
92              articleURL, serviceContext);
93      }
94  
95      public JournalArticle copyArticle(
96              long groupId, String oldArticleId, String newArticleId,
97              boolean autoArticleId, double version)
98          throws PortalException, SystemException {
99  
100         JournalPermission.check(
101             getPermissionChecker(), groupId, ActionKeys.ADD_ARTICLE);
102 
103         return journalArticleLocalService.copyArticle(
104             getUserId(), groupId, oldArticleId, newArticleId, autoArticleId,
105             version);
106     }
107 
108     public void deleteArticle(
109             long groupId, String articleId, double version, String articleURL,
110             ServiceContext serviceContext)
111         throws PortalException, SystemException {
112 
113         JournalArticlePermission.check(
114             getPermissionChecker(), groupId, articleId, ActionKeys.DELETE);
115 
116         journalArticleLocalService.deleteArticle(
117             groupId, articleId, version, articleURL, serviceContext);
118     }
119 
120     public void deleteArticle(
121             long groupId, String articleId, String articleURL,
122             ServiceContext serviceContext)
123         throws PortalException, SystemException {
124 
125         JournalArticlePermission.check(
126             getPermissionChecker(), groupId, articleId, ActionKeys.DELETE);
127 
128         journalArticleLocalService.deleteArticle(
129             groupId, articleId, serviceContext);
130     }
131 
132     public JournalArticle expireArticle(
133             long groupId, String articleId, double version, String articleURL,
134             ServiceContext serviceContext)
135         throws PortalException, SystemException {
136 
137         JournalArticlePermission.check(
138             getPermissionChecker(), groupId, articleId, ActionKeys.EXPIRE);
139 
140         return journalArticleLocalService.expireArticle(
141             getUserId(), groupId, articleId, version, articleURL,
142             serviceContext);
143     }
144 
145     public JournalArticle getArticle(long groupId, String articleId)
146         throws PortalException, SystemException {
147 
148         JournalArticlePermission.check(
149             getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
150 
151         return journalArticleLocalService.getArticle(groupId, articleId);
152     }
153 
154     public JournalArticle getArticle(
155             long groupId, String articleId, double version)
156         throws PortalException, SystemException {
157 
158         JournalArticlePermission.check(
159             getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
160 
161         return journalArticleLocalService.getArticle(
162             groupId, articleId, version);
163     }
164 
165     public JournalArticle getArticleByUrlTitle(long groupId, String urlTitle)
166         throws PortalException, SystemException {
167 
168         JournalArticle article =
169             journalArticleLocalService.getArticleByUrlTitle(groupId, urlTitle);
170 
171         JournalArticlePermission.check(
172             getPermissionChecker(), article, ActionKeys.VIEW);
173 
174         return article;
175     }
176 
177     public String getArticleContent(
178             long groupId, String articleId, double version, String languageId,
179             ThemeDisplay themeDisplay)
180         throws PortalException, SystemException {
181 
182         JournalArticlePermission.check(
183             getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
184 
185         return journalArticleLocalService.getArticleContent(
186             groupId, articleId, version, null, languageId, themeDisplay);
187     }
188 
189     public String getArticleContent(
190             long groupId, String articleId, String languageId,
191             ThemeDisplay themeDisplay)
192         throws PortalException, SystemException {
193 
194         JournalArticlePermission.check(
195             getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
196 
197         return journalArticleLocalService.getArticleContent(
198             groupId, articleId, null, languageId, themeDisplay);
199     }
200 
201     public JournalArticle getLatestArticle(
202             long groupId, String articleId, int status)
203         throws PortalException, SystemException {
204 
205         JournalArticlePermission.check(
206             getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
207 
208         return journalArticleLocalService.getLatestArticle(
209             groupId, articleId, status);
210     }
211 
212     public void removeArticleLocale(long companyId, String languageId)
213         throws PortalException, SystemException {
214 
215         for (JournalArticle article :
216                 journalArticlePersistence.findByCompanyId(companyId)) {
217 
218             removeArticleLocale(
219                 article.getGroupId(), article.getArticleId(),
220                 article.getVersion(), languageId);
221         }
222     }
223 
224     public JournalArticle removeArticleLocale(
225             long groupId, String articleId, double version, String languageId)
226         throws PortalException, SystemException {
227 
228         JournalArticlePermission.check(
229             getPermissionChecker(), groupId, articleId, ActionKeys.UPDATE);
230 
231         return journalArticleLocalService.removeArticleLocale(
232             groupId, articleId, version, languageId);
233     }
234 
235     public JournalArticle updateArticle(
236             long groupId, String articleId, double version, String content)
237         throws PortalException, SystemException {
238 
239         JournalArticlePermission.check(
240             getPermissionChecker(), groupId, articleId, ActionKeys.UPDATE);
241 
242         return journalArticleLocalService.updateArticle(
243             getUserId(), groupId, articleId, version, content);
244     }
245 
246     public JournalArticle updateArticle(
247             long groupId, String articleId, double version,
248             String title, String description, String content, String type,
249             String structureId, String templateId, int displayDateMonth,
250             int displayDateDay, int displayDateYear, int displayDateHour,
251             int displayDateMinute, int expirationDateMonth,
252             int expirationDateDay, int expirationDateYear,
253             int expirationDateHour, int expirationDateMinute,
254             boolean neverExpire, int reviewDateMonth, int reviewDateDay,
255             int reviewDateYear, int reviewDateHour, int reviewDateMinute,
256             boolean neverReview, boolean indexable, boolean smallImage,
257             String smallImageURL, File smallFile, Map<String, byte[]> images,
258             String articleURL, ServiceContext serviceContext)
259         throws PortalException, SystemException {
260 
261         JournalArticlePermission.check(
262             getPermissionChecker(), groupId, articleId, ActionKeys.UPDATE);
263 
264         return journalArticleLocalService.updateArticle(
265             getUserId(), groupId, articleId, version, title, description,
266             content, type, structureId, templateId, displayDateMonth,
267             displayDateDay, displayDateYear, displayDateHour, displayDateMinute,
268             expirationDateMonth, expirationDateDay, expirationDateYear,
269             expirationDateHour, expirationDateMinute, neverExpire,
270             reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour,
271             reviewDateMinute, neverReview, indexable, smallImage, smallImageURL,
272             smallFile, images, articleURL, serviceContext);
273     }
274 
275     public JournalArticle updateContent(
276             long groupId, String articleId, double version, String content)
277         throws PortalException, SystemException {
278 
279         JournalArticlePermission.check(
280             getPermissionChecker(), groupId, articleId, ActionKeys.UPDATE);
281 
282         return journalArticleLocalService.updateContent(
283             groupId, articleId, version, content);
284     }
285 
286 }