1   /**
2    * Copyright (c) 2000-2008 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.permission.PortletPermissionUtil;
30  import com.liferay.portal.theme.ThemeDisplay;
31  import com.liferay.portal.util.PortletKeys;
32  import com.liferay.portlet.journal.model.JournalArticle;
33  import com.liferay.portlet.journal.service.base.JournalArticleServiceBaseImpl;
34  import com.liferay.portlet.journal.service.permission.JournalArticlePermission;
35  
36  import java.io.File;
37  
38  import java.util.Map;
39  
40  import javax.portlet.PortletPreferences;
41  
42  /**
43   * <a href="JournalArticleServiceImpl.java.html"><b><i>View Source</i></b></a>
44   *
45   * @author Brian Wing Shun Chan
46   *
47   */
48  public class JournalArticleServiceImpl extends JournalArticleServiceBaseImpl {
49  
50      public JournalArticle addArticle(
51              String articleId, boolean autoArticleId, long plid, String title,
52              String description, String content, String type, String structureId,
53              String templateId, int displayDateMonth, int displayDateDay,
54              int displayDateYear, int displayDateHour, int displayDateMinute,
55              int expirationDateMonth, int expirationDateDay,
56              int expirationDateYear, int expirationDateHour,
57              int expirationDateMinute, boolean neverExpire, int reviewDateMonth,
58              int reviewDateDay, int reviewDateYear, int reviewDateHour,
59              int reviewDateMinute, boolean neverReview, boolean indexable,
60              boolean smallImage, String smallImageURL, File smallFile,
61              Map<String, byte[]> images, String articleURL,
62              PortletPreferences prefs, String[] tagsEntries,
63              boolean addCommunityPermissions, boolean addGuestPermissions)
64          throws PortalException, SystemException {
65  
66          PortletPermissionUtil.check(
67              getPermissionChecker(), plid, PortletKeys.JOURNAL,
68              ActionKeys.ADD_ARTICLE);
69  
70          return journalArticleLocalService.addArticle(
71              getUserId(), articleId, autoArticleId, plid, title, description,
72              content, type, structureId, templateId, displayDateMonth,
73              displayDateDay, displayDateYear, displayDateHour, displayDateMinute,
74              expirationDateMonth, expirationDateDay, expirationDateYear,
75              expirationDateHour, expirationDateMinute, neverExpire,
76              reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour,
77              reviewDateMinute, neverReview, indexable, smallImage, smallImageURL,
78              smallFile, images, articleURL, prefs, tagsEntries,
79              addCommunityPermissions, addGuestPermissions);
80      }
81  
82      public JournalArticle addArticle(
83              String articleId, boolean autoArticleId, long plid, String title,
84              String description, String content, String type, String structureId,
85              String templateId, int displayDateMonth, int displayDateDay,
86              int displayDateYear, int displayDateHour, int displayDateMinute,
87              int expirationDateMonth, int expirationDateDay,
88              int expirationDateYear, int expirationDateHour,
89              int expirationDateMinute, boolean neverExpire, int reviewDateMonth,
90              int reviewDateDay, int reviewDateYear, int reviewDateHour,
91              int reviewDateMinute, boolean neverReview, boolean indexable,
92              boolean smallImage, String smallImageURL, File smallFile,
93              Map<String, byte[]> images, String articleURL,
94              PortletPreferences prefs, String[] tagsEntries,
95              String[] communityPermissions, String[] guestPermissions)
96          throws PortalException, SystemException {
97  
98          PortletPermissionUtil.check(
99              getPermissionChecker(), plid, PortletKeys.JOURNAL,
100             ActionKeys.ADD_ARTICLE);
101 
102         return journalArticleLocalService.addArticle(
103             getUserId(), articleId, autoArticleId, plid, title, description,
104             content, type, structureId, templateId, displayDateMonth,
105             displayDateDay, displayDateYear, displayDateHour, displayDateMinute,
106             expirationDateMonth, expirationDateDay, expirationDateYear,
107             expirationDateHour, expirationDateMinute, neverExpire,
108             reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour,
109             reviewDateMinute, neverReview, indexable, smallImage, smallImageURL,
110             smallFile, images, articleURL, prefs, tagsEntries,
111             communityPermissions, guestPermissions);
112     }
113 
114     public JournalArticle approveArticle(
115             long groupId, String articleId, double version, long plid,
116             String articleURL, PortletPreferences prefs)
117         throws PortalException, SystemException {
118 
119         User user = getUser();
120 
121         PortletPermissionUtil.check(
122             getPermissionChecker(), plid, PortletKeys.JOURNAL,
123             ActionKeys.APPROVE_ARTICLE);
124 
125         return journalArticleLocalService.approveArticle(
126             user.getUserId(), groupId, articleId, version, articleURL, prefs);
127     }
128 
129     public JournalArticle getArticle(
130             long groupId, String articleId, double version)
131         throws PortalException, SystemException {
132 
133         JournalArticlePermission.check(
134             getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
135 
136         return journalArticleLocalService.getArticle(
137             groupId, articleId, version);
138     }
139 
140     public String getArticleContent(
141             long groupId, String articleId, String languageId,
142             ThemeDisplay themeDisplay)
143         throws PortalException, SystemException {
144 
145         JournalArticlePermission.check(
146             getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
147 
148         return journalArticleLocalService.getArticleContent(
149             groupId, articleId, languageId, themeDisplay);
150     }
151 
152     public String getArticleContent(
153             long groupId, String articleId, double version, String languageId,
154             ThemeDisplay themeDisplay)
155         throws PortalException, SystemException {
156 
157         JournalArticlePermission.check(
158             getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
159 
160         return journalArticleLocalService.getArticleContent(
161             groupId, articleId, version, languageId, themeDisplay);
162     }
163 
164     public void deleteArticle(
165             long groupId, String articleId, double version, String articleURL,
166             PortletPreferences prefs)
167         throws PortalException, SystemException {
168 
169         JournalArticlePermission.check(
170             getPermissionChecker(), groupId, articleId, ActionKeys.DELETE);
171 
172         journalArticleLocalService.deleteArticle(
173             groupId, articleId, version, articleURL, prefs);
174     }
175 
176     public void expireArticle(
177             long groupId, String articleId, double version, String articleURL,
178             PortletPreferences prefs)
179         throws PortalException, SystemException {
180 
181         JournalArticlePermission.check(
182             getPermissionChecker(), groupId, articleId, ActionKeys.EXPIRE);
183 
184         journalArticleLocalService.expireArticle(
185             groupId, articleId, version, articleURL, prefs);
186     }
187 
188     public void removeArticleLocale(long companyId, String languageId)
189         throws PortalException, SystemException {
190 
191         for (JournalArticle article :
192                 journalArticlePersistence.findByCompanyId(companyId)) {
193 
194             removeArticleLocale(
195                 article.getGroupId(), article.getArticleId(),
196                 article.getVersion(), languageId);
197         }
198     }
199 
200     public JournalArticle removeArticleLocale(
201             long groupId, String articleId, double version, String languageId)
202         throws PortalException, SystemException {
203 
204         JournalArticlePermission.check(
205             getPermissionChecker(), groupId, articleId, ActionKeys.UPDATE);
206 
207         return journalArticleLocalService.removeArticleLocale(
208             groupId, articleId, version, languageId);
209     }
210 
211     public JournalArticle updateArticle(
212             long groupId, String articleId, double version,
213             boolean incrementVersion, String title, String description,
214             String content, String type, String structureId, String templateId,
215             int displayDateMonth, int displayDateDay, int displayDateYear,
216             int displayDateHour, int displayDateMinute, int expirationDateMonth,
217             int expirationDateDay, int expirationDateYear,
218             int expirationDateHour, int expirationDateMinute,
219             boolean neverExpire, int reviewDateMonth, int reviewDateDay,
220             int reviewDateYear, int reviewDateHour, int reviewDateMinute,
221             boolean neverReview, boolean indexable, boolean smallImage,
222             String smallImageURL, File smallFile, Map<String, byte[]> images,
223             String articleURL, PortletPreferences prefs, String[] tagsEntries)
224         throws PortalException, SystemException {
225 
226         JournalArticlePermission.check(
227             getPermissionChecker(), groupId, articleId, ActionKeys.UPDATE);
228 
229         return journalArticleLocalService.updateArticle(
230             getUserId(), groupId, articleId, version, incrementVersion, title,
231             description, content, type, structureId, templateId,
232             displayDateMonth, displayDateDay, displayDateYear, displayDateHour,
233             displayDateMinute, expirationDateMonth, expirationDateDay,
234             expirationDateYear, expirationDateHour, expirationDateMinute,
235             neverExpire, reviewDateMonth, reviewDateDay, reviewDateYear,
236             reviewDateHour, reviewDateMinute, neverReview, indexable,
237             smallImage, smallImageURL, smallFile, images, articleURL, prefs,
238             tagsEntries);
239     }
240 
241     public JournalArticle updateContent(
242             long groupId, String articleId, double version, String content)
243         throws PortalException, SystemException {
244 
245         JournalArticlePermission.check(
246             getPermissionChecker(), groupId, articleId, ActionKeys.UPDATE);
247 
248         return journalArticleLocalService.updateContent(
249             groupId, articleId, version, content);
250     }
251 
252 }