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