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.kernel.workflow.StatusConstants;
20  import com.liferay.portal.security.permission.ActionKeys;
21  import com.liferay.portal.service.ServiceContext;
22  import com.liferay.portal.theme.ThemeDisplay;
23  import com.liferay.portlet.journal.model.JournalArticle;
24  import com.liferay.portlet.journal.service.base.JournalArticleServiceBaseImpl;
25  import com.liferay.portlet.journal.service.permission.JournalArticlePermission;
26  import com.liferay.portlet.journal.service.permission.JournalPermission;
27  
28  import java.io.File;
29  
30  import java.util.Map;
31  
32  /**
33   * <a href="JournalArticleServiceImpl.java.html"><b><i>View Source</i></b></a>
34   *
35   * @author Brian Wing Shun Chan
36   * @author Raymond Augé
37   */
38  public class JournalArticleServiceImpl extends JournalArticleServiceBaseImpl {
39  
40      public JournalArticle addArticle(
41              long groupId, String articleId, boolean autoArticleId, String title,
42              String description, String content, String type, String structureId,
43              String templateId, int displayDateMonth, int displayDateDay,
44              int displayDateYear, int displayDateHour, int displayDateMinute,
45              int expirationDateMonth, int expirationDateDay,
46              int expirationDateYear, int expirationDateHour,
47              int expirationDateMinute, boolean neverExpire, int reviewDateMonth,
48              int reviewDateDay, int reviewDateYear, int reviewDateHour,
49              int reviewDateMinute, boolean neverReview, boolean indexable,
50              boolean smallImage, String smallImageURL, File smallFile,
51              Map<String, byte[]> images, String articleURL,
52              ServiceContext serviceContext)
53          throws PortalException, SystemException {
54  
55          JournalPermission.check(
56              getPermissionChecker(), groupId, ActionKeys.ADD_ARTICLE);
57  
58          return journalArticleLocalService.addArticle(
59              getUserId(), groupId, articleId, autoArticleId, title, description,
60              content, type, structureId, templateId, displayDateMonth,
61              displayDateDay, displayDateYear, displayDateHour, displayDateMinute,
62              expirationDateMonth, expirationDateDay, expirationDateYear,
63              expirationDateHour, expirationDateMinute, neverExpire,
64              reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour,
65              reviewDateMinute, neverReview, indexable, smallImage, smallImageURL,
66              smallFile, images, articleURL, serviceContext);
67      }
68  
69      public JournalArticle addArticle(
70              long groupId, String articleId, boolean autoArticleId, String title,
71              String description, String content, String type, String structureId,
72              String templateId, int displayDateMonth, int displayDateDay,
73              int displayDateYear, int displayDateHour, int displayDateMinute,
74              int expirationDateMonth, int expirationDateDay,
75              int expirationDateYear, int expirationDateHour,
76              int expirationDateMinute, boolean neverExpire, int reviewDateMonth,
77              int reviewDateDay, int reviewDateYear, int reviewDateHour,
78              int reviewDateMinute, boolean neverReview, boolean indexable,
79              String articleURL, ServiceContext serviceContext)
80          throws PortalException, SystemException {
81  
82          JournalPermission.check(
83              getPermissionChecker(), groupId, ActionKeys.ADD_ARTICLE);
84  
85          return journalArticleLocalService.addArticle(
86              getUserId(), groupId, articleId, autoArticleId, title, description,
87              content, type, structureId, templateId, displayDateMonth,
88              displayDateDay, displayDateYear, displayDateHour, displayDateMinute,
89              expirationDateMonth, expirationDateDay, expirationDateYear,
90              expirationDateHour, expirationDateMinute, neverExpire,
91              reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour,
92              reviewDateMinute, neverReview, indexable, false, null, null, null,
93              articleURL, serviceContext);
94      }
95  
96      public JournalArticle copyArticle(
97              long groupId, String oldArticleId, String newArticleId,
98              boolean autoArticleId, double version)
99          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, version,
116             ActionKeys.DELETE);
117 
118         journalArticleLocalService.deleteArticle(
119             groupId, articleId, version, articleURL, serviceContext);
120     }
121 
122     public JournalArticle getArticle(long groupId, String articleId)
123         throws PortalException, SystemException {
124 
125         JournalArticlePermission.check(
126             getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
127 
128         return journalArticleLocalService.getArticle(groupId, articleId);
129     }
130 
131     public JournalArticle getArticle(
132             long groupId, String articleId, double version)
133         throws PortalException, SystemException {
134 
135         JournalArticlePermission.check(
136             getPermissionChecker(), groupId, articleId, version,
137             ActionKeys.VIEW);
138 
139         return journalArticleLocalService.getArticle(
140             groupId, articleId, version);
141     }
142 
143     public JournalArticle getArticleByUrlTitle(long groupId, String urlTitle)
144         throws PortalException, SystemException {
145 
146         JournalArticle article =
147             journalArticleLocalService.getArticleByUrlTitle(groupId, urlTitle);
148 
149         JournalArticlePermission.check(
150             getPermissionChecker(), article, ActionKeys.VIEW);
151 
152         return article;
153     }
154 
155     public String getArticleContent(
156             long groupId, String articleId, double version, String languageId,
157             ThemeDisplay themeDisplay)
158         throws PortalException, SystemException {
159 
160         JournalArticlePermission.check(
161             getPermissionChecker(), groupId, articleId, version,
162             ActionKeys.VIEW);
163 
164         return journalArticleLocalService.getArticleContent(
165             groupId, articleId, version, null, languageId, themeDisplay);
166     }
167 
168     public String getArticleContent(
169             long groupId, String articleId, String languageId,
170             ThemeDisplay themeDisplay)
171         throws PortalException, SystemException {
172 
173         JournalArticlePermission.check(
174             getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
175 
176         return journalArticleLocalService.getArticleContent(
177             groupId, articleId, null, languageId, themeDisplay);
178     }
179 
180     public void removeArticleLocale(long companyId, String languageId)
181         throws PortalException, SystemException {
182 
183         for (JournalArticle article :
184                 journalArticlePersistence.findByCompanyId(companyId)) {
185 
186             removeArticleLocale(
187                 article.getGroupId(), article.getArticleId(),
188                 article.getVersion(), languageId);
189         }
190     }
191 
192     public JournalArticle removeArticleLocale(
193             long groupId, String articleId, double version, String languageId)
194         throws PortalException, SystemException {
195 
196         JournalArticlePermission.check(
197             getPermissionChecker(), groupId, articleId, version,
198             ActionKeys.UPDATE);
199 
200         return journalArticleLocalService.removeArticleLocale(
201             groupId, articleId, version, languageId);
202     }
203 
204     public JournalArticle updateArticle(
205             long groupId, String articleId, double version,
206             boolean incrementVersion, String content)
207         throws PortalException, SystemException {
208 
209         JournalArticlePermission.check(
210             getPermissionChecker(), groupId, articleId, version,
211             ActionKeys.UPDATE);
212 
213         return journalArticleLocalService.updateArticle(
214             getUserId(), groupId, articleId, version, incrementVersion,
215             content);
216     }
217 
218     public JournalArticle updateArticle(
219             long groupId, String articleId, double version,
220             boolean incrementVersion, String title, String description,
221             String content, String type, String structureId, String templateId,
222             int displayDateMonth, int displayDateDay, int displayDateYear,
223             int displayDateHour, int displayDateMinute, int expirationDateMonth,
224             int expirationDateDay, int expirationDateYear,
225             int expirationDateHour, int expirationDateMinute,
226             boolean neverExpire, int reviewDateMonth, int reviewDateDay,
227             int reviewDateYear, int reviewDateHour, int reviewDateMinute,
228             boolean neverReview, boolean indexable, boolean smallImage,
229             String smallImageURL, File smallFile, Map<String, byte[]> images,
230             String articleURL, ServiceContext serviceContext)
231         throws PortalException, SystemException {
232 
233         JournalArticlePermission.check(
234             getPermissionChecker(), groupId, articleId, version,
235             ActionKeys.UPDATE);
236 
237         return journalArticleLocalService.updateArticle(
238             getUserId(), groupId, articleId, version, incrementVersion, title,
239             description, content, type, structureId, templateId,
240             displayDateMonth, displayDateDay, displayDateYear, displayDateHour,
241             displayDateMinute, expirationDateMonth, expirationDateDay,
242             expirationDateYear, expirationDateHour, expirationDateMinute,
243             neverExpire, reviewDateMonth, reviewDateDay, reviewDateYear,
244             reviewDateHour, reviewDateMinute, neverReview, indexable,
245             smallImage, smallImageURL, smallFile, images, articleURL,
246             serviceContext);
247     }
248 
249     public JournalArticle updateContent(
250             long groupId, String articleId, double version, String content)
251         throws PortalException, SystemException {
252 
253         JournalArticlePermission.check(
254             getPermissionChecker(), groupId, articleId, version,
255             ActionKeys.UPDATE);
256 
257         return journalArticleLocalService.updateContent(
258             groupId, articleId, version, content);
259     }
260 
261     public JournalArticle updateStatus(
262             long groupId, String articleId, double version, int status,
263             String articleURL, ServiceContext serviceContext)
264         throws PortalException, SystemException {
265 
266         if (status == StatusConstants.APPROVED) {
267             JournalPermission.check(
268                 getPermissionChecker(), groupId, ActionKeys.APPROVE_ARTICLE);
269         }
270         else if (status == StatusConstants.EXPIRED) {
271             JournalPermission.check(
272                 getPermissionChecker(), groupId, ActionKeys.EXPIRE);
273         }
274 
275         return journalArticleLocalService.updateStatus(
276             getUserId(), groupId, articleId, version, status, articleURL,
277             serviceContext);
278     }
279 
280 }