1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.journal.service.impl;
21  
22  import com.liferay.portal.PortalException;
23  import com.liferay.portal.SystemException;
24  import com.liferay.portal.model.User;
25  import com.liferay.portal.security.permission.ActionKeys;
26  import com.liferay.portal.service.ServiceContext;
27  import com.liferay.portal.theme.ThemeDisplay;
28  import com.liferay.portlet.journal.model.JournalArticle;
29  import com.liferay.portlet.journal.service.base.JournalArticleServiceBaseImpl;
30  import com.liferay.portlet.journal.service.permission.JournalArticlePermission;
31  import com.liferay.portlet.journal.service.permission.JournalPermission;
32  
33  import java.io.File;
34  
35  import java.util.Map;
36  
37  /**
38   * <a href="JournalArticleServiceImpl.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author Brian Wing Shun Chan
41   * @author Raymond Augé
42   *
43   */
44  public class JournalArticleServiceImpl extends JournalArticleServiceBaseImpl {
45  
46      public JournalArticle addArticle(
47              long groupId, String articleId, boolean autoArticleId, String title,
48              String description, String content, String type, String structureId,
49              String templateId, int displayDateMonth, int displayDateDay,
50              int displayDateYear, int displayDateHour, int displayDateMinute,
51              int expirationDateMonth, int expirationDateDay,
52              int expirationDateYear, int expirationDateHour,
53              int expirationDateMinute, boolean neverExpire, int reviewDateMonth,
54              int reviewDateDay, int reviewDateYear, int reviewDateHour,
55              int reviewDateMinute, boolean neverReview, boolean indexable,
56              String articleURL, ServiceContext serviceContext)
57          throws PortalException, SystemException {
58  
59          JournalPermission.check(
60              getPermissionChecker(), groupId, ActionKeys.ADD_ARTICLE);
61  
62          return journalArticleLocalService.addArticle(
63              getUserId(), groupId, articleId, autoArticleId, title, description,
64              content, type, structureId, templateId, displayDateMonth,
65              displayDateDay, displayDateYear, displayDateHour, displayDateMinute,
66              expirationDateMonth, expirationDateDay, expirationDateYear,
67              expirationDateHour, expirationDateMinute, neverExpire,
68              reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour,
69              reviewDateMinute, neverReview, indexable, false, null, null, null,
70              articleURL, serviceContext);
71      }
72  
73      public JournalArticle addArticle(
74              long groupId, String articleId, boolean autoArticleId, String title,
75              String description, String content, String type, String structureId,
76              String templateId, int displayDateMonth, int displayDateDay,
77              int displayDateYear, int displayDateHour, int displayDateMinute,
78              int expirationDateMonth, int expirationDateDay,
79              int expirationDateYear, int expirationDateHour,
80              int expirationDateMinute, boolean neverExpire, int reviewDateMonth,
81              int reviewDateDay, int reviewDateYear, int reviewDateHour,
82              int reviewDateMinute, boolean neverReview, boolean indexable,
83              boolean smallImage, String smallImageURL, File smallFile,
84              Map<String, byte[]> images, String articleURL,
85              ServiceContext serviceContext)
86          throws PortalException, SystemException {
87  
88          JournalPermission.check(
89              getPermissionChecker(), groupId, ActionKeys.ADD_ARTICLE);
90  
91          return journalArticleLocalService.addArticle(
92              getUserId(), groupId, articleId, autoArticleId, title, description,
93              content, type, structureId, templateId, displayDateMonth,
94              displayDateDay, displayDateYear, displayDateHour, displayDateMinute,
95              expirationDateMonth, expirationDateDay, expirationDateYear,
96              expirationDateHour, expirationDateMinute, neverExpire,
97              reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour,
98              reviewDateMinute, neverReview, indexable, smallImage, smallImageURL,
99              smallFile, images, articleURL, serviceContext);
100     }
101 
102     public JournalArticle approveArticle(
103             long groupId, String articleId, double version, String articleURL,
104             ServiceContext serviceContext)
105         throws PortalException, SystemException {
106 
107         User user = getUser();
108 
109         JournalPermission.check(
110             getPermissionChecker(), groupId, ActionKeys.APPROVE_ARTICLE);
111 
112         return journalArticleLocalService.approveArticle(
113             user.getUserId(), groupId, articleId, version, articleURL,
114             serviceContext);
115     }
116 
117     public JournalArticle copyArticle(
118             long groupId, String oldArticleId, String newArticleId,
119             boolean autoArticleId, double version)
120         throws PortalException, SystemException {
121 
122         JournalPermission.check(
123             getPermissionChecker(), groupId, ActionKeys.ADD_ARTICLE);
124 
125         return journalArticleLocalService.copyArticle(
126             getUserId(), groupId, oldArticleId, newArticleId, autoArticleId,
127             version);
128     }
129 
130     public JournalArticle getArticle(long groupId, String articleId)
131         throws PortalException, SystemException {
132 
133         JournalArticlePermission.check(
134             getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
135 
136         return journalArticleLocalService.getArticle(groupId, articleId);
137     }
138 
139     public JournalArticle getArticle(
140             long groupId, String articleId, double version)
141         throws PortalException, SystemException {
142 
143         JournalArticlePermission.check(
144             getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
145 
146         return journalArticleLocalService.getArticle(
147             groupId, articleId, version);
148     }
149 
150     public JournalArticle getArticleByUrlTitle(long groupId, String urlTitle)
151         throws PortalException, SystemException {
152 
153         JournalArticle article =
154             journalArticleLocalService.getArticleByUrlTitle(groupId, urlTitle);
155 
156         JournalArticlePermission.check(
157             getPermissionChecker(), article, ActionKeys.VIEW);
158 
159         return article;
160     }
161 
162     public String getArticleContent(
163             long groupId, String articleId, String languageId,
164             ThemeDisplay themeDisplay)
165         throws PortalException, SystemException {
166 
167         JournalArticlePermission.check(
168             getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
169 
170         return journalArticleLocalService.getArticleContent(
171             groupId, articleId, null, languageId, themeDisplay);
172     }
173 
174     public String getArticleContent(
175             long groupId, String articleId, double version, String languageId,
176             ThemeDisplay themeDisplay)
177         throws PortalException, SystemException {
178 
179         JournalArticlePermission.check(
180             getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
181 
182         return journalArticleLocalService.getArticleContent(
183             groupId, articleId, version, null, languageId, themeDisplay);
184     }
185 
186     public void deleteArticle(
187             long groupId, String articleId, double version, String articleURL,
188             ServiceContext serviceContext)
189         throws PortalException, SystemException {
190 
191         JournalArticlePermission.check(
192             getPermissionChecker(), groupId, articleId, ActionKeys.DELETE);
193 
194         journalArticleLocalService.deleteArticle(
195             groupId, articleId, version, articleURL, serviceContext);
196     }
197 
198     public void expireArticle(
199             long groupId, String articleId, double version, String articleURL,
200             ServiceContext serviceContext)
201         throws PortalException, SystemException {
202 
203         JournalArticlePermission.check(
204             getPermissionChecker(), groupId, articleId, ActionKeys.EXPIRE);
205 
206         journalArticleLocalService.expireArticle(
207             groupId, articleId, version, articleURL, serviceContext);
208     }
209 
210     public void removeArticleLocale(long companyId, String languageId)
211         throws PortalException, SystemException {
212 
213         for (JournalArticle article :
214                 journalArticlePersistence.findByCompanyId(companyId)) {
215 
216             removeArticleLocale(
217                 article.getGroupId(), article.getArticleId(),
218                 article.getVersion(), languageId);
219         }
220     }
221 
222     public JournalArticle removeArticleLocale(
223             long groupId, String articleId, double version, String languageId)
224         throws PortalException, SystemException {
225 
226         JournalArticlePermission.check(
227             getPermissionChecker(), groupId, articleId, ActionKeys.UPDATE);
228 
229         return journalArticleLocalService.removeArticleLocale(
230             groupId, articleId, version, languageId);
231     }
232 
233     public JournalArticle updateArticle(
234             long groupId, String articleId, double version,
235             boolean incrementVersion, String content)
236         throws PortalException, SystemException {
237 
238         JournalArticlePermission.check(
239             getPermissionChecker(), groupId, articleId, ActionKeys.UPDATE);
240 
241         return journalArticleLocalService.updateArticle(
242             getUserId(), groupId, articleId, version, incrementVersion,
243             content);
244     }
245 
246     public JournalArticle updateArticle(
247             long groupId, String articleId, double version,
248             boolean incrementVersion, String title, String description,
249             String content, String type, String structureId, String templateId,
250             int displayDateMonth, int displayDateDay, int displayDateYear,
251             int displayDateHour, 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, incrementVersion, title,
266             description, content, type, structureId, templateId,
267             displayDateMonth, displayDateDay, displayDateYear, displayDateHour,
268             displayDateMinute, expirationDateMonth, expirationDateDay,
269             expirationDateYear, expirationDateHour, expirationDateMinute,
270             neverExpire, reviewDateMonth, reviewDateDay, reviewDateYear,
271             reviewDateHour, reviewDateMinute, neverReview, indexable,
272             smallImage, smallImageURL, smallFile, images, articleURL,
273             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 }