001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.journal.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.util.OrderByComparator;
020    import com.liferay.portal.security.permission.ActionKeys;
021    import com.liferay.portal.service.ServiceContext;
022    import com.liferay.portal.theme.ThemeDisplay;
023    import com.liferay.portlet.journal.model.JournalArticle;
024    import com.liferay.portlet.journal.model.JournalArticleConstants;
025    import com.liferay.portlet.journal.service.base.JournalArticleServiceBaseImpl;
026    import com.liferay.portlet.journal.service.permission.JournalArticlePermission;
027    import com.liferay.portlet.journal.service.permission.JournalPermission;
028    
029    import java.io.File;
030    
031    import java.util.Date;
032    import java.util.List;
033    import java.util.Locale;
034    import java.util.Map;
035    
036    /**
037     * @author Brian Wing Shun Chan
038     * @author Raymond Augé
039     */
040    public class JournalArticleServiceImpl extends JournalArticleServiceBaseImpl {
041    
042            public JournalArticle addArticle(
043                            long groupId, long classNameId, long classPK, String articleId,
044                            boolean autoArticleId, Map<Locale, String> titleMap,
045                            Map<Locale, String> descriptionMap, String content, String type,
046                            String structureId, String templateId, String layoutUuid,
047                            int displayDateMonth, int displayDateDay, int displayDateYear,
048                            int displayDateHour, int displayDateMinute, int expirationDateMonth,
049                            int expirationDateDay, int expirationDateYear,
050                            int expirationDateHour, int expirationDateMinute,
051                            boolean neverExpire, int reviewDateMonth, int reviewDateDay,
052                            int reviewDateYear, int reviewDateHour, int reviewDateMinute,
053                            boolean neverReview, boolean indexable, boolean smallImage,
054                            String smallImageURL, File smallFile, Map<String, byte[]> images,
055                            String articleURL, ServiceContext serviceContext)
056                    throws PortalException, SystemException {
057    
058                    JournalPermission.check(
059                            getPermissionChecker(), groupId, ActionKeys.ADD_ARTICLE);
060    
061                    return journalArticleLocalService.addArticle(
062                            getUserId(), groupId, classNameId, classPK, articleId,
063                            autoArticleId, JournalArticleConstants.VERSION_DEFAULT, titleMap,
064                            descriptionMap, content, type, structureId, templateId, layoutUuid,
065                            displayDateMonth, displayDateDay, displayDateYear, displayDateHour,
066                            displayDateMinute, expirationDateMonth, expirationDateDay,
067                            expirationDateYear, expirationDateHour, expirationDateMinute,
068                            neverExpire, reviewDateMonth, reviewDateDay, reviewDateYear,
069                            reviewDateHour, reviewDateMinute, neverReview, indexable,
070                            smallImage, smallImageURL, smallFile, images, articleURL,
071                            serviceContext);
072            }
073    
074            public JournalArticle addArticle(
075                            long groupId, long classNameId, long classPK, String articleId,
076                            boolean autoArticleId, Map<Locale, String> titleMap,
077                            Map<Locale, String> descriptionMap, String content, String type,
078                            String structureId, String templateId, String layoutUuid,
079                            int displayDateMonth, int displayDateDay, int displayDateYear,
080                            int displayDateHour, int displayDateMinute, int expirationDateMonth,
081                            int expirationDateDay, int expirationDateYear,
082                            int expirationDateHour, int expirationDateMinute,
083                            boolean neverExpire, int reviewDateMonth, int reviewDateDay,
084                            int reviewDateYear, int reviewDateHour, int reviewDateMinute,
085                            boolean neverReview, boolean indexable, String articleURL,
086                            ServiceContext serviceContext)
087                    throws PortalException, SystemException {
088    
089                    JournalPermission.check(
090                            getPermissionChecker(), groupId, ActionKeys.ADD_ARTICLE);
091    
092                    return journalArticleLocalService.addArticle(
093                            getUserId(), groupId, classNameId, classPK, articleId,
094                            autoArticleId, JournalArticleConstants.VERSION_DEFAULT, titleMap,
095                            descriptionMap, content, type, structureId, templateId, layoutUuid,
096                            displayDateMonth, displayDateDay, displayDateYear, displayDateHour,
097                            displayDateMinute, expirationDateMonth, expirationDateDay,
098                            expirationDateYear, expirationDateHour, expirationDateMinute,
099                            neverExpire, reviewDateMonth, reviewDateDay, reviewDateYear,
100                            reviewDateHour, reviewDateMinute, neverReview, indexable, false,
101                            null, null, null, articleURL, serviceContext);
102            }
103    
104            public JournalArticle copyArticle(
105                            long groupId, String oldArticleId, String newArticleId,
106                            boolean autoArticleId, double version)
107                    throws PortalException, SystemException {
108    
109                    JournalPermission.check(
110                            getPermissionChecker(), groupId, ActionKeys.ADD_ARTICLE);
111    
112                    return journalArticleLocalService.copyArticle(
113                            getUserId(), groupId, oldArticleId, newArticleId, autoArticleId,
114                            version);
115            }
116    
117            public void deleteArticle(
118                            long groupId, String articleId, double version, String articleURL,
119                            ServiceContext serviceContext)
120                    throws PortalException, SystemException {
121    
122                    JournalArticlePermission.check(
123                            getPermissionChecker(), groupId, articleId, version,
124                            ActionKeys.DELETE);
125    
126                    journalArticleLocalService.deleteArticle(
127                            groupId, articleId, version, articleURL, serviceContext);
128            }
129    
130            public void deleteArticle(
131                            long groupId, String articleId, String articleURL,
132                            ServiceContext serviceContext)
133                    throws PortalException, SystemException {
134    
135                    JournalArticlePermission.check(
136                            getPermissionChecker(), groupId, articleId, ActionKeys.DELETE);
137    
138                    journalArticleLocalService.deleteArticle(
139                            groupId, articleId, serviceContext);
140            }
141    
142            public JournalArticle expireArticle(
143                            long groupId, String articleId, double version, String articleURL,
144                            ServiceContext serviceContext)
145                    throws PortalException, SystemException {
146    
147                    JournalArticlePermission.check(
148                            getPermissionChecker(), groupId, articleId, version,
149                            ActionKeys.EXPIRE);
150    
151                    return journalArticleLocalService.expireArticle(
152                            getUserId(), groupId, articleId, version, articleURL,
153                            serviceContext);
154            }
155    
156            public void expireArticle(
157                            long groupId, String articleId, String articleURL,
158                            ServiceContext serviceContext)
159                    throws PortalException, SystemException {
160    
161                    JournalArticlePermission.check(
162                            getPermissionChecker(), groupId, articleId, ActionKeys.EXPIRE);
163    
164                    journalArticleLocalService.expireArticle(
165                            getUserId(), groupId, articleId, articleURL, serviceContext);
166            }
167    
168            public JournalArticle getArticle(long id)
169                    throws PortalException, SystemException {
170    
171                    JournalArticle article = journalArticleLocalService.getArticle(id);
172    
173                    JournalArticlePermission.check(
174                            getPermissionChecker(), article, ActionKeys.VIEW);
175    
176                    return article;
177            }
178    
179            public JournalArticle getArticle(long groupId, String articleId)
180                    throws PortalException, SystemException {
181    
182                    JournalArticlePermission.check(
183                            getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
184    
185                    return journalArticleLocalService.getArticle(groupId, articleId);
186            }
187    
188            public JournalArticle getArticle(
189                            long groupId, String articleId, double version)
190                    throws PortalException, SystemException {
191    
192                    JournalArticlePermission.check(
193                            getPermissionChecker(), groupId, articleId, version,
194                            ActionKeys.VIEW);
195    
196                    return journalArticleLocalService.getArticle(
197                            groupId, articleId, version);
198            }
199    
200            public JournalArticle getArticle(
201                            long groupId, String className, long classPK)
202                    throws PortalException, SystemException {
203    
204                    JournalArticle article = journalArticleLocalService.getArticle(
205                            groupId, className, classPK);
206    
207                    JournalArticlePermission.check(
208                            getPermissionChecker(), groupId, article.getArticleId(),
209                            article.getVersion(), ActionKeys.VIEW);
210    
211                    return article;
212            }
213    
214            public JournalArticle getArticleByUrlTitle(long groupId, String urlTitle)
215                    throws PortalException, SystemException {
216    
217                    JournalArticle article =
218                            journalArticleLocalService.getArticleByUrlTitle(groupId, urlTitle);
219    
220                    JournalArticlePermission.check(
221                            getPermissionChecker(), article, ActionKeys.VIEW);
222    
223                    return article;
224            }
225    
226            public String getArticleContent(
227                            long groupId, String articleId, double version, String languageId,
228                            ThemeDisplay themeDisplay)
229                    throws PortalException, SystemException {
230    
231                    JournalArticlePermission.check(
232                            getPermissionChecker(), groupId, articleId, version,
233                            ActionKeys.VIEW);
234    
235                    return journalArticleLocalService.getArticleContent(
236                            groupId, articleId, version, null, languageId, themeDisplay);
237            }
238    
239            public String getArticleContent(
240                            long groupId, String articleId, String languageId,
241                            ThemeDisplay themeDisplay)
242                    throws PortalException, SystemException {
243    
244                    JournalArticlePermission.check(
245                            getPermissionChecker(), groupId, articleId, ActionKeys.VIEW);
246    
247                    return journalArticleLocalService.getArticleContent(
248                            groupId, articleId, null, languageId, themeDisplay);
249            }
250    
251            public List<JournalArticle> getArticlesByLayoutUuid(
252                            long groupId, String layoutUuid)
253                    throws SystemException {
254    
255                    return journalArticlePersistence.filterFindByG_L(groupId, layoutUuid);
256            }
257    
258            public JournalArticle getLatestArticle(long resourcePrimKey)
259                    throws PortalException, SystemException {
260    
261                    JournalArticlePermission.check(
262                            getPermissionChecker(), resourcePrimKey, ActionKeys.VIEW);
263    
264                    return journalArticleLocalService.getLatestArticle(resourcePrimKey);
265            }
266    
267            public JournalArticle getLatestArticle(
268                            long groupId, String articleId, int status)
269                    throws PortalException, SystemException {
270    
271                    JournalArticlePermission.check(
272                            getPermissionChecker(), groupId, articleId, status,
273                            ActionKeys.VIEW);
274    
275                    return journalArticleLocalService.getLatestArticle(
276                            groupId, articleId, status);
277            }
278    
279            public JournalArticle getLatestArticle(
280                            long groupId, String className, long classPK)
281                    throws PortalException, SystemException {
282    
283                    JournalArticle article = journalArticleLocalService.getLatestArticle(
284                            groupId, className, classPK);
285    
286                    JournalArticlePermission.check(
287                            getPermissionChecker(), groupId, article.getArticleId(),
288                            article.getVersion(), ActionKeys.VIEW);
289    
290                    return article;
291            }
292    
293            public void removeArticleLocale(long companyId, String languageId)
294                    throws PortalException, SystemException {
295    
296                    for (JournalArticle article :
297                                    journalArticlePersistence.findByCompanyId(companyId)) {
298    
299                            removeArticleLocale(
300                                    article.getGroupId(), article.getArticleId(),
301                                    article.getVersion(), languageId);
302                    }
303            }
304    
305            public JournalArticle removeArticleLocale(
306                            long groupId, String articleId, double version, String languageId)
307                    throws PortalException, SystemException {
308    
309                    JournalArticlePermission.check(
310                            getPermissionChecker(), groupId, articleId, version,
311                            ActionKeys.UPDATE);
312    
313                    return journalArticleLocalService.removeArticleLocale(
314                            groupId, articleId, version, languageId);
315            }
316    
317            public List<JournalArticle> search(
318                            long companyId, long groupId, long classNameId, String keywords,
319                            Double version, String type, String structureId, String templateId,
320                            Date displayDateGT, Date displayDateLT, int status, Date reviewDate,
321                            int start, int end, OrderByComparator obc)
322                    throws SystemException {
323    
324                    return journalArticleFinder.filterFindByKeywords(
325                            companyId, groupId, classNameId, keywords, version, type,
326                            structureId, templateId, displayDateGT, displayDateLT, status,
327                            reviewDate, start, end, obc);
328            }
329    
330            public List<JournalArticle> search(
331                            long companyId, long groupId, long classNameId, String articleId,
332                            Double version, String title, String description, String content,
333                            String type, String structureId, String templateId,
334                            Date displayDateGT, Date displayDateLT, int status, Date reviewDate,
335                            boolean andOperator, int start, int end, OrderByComparator obc)
336                    throws SystemException {
337    
338                    return journalArticleFinder.filterFindByC_G_C_A_V_T_D_C_T_S_T_D_S_R(
339                            companyId, groupId, classNameId, articleId, version, title,
340                            description, content, type, structureId, templateId, displayDateGT,
341                            displayDateLT, status, reviewDate, andOperator, start, end, obc);
342            }
343    
344            public List<JournalArticle> search(
345                            long companyId, long groupId, long classNameId, String articleId,
346                            Double version, String title, String description, String content,
347                            String type, String[] structureIds, String[] templateIds,
348                            Date displayDateGT, Date displayDateLT, int status, Date reviewDate,
349                            boolean andOperator, int start, int end, OrderByComparator obc)
350                    throws SystemException {
351    
352                    return journalArticleFinder.filterFindByC_G_C_A_V_T_D_C_T_S_T_D_S_R(
353                            companyId, groupId, classNameId, articleId, version, title,
354                            description, content, type, structureIds, templateIds,
355                            displayDateGT, displayDateLT, status, reviewDate, andOperator,
356                            start, end, obc);
357            }
358    
359            public int searchCount(
360                            long companyId, long groupId, long classNameId, String keywords,
361                            Double version, String type, String structureId, String templateId,
362                            Date displayDateGT, Date displayDateLT, int status, Date reviewDate)
363                    throws SystemException {
364    
365                    return journalArticleFinder.filterCountByKeywords(
366                            companyId, groupId, classNameId, keywords, version, type,
367                            structureId, templateId, displayDateGT, displayDateLT, status,
368                            reviewDate);
369            }
370    
371            public int searchCount(
372                            long companyId, long groupId, long classNameId, String articleId,
373                            Double version, String title, String description, String content,
374                            String type, String structureId, String templateId,
375                            Date displayDateGT, Date displayDateLT, int status, Date reviewDate,
376                            boolean andOperator)
377                    throws SystemException {
378    
379                    return journalArticleFinder.filterCountByC_G_C_A_V_T_D_C_T_S_T_D_S_R(
380                            companyId, groupId, classNameId, articleId, version, title,
381                            description, content, type, structureId, templateId, displayDateGT,
382                            displayDateLT, status, reviewDate, andOperator);
383            }
384    
385            public int searchCount(
386                            long companyId, long groupId, long classNameId, String articleId,
387                            Double version, String title, String description, String content,
388                            String type, String[] structureIds, String[] templateIds,
389                            Date displayDateGT, Date displayDateLT, int status, Date reviewDate,
390                            boolean andOperator)
391                    throws SystemException {
392    
393                    return journalArticleFinder.filterCountByC_G_C_A_V_T_D_C_T_S_T_D_S_R(
394                            companyId, groupId, classNameId, articleId, version, title,
395                            description, content, type, structureIds, templateIds,
396                            displayDateGT, displayDateLT, status, reviewDate, andOperator);
397            }
398    
399            public void subscribe(long groupId)
400                    throws PortalException, SystemException {
401    
402                    JournalPermission.check(
403                            getPermissionChecker(), groupId, ActionKeys.SUBSCRIBE);
404    
405                    journalArticleLocalService.subscribe(getUserId(), groupId);
406            }
407    
408            public void unsubscribe(long groupId)
409                    throws PortalException, SystemException {
410    
411                    JournalPermission.check(
412                            getPermissionChecker(), groupId, ActionKeys.SUBSCRIBE);
413    
414                    journalArticleLocalService.unsubscribe(getUserId(), groupId);
415            }
416    
417            public JournalArticle updateArticle(
418                            long userId, long groupId, String articleId, double version,
419                            Map<Locale, String> titleMap, Map<Locale, String> descriptionMap,
420                            String content, String layoutUuid, ServiceContext serviceContext)
421                    throws PortalException, SystemException {
422    
423                    return journalArticleLocalService.updateArticle(
424                            userId, groupId, articleId, version, titleMap, descriptionMap,
425                            content, layoutUuid, serviceContext);
426            }
427    
428            public JournalArticle updateArticle(
429                            long groupId, String articleId, double version,
430                            Map<Locale, String> titleMap, Map<Locale, String> descriptionMap,
431                            String content, String type, String structureId, String templateId,
432                            String layoutUuid, int displayDateMonth, int displayDateDay,
433                            int displayDateYear, int displayDateHour, int displayDateMinute,
434                            int expirationDateMonth, int expirationDateDay,
435                            int expirationDateYear, int expirationDateHour,
436                            int expirationDateMinute, boolean neverExpire, int reviewDateMonth,
437                            int reviewDateDay, int reviewDateYear, int reviewDateHour,
438                            int reviewDateMinute, boolean neverReview, boolean indexable,
439                            boolean smallImage, String smallImageURL, File smallFile,
440                            Map<String, byte[]> images, String articleURL,
441                            ServiceContext serviceContext)
442                    throws PortalException, SystemException {
443    
444                    JournalArticlePermission.check(
445                            getPermissionChecker(), groupId, articleId, version,
446                            ActionKeys.UPDATE);
447    
448                    return journalArticleLocalService.updateArticle(
449                            getUserId(), groupId, articleId, version, titleMap, descriptionMap,
450                            content, type, structureId, templateId, layoutUuid,
451                            displayDateMonth, displayDateDay, displayDateYear, displayDateHour,
452                            displayDateMinute, expirationDateMonth, expirationDateDay,
453                            expirationDateYear, expirationDateHour, expirationDateMinute,
454                            neverExpire, reviewDateMonth, reviewDateDay, reviewDateYear,
455                            reviewDateHour, reviewDateMinute, neverReview, indexable,
456                            smallImage, smallImageURL, smallFile, images, articleURL,
457                            serviceContext);
458            }
459    
460            public JournalArticle updateArticle(
461                            long groupId, String articleId, double version, String content,
462                            ServiceContext serviceContext)
463                    throws PortalException, SystemException {
464    
465                    JournalArticlePermission.check(
466                            getPermissionChecker(), groupId, articleId, version,
467                            ActionKeys.UPDATE);
468    
469                    return journalArticleLocalService.updateArticle(
470                            getUserId(), groupId, articleId, version, content, serviceContext);
471            }
472    
473            public JournalArticle updateArticleTranslation(
474                            long groupId, String articleId, double version, Locale locale,
475                            String title, String description, String content)
476                    throws PortalException, SystemException {
477    
478                    JournalArticlePermission.check(
479                            getPermissionChecker(), groupId, articleId, version,
480                            ActionKeys.UPDATE);
481    
482                    return journalArticleLocalService.updateArticleTranslation(
483                            groupId, articleId, version, locale, title, description, content);
484            }
485    
486            public JournalArticle updateContent(
487                            long groupId, String articleId, double version, String content)
488                    throws PortalException, SystemException {
489    
490                    JournalArticlePermission.check(
491                            getPermissionChecker(), groupId, articleId, version,
492                            ActionKeys.UPDATE);
493    
494                    return journalArticleLocalService.updateContent(
495                            groupId, articleId, version, content);
496            }
497    
498    }