1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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.ServiceContext;
30  import com.liferay.portal.theme.ThemeDisplay;
31  import com.liferay.portlet.journal.model.JournalArticle;
32  import com.liferay.portlet.journal.service.base.JournalArticleServiceBaseImpl;
33  import com.liferay.portlet.journal.service.permission.JournalArticlePermission;
34  import com.liferay.portlet.journal.service.permission.JournalPermission;
35  
36  import java.io.File;
37  
38  import java.util.Map;
39  
40  /**
41   * <a href="JournalArticleServiceImpl.java.html"><b><i>View Source</i></b></a>
42   *
43   * @author Brian Wing Shun Chan
44   * @author Raymond Augé
45   */
46  public class JournalArticleServiceImpl extends JournalArticleServiceBaseImpl {
47  
48      public JournalArticle addArticle(
49              long groupId, String articleId, boolean autoArticleId, String title,
50              String description, String content, String type, String structureId,
51              String templateId, int displayDateMonth, int displayDateDay,
52              int displayDateYear, int displayDateHour, int displayDateMinute,
53              int expirationDateMonth, int expirationDateDay,
54              int expirationDateYear, int expirationDateHour,
55              int expirationDateMinute, boolean neverExpire, int reviewDateMonth,
56              int reviewDateDay, int reviewDateYear, int reviewDateHour,
57              int reviewDateMinute, boolean neverReview, boolean indexable,
58              String articleURL, ServiceContext serviceContext)
59          throws PortalException, SystemException {
60  
61          JournalPermission.check(
62              getPermissionChecker(), groupId, ActionKeys.ADD_ARTICLE);
63  
64          return journalArticleLocalService.addArticle(
65              getUserId(), groupId, articleId, autoArticleId, title, description,
66              content, type, structureId, templateId, displayDateMonth,
67              displayDateDay, displayDateYear, displayDateHour, displayDateMinute,
68              expirationDateMonth, expirationDateDay, expirationDateYear,
69              expirationDateHour, expirationDateMinute, neverExpire,
70              reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour,
71              reviewDateMinute, neverReview, indexable, false, null, null, null,
72              articleURL, serviceContext);
73      }
74  
75      public JournalArticle addArticle(
76              long groupId, String articleId, boolean autoArticleId, String title,
77              String description, String content, String type, String structureId,
78              String templateId, int displayDateMonth, int displayDateDay,
79              int displayDateYear, int displayDateHour, int displayDateMinute,
80              int expirationDateMonth, int expirationDateDay,
81              int expirationDateYear, int expirationDateHour,
82              int expirationDateMinute, boolean neverExpire, int reviewDateMonth,
83              int reviewDateDay, int reviewDateYear, int reviewDateHour,
84              int reviewDateMinute, boolean neverReview, boolean indexable,
85              boolean smallImage, String smallImageURL, File smallFile,
86              Map<String, byte[]> images, String articleURL,
87              ServiceContext serviceContext)
88          throws PortalException, SystemException {
89  
90          JournalPermission.check(
91              getPermissionChecker(), groupId, ActionKeys.ADD_ARTICLE);
92  
93          return journalArticleLocalService.addArticle(
94              getUserId(), groupId, articleId, autoArticleId, title, description,
95              content, type, structureId, templateId, displayDateMonth,
96              displayDateDay, displayDateYear, displayDateHour, displayDateMinute,
97              expirationDateMonth, expirationDateDay, expirationDateYear,
98              expirationDateHour, expirationDateMinute, neverExpire,
99              reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour,
100             reviewDateMinute, neverReview, indexable, smallImage, smallImageURL,
101             smallFile, images, articleURL, serviceContext);
102     }
103 
104     public JournalArticle approveArticle(
105             long groupId, String articleId, double version, String articleURL,
106             ServiceContext serviceContext)
107         throws PortalException, SystemException {
108 
109         User user = getUser();
110 
111         JournalPermission.check(
112             getPermissionChecker(), groupId, ActionKeys.APPROVE_ARTICLE);
113 
114         return journalArticleLocalService.approveArticle(
115             user.getUserId(), groupId, articleId, version, articleURL,
116             serviceContext);
117     }
118 
119     public JournalArticle copyArticle(
120             long groupId, String oldArticleId, String newArticleId,
121             boolean autoArticleId, double version)
122         throws PortalException, SystemException {
123 
124         JournalPermission.check(
125             getPermissionChecker(), groupId, ActionKeys.ADD_ARTICLE);
126 
127         return journalArticleLocalService.copyArticle(
128             getUserId(), groupId, oldArticleId, newArticleId, autoArticleId,
129             version);
130     }
131 
132     public JournalArticle getArticle(long groupId, String articleId)
133         throws PortalException, SystemException {
134 
135         JournalArticlePermission.check(
136             getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
137 
138         return journalArticleLocalService.getArticle(groupId, articleId);
139     }
140 
141     public JournalArticle getArticle(
142             long groupId, String articleId, double version)
143         throws PortalException, SystemException {
144 
145         JournalArticlePermission.check(
146             getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
147 
148         return journalArticleLocalService.getArticle(
149             groupId, articleId, version);
150     }
151 
152     public JournalArticle getArticleByUrlTitle(long groupId, String urlTitle)
153         throws PortalException, SystemException {
154 
155         JournalArticle article =
156             journalArticleLocalService.getArticleByUrlTitle(groupId, urlTitle);
157 
158         JournalArticlePermission.check(
159             getPermissionChecker(), article, ActionKeys.VIEW);
160 
161         return article;
162     }
163 
164     public String getArticleContent(
165             long groupId, String articleId, String languageId,
166             ThemeDisplay themeDisplay)
167         throws PortalException, SystemException {
168 
169         JournalArticlePermission.check(
170             getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
171 
172         return journalArticleLocalService.getArticleContent(
173             groupId, articleId, null, languageId, themeDisplay);
174     }
175 
176     public String getArticleContent(
177             long groupId, String articleId, double version, String languageId,
178             ThemeDisplay themeDisplay)
179         throws PortalException, SystemException {
180 
181         JournalArticlePermission.check(
182             getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
183 
184         return journalArticleLocalService.getArticleContent(
185             groupId, articleId, version, null, languageId, themeDisplay);
186     }
187 
188     public void deleteArticle(
189             long groupId, String articleId, double version, String articleURL,
190             ServiceContext serviceContext)
191         throws PortalException, SystemException {
192 
193         JournalArticlePermission.check(
194             getPermissionChecker(), groupId, articleId, ActionKeys.DELETE);
195 
196         journalArticleLocalService.deleteArticle(
197             groupId, articleId, version, articleURL, serviceContext);
198     }
199 
200     public void expireArticle(
201             long groupId, String articleId, double version, String articleURL,
202             ServiceContext serviceContext)
203         throws PortalException, SystemException {
204 
205         JournalArticlePermission.check(
206             getPermissionChecker(), groupId, articleId, ActionKeys.EXPIRE);
207 
208         journalArticleLocalService.expireArticle(
209             groupId, articleId, version, articleURL, serviceContext);
210     }
211 
212     public void removeArticleLocale(long companyId, String languageId)
213         throws PortalException, SystemException {
214 
215         for (JournalArticle article :
216                 journalArticlePersistence.findByCompanyId(companyId)) {
217 
218             removeArticleLocale(
219                 article.getGroupId(), article.getArticleId(),
220                 article.getVersion(), languageId);
221         }
222     }
223 
224     public JournalArticle removeArticleLocale(
225             long groupId, String articleId, double version, String languageId)
226         throws PortalException, SystemException {
227 
228         JournalArticlePermission.check(
229             getPermissionChecker(), groupId, articleId, ActionKeys.UPDATE);
230 
231         return journalArticleLocalService.removeArticleLocale(
232             groupId, articleId, version, languageId);
233     }
234 
235     public JournalArticle updateArticle(
236             long groupId, String articleId, double version,
237             boolean incrementVersion, String content)
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,
245             content);
246     }
247 
248     public JournalArticle updateArticle(
249             long groupId, String articleId, double version,
250             boolean incrementVersion, String title, String description,
251             String content, String type, String structureId, String templateId,
252             int displayDateMonth, int displayDateDay, int displayDateYear,
253             int displayDateHour, int displayDateMinute, int expirationDateMonth,
254             int expirationDateDay, int expirationDateYear,
255             int expirationDateHour, int expirationDateMinute,
256             boolean neverExpire, int reviewDateMonth, int reviewDateDay,
257             int reviewDateYear, int reviewDateHour, int reviewDateMinute,
258             boolean neverReview, boolean indexable, boolean smallImage,
259             String smallImageURL, File smallFile, Map<String, byte[]> images,
260             String articleURL, ServiceContext serviceContext)
261         throws PortalException, SystemException {
262 
263         JournalArticlePermission.check(
264             getPermissionChecker(), groupId, articleId, ActionKeys.UPDATE);
265 
266         return journalArticleLocalService.updateArticle(
267             getUserId(), groupId, articleId, version, incrementVersion, title,
268             description, content, type, structureId, templateId,
269             displayDateMonth, displayDateDay, displayDateYear, displayDateHour,
270             displayDateMinute, expirationDateMonth, expirationDateDay,
271             expirationDateYear, expirationDateHour, expirationDateMinute,
272             neverExpire, reviewDateMonth, reviewDateDay, reviewDateYear,
273             reviewDateHour, reviewDateMinute, neverReview, indexable,
274             smallImage, smallImageURL, smallFile, images, articleURL,
275             serviceContext);
276     }
277 
278     public JournalArticle updateContent(
279             long groupId, String articleId, double version, String content)
280         throws PortalException, SystemException {
281 
282         JournalArticlePermission.check(
283             getPermissionChecker(), groupId, articleId, ActionKeys.UPDATE);
284 
285         return journalArticleLocalService.updateContent(
286             groupId, articleId, version, content);
287     }
288 
289 }