1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.journal.service.impl;
24  
25  import com.liferay.portal.PortalException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.model.User;
28  import com.liferay.portal.security.permission.ActionKeys;
29  import com.liferay.portal.service.ServiceContext;
30  import com.liferay.portal.theme.ThemeDisplay;
31  import com.liferay.portlet.journal.model.JournalArticle;
32  import com.liferay.portlet.journal.service.base.JournalArticleServiceBaseImpl;
33  import com.liferay.portlet.journal.service.permission.JournalArticlePermission;
34  import com.liferay.portlet.journal.service.permission.JournalPermission;
35  
36  import java.io.File;
37  
38  import java.util.Map;
39  
40  /**
41   * <a href="JournalArticleServiceImpl.java.html"><b><i>View Source</i></b></a>
42   *
43   * @author Brian Wing Shun Chan
44   * @author Raymond Augé
45   *
46   */
47  public class JournalArticleServiceImpl extends JournalArticleServiceBaseImpl {
48  
49      public JournalArticle addArticle(
50              long groupId, String articleId, boolean autoArticleId, String title,
51              String description, String content, String type, String structureId,
52              String templateId, int displayDateMonth, int displayDateDay,
53              int displayDateYear, int displayDateHour, int displayDateMinute,
54              int expirationDateMonth, int expirationDateDay,
55              int expirationDateYear, int expirationDateHour,
56              int expirationDateMinute, boolean neverExpire, int reviewDateMonth,
57              int reviewDateDay, int reviewDateYear, int reviewDateHour,
58              int reviewDateMinute, boolean neverReview, boolean indexable,
59              String articleURL, ServiceContext serviceContext)
60          throws PortalException, SystemException {
61  
62          JournalPermission.check(
63              getPermissionChecker(), groupId, ActionKeys.ADD_ARTICLE);
64  
65          return journalArticleLocalService.addArticle(
66              getUserId(), groupId, articleId, autoArticleId, title, description,
67              content, type, structureId, templateId, displayDateMonth,
68              displayDateDay, displayDateYear, displayDateHour, displayDateMinute,
69              expirationDateMonth, expirationDateDay, expirationDateYear,
70              expirationDateHour, expirationDateMinute, neverExpire,
71              reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour,
72              reviewDateMinute, neverReview, indexable, false, null, null, null,
73              articleURL, serviceContext);
74      }
75  
76      public JournalArticle addArticle(
77              long groupId, String articleId, boolean autoArticleId, String title,
78              String description, String content, String type, String structureId,
79              String templateId, int displayDateMonth, int displayDateDay,
80              int displayDateYear, int displayDateHour, int displayDateMinute,
81              int expirationDateMonth, int expirationDateDay,
82              int expirationDateYear, int expirationDateHour,
83              int expirationDateMinute, boolean neverExpire, int reviewDateMonth,
84              int reviewDateDay, int reviewDateYear, int reviewDateHour,
85              int reviewDateMinute, boolean neverReview, boolean indexable,
86              boolean smallImage, String smallImageURL, File smallFile,
87              Map<String, byte[]> images, String articleURL,
88              ServiceContext serviceContext)
89          throws PortalException, SystemException {
90  
91          JournalPermission.check(
92              getPermissionChecker(), groupId, ActionKeys.ADD_ARTICLE);
93  
94          return journalArticleLocalService.addArticle(
95              getUserId(), groupId, articleId, autoArticleId, title, description,
96              content, type, structureId, templateId, displayDateMonth,
97              displayDateDay, displayDateYear, displayDateHour, displayDateMinute,
98              expirationDateMonth, expirationDateDay, expirationDateYear,
99              expirationDateHour, expirationDateMinute, neverExpire,
100             reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour,
101             reviewDateMinute, neverReview, indexable, smallImage, smallImageURL,
102             smallFile, images, articleURL, serviceContext);
103     }
104 
105     public JournalArticle approveArticle(
106             long groupId, String articleId, double version, String articleURL,
107             ServiceContext serviceContext)
108         throws PortalException, SystemException {
109 
110         User user = getUser();
111 
112         JournalPermission.check(
113             getPermissionChecker(), groupId, ActionKeys.APPROVE_ARTICLE);
114 
115         return journalArticleLocalService.approveArticle(
116             user.getUserId(), groupId, articleId, version, articleURL,
117             serviceContext);
118     }
119 
120     public JournalArticle copyArticle(
121             long groupId, String oldArticleId, String newArticleId,
122             boolean autoArticleId, double version)
123         throws PortalException, SystemException {
124 
125         JournalPermission.check(
126             getPermissionChecker(), groupId, ActionKeys.ADD_ARTICLE);
127 
128         return journalArticleLocalService.copyArticle(
129             getUserId(), groupId, oldArticleId, newArticleId, autoArticleId,
130             version);
131     }
132 
133     public JournalArticle getArticle(long groupId, String articleId)
134         throws PortalException, SystemException {
135 
136         JournalArticlePermission.check(
137             getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
138 
139         return journalArticleLocalService.getArticle(groupId, articleId);
140     }
141 
142     public JournalArticle getArticle(
143             long groupId, String articleId, double version)
144         throws PortalException, SystemException {
145 
146         JournalArticlePermission.check(
147             getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
148 
149         return journalArticleLocalService.getArticle(
150             groupId, articleId, version);
151     }
152 
153     public JournalArticle getArticleByUrlTitle(long groupId, String urlTitle)
154         throws PortalException, SystemException {
155 
156         JournalArticle article =
157             journalArticleLocalService.getArticleByUrlTitle(groupId, urlTitle);
158 
159         JournalArticlePermission.check(
160             getPermissionChecker(), article, ActionKeys.VIEW);
161 
162         return article;
163     }
164 
165     public String getArticleContent(
166             long groupId, String articleId, String languageId,
167             ThemeDisplay themeDisplay)
168         throws PortalException, SystemException {
169 
170         JournalArticlePermission.check(
171             getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
172 
173         return journalArticleLocalService.getArticleContent(
174             groupId, articleId, null, languageId, themeDisplay);
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 void deleteArticle(
190             long groupId, String articleId, double version, String articleURL,
191             ServiceContext serviceContext)
192         throws PortalException, SystemException {
193 
194         JournalArticlePermission.check(
195             getPermissionChecker(), groupId, articleId, ActionKeys.DELETE);
196 
197         journalArticleLocalService.deleteArticle(
198             groupId, articleId, version, articleURL, serviceContext);
199     }
200 
201     public void expireArticle(
202             long groupId, String articleId, double version, String articleURL,
203             ServiceContext serviceContext)
204         throws PortalException, SystemException {
205 
206         JournalArticlePermission.check(
207             getPermissionChecker(), groupId, articleId, ActionKeys.EXPIRE);
208 
209         journalArticleLocalService.expireArticle(
210             groupId, articleId, version, articleURL, serviceContext);
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,
238             boolean incrementVersion, String content)
239         throws PortalException, SystemException {
240 
241         JournalArticlePermission.check(
242             getPermissionChecker(), groupId, articleId, ActionKeys.UPDATE);
243 
244         return journalArticleLocalService.updateArticle(
245             getUserId(), groupId, articleId, version, incrementVersion,
246             content);
247     }
248 
249     public JournalArticle updateArticle(
250             long groupId, String articleId, double version,
251             boolean incrementVersion, String title, String description,
252             String content, String type, String structureId, String templateId,
253             int displayDateMonth, int displayDateDay, int displayDateYear,
254             int displayDateHour, int displayDateMinute, int expirationDateMonth,
255             int expirationDateDay, int expirationDateYear,
256             int expirationDateHour, int expirationDateMinute,
257             boolean neverExpire, int reviewDateMonth, int reviewDateDay,
258             int reviewDateYear, int reviewDateHour, int reviewDateMinute,
259             boolean neverReview, boolean indexable, boolean smallImage,
260             String smallImageURL, File smallFile, Map<String, byte[]> images,
261             String articleURL, ServiceContext serviceContext)
262         throws PortalException, SystemException {
263 
264         JournalArticlePermission.check(
265             getPermissionChecker(), groupId, articleId, ActionKeys.UPDATE);
266 
267         return journalArticleLocalService.updateArticle(
268             getUserId(), groupId, articleId, version, incrementVersion, title,
269             description, content, type, structureId, templateId,
270             displayDateMonth, displayDateDay, displayDateYear, displayDateHour,
271             displayDateMinute, expirationDateMonth, expirationDateDay,
272             expirationDateYear, expirationDateHour, expirationDateMinute,
273             neverExpire, reviewDateMonth, reviewDateDay, reviewDateYear,
274             reviewDateHour, reviewDateMinute, neverReview, indexable,
275             smallImage, smallImageURL, smallFile, images, articleURL,
276             serviceContext);
277     }
278 
279     public JournalArticle updateContent(
280             long groupId, String articleId, double version, String content)
281         throws PortalException, SystemException {
282 
283         JournalArticlePermission.check(
284             getPermissionChecker(), groupId, articleId, ActionKeys.UPDATE);
285 
286         return journalArticleLocalService.updateContent(
287             groupId, articleId, version, content);
288     }
289 
290 }