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 copyArticle(
130             long groupId, String oldArticleId, String newArticleId,
131             boolean autoArticleId, double version)
132         throws PortalException, SystemException {
133 
134         JournalArticlePermission.check(
135             getPermissionChecker(), groupId, oldArticleId,
136             ActionKeys.ADD_ARTICLE);
137 
138         return journalArticleLocalService.copyArticle(
139             getUserId(), groupId, oldArticleId, newArticleId, autoArticleId,
140             version);
141     }
142 
143     public JournalArticle getArticle(
144             long groupId, String articleId, double version)
145         throws PortalException, SystemException {
146 
147         JournalArticlePermission.check(
148             getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
149 
150         return journalArticleLocalService.getArticle(
151             groupId, articleId, version);
152     }
153 
154     public String getArticleContent(
155             long groupId, String articleId, String languageId,
156             ThemeDisplay themeDisplay)
157         throws PortalException, SystemException {
158 
159         JournalArticlePermission.check(
160             getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
161 
162         return journalArticleLocalService.getArticleContent(
163             groupId, articleId, languageId, themeDisplay);
164     }
165 
166     public String getArticleContent(
167             long groupId, String articleId, double version, String languageId,
168             ThemeDisplay themeDisplay)
169         throws PortalException, SystemException {
170 
171         JournalArticlePermission.check(
172             getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
173 
174         return journalArticleLocalService.getArticleContent(
175             groupId, articleId, version, languageId, themeDisplay);
176     }
177 
178     public void deleteArticle(
179             long groupId, String articleId, double version, String articleURL,
180             PortletPreferences prefs)
181         throws PortalException, SystemException {
182 
183         JournalArticlePermission.check(
184             getPermissionChecker(), groupId, articleId, ActionKeys.DELETE);
185 
186         journalArticleLocalService.deleteArticle(
187             groupId, articleId, version, articleURL, prefs);
188     }
189 
190     public void expireArticle(
191             long groupId, String articleId, double version, String articleURL,
192             PortletPreferences prefs)
193         throws PortalException, SystemException {
194 
195         JournalArticlePermission.check(
196             getPermissionChecker(), groupId, articleId, ActionKeys.EXPIRE);
197 
198         journalArticleLocalService.expireArticle(
199             groupId, articleId, version, articleURL, prefs);
200     }
201 
202     public void removeArticleLocale(long companyId, String languageId)
203         throws PortalException, SystemException {
204 
205         for (JournalArticle article :
206                 journalArticlePersistence.findByCompanyId(companyId)) {
207 
208             removeArticleLocale(
209                 article.getGroupId(), article.getArticleId(),
210                 article.getVersion(), languageId);
211         }
212     }
213 
214     public JournalArticle removeArticleLocale(
215             long groupId, String articleId, double version, String languageId)
216         throws PortalException, SystemException {
217 
218         JournalArticlePermission.check(
219             getPermissionChecker(), groupId, articleId, ActionKeys.UPDATE);
220 
221         return journalArticleLocalService.removeArticleLocale(
222             groupId, articleId, version, languageId);
223     }
224 
225     public JournalArticle updateArticle(
226             long groupId, String articleId, double version,
227             boolean incrementVersion, String title, String description,
228             String content, String type, String structureId, String templateId,
229             int displayDateMonth, int displayDateDay, int displayDateYear,
230             int displayDateHour, int displayDateMinute, int expirationDateMonth,
231             int expirationDateDay, int expirationDateYear,
232             int expirationDateHour, int expirationDateMinute,
233             boolean neverExpire, int reviewDateMonth, int reviewDateDay,
234             int reviewDateYear, int reviewDateHour, int reviewDateMinute,
235             boolean neverReview, boolean indexable, boolean smallImage,
236             String smallImageURL, File smallFile, Map<String, byte[]> images,
237             String articleURL, PortletPreferences prefs, String[] tagsEntries)
238         throws PortalException, SystemException {
239 
240         JournalArticlePermission.check(
241             getPermissionChecker(), groupId, articleId, ActionKeys.UPDATE);
242 
243         return journalArticleLocalService.updateArticle(
244             getUserId(), groupId, articleId, version, incrementVersion, title,
245             description, content, type, structureId, templateId,
246             displayDateMonth, displayDateDay, displayDateYear, displayDateHour,
247             displayDateMinute, expirationDateMonth, expirationDateDay,
248             expirationDateYear, expirationDateHour, expirationDateMinute,
249             neverExpire, reviewDateMonth, reviewDateDay, reviewDateYear,
250             reviewDateHour, reviewDateMinute, neverReview, indexable,
251             smallImage, smallImageURL, smallFile, images, articleURL, prefs,
252             tagsEntries);
253     }
254 
255     public JournalArticle updateContent(
256             long groupId, String articleId, double version, String content)
257         throws PortalException, SystemException {
258 
259         JournalArticlePermission.check(
260             getPermissionChecker(), groupId, articleId, ActionKeys.UPDATE);
261 
262         return journalArticleLocalService.updateContent(
263             groupId, articleId, version, content);
264     }
265 
266 }