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