001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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> getArticlesByArticleId(
252                            long groupId, String articleId, int start, int end,
253                            OrderByComparator obc)
254                    throws SystemException {
255    
256                    return journalArticlePersistence.filterFindByG_A(
257                            groupId, articleId, start, end, obc);
258            }
259    
260            public List<JournalArticle> getArticlesByLayoutUuid(
261                            long groupId, String layoutUuid)
262                    throws SystemException {
263    
264                    return journalArticlePersistence.filterFindByG_L(groupId, layoutUuid);
265            }
266    
267            public int getArticlesCountByArticleId(long groupId, String articleId)
268                    throws SystemException {
269    
270                    return journalArticlePersistence.filterCountByG_A(groupId, articleId);
271            }
272    
273            public JournalArticle getDisplayArticleByUrlTitle(
274                            long groupId, String urlTitle)
275                    throws PortalException, SystemException {
276    
277                    JournalArticle article =
278                            journalArticleLocalService.getDisplayArticleByUrlTitle(
279                                    groupId, urlTitle);
280    
281                    JournalArticlePermission.check(
282                            getPermissionChecker(), article, ActionKeys.VIEW);
283    
284                    return article;
285            }
286    
287            public JournalArticle getLatestArticle(long resourcePrimKey)
288                    throws PortalException, SystemException {
289    
290                    JournalArticlePermission.check(
291                            getPermissionChecker(), resourcePrimKey, ActionKeys.VIEW);
292    
293                    return journalArticleLocalService.getLatestArticle(resourcePrimKey);
294            }
295    
296            public JournalArticle getLatestArticle(
297                            long groupId, String articleId, int status)
298                    throws PortalException, SystemException {
299    
300                    JournalArticlePermission.check(
301                            getPermissionChecker(), groupId, articleId, status,
302                            ActionKeys.VIEW);
303    
304                    return journalArticleLocalService.getLatestArticle(
305                            groupId, articleId, status);
306            }
307    
308            public JournalArticle getLatestArticle(
309                            long groupId, String className, long classPK)
310                    throws PortalException, SystemException {
311    
312                    JournalArticle article = journalArticleLocalService.getLatestArticle(
313                            groupId, className, classPK);
314    
315                    JournalArticlePermission.check(
316                            getPermissionChecker(), groupId, article.getArticleId(),
317                            article.getVersion(), ActionKeys.VIEW);
318    
319                    return article;
320            }
321    
322            public void removeArticleLocale(long companyId, String languageId)
323                    throws PortalException, SystemException {
324    
325                    for (JournalArticle article :
326                                    journalArticlePersistence.findByCompanyId(companyId)) {
327    
328                            removeArticleLocale(
329                                    article.getGroupId(), article.getArticleId(),
330                                    article.getVersion(), languageId);
331                    }
332            }
333    
334            public JournalArticle removeArticleLocale(
335                            long groupId, String articleId, double version, String languageId)
336                    throws PortalException, SystemException {
337    
338                    JournalArticlePermission.check(
339                            getPermissionChecker(), groupId, articleId, version,
340                            ActionKeys.UPDATE);
341    
342                    return journalArticleLocalService.removeArticleLocale(
343                            groupId, articleId, version, languageId);
344            }
345    
346            public List<JournalArticle> search(
347                            long companyId, long groupId, long classNameId, String keywords,
348                            Double version, String type, String structureId, String templateId,
349                            Date displayDateGT, Date displayDateLT, int status, Date reviewDate,
350                            int start, int end, OrderByComparator obc)
351                    throws SystemException {
352    
353                    return journalArticleFinder.filterFindByKeywords(
354                            companyId, groupId, classNameId, keywords, version, type,
355                            structureId, templateId, displayDateGT, displayDateLT, status,
356                            reviewDate, start, end, obc);
357            }
358    
359            public List<JournalArticle> search(
360                            long companyId, long groupId, long classNameId, String articleId,
361                            Double version, String title, String description, String content,
362                            String type, String structureId, String templateId,
363                            Date displayDateGT, Date displayDateLT, int status, Date reviewDate,
364                            boolean andOperator, int start, int end, OrderByComparator obc)
365                    throws SystemException {
366    
367                    return journalArticleFinder.filterFindByC_G_C_A_V_T_D_C_T_S_T_D_S_R(
368                            companyId, groupId, classNameId, articleId, version, title,
369                            description, content, type, structureId, templateId, displayDateGT,
370                            displayDateLT, status, reviewDate, andOperator, start, end, obc);
371            }
372    
373            public List<JournalArticle> search(
374                            long companyId, long groupId, long classNameId, String articleId,
375                            Double version, String title, String description, String content,
376                            String type, String[] structureIds, String[] templateIds,
377                            Date displayDateGT, Date displayDateLT, int status, Date reviewDate,
378                            boolean andOperator, int start, int end, OrderByComparator obc)
379                    throws SystemException {
380    
381                    return journalArticleFinder.filterFindByC_G_C_A_V_T_D_C_T_S_T_D_S_R(
382                            companyId, groupId, classNameId, articleId, version, title,
383                            description, content, type, structureIds, templateIds,
384                            displayDateGT, displayDateLT, status, reviewDate, andOperator,
385                            start, end, obc);
386            }
387    
388            public int searchCount(
389                            long companyId, long groupId, long classNameId, String keywords,
390                            Double version, String type, String structureId, String templateId,
391                            Date displayDateGT, Date displayDateLT, int status, Date reviewDate)
392                    throws SystemException {
393    
394                    return journalArticleFinder.filterCountByKeywords(
395                            companyId, groupId, classNameId, keywords, version, type,
396                            structureId, templateId, displayDateGT, displayDateLT, status,
397                            reviewDate);
398            }
399    
400            public int searchCount(
401                            long companyId, long groupId, long classNameId, String articleId,
402                            Double version, String title, String description, String content,
403                            String type, String structureId, String templateId,
404                            Date displayDateGT, Date displayDateLT, int status, Date reviewDate,
405                            boolean andOperator)
406                    throws SystemException {
407    
408                    return journalArticleFinder.filterCountByC_G_C_A_V_T_D_C_T_S_T_D_S_R(
409                            companyId, groupId, classNameId, articleId, version, title,
410                            description, content, type, structureId, templateId, displayDateGT,
411                            displayDateLT, status, reviewDate, andOperator);
412            }
413    
414            public int searchCount(
415                            long companyId, long groupId, long classNameId, String articleId,
416                            Double version, String title, String description, String content,
417                            String type, String[] structureIds, String[] templateIds,
418                            Date displayDateGT, Date displayDateLT, int status, Date reviewDate,
419                            boolean andOperator)
420                    throws SystemException {
421    
422                    return journalArticleFinder.filterCountByC_G_C_A_V_T_D_C_T_S_T_D_S_R(
423                            companyId, groupId, classNameId, articleId, version, title,
424                            description, content, type, structureIds, templateIds,
425                            displayDateGT, displayDateLT, status, reviewDate, andOperator);
426            }
427    
428            public void subscribe(long groupId)
429                    throws PortalException, SystemException {
430    
431                    JournalPermission.check(
432                            getPermissionChecker(), groupId, ActionKeys.SUBSCRIBE);
433    
434                    journalArticleLocalService.subscribe(getUserId(), groupId);
435            }
436    
437            public void unsubscribe(long groupId)
438                    throws PortalException, SystemException {
439    
440                    JournalPermission.check(
441                            getPermissionChecker(), groupId, ActionKeys.SUBSCRIBE);
442    
443                    journalArticleLocalService.unsubscribe(getUserId(), groupId);
444            }
445    
446            public JournalArticle updateArticle(
447                            long userId, long groupId, String articleId, double version,
448                            Map<Locale, String> titleMap, Map<Locale, String> descriptionMap,
449                            String content, String layoutUuid, ServiceContext serviceContext)
450                    throws PortalException, SystemException {
451    
452                    return journalArticleLocalService.updateArticle(
453                            userId, groupId, articleId, version, titleMap, descriptionMap,
454                            content, layoutUuid, serviceContext);
455            }
456    
457            public JournalArticle updateArticle(
458                            long groupId, String articleId, double version,
459                            Map<Locale, String> titleMap, Map<Locale, String> descriptionMap,
460                            String content, String type, String structureId, String templateId,
461                            String layoutUuid, int displayDateMonth, int displayDateDay,
462                            int displayDateYear, int displayDateHour, int displayDateMinute,
463                            int expirationDateMonth, int expirationDateDay,
464                            int expirationDateYear, int expirationDateHour,
465                            int expirationDateMinute, boolean neverExpire, int reviewDateMonth,
466                            int reviewDateDay, int reviewDateYear, int reviewDateHour,
467                            int reviewDateMinute, boolean neverReview, boolean indexable,
468                            boolean smallImage, String smallImageURL, File smallFile,
469                            Map<String, byte[]> images, String articleURL,
470                            ServiceContext serviceContext)
471                    throws PortalException, SystemException {
472    
473                    JournalArticlePermission.check(
474                            getPermissionChecker(), groupId, articleId, version,
475                            ActionKeys.UPDATE);
476    
477                    return journalArticleLocalService.updateArticle(
478                            getUserId(), groupId, articleId, version, titleMap, descriptionMap,
479                            content, type, structureId, templateId, layoutUuid,
480                            displayDateMonth, displayDateDay, displayDateYear, displayDateHour,
481                            displayDateMinute, expirationDateMonth, expirationDateDay,
482                            expirationDateYear, expirationDateHour, expirationDateMinute,
483                            neverExpire, reviewDateMonth, reviewDateDay, reviewDateYear,
484                            reviewDateHour, reviewDateMinute, neverReview, indexable,
485                            smallImage, smallImageURL, smallFile, images, articleURL,
486                            serviceContext);
487            }
488    
489            public JournalArticle updateArticle(
490                            long groupId, String articleId, double version, String content,
491                            ServiceContext serviceContext)
492                    throws PortalException, SystemException {
493    
494                    JournalArticlePermission.check(
495                            getPermissionChecker(), groupId, articleId, version,
496                            ActionKeys.UPDATE);
497    
498                    return journalArticleLocalService.updateArticle(
499                            getUserId(), groupId, articleId, version, content, serviceContext);
500            }
501    
502            /**
503             * @deprecated {@link #updateArticleTranslation(long, String, double,
504             *             Locale, String, String, String, Map, ServiceContext)}
505             */
506            public JournalArticle updateArticleTranslation(
507                            long groupId, String articleId, double version, Locale locale,
508                            String title, String description, String content,
509                            Map<String, byte[]> images)
510                    throws PortalException, SystemException {
511    
512                    return updateArticleTranslation(
513                            groupId, articleId, version, locale, title, description, content,
514                            images, null);
515            }
516    
517            public JournalArticle updateArticleTranslation(
518                            long groupId, String articleId, double version, Locale locale,
519                            String title, String description, String content,
520                            Map<String, byte[]> images, ServiceContext serviceContext)
521                    throws PortalException, SystemException {
522    
523                    JournalArticlePermission.check(
524                            getPermissionChecker(), groupId, articleId, version,
525                            ActionKeys.UPDATE);
526    
527                    return journalArticleLocalService.updateArticleTranslation(
528                            groupId, articleId, version, locale, title, description, content,
529                            images, serviceContext);
530            }
531    
532            public JournalArticle updateContent(
533                            long groupId, String articleId, double version, String content)
534                    throws PortalException, SystemException {
535    
536                    JournalArticlePermission.check(
537                            getPermissionChecker(), groupId, articleId, version,
538                            ActionKeys.UPDATE);
539    
540                    return journalArticleLocalService.updateContent(
541                            groupId, articleId, version, content);
542            }
543    
544    }