001    /**
002     * Copyright (c) 2000-present 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.blogs.service.impl;
016    
017    import com.liferay.portal.kernel.bean.BeanReference;
018    import com.liferay.portal.kernel.comment.CommentManager;
019    import com.liferay.portal.kernel.dao.orm.QueryDefinition;
020    import com.liferay.portal.kernel.exception.PortalException;
021    import com.liferay.portal.kernel.json.JSONFactoryUtil;
022    import com.liferay.portal.kernel.json.JSONObject;
023    import com.liferay.portal.kernel.log.Log;
024    import com.liferay.portal.kernel.log.LogFactoryUtil;
025    import com.liferay.portal.kernel.notifications.UserNotificationDefinition;
026    import com.liferay.portal.kernel.repository.model.FileEntry;
027    import com.liferay.portal.kernel.repository.model.Folder;
028    import com.liferay.portal.kernel.search.Indexable;
029    import com.liferay.portal.kernel.search.IndexableType;
030    import com.liferay.portal.kernel.search.Indexer;
031    import com.liferay.portal.kernel.search.IndexerRegistryUtil;
032    import com.liferay.portal.kernel.servlet.taglib.ui.ImageSelector;
033    import com.liferay.portal.kernel.settings.LocalizedValuesMap;
034    import com.liferay.portal.kernel.systemevent.SystemEvent;
035    import com.liferay.portal.kernel.util.ArrayUtil;
036    import com.liferay.portal.kernel.util.Constants;
037    import com.liferay.portal.kernel.util.ContentTypes;
038    import com.liferay.portal.kernel.util.GetterUtil;
039    import com.liferay.portal.kernel.util.HtmlUtil;
040    import com.liferay.portal.kernel.util.HttpUtil;
041    import com.liferay.portal.kernel.util.MimeTypesUtil;
042    import com.liferay.portal.kernel.util.OrderByComparator;
043    import com.liferay.portal.kernel.util.ParamUtil;
044    import com.liferay.portal.kernel.util.PropsKeys;
045    import com.liferay.portal.kernel.util.SetUtil;
046    import com.liferay.portal.kernel.util.StringBundler;
047    import com.liferay.portal.kernel.util.StringPool;
048    import com.liferay.portal.kernel.util.StringUtil;
049    import com.liferay.portal.kernel.util.TempFileEntryUtil;
050    import com.liferay.portal.kernel.util.Time;
051    import com.liferay.portal.kernel.util.Validator;
052    import com.liferay.portal.kernel.util.WebKeys;
053    import com.liferay.portal.kernel.workflow.WorkflowConstants;
054    import com.liferay.portal.kernel.workflow.WorkflowHandlerRegistryUtil;
055    import com.liferay.portal.model.Group;
056    import com.liferay.portal.model.ResourceConstants;
057    import com.liferay.portal.model.SystemEventConstants;
058    import com.liferay.portal.model.User;
059    import com.liferay.portal.portletfilerepository.PortletFileRepositoryUtil;
060    import com.liferay.portal.service.ServiceContext;
061    import com.liferay.portal.theme.ThemeDisplay;
062    import com.liferay.portal.util.Portal;
063    import com.liferay.portal.util.PortalUtil;
064    import com.liferay.portal.util.PortletKeys;
065    import com.liferay.portal.util.PrefsPropsUtil;
066    import com.liferay.portal.util.PropsValues;
067    import com.liferay.portal.util.SubscriptionSender;
068    import com.liferay.portlet.PortletURLFactoryUtil;
069    import com.liferay.portlet.asset.model.AssetEntry;
070    import com.liferay.portlet.asset.model.AssetLinkConstants;
071    import com.liferay.portlet.blogs.BlogsSettings;
072    import com.liferay.portlet.blogs.EntryContentException;
073    import com.liferay.portlet.blogs.EntryDisplayDateException;
074    import com.liferay.portlet.blogs.EntrySmallImageNameException;
075    import com.liferay.portlet.blogs.EntrySmallImageSizeException;
076    import com.liferay.portlet.blogs.EntryTitleException;
077    import com.liferay.portlet.blogs.model.BlogsEntry;
078    import com.liferay.portlet.blogs.service.base.BlogsEntryLocalServiceBaseImpl;
079    import com.liferay.portlet.blogs.social.BlogsActivityKeys;
080    import com.liferay.portlet.blogs.util.BlogsUtil;
081    import com.liferay.portlet.blogs.util.LinkbackProducerUtil;
082    import com.liferay.portlet.blogs.util.comparator.EntryDisplayDateComparator;
083    import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
084    import com.liferay.portlet.social.model.SocialActivityConstants;
085    import com.liferay.portlet.trash.model.TrashEntry;
086    
087    import java.io.IOException;
088    import java.io.InputStream;
089    import java.io.Serializable;
090    
091    import java.util.Date;
092    import java.util.HashMap;
093    import java.util.HashSet;
094    import java.util.List;
095    import java.util.Map;
096    import java.util.Set;
097    
098    import javax.portlet.PortletRequest;
099    import javax.portlet.PortletURL;
100    
101    import javax.servlet.http.HttpServletRequest;
102    
103    import net.htmlparser.jericho.Source;
104    import net.htmlparser.jericho.StartTag;
105    
106    /**
107     * Provides the local service for accessing, adding, checking, deleting,
108     * subscription handling of, trash handling of, and updating blog entries.
109     *
110     * @author Brian Wing Shun Chan
111     * @author Wilson S. Man
112     * @author Raymond Aug??
113     * @author Thiago Moreira
114     * @author Juan Fern??ndez
115     * @author Zsolt Berentey
116     */
117    public class BlogsEntryLocalServiceImpl extends BlogsEntryLocalServiceBaseImpl {
118    
119            /**
120             * @deprecated As of 7.0.0, replaced by {@link #addEntry(long, String,
121             *             String, String, String, int, int, int, int, int, boolean,
122             *             boolean, String[], boolean, String, String, InputStream,
123             *             ServiceContext)}
124             */
125            @Deprecated
126            @Override
127            public BlogsEntry addEntry(
128                            long userId, String title, String description, String content,
129                            int displayDateMonth, int displayDateDay, int displayDateYear,
130                            int displayDateHour, int displayDateMinute, boolean allowPingbacks,
131                            boolean allowTrackbacks, String[] trackbacks, boolean smallImage,
132                            String smallImageURL, String smallImageFileName,
133                            InputStream smallImageInputStream, ServiceContext serviceContext)
134                    throws PortalException {
135    
136                    ImageSelector imageSelector = null;
137    
138                    if (smallImage && Validator.isNotNull(smallImageFileName) &&
139                            (smallImageInputStream != null)) {
140    
141                            FileEntry fileEntry = TempFileEntryUtil.addTempFileEntry(
142                                    serviceContext.getScopeGroupId(), userId,
143                                    BlogsEntry.class.getName(), smallImageFileName,
144                                    smallImageInputStream,
145                                    MimeTypesUtil.getContentType(smallImageFileName));
146    
147                            imageSelector = new ImageSelector(
148                                    fileEntry.getFileEntryId(), smallImageURL);
149                    }
150    
151                    return addEntry(
152                            userId, title, StringPool.BLANK, description, content,
153                            displayDateMonth, displayDateDay, displayDateYear, displayDateHour,
154                            displayDateMinute, allowPingbacks, allowTrackbacks, trackbacks,
155                            imageSelector, serviceContext);
156            }
157    
158            @Indexable(type = IndexableType.REINDEX)
159            @Override
160            public BlogsEntry addEntry(
161                            long userId, String title, String subtitle, String description,
162                            String content, int displayDateMonth, int displayDateDay,
163                            int displayDateYear, int displayDateHour, int displayDateMinute,
164                            boolean allowPingbacks, boolean allowTrackbacks,
165                            String[] trackbacks, ImageSelector imageSelector,
166                            ServiceContext serviceContext)
167                    throws PortalException {
168    
169                    // Entry
170    
171                    User user = userPersistence.findByPrimaryKey(userId);
172                    long groupId = serviceContext.getScopeGroupId();
173                    Date displayDate = PortalUtil.getDate(
174                            displayDateMonth, displayDateDay, displayDateYear, displayDateHour,
175                            displayDateMinute, user.getTimeZone(),
176                            EntryDisplayDateException.class);
177    
178                    boolean smallImage = false;
179                    long smallImageFileEntryId = 0;
180                    String smallImageURL = null;
181    
182                    if (imageSelector != null) {
183                            smallImage = !imageSelector.isRemoveSmallImage();
184                            smallImageFileEntryId = imageSelector.getImageId();
185                            smallImageURL = imageSelector.getImageURL();
186                    }
187    
188                    long entryId = counterLocalService.increment();
189    
190                    if (smallImageFileEntryId != 0) {
191                            FileEntry tempFileEntry =
192                                    PortletFileRepositoryUtil.getPortletFileEntry(
193                                            smallImageFileEntryId);
194    
195                            Folder folder = PortletFileRepositoryUtil.addPortletFolder(
196                                    groupId, userId, PortletKeys.BLOGS,
197                                    DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
198                                    String.valueOf(entryId), serviceContext);
199    
200                            FileEntry fileEntry =
201                                    PortletFileRepositoryUtil.addPortletFileEntry(
202                                            groupId, userId, BlogsEntry.class.getName(), entryId,
203                                            PortletKeys.BLOGS, folder.getFolderId(),
204                                            tempFileEntry.getContentStream(), tempFileEntry.getTitle(),
205                                            tempFileEntry.getMimeType(), false);
206    
207                            smallImageFileEntryId = fileEntry.getFileEntryId();
208    
209                            PortletFileRepositoryUtil.deletePortletFileEntry(
210                                    tempFileEntry.getFileEntryId());
211                    }
212    
213                    Date now = new Date();
214    
215                    validate(title, content, smallImageFileEntryId);
216    
217                    BlogsEntry entry = blogsEntryPersistence.create(entryId);
218    
219                    entry.setUuid(serviceContext.getUuid());
220                    entry.setGroupId(groupId);
221                    entry.setCompanyId(user.getCompanyId());
222                    entry.setUserId(user.getUserId());
223                    entry.setUserName(user.getFullName());
224                    entry.setCreateDate(serviceContext.getCreateDate(now));
225                    entry.setModifiedDate(serviceContext.getModifiedDate(now));
226                    entry.setTitle(title);
227                    entry.setSubtitle(subtitle);
228                    entry.setUrlTitle(
229                            getUniqueUrlTitle(entryId, title, null, serviceContext));
230                    entry.setDescription(description);
231                    entry.setContent(content);
232                    entry.setDisplayDate(displayDate);
233                    entry.setAllowPingbacks(allowPingbacks);
234                    entry.setAllowTrackbacks(allowTrackbacks);
235                    entry.setSmallImage(smallImage);
236                    entry.setSmallImageFileEntryId(smallImageFileEntryId);
237                    entry.setSmallImageURL(smallImageURL);
238                    entry.setStatus(WorkflowConstants.STATUS_DRAFT);
239                    entry.setStatusByUserId(userId);
240                    entry.setStatusDate(serviceContext.getModifiedDate(now));
241                    entry.setExpandoBridgeAttributes(serviceContext);
242    
243                    blogsEntryPersistence.update(entry);
244    
245                    // Resources
246    
247                    if (serviceContext.isAddGroupPermissions() ||
248                            serviceContext.isAddGuestPermissions()) {
249    
250                            addEntryResources(
251                                    entry, serviceContext.isAddGroupPermissions(),
252                                    serviceContext.isAddGuestPermissions());
253                    }
254                    else {
255                            addEntryResources(
256                                    entry, serviceContext.getGroupPermissions(),
257                                    serviceContext.getGuestPermissions());
258                    }
259    
260                    // Asset
261    
262                    updateAsset(
263                            userId, entry, serviceContext.getAssetCategoryIds(),
264                            serviceContext.getAssetTagNames(),
265                            serviceContext.getAssetLinkEntryIds());
266    
267                    // Comments
268    
269                    addDiscussion(entry, userId, groupId);
270    
271                    // Workflow
272    
273                    if (ArrayUtil.isNotEmpty(trackbacks)) {
274                            serviceContext.setAttribute("trackbacks", trackbacks);
275                    }
276                    else {
277                            serviceContext.setAttribute("trackbacks", null);
278                    }
279    
280                    return startWorkflowInstance(userId, entry, serviceContext);
281            }
282    
283            @Override
284            public void addEntryResources(
285                            BlogsEntry entry, boolean addGroupPermissions,
286                            boolean addGuestPermissions)
287                    throws PortalException {
288    
289                    resourceLocalService.addResources(
290                            entry.getCompanyId(), entry.getGroupId(), entry.getUserId(),
291                            BlogsEntry.class.getName(), entry.getEntryId(), false,
292                            addGroupPermissions, addGuestPermissions);
293            }
294    
295            @Override
296            public void addEntryResources(
297                            BlogsEntry entry, String[] groupPermissions,
298                            String[] guestPermissions)
299                    throws PortalException {
300    
301                    resourceLocalService.addModelResources(
302                            entry.getCompanyId(), entry.getGroupId(), entry.getUserId(),
303                            BlogsEntry.class.getName(), entry.getEntryId(), groupPermissions,
304                            guestPermissions);
305            }
306    
307            @Override
308            public void addEntryResources(
309                            long entryId, boolean addGroupPermissions,
310                            boolean addGuestPermissions)
311                    throws PortalException {
312    
313                    BlogsEntry entry = blogsEntryPersistence.findByPrimaryKey(entryId);
314    
315                    addEntryResources(entry, addGroupPermissions, addGuestPermissions);
316            }
317    
318            @Override
319            public void addEntryResources(
320                            long entryId, String[] groupPermissions, String[] guestPermissions)
321                    throws PortalException {
322    
323                    BlogsEntry entry = blogsEntryPersistence.findByPrimaryKey(entryId);
324    
325                    addEntryResources(entry, groupPermissions, guestPermissions);
326            }
327    
328            @Override
329            public void checkEntries() throws PortalException {
330                    Date now = new Date();
331    
332                    int count = blogsEntryPersistence.countByLtD_S(
333                            now, WorkflowConstants.STATUS_SCHEDULED);
334    
335                    if (count == 0) {
336                            return;
337                    }
338    
339                    List<BlogsEntry> entries = blogsEntryPersistence.findByLtD_S(
340                            now, WorkflowConstants.STATUS_SCHEDULED);
341    
342                    for (BlogsEntry entry : entries) {
343                            ServiceContext serviceContext = new ServiceContext();
344    
345                            String[] trackbacks = StringUtil.split(entry.getTrackbacks());
346    
347                            serviceContext.setAttribute("trackbacks", trackbacks);
348    
349                            serviceContext.setCommand(Constants.UPDATE);
350    
351                            String layoutFullURL = PortalUtil.getLayoutFullURL(
352                                    entry.getGroupId(), PortletKeys.BLOGS);
353    
354                            serviceContext.setLayoutFullURL(layoutFullURL);
355    
356                            serviceContext.setScopeGroupId(entry.getGroupId());
357    
358                            blogsEntryLocalService.updateStatus(
359                                    entry.getStatusByUserId(), entry.getEntryId(),
360                                    WorkflowConstants.STATUS_APPROVED, serviceContext,
361                                    new HashMap<String, Serializable>());
362                    }
363            }
364    
365            @Override
366            public void deleteEntries(long groupId) throws PortalException {
367                    for (BlogsEntry entry : blogsEntryPersistence.findByGroupId(groupId)) {
368                            blogsEntryLocalService.deleteEntry(entry);
369                    }
370            }
371    
372            @Indexable(type = IndexableType.DELETE)
373            @Override
374            @SystemEvent(type = SystemEventConstants.TYPE_DELETE)
375            public BlogsEntry deleteEntry(BlogsEntry entry) throws PortalException {
376    
377                    // Entry
378    
379                    blogsEntryPersistence.remove(entry);
380    
381                    // Resources
382    
383                    resourceLocalService.deleteResource(
384                            entry.getCompanyId(), BlogsEntry.class.getName(),
385                            ResourceConstants.SCOPE_INDIVIDUAL, entry.getEntryId());
386    
387                    // Image
388    
389                    imageLocalService.deleteImage(entry.getSmallImageId());
390    
391                    // Portlet file repository
392    
393                    long smallImageFolderId = entry.getSmallImageFolderId();
394    
395                    if (smallImageFolderId != 0) {
396                            PortletFileRepositoryUtil.deletePortletFolder(smallImageFolderId);
397                    }
398    
399                    // Subscriptions
400    
401                    subscriptionLocalService.deleteSubscriptions(
402                            entry.getCompanyId(), BlogsEntry.class.getName(),
403                            entry.getEntryId());
404    
405                    // Statistics
406    
407                    blogsStatsUserLocalService.updateStatsUser(
408                            entry.getGroupId(), entry.getUserId(), entry.getDisplayDate());
409    
410                    // Asset
411    
412                    assetEntryLocalService.deleteEntry(
413                            BlogsEntry.class.getName(), entry.getEntryId());
414    
415                    // Comment
416    
417                    deleteDiscussion(entry);
418    
419                    // Expando
420    
421                    expandoRowLocalService.deleteRows(entry.getEntryId());
422    
423                    // Ratings
424    
425                    ratingsStatsLocalService.deleteStats(
426                            BlogsEntry.class.getName(), entry.getEntryId());
427    
428                    // Trash
429    
430                    trashEntryLocalService.deleteEntry(
431                            BlogsEntry.class.getName(), entry.getEntryId());
432    
433                    // Indexer
434    
435                    Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(
436                            BlogsEntry.class);
437    
438                    indexer.delete(entry);
439    
440                    // Workflow
441    
442                    workflowInstanceLinkLocalService.deleteWorkflowInstanceLinks(
443                            entry.getCompanyId(), entry.getGroupId(),
444                            BlogsEntry.class.getName(), entry.getEntryId());
445    
446                    return entry;
447            }
448    
449            @Override
450            public void deleteEntry(long entryId) throws PortalException {
451                    BlogsEntry entry = blogsEntryPersistence.findByPrimaryKey(entryId);
452    
453                    blogsEntryLocalService.deleteEntry(entry);
454            }
455    
456            /**
457             * @deprecated As of 6.2.0, replaced by {@link #getCompanyEntries(long,
458             *             Date, QueryDefinition)}
459             */
460            @Deprecated
461            @Override
462            public List<BlogsEntry> getCompanyEntries(
463                    long companyId, Date displayDate, int status, int start, int end) {
464    
465                    QueryDefinition<BlogsEntry> queryDefinition =
466                            new QueryDefinition<BlogsEntry>(status, start, end, null);
467    
468                    return getCompanyEntries(companyId, displayDate, queryDefinition);
469            }
470    
471            /**
472             * @deprecated As of 6.2.0, replaced by {@link #getCompanyEntries(long,
473             *             Date, QueryDefinition)}
474             */
475            @Deprecated
476            @Override
477            public List<BlogsEntry> getCompanyEntries(
478                    long companyId, Date displayDate, int status, int start, int end,
479                    OrderByComparator<BlogsEntry> obc) {
480    
481                    QueryDefinition<BlogsEntry> queryDefinition =
482                            new QueryDefinition<BlogsEntry>(status, start, end, obc);
483    
484                    return getCompanyEntries(companyId, displayDate, queryDefinition);
485            }
486    
487            @Override
488            public List<BlogsEntry> getCompanyEntries(
489                    long companyId, Date displayDate,
490                    QueryDefinition<BlogsEntry> queryDefinition) {
491    
492                    if (queryDefinition.isExcludeStatus()) {
493                            return blogsEntryPersistence.findByC_LtD_NotS(
494                                    companyId, displayDate, queryDefinition.getStatus(),
495                                    queryDefinition.getStart(), queryDefinition.getEnd(),
496                                    queryDefinition.getOrderByComparator());
497                    }
498                    else {
499                            return blogsEntryPersistence.findByC_LtD_S(
500                                    companyId, displayDate, queryDefinition.getStatus(),
501                                    queryDefinition.getStart(), queryDefinition.getEnd(),
502                                    queryDefinition.getOrderByComparator());
503                    }
504            }
505    
506            /**
507             * @deprecated As of 6.2.0, replaced by {@link #getCompanyEntriesCount(long,
508             *             Date, QueryDefinition)}
509             */
510            @Deprecated
511            @Override
512            public int getCompanyEntriesCount(
513                    long companyId, Date displayDate, int status) {
514    
515                    QueryDefinition<BlogsEntry> queryDefinition =
516                            new QueryDefinition<BlogsEntry>(status);
517    
518                    return getCompanyEntriesCount(companyId, displayDate, queryDefinition);
519            }
520    
521            @Override
522            public int getCompanyEntriesCount(
523                    long companyId, Date displayDate,
524                    QueryDefinition<BlogsEntry> queryDefinition) {
525    
526                    if (queryDefinition.isExcludeStatus()) {
527                            return blogsEntryPersistence.countByC_LtD_NotS(
528                                    companyId, displayDate, queryDefinition.getStatus());
529                    }
530                    else {
531                            return blogsEntryPersistence.countByC_LtD_S(
532                                    companyId, displayDate, queryDefinition.getStatus());
533                    }
534            }
535    
536            @Override
537            public BlogsEntry[] getEntriesPrevAndNext(long entryId)
538                    throws PortalException {
539    
540                    BlogsEntry entry = blogsEntryPersistence.findByPrimaryKey(entryId);
541    
542                    return blogsEntryPersistence.findByG_S_PrevAndNext(
543                            entry.getEntryId(), entry.getGroupId(),
544                            WorkflowConstants.STATUS_APPROVED,
545                            new EntryDisplayDateComparator(true));
546            }
547    
548            @Override
549            public BlogsEntry getEntry(long entryId) throws PortalException {
550                    return blogsEntryPersistence.findByPrimaryKey(entryId);
551            }
552    
553            @Override
554            public BlogsEntry getEntry(long groupId, String urlTitle)
555                    throws PortalException {
556    
557                    return blogsEntryPersistence.findByG_UT(groupId, urlTitle);
558            }
559    
560            /**
561             * @deprecated As of 6.2.0, replaced by {@link #getGroupEntries(long, Date,
562             *             QueryDefinition)}
563             */
564            @Deprecated
565            @Override
566            public List<BlogsEntry> getGroupEntries(
567                    long groupId, Date displayDate, int status, int start, int end) {
568    
569                    QueryDefinition<BlogsEntry> queryDefinition =
570                            new QueryDefinition<BlogsEntry>(status, start, end, null);
571    
572                    return getGroupEntries(groupId, displayDate, queryDefinition);
573            }
574    
575            /**
576             * @deprecated As of 6.2.0, replaced by {@link #getGroupEntries(long, Date,
577             *             QueryDefinition)}
578             */
579            @Deprecated
580            @Override
581            public List<BlogsEntry> getGroupEntries(
582                    long groupId, Date displayDate, int status, int start, int end,
583                    OrderByComparator<BlogsEntry> obc) {
584    
585                    QueryDefinition<BlogsEntry> queryDefinition =
586                            new QueryDefinition<BlogsEntry>(status, start, end, obc);
587    
588                    return getGroupEntries(groupId, displayDate, queryDefinition);
589            }
590    
591            @Override
592            public List<BlogsEntry> getGroupEntries(
593                    long groupId, Date displayDate,
594                    QueryDefinition<BlogsEntry> queryDefinition) {
595    
596                    if (queryDefinition.isExcludeStatus()) {
597                            return blogsEntryPersistence.findByG_LtD_NotS(
598                                    groupId, displayDate, queryDefinition.getStatus(),
599                                    queryDefinition.getStart(), queryDefinition.getEnd(),
600                                    queryDefinition.getOrderByComparator());
601                    }
602                    else {
603                            return blogsEntryPersistence.findByG_LtD_S(
604                                    groupId, displayDate, queryDefinition.getStatus(),
605                                    queryDefinition.getStart(), queryDefinition.getEnd(),
606                                    queryDefinition.getOrderByComparator());
607                    }
608            }
609    
610            /**
611             * @deprecated As of 6.2.0, replaced by {@link #getGroupEntries(long,
612             *             QueryDefinition)}
613             */
614            @Deprecated
615            @Override
616            public List<BlogsEntry> getGroupEntries(
617                    long groupId, int status, int start, int end) {
618    
619                    QueryDefinition<BlogsEntry> queryDefinition =
620                            new QueryDefinition<BlogsEntry>(status, start, end, null);
621    
622                    return getGroupEntries(groupId, queryDefinition);
623            }
624    
625            /**
626             * @deprecated As of 6.2.0, replaced by {@link #getGroupEntries(long,
627             *             QueryDefinition)}
628             */
629            @Deprecated
630            @Override
631            public List<BlogsEntry> getGroupEntries(
632                    long groupId, int status, int start, int end,
633                    OrderByComparator<BlogsEntry> obc) {
634    
635                    QueryDefinition<BlogsEntry> queryDefinition =
636                            new QueryDefinition<BlogsEntry>(status, start, end, obc);
637    
638                    return getGroupEntries(groupId, queryDefinition);
639            }
640    
641            @Override
642            public List<BlogsEntry> getGroupEntries(
643                    long groupId, QueryDefinition<BlogsEntry> queryDefinition) {
644    
645                    if (queryDefinition.isExcludeStatus()) {
646                            return blogsEntryPersistence.findByG_NotS(
647                                    groupId, queryDefinition.getStatus(),
648                                    queryDefinition.getStart(), queryDefinition.getEnd(),
649                                    queryDefinition.getOrderByComparator());
650                    }
651                    else {
652                            return blogsEntryPersistence.findByG_S(
653                                    groupId, queryDefinition.getStatus(),
654                                    queryDefinition.getStart(), queryDefinition.getEnd(),
655                                    queryDefinition.getOrderByComparator());
656                    }
657            }
658    
659            /**
660             * @deprecated As of 6.2.0, replaced by {@link #getGroupEntriesCount(long,
661             *             Date, QueryDefinition)}
662             */
663            @Deprecated
664            @Override
665            public int getGroupEntriesCount(
666                    long groupId, Date displayDate, int status) {
667    
668                    QueryDefinition<BlogsEntry> queryDefinition =
669                            new QueryDefinition<BlogsEntry>(status);
670    
671                    return getGroupEntriesCount(groupId, displayDate, queryDefinition);
672            }
673    
674            @Override
675            public int getGroupEntriesCount(
676                    long groupId, Date displayDate,
677                    QueryDefinition<BlogsEntry> queryDefinition) {
678    
679                    if (queryDefinition.isExcludeStatus()) {
680                            return blogsEntryPersistence.countByG_LtD_NotS(
681                                    groupId, displayDate, queryDefinition.getStatus());
682                    }
683                    else {
684                            return blogsEntryPersistence.countByG_LtD_S(
685                                    groupId, displayDate, queryDefinition.getStatus());
686                    }
687            }
688    
689            /**
690             * @deprecated As of 6.2.0, replaced by {@link #getGroupEntriesCount(long,
691             *             QueryDefinition)}
692             */
693            @Deprecated
694            @Override
695            public int getGroupEntriesCount(long groupId, int status) {
696                    QueryDefinition<BlogsEntry> queryDefinition =
697                            new QueryDefinition<BlogsEntry>(status);
698    
699                    return getGroupEntriesCount(groupId, queryDefinition);
700            }
701    
702            @Override
703            public int getGroupEntriesCount(
704                    long groupId, QueryDefinition<BlogsEntry> queryDefinition) {
705    
706                    if (queryDefinition.isExcludeStatus()) {
707                            return blogsEntryPersistence.countByG_NotS(
708                                    groupId, queryDefinition.getStatus());
709                    }
710                    else {
711                            return blogsEntryPersistence.countByG_S(
712                                    groupId, queryDefinition.getStatus());
713                    }
714            }
715    
716            /**
717             * @deprecated As of 6.2.0, replaced by {@link #getGroupsEntries(long, long,
718             *             Date, QueryDefinition)}
719             */
720            @Deprecated
721            @Override
722            public List<BlogsEntry> getGroupsEntries(
723                    long companyId, long groupId, Date displayDate, int status, int start,
724                    int end) {
725    
726                    QueryDefinition<BlogsEntry> queryDefinition =
727                            new QueryDefinition<BlogsEntry>(status, start, end, null);
728    
729                    return getGroupsEntries(
730                            companyId, groupId, displayDate, queryDefinition);
731            }
732    
733            @Override
734            public List<BlogsEntry> getGroupsEntries(
735                    long companyId, long groupId, Date displayDate,
736                    QueryDefinition<BlogsEntry> queryDefinition) {
737    
738                    return blogsEntryFinder.findByGroupIds(
739                            companyId, groupId, displayDate, queryDefinition);
740            }
741    
742            /**
743             * @deprecated As of 6.2.0, replaced by {@link #getGroupUserEntries(long,
744             *             long, Date, QueryDefinition)}
745             */
746            @Deprecated
747            @Override
748            public List<BlogsEntry> getGroupUserEntries(
749                    long groupId, long userId, Date displayDate, int status, int start,
750                    int end) {
751    
752                    QueryDefinition<BlogsEntry> queryDefinition =
753                            new QueryDefinition<BlogsEntry>(status, start, end, null);
754    
755                    return getGroupUserEntries(
756                            groupId, userId, displayDate, queryDefinition);
757            }
758    
759            /**
760             * @deprecated As of 6.2.0, replaced by {@link #getGroupUserEntries(long,
761             *             long, Date, QueryDefinition)}
762             */
763            @Deprecated
764            @Override
765            public List<BlogsEntry> getGroupUserEntries(
766                    long groupId, long userId, Date displayDate, int status, int start,
767                    int end, OrderByComparator<BlogsEntry> obc) {
768    
769                    QueryDefinition<BlogsEntry> queryDefinition =
770                            new QueryDefinition<BlogsEntry>(status, start, end, obc);
771    
772                    return getGroupUserEntries(
773                            groupId, userId, displayDate, queryDefinition);
774            }
775    
776            @Override
777            public List<BlogsEntry> getGroupUserEntries(
778                    long groupId, long userId, Date displayDate,
779                    QueryDefinition<BlogsEntry> queryDefinition) {
780    
781                    if (queryDefinition.isExcludeStatus()) {
782                            return blogsEntryPersistence.findByG_U_NotS(
783                                    groupId, userId, queryDefinition.getStatus(),
784                                    queryDefinition.getStart(), queryDefinition.getEnd(),
785                                    queryDefinition.getOrderByComparator());
786                    }
787                    else {
788                            return blogsEntryPersistence.findByG_U_S(
789                                    groupId, userId, queryDefinition.getStatus(),
790                                    queryDefinition.getStart(), queryDefinition.getEnd(),
791                                    queryDefinition.getOrderByComparator());
792                    }
793            }
794    
795            /**
796             * @deprecated As of 6.2.0, replaced by {@link
797             *             #getGroupUserEntriesCount(long, long, Date, QueryDefinition)}
798             */
799            @Deprecated
800            @Override
801            public int getGroupUserEntriesCount(
802                    long groupId, long userId, Date displayDate, int status) {
803    
804                    QueryDefinition<BlogsEntry> queryDefinition =
805                            new QueryDefinition<BlogsEntry>(status);
806    
807                    return getGroupUserEntriesCount(
808                            groupId, userId, displayDate, queryDefinition);
809            }
810    
811            @Override
812            public int getGroupUserEntriesCount(
813                    long groupId, long userId, Date displayDate,
814                    QueryDefinition<BlogsEntry> queryDefinition) {
815    
816                    if (queryDefinition.isExcludeStatus()) {
817                            return blogsEntryPersistence.countByG_U_LtD_NotS(
818                                    groupId, userId, displayDate, queryDefinition.getStatus());
819                    }
820                    else {
821                            return blogsEntryPersistence.countByG_U_LtD_S(
822                                    groupId, userId, displayDate, queryDefinition.getStatus());
823                    }
824            }
825    
826            @Override
827            public List<BlogsEntry> getNoAssetEntries() {
828                    return blogsEntryFinder.findByNoAssets();
829            }
830    
831            /**
832             * @deprecated As of 6.2.0, replaced by {@link #getOrganizationEntries(long,
833             *             Date, QueryDefinition)}
834             */
835            @Deprecated
836            @Override
837            public List<BlogsEntry> getOrganizationEntries(
838                    long organizationId, Date displayDate, int status, int start, int end) {
839    
840                    QueryDefinition<BlogsEntry> queryDefinition =
841                            new QueryDefinition<BlogsEntry>(status, start, end, null);
842    
843                    return getOrganizationEntries(
844                            organizationId, displayDate, queryDefinition);
845            }
846    
847            /**
848             * @deprecated As of 6.2.0, replaced by {@link #getOrganizationEntries(long,
849             *             Date, QueryDefinition)}
850             */
851            @Deprecated
852            @Override
853            public List<BlogsEntry> getOrganizationEntries(
854                    long organizationId, Date displayDate, int status, int start, int end,
855                    OrderByComparator<BlogsEntry> obc) {
856    
857                    QueryDefinition<BlogsEntry> queryDefinition =
858                            new QueryDefinition<BlogsEntry>(status, start, end, obc);
859    
860                    return getOrganizationEntries(
861                            organizationId, displayDate, queryDefinition);
862            }
863    
864            @Override
865            public List<BlogsEntry> getOrganizationEntries(
866                    long organizationId, Date displayDate,
867                    QueryDefinition<BlogsEntry> queryDefinition) {
868    
869                    return blogsEntryFinder.findByOrganizationId(
870                            organizationId, displayDate, queryDefinition);
871            }
872    
873            /**
874             * @deprecated As of 6.2.0, replaced by {@link
875             *             #getOrganizationEntriesCount(long, Date, QueryDefinition)}
876             */
877            @Deprecated
878            @Override
879            public int getOrganizationEntriesCount(
880                    long organizationId, Date displayDate, int status) {
881    
882                    QueryDefinition<BlogsEntry> queryDefinition =
883                            new QueryDefinition<BlogsEntry>(status);
884    
885                    return getOrganizationEntriesCount(
886                            organizationId, displayDate, queryDefinition);
887            }
888    
889            @Override
890            public int getOrganizationEntriesCount(
891                    long organizationId, Date displayDate,
892                    QueryDefinition<BlogsEntry> queryDefinition) {
893    
894                    return blogsEntryFinder.countByOrganizationId(
895                            organizationId, displayDate, queryDefinition);
896            }
897    
898            @Override
899            public void moveEntriesToTrash(long groupId, long userId)
900                    throws PortalException {
901    
902                    List<BlogsEntry> entries = blogsEntryPersistence.findByGroupId(groupId);
903    
904                    for (BlogsEntry entry : entries) {
905                            blogsEntryLocalService.moveEntryToTrash(userId, entry);
906                    }
907            }
908    
909            /**
910             * Moves the blogs entry to the recycle bin. Social activity counters for
911             * this entry get disabled.
912             *
913             * @param  userId the primary key of the user moving the blogs entry
914             * @param  entry the blogs entry to be moved
915             * @return the moved blogs entry
916             * @throws PortalException if a user with the primary key could not be found
917             *         or if the blogs entry owner's social activity counter could not
918             *         be updated
919             */
920            @Indexable(type = IndexableType.REINDEX)
921            @Override
922            public BlogsEntry moveEntryToTrash(long userId, BlogsEntry entry)
923                    throws PortalException {
924    
925                    // Entry
926    
927                    int oldStatus = entry.getStatus();
928    
929                    if (oldStatus == WorkflowConstants.STATUS_PENDING) {
930                            entry.setStatus(WorkflowConstants.STATUS_DRAFT);
931    
932                            blogsEntryPersistence.update(entry);
933                    }
934    
935                    entry = updateStatus(
936                            userId, entry.getEntryId(), WorkflowConstants.STATUS_IN_TRASH,
937                            new ServiceContext());
938    
939                    // Social
940    
941                    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();
942    
943                    extraDataJSONObject.put("title", entry.getTitle());
944    
945                    socialActivityLocalService.addActivity(
946                            userId, entry.getGroupId(), BlogsEntry.class.getName(),
947                            entry.getEntryId(), SocialActivityConstants.TYPE_MOVE_TO_TRASH,
948                            extraDataJSONObject.toString(), 0);
949    
950                    // Workflow
951    
952                    if (oldStatus == WorkflowConstants.STATUS_PENDING) {
953                            workflowInstanceLinkLocalService.deleteWorkflowInstanceLink(
954                                    entry.getCompanyId(), entry.getGroupId(),
955                                    BlogsEntry.class.getName(), entry.getEntryId());
956                    }
957    
958                    return entry;
959            }
960    
961            /**
962             * Moves the blogs entry with the ID to the recycle bin.
963             *
964             * @param  userId the primary key of the user moving the blogs entry
965             * @param  entryId the primary key of the blogs entry to be moved
966             * @return the moved blogs entry
967             * @throws PortalException if a user or blogs entry with the primary key
968             *         could not be found or if the blogs entry owner's social activity
969             *         counter could not be updated
970             */
971            @Override
972            public BlogsEntry moveEntryToTrash(long userId, long entryId)
973                    throws PortalException {
974    
975                    BlogsEntry entry = blogsEntryPersistence.findByPrimaryKey(entryId);
976    
977                    return blogsEntryLocalService.moveEntryToTrash(userId, entry);
978            }
979    
980            /**
981             * Restores the blogs entry with the ID from the recycle bin. Social
982             * activity counters for this entry get activated.
983             *
984             * @param  userId the primary key of the user restoring the blogs entry
985             * @param  entryId the primary key of the blogs entry to be restored
986             * @return the restored blogs entry from the recycle bin
987             * @throws PortalException if a user or blogs entry with the primary key
988             *         could not be found or if the blogs entry owner's social activity
989             *         counter could not be updated
990             */
991            @Indexable(type = IndexableType.REINDEX)
992            @Override
993            public BlogsEntry restoreEntryFromTrash(long userId, long entryId)
994                    throws PortalException {
995    
996                    // Entry
997    
998                    TrashEntry trashEntry = trashEntryLocalService.getEntry(
999                            BlogsEntry.class.getName(), entryId);
1000    
1001                    BlogsEntry entry = updateStatus(
1002                            userId, entryId, trashEntry.getStatus(), new ServiceContext());
1003    
1004                    // Social
1005    
1006                    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();
1007    
1008                    extraDataJSONObject.put("title", entry.getTitle());
1009    
1010                    socialActivityLocalService.addActivity(
1011                            userId, trashEntry.getGroupId(), BlogsEntry.class.getName(),
1012                            entryId, SocialActivityConstants.TYPE_RESTORE_FROM_TRASH,
1013                            extraDataJSONObject.toString(), 0);
1014    
1015                    return entry;
1016            }
1017    
1018            @Override
1019            public void subscribe(long userId, long groupId) throws PortalException {
1020                    subscriptionLocalService.addSubscription(
1021                            userId, groupId, BlogsEntry.class.getName(), groupId);
1022            }
1023    
1024            @Override
1025            public void unsubscribe(long userId, long groupId) throws PortalException {
1026                    subscriptionLocalService.deleteSubscription(
1027                            userId, BlogsEntry.class.getName(), groupId);
1028            }
1029    
1030            @Override
1031            public void updateAsset(
1032                            long userId, BlogsEntry entry, long[] assetCategoryIds,
1033                            String[] assetTagNames, long[] assetLinkEntryIds)
1034                    throws PortalException {
1035    
1036                    boolean visible = false;
1037    
1038                    if (entry.isApproved()) {
1039                            visible = true;
1040                    }
1041    
1042                    String summary = HtmlUtil.extractText(
1043                            StringUtil.shorten(entry.getContent(), 500));
1044    
1045                    AssetEntry assetEntry = assetEntryLocalService.updateEntry(
1046                            userId, entry.getGroupId(), entry.getCreateDate(),
1047                            entry.getModifiedDate(), BlogsEntry.class.getName(),
1048                            entry.getEntryId(), entry.getUuid(), 0, assetCategoryIds,
1049                            assetTagNames, visible, null, null, null, ContentTypes.TEXT_HTML,
1050                            entry.getTitle(), entry.getDescription(), summary, null, null, 0, 0,
1051                            null, false);
1052    
1053                    assetLinkLocalService.updateLinks(
1054                            userId, assetEntry.getEntryId(), assetLinkEntryIds,
1055                            AssetLinkConstants.TYPE_RELATED);
1056            }
1057    
1058            /**
1059             * @deprecated As of 7.0.0, replaced by {@link #updateEntry(long, long,
1060             *             String, String, String, String, int, int, int, int, int,
1061             *             boolean, boolean, String[], boolean, String, long,
1062             *             ServiceContext)}
1063             */
1064            @Deprecated
1065            @Override
1066            public BlogsEntry updateEntry(
1067                            long userId, long entryId, String title, String description,
1068                            String content, int displayDateMonth, int displayDateDay,
1069                            int displayDateYear, int displayDateHour, int displayDateMinute,
1070                            boolean allowPingbacks, boolean allowTrackbacks,
1071                            String[] trackbacks, boolean smallImage, String smallImageURL,
1072                            String smallImageFileName, InputStream smallImageInputStream,
1073                            ServiceContext serviceContext)
1074                    throws PortalException {
1075    
1076                    ImageSelector imageSelector = null;
1077    
1078                    if (smallImage) {
1079                            if (Validator.isNotNull(smallImageFileName) &&
1080                                    (smallImageInputStream != null)) {
1081    
1082                                    FileEntry fileEntry = TempFileEntryUtil.addTempFileEntry(
1083                                            serviceContext.getScopeGroupId(), userId,
1084                                            BlogsEntry.class.getName(), smallImageFileName,
1085                                            smallImageInputStream,
1086                                            MimeTypesUtil.getContentType(smallImageFileName));
1087    
1088                                    imageSelector = new ImageSelector(
1089                                            fileEntry.getFileEntryId(), smallImageURL);
1090                            }
1091                    }
1092                    else {
1093                            imageSelector = new ImageSelector(0);
1094                    }
1095    
1096                    return updateEntry(
1097                            userId, entryId, title, StringPool.BLANK, description, content,
1098                            displayDateMonth, displayDateDay, displayDateYear, displayDateHour,
1099                            displayDateMinute, allowPingbacks, allowTrackbacks, trackbacks,
1100                            imageSelector, serviceContext);
1101            }
1102    
1103            @Indexable(type = IndexableType.REINDEX)
1104            @Override
1105            public BlogsEntry updateEntry(
1106                            long userId, long entryId, String title, String subtitle,
1107                            String description, String content, int displayDateMonth,
1108                            int displayDateDay, int displayDateYear, int displayDateHour,
1109                            int displayDateMinute, boolean allowPingbacks,
1110                            boolean allowTrackbacks, String[] trackbacks,
1111                            ImageSelector imageSelector, ServiceContext serviceContext)
1112                    throws PortalException {
1113    
1114                    // Entry
1115    
1116                    User user = userPersistence.findByPrimaryKey(userId);
1117                    Date displayDate = PortalUtil.getDate(
1118                            displayDateMonth, displayDateDay, displayDateYear, displayDateHour,
1119                            displayDateMinute, user.getTimeZone(),
1120                            EntryDisplayDateException.class);
1121    
1122                    BlogsEntry entry = blogsEntryPersistence.findByPrimaryKey(entryId);
1123    
1124                    boolean smallImage = entry.isSmallImage();
1125                    long smallImageFileEntryId = 0;
1126                    String smallImageURL = null;
1127    
1128                    if (imageSelector != null) {
1129                            if (imageSelector.getImageId() == 0) {
1130                                    if (entry.getSmallImageFileEntryId() != 0) {
1131                                            PortletFileRepositoryUtil.deletePortletFileEntry(
1132                                                    entry.getSmallImageFileEntryId());
1133                                    }
1134                            }
1135                            else if (imageSelector.getImageId() !=
1136                                                    entry.getSmallImageFileEntryId()) {
1137    
1138                                    if (entry.getSmallImageFileEntryId() != 0) {
1139                                            PortletFileRepositoryUtil.deletePortletFileEntry(
1140                                                    entry.getSmallImageFileEntryId());
1141                                    }
1142    
1143                                    FileEntry tempFileEntry =
1144                                            PortletFileRepositoryUtil.getPortletFileEntry(
1145                                                    imageSelector.getImageId());
1146    
1147                                    FileEntry fileEntry =
1148                                            PortletFileRepositoryUtil.addPortletFileEntry(
1149                                                    entry.getGroupId(), userId, BlogsEntry.class.getName(),
1150                                                    entry.getEntryId(), PortletKeys.BLOGS,
1151                                                    DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
1152                                                    tempFileEntry.getContentStream(),
1153                                                    tempFileEntry.getTitle(), tempFileEntry.getMimeType(),
1154                                                    false);
1155    
1156                                    smallImageFileEntryId = fileEntry.getFileEntryId();
1157    
1158                                    PortletFileRepositoryUtil.deletePortletFileEntry(
1159                                            tempFileEntry.getFileEntryId());
1160                            }
1161    
1162                            smallImage = !imageSelector.isRemoveSmallImage();
1163                            smallImageURL = imageSelector.getImageURL();
1164                    }
1165    
1166                    validate(title, content, smallImageFileEntryId);
1167    
1168                    String oldUrlTitle = entry.getUrlTitle();
1169    
1170                    entry.setModifiedDate(serviceContext.getModifiedDate(null));
1171                    entry.setTitle(title);
1172                    entry.setSubtitle(subtitle);
1173                    entry.setUrlTitle(
1174                            getUniqueUrlTitle(entryId, title, oldUrlTitle, serviceContext));
1175                    entry.setDescription(description);
1176                    entry.setContent(content);
1177                    entry.setDisplayDate(displayDate);
1178                    entry.setAllowPingbacks(allowPingbacks);
1179                    entry.setAllowTrackbacks(allowTrackbacks);
1180                    entry.setSmallImage(smallImage);
1181                    entry.setSmallImageFileEntryId(smallImageFileEntryId);
1182                    entry.setSmallImageURL(smallImageURL);
1183    
1184                    if (entry.isPending() || entry.isDraft()) {
1185                    }
1186                    else {
1187                            entry.setStatus(WorkflowConstants.STATUS_DRAFT);
1188                    }
1189    
1190                    entry.setExpandoBridgeAttributes(serviceContext);
1191    
1192                    blogsEntryPersistence.update(entry);
1193    
1194                    // Resources
1195    
1196                    if ((serviceContext.getGroupPermissions() != null) ||
1197                            (serviceContext.getGuestPermissions() != null)) {
1198    
1199                            updateEntryResources(
1200                                    entry, serviceContext.getGroupPermissions(),
1201                                    serviceContext.getGuestPermissions());
1202                    }
1203    
1204                    // Asset
1205    
1206                    updateAsset(
1207                            userId, entry, serviceContext.getAssetCategoryIds(),
1208                            serviceContext.getAssetTagNames(),
1209                            serviceContext.getAssetLinkEntryIds());
1210    
1211                    // Workflow
1212    
1213                    boolean pingOldTrackbacks = false;
1214    
1215                    if (!oldUrlTitle.equals(entry.getUrlTitle())) {
1216                            pingOldTrackbacks = true;
1217                    }
1218    
1219                    serviceContext.setAttribute(
1220                            "pingOldTrackbacks", String.valueOf(pingOldTrackbacks));
1221    
1222                    if (ArrayUtil.isNotEmpty(trackbacks)) {
1223                            serviceContext.setAttribute("trackbacks", trackbacks);
1224                    }
1225                    else {
1226                            serviceContext.setAttribute("trackbacks", null);
1227                    }
1228    
1229                    return startWorkflowInstance(userId, entry, serviceContext);
1230            }
1231    
1232            @Override
1233            public void updateEntryResources(
1234                            BlogsEntry entry, String[] groupPermissions,
1235                            String[] guestPermissions)
1236                    throws PortalException {
1237    
1238                    resourceLocalService.updateResources(
1239                            entry.getCompanyId(), entry.getGroupId(),
1240                            BlogsEntry.class.getName(), entry.getEntryId(), groupPermissions,
1241                            guestPermissions);
1242            }
1243    
1244            /**
1245             * @deprecated As of 7.0.0, replaced by {@link #updateStatus(long, long,
1246             *             int, ServiceContext, Map)}
1247             */
1248            @Deprecated
1249            @Override
1250            public BlogsEntry updateStatus(
1251                            long userId, long entryId, int status,
1252                            ServiceContext serviceContext)
1253                    throws PortalException {
1254    
1255                    return updateStatus(
1256                            userId, entryId, status, serviceContext,
1257                            new HashMap<String, Serializable>());
1258            }
1259    
1260            @Indexable(type = IndexableType.REINDEX)
1261            @Override
1262            public BlogsEntry updateStatus(
1263                            long userId, long entryId, int status,
1264                            ServiceContext serviceContext,
1265                            Map<String, Serializable> workflowContext)
1266                    throws PortalException {
1267    
1268                    // Entry
1269    
1270                    User user = userPersistence.findByPrimaryKey(userId);
1271                    Date now = new Date();
1272    
1273                    BlogsEntry entry = blogsEntryPersistence.findByPrimaryKey(entryId);
1274    
1275                    int oldStatus = entry.getStatus();
1276    
1277                    if ((status == WorkflowConstants.STATUS_APPROVED) &&
1278                            now.before(entry.getDisplayDate())) {
1279    
1280                            status = WorkflowConstants.STATUS_SCHEDULED;
1281                    }
1282    
1283                    entry.setModifiedDate(serviceContext.getModifiedDate(now));
1284                    entry.setStatus(status);
1285                    entry.setStatusByUserId(user.getUserId());
1286                    entry.setStatusByUserName(user.getFullName());
1287                    entry.setStatusDate(serviceContext.getModifiedDate(now));
1288    
1289                    blogsEntryPersistence.update(entry);
1290    
1291                    // Statistics
1292    
1293                    blogsStatsUserLocalService.updateStatsUser(
1294                            entry.getGroupId(), entry.getUserId(), entry.getDisplayDate());
1295    
1296                    AssetEntry assetEntry = assetEntryLocalService.fetchEntry(
1297                            BlogsEntry.class.getName(), entryId);
1298    
1299                    if ((assetEntry == null) || (assetEntry.getPublishDate() == null)) {
1300                            serviceContext.setCommand(Constants.ADD);
1301                    }
1302    
1303                    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();
1304    
1305                    extraDataJSONObject.put("title", entry.getTitle());
1306    
1307                    if (status == WorkflowConstants.STATUS_APPROVED) {
1308    
1309                            // Asset
1310    
1311                            assetEntryLocalService.updateEntry(
1312                                    BlogsEntry.class.getName(), entryId, entry.getDisplayDate(),
1313                                    true);
1314    
1315                            // Social
1316    
1317                            if ((oldStatus != WorkflowConstants.STATUS_IN_TRASH) &&
1318                                    (oldStatus != WorkflowConstants.STATUS_SCHEDULED)) {
1319    
1320                                    if (serviceContext.isCommandUpdate()) {
1321                                            socialActivityLocalService.addActivity(
1322                                                    user.getUserId(), entry.getGroupId(),
1323                                                    BlogsEntry.class.getName(), entryId,
1324                                                    BlogsActivityKeys.UPDATE_ENTRY,
1325                                                    extraDataJSONObject.toString(), 0);
1326                                    }
1327                                    else {
1328                                            socialActivityLocalService.addUniqueActivity(
1329                                                    user.getUserId(), entry.getGroupId(),
1330                                                    BlogsEntry.class.getName(), entryId,
1331                                                    BlogsActivityKeys.ADD_ENTRY,
1332                                                    extraDataJSONObject.toString(), 0);
1333                                    }
1334                            }
1335    
1336                            // Trash
1337    
1338                            if (oldStatus == WorkflowConstants.STATUS_IN_TRASH) {
1339                                    trashEntryLocalService.deleteEntry(
1340                                            BlogsEntry.class.getName(), entryId);
1341                            }
1342    
1343                            if (oldStatus != WorkflowConstants.STATUS_IN_TRASH) {
1344    
1345                                    // Subscriptions
1346    
1347                                    notifySubscribers(entry, serviceContext, workflowContext);
1348    
1349                                    // Ping
1350    
1351                                    String[] trackbacks = (String[])serviceContext.getAttribute(
1352                                            "trackbacks");
1353                                    Boolean pingOldTrackbacks = ParamUtil.getBoolean(
1354                                            serviceContext, "pingOldTrackbacks");
1355    
1356                                    pingGoogle(entry, serviceContext);
1357                                    pingPingback(entry, serviceContext);
1358                                    pingTrackbacks(
1359                                            entry, trackbacks, pingOldTrackbacks, serviceContext);
1360                            }
1361                    }
1362                    else {
1363    
1364                            // Asset
1365    
1366                            assetEntryLocalService.updateVisible(
1367                                    BlogsEntry.class.getName(), entryId, false);
1368    
1369                            // Social
1370    
1371                            if ((status == WorkflowConstants.STATUS_SCHEDULED) &&
1372                                    (oldStatus != WorkflowConstants.STATUS_IN_TRASH)) {
1373    
1374                                    if (serviceContext.isCommandUpdate()) {
1375                                            socialActivityLocalService.addActivity(
1376                                                    user.getUserId(), entry.getGroupId(),
1377                                                    BlogsEntry.class.getName(), entryId,
1378                                                    BlogsActivityKeys.UPDATE_ENTRY,
1379                                                    extraDataJSONObject.toString(), 0);
1380                                    }
1381                                    else {
1382                                            socialActivityLocalService.addUniqueActivity(
1383                                                    user.getUserId(), entry.getGroupId(),
1384                                                    BlogsEntry.class.getName(), entryId,
1385                                                    BlogsActivityKeys.ADD_ENTRY,
1386                                                    extraDataJSONObject.toString(), 0);
1387                                    }
1388                            }
1389    
1390                            // Trash
1391    
1392                            if (status == WorkflowConstants.STATUS_IN_TRASH) {
1393                                    trashEntryLocalService.addTrashEntry(
1394                                            userId, entry.getGroupId(), BlogsEntry.class.getName(),
1395                                            entry.getEntryId(), entry.getUuid(), null, oldStatus, null,
1396                                            null);
1397                            }
1398                            else if (oldStatus == WorkflowConstants.STATUS_IN_TRASH) {
1399                                    trashEntryLocalService.deleteEntry(
1400                                            BlogsEntry.class.getName(), entryId);
1401                            }
1402                    }
1403    
1404                    return entry;
1405            }
1406    
1407            protected void addDiscussion(BlogsEntry entry, long userId, long groupId)
1408                    throws PortalException {
1409    
1410                    if (PropsValues.BLOGS_ENTRY_COMMENTS_ENABLED) {
1411                            commentManager.addDiscussion(
1412                                    userId, groupId, BlogsEntry.class.getName(), entry.getEntryId(),
1413                                    entry.getUserName());
1414                    }
1415            }
1416    
1417            protected void deleteDiscussion(BlogsEntry entry) throws PortalException {
1418                    commentManager.deleteDiscussion(
1419                            BlogsEntry.class.getName(), entry.getEntryId());
1420            }
1421    
1422            protected String getEntryURL(
1423                            BlogsEntry entry, ServiceContext serviceContext)
1424                    throws PortalException {
1425    
1426                    HttpServletRequest request = serviceContext.getRequest();
1427    
1428                    if (request == null) {
1429                            return StringPool.BLANK;
1430                    }
1431    
1432                    String layoutURL = getLayoutURL(
1433                            entry.getGroupId(), PortletKeys.BLOGS, serviceContext);
1434    
1435                    if (Validator.isNotNull(layoutURL)) {
1436                            return layoutURL + Portal.FRIENDLY_URL_SEPARATOR + "blogs" +
1437                                    StringPool.SLASH + entry.getEntryId();
1438                    }
1439    
1440                    long controlPanelPlid = PortalUtil.getControlPanelPlid(
1441                            serviceContext.getCompanyId());
1442    
1443                    PortletURL portletURL = PortletURLFactoryUtil.create(
1444                            request, PortletKeys.BLOGS_ADMIN, controlPanelPlid,
1445                            PortletRequest.RENDER_PHASE);
1446    
1447                    portletURL.setParameter("struts_action", "/blogs_admin/view_entry");
1448                    portletURL.setParameter("entryId", String.valueOf(entry.getEntryId()));
1449    
1450                    return portletURL.toString();
1451            }
1452    
1453            protected String getUniqueUrlTitle(
1454                    long entryId, long groupId, String title) {
1455    
1456                    String urlTitle = BlogsUtil.getUrlTitle(entryId, title);
1457    
1458                    for (int i = 1;; i++) {
1459                            BlogsEntry entry = blogsEntryPersistence.fetchByG_UT(
1460                                    groupId, urlTitle);
1461    
1462                            if ((entry == null) || (entryId == entry.getEntryId())) {
1463                                    break;
1464                            }
1465                            else {
1466                                    String suffix = StringPool.DASH + i;
1467    
1468                                    String prefix = urlTitle;
1469    
1470                                    if (urlTitle.length() > suffix.length()) {
1471                                            prefix = urlTitle.substring(
1472                                                    0, urlTitle.length() - suffix.length());
1473                                    }
1474    
1475                                    urlTitle = prefix + suffix;
1476                            }
1477                    }
1478    
1479                    return urlTitle;
1480            }
1481    
1482            protected String getUniqueUrlTitle(
1483                    long entryId, String title, String oldUrlTitle,
1484                    ServiceContext serviceContext) {
1485    
1486                    String serviceContextUrlTitle = ParamUtil.getString(
1487                            serviceContext, "urlTitle");
1488    
1489                    String urlTitle = null;
1490    
1491                    if (Validator.isNotNull(serviceContextUrlTitle)) {
1492                            urlTitle = BlogsUtil.getUrlTitle(entryId, serviceContextUrlTitle);
1493                    }
1494                    else if (Validator.isNotNull(oldUrlTitle)) {
1495                            return oldUrlTitle;
1496                    }
1497                    else {
1498                            urlTitle = getUniqueUrlTitle(
1499                                    entryId, serviceContext.getScopeGroupId(), title);
1500                    }
1501    
1502                    BlogsEntry urlTitleEntry = blogsEntryPersistence.fetchByG_UT(
1503                            serviceContext.getScopeGroupId(), urlTitle);
1504    
1505                    if ((urlTitleEntry != null) &&
1506                            (urlTitleEntry.getEntryId() != entryId)) {
1507    
1508                            urlTitle = getUniqueUrlTitle(
1509                                    entryId, serviceContext.getScopeGroupId(), urlTitle);
1510                    }
1511    
1512                    return urlTitle;
1513            }
1514    
1515            protected void notifySubscribers(
1516                            BlogsEntry entry, ServiceContext serviceContext,
1517                            Map<String, Serializable> workflowContext)
1518                    throws PortalException {
1519    
1520                    String entryURL = (String)workflowContext.get(
1521                            WorkflowConstants.CONTEXT_URL);
1522    
1523                    if (!entry.isApproved() || Validator.isNull(entryURL)) {
1524                            return;
1525                    }
1526    
1527                    BlogsSettings blogsSettings = BlogsSettings.getInstance(
1528                            entry.getGroupId());
1529    
1530                    boolean sendEmailEntryUpdated = GetterUtil.getBoolean(
1531                            serviceContext.getAttribute("sendEmailEntryUpdated"));
1532    
1533                    if (serviceContext.isCommandAdd() &&
1534                            blogsSettings.isEmailEntryAddedEnabled()) {
1535                    }
1536                    else if (sendEmailEntryUpdated && serviceContext.isCommandUpdate() &&
1537                                     blogsSettings.isEmailEntryUpdatedEnabled()) {
1538                    }
1539                    else {
1540                            return;
1541                    }
1542    
1543                    String entryTitle = entry.getTitle();
1544    
1545                    String fromName = blogsSettings.getEmailFromName();
1546                    String fromAddress = blogsSettings.getEmailFromAddress();
1547    
1548                    LocalizedValuesMap subjectLocalizedValuesMap = null;
1549                    LocalizedValuesMap bodyLocalizedValuesMap = null;
1550    
1551                    if (serviceContext.isCommandUpdate()) {
1552                            subjectLocalizedValuesMap =
1553                                    blogsSettings.getEmailEntryUpdatedSubject();
1554                            bodyLocalizedValuesMap = blogsSettings.getEmailEntryUpdatedBody();
1555                    }
1556                    else {
1557                            subjectLocalizedValuesMap =
1558                                    blogsSettings.getEmailEntryAddedSubject();
1559                            bodyLocalizedValuesMap = blogsSettings.getEmailEntryAddedBody();
1560                    }
1561    
1562                    SubscriptionSender subscriptionSender = new SubscriptionSender();
1563    
1564                    subscriptionSender.setClassPK(entry.getEntryId());
1565                    subscriptionSender.setClassName(entry.getModelClassName());
1566                    subscriptionSender.setCompanyId(entry.getCompanyId());
1567                    subscriptionSender.setContextAttribute(
1568                            "[$BLOGS_ENTRY_CONTENT$]",
1569                            StringUtil.shorten(HtmlUtil.stripHtml(entry.getContent()), 500),
1570                            false);
1571    
1572                    subscriptionSender.setContextAttributes(
1573                            "[$BLOGS_ENTRY_CREATE_DATE$]",
1574                            Time.getSimpleDate(entry.getCreateDate(), "yyyy/MM/dd"),
1575                            "[$BLOGS_ENTRY_DESCRIPTION$]", entry.getDescription(),
1576                            "[$BLOGS_ENTRY_SITE_NAME$]",
1577                            groupLocalService.getGroupDescriptiveName(
1578                                    entry.getGroupId(), serviceContext.getLocale()),
1579                            "[$BLOGS_ENTRY_STATUS_BY_USER_NAME$]", entry.getStatusByUserName(),
1580                            "[$BLOGS_ENTRY_TITLE$]", entryTitle,
1581                            "[$BLOGS_ENTRY_UPDATE_COMMENT$]",
1582                            HtmlUtil.replaceNewLine(
1583                                    GetterUtil.getString(
1584                                            serviceContext.getAttribute("emailEntryUpdatedComment"))),
1585                            "[$BLOGS_ENTRY_URL$]", entryURL,
1586                            "[$BLOGS_ENTRY_USER_PORTRAIT_URL$]",
1587                            workflowContext.get(WorkflowConstants.CONTEXT_USER_PORTRAIT_URL),
1588                            "[$BLOGS_ENTRY_USER_URL$]",
1589                            workflowContext.get(WorkflowConstants.CONTEXT_USER_URL));
1590    
1591                    subscriptionSender.setContextUserPrefix("BLOGS_ENTRY");
1592                    subscriptionSender.setEntryTitle(entryTitle);
1593                    subscriptionSender.setEntryURL(entryURL);
1594                    subscriptionSender.setFrom(fromAddress, fromName);
1595                    subscriptionSender.setHtmlFormat(true);
1596                    subscriptionSender.setLocalizedBodyMap(bodyLocalizedValuesMap);
1597                    subscriptionSender.setLocalizedSubjectMap(subjectLocalizedValuesMap);
1598                    subscriptionSender.setMailId("blogs_entry", entry.getEntryId());
1599    
1600                    int notificationType =
1601                            UserNotificationDefinition.NOTIFICATION_TYPE_ADD_ENTRY;
1602    
1603                    if (serviceContext.isCommandUpdate()) {
1604                            notificationType =
1605                                    UserNotificationDefinition.NOTIFICATION_TYPE_UPDATE_ENTRY;
1606                    }
1607    
1608                    subscriptionSender.setNotificationType(notificationType);
1609    
1610                    subscriptionSender.setPortletId(PortletKeys.BLOGS);
1611                    subscriptionSender.setReplyToAddress(fromAddress);
1612                    subscriptionSender.setScopeGroupId(entry.getGroupId());
1613                    subscriptionSender.setServiceContext(serviceContext);
1614                    subscriptionSender.setUserId(entry.getUserId());
1615    
1616                    subscriptionSender.addPersistedSubscribers(
1617                            BlogsEntry.class.getName(), entry.getGroupId());
1618    
1619                    subscriptionSender.addPersistedSubscribers(
1620                            BlogsEntry.class.getName(), entry.getEntryId());
1621    
1622                    subscriptionSender.flushNotificationsAsync();
1623            }
1624    
1625            protected void pingGoogle(BlogsEntry entry, ServiceContext serviceContext)
1626                    throws PortalException {
1627    
1628                    if (!PropsValues.BLOGS_PING_GOOGLE_ENABLED || !entry.isApproved()) {
1629                            return;
1630                    }
1631    
1632                    String layoutFullURL = PortalUtil.getLayoutFullURL(
1633                            serviceContext.getScopeGroupId(), PortletKeys.BLOGS);
1634    
1635                    if (Validator.isNull(layoutFullURL)) {
1636                            return;
1637                    }
1638    
1639                    if (layoutFullURL.contains("://localhost")) {
1640                            if (_log.isDebugEnabled()) {
1641                                    _log.debug(
1642                                            "Not pinging Google because of localhost URL " +
1643                                                    layoutFullURL);
1644                            }
1645    
1646                            return;
1647                    }
1648    
1649                    Group group = groupPersistence.findByPrimaryKey(entry.getGroupId());
1650    
1651                    StringBundler sb = new StringBundler(6);
1652    
1653                    String name = group.getDescriptiveName();
1654                    String url = layoutFullURL + Portal.FRIENDLY_URL_SEPARATOR + "blogs";
1655                    String changesURL =
1656                            layoutFullURL + Portal.FRIENDLY_URL_SEPARATOR + "blogs/rss";
1657    
1658                    sb.append("http://blogsearch.google.com/ping?name=");
1659                    sb.append(HttpUtil.encodeURL(name));
1660                    sb.append("&url=");
1661                    sb.append(HttpUtil.encodeURL(url));
1662                    sb.append("&changesURL=");
1663                    sb.append(HttpUtil.encodeURL(changesURL));
1664    
1665                    String location = sb.toString();
1666    
1667                    if (_log.isInfoEnabled()) {
1668                            _log.info("Pinging Google at " + location);
1669                    }
1670    
1671                    try {
1672                            String response = HttpUtil.URLtoString(sb.toString());
1673    
1674                            if (_log.isInfoEnabled()) {
1675                                    _log.info("Google ping response: " + response);
1676                            }
1677                    }
1678                    catch (IOException ioe) {
1679                            _log.error("Unable to ping Google at " + location, ioe);
1680                    }
1681            }
1682    
1683            protected void pingPingback(BlogsEntry entry, ServiceContext serviceContext)
1684                    throws PortalException {
1685    
1686                    if (!PropsValues.BLOGS_PINGBACK_ENABLED ||
1687                            !entry.isAllowPingbacks() || !entry.isApproved()) {
1688    
1689                            return;
1690                    }
1691    
1692                    HttpServletRequest request = serviceContext.getRequest();
1693    
1694                    if (request == null) {
1695                            return;
1696                    }
1697    
1698                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
1699                            WebKeys.THEME_DISPLAY);
1700    
1701                    String layoutFullURL = PortalUtil.getLayoutFullURL(themeDisplay);
1702    
1703                    if (Validator.isNull(layoutFullURL)) {
1704                            return;
1705                    }
1706    
1707                    String sourceUri =
1708                            layoutFullURL + Portal.FRIENDLY_URL_SEPARATOR + "blogs/" +
1709                                    entry.getUrlTitle();
1710    
1711                    Source source = new Source(entry.getContent());
1712    
1713                    List<StartTag> tags = source.getAllStartTags("a");
1714    
1715                    for (StartTag tag : tags) {
1716                            String targetUri = tag.getAttributeValue("href");
1717    
1718                            if (Validator.isNotNull(targetUri)) {
1719                                    try {
1720                                            LinkbackProducerUtil.sendPingback(sourceUri, targetUri);
1721                                    }
1722                                    catch (Exception e) {
1723                                            _log.error("Error while sending pingback " + targetUri, e);
1724                                    }
1725                            }
1726                    }
1727            }
1728    
1729            protected void pingTrackbacks(
1730                            BlogsEntry entry, String[] trackbacks, boolean pingOldTrackbacks,
1731                            ServiceContext serviceContext)
1732                    throws PortalException {
1733    
1734                    if (!PropsValues.BLOGS_TRACKBACK_ENABLED ||
1735                            !entry.isAllowTrackbacks() || !entry.isApproved()) {
1736    
1737                            return;
1738                    }
1739    
1740                    HttpServletRequest request = serviceContext.getRequest();
1741    
1742                    if (request == null) {
1743                            return;
1744                    }
1745    
1746                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
1747                            WebKeys.THEME_DISPLAY);
1748    
1749                    String layoutFullURL = PortalUtil.getLayoutFullURL(themeDisplay);
1750    
1751                    if (Validator.isNull(layoutFullURL)) {
1752                            return;
1753                    }
1754    
1755                    Map<String, String> parts = new HashMap<String, String>();
1756    
1757                    String excerpt = StringUtil.shorten(
1758                            HtmlUtil.extractText(entry.getContent()),
1759                            PropsValues.BLOGS_LINKBACK_EXCERPT_LENGTH);
1760                    String url =
1761                            layoutFullURL + Portal.FRIENDLY_URL_SEPARATOR + "blogs/" +
1762                                    entry.getUrlTitle();
1763    
1764                    parts.put("title", entry.getTitle());
1765                    parts.put("excerpt", excerpt);
1766                    parts.put("url", url);
1767                    parts.put("blog_name", entry.getUserName());
1768    
1769                    Set<String> trackbacksSet = null;
1770    
1771                    if (ArrayUtil.isNotEmpty(trackbacks)) {
1772                            trackbacksSet = SetUtil.fromArray(trackbacks);
1773                    }
1774                    else {
1775                            trackbacksSet = new HashSet<String>();
1776                    }
1777    
1778                    if (pingOldTrackbacks) {
1779                            trackbacksSet.addAll(
1780                                    SetUtil.fromArray(StringUtil.split(entry.getTrackbacks())));
1781    
1782                            entry.setTrackbacks(StringPool.BLANK);
1783    
1784                            blogsEntryPersistence.update(entry);
1785                    }
1786    
1787                    Set<String> oldTrackbacks = SetUtil.fromArray(
1788                            StringUtil.split(entry.getTrackbacks()));
1789    
1790                    Set<String> validTrackbacks = new HashSet<String>();
1791    
1792                    for (String trackback : trackbacksSet) {
1793                            if (oldTrackbacks.contains(trackback)) {
1794                                    continue;
1795                            }
1796    
1797                            try {
1798                                    if (LinkbackProducerUtil.sendTrackback(trackback, parts)) {
1799                                            validTrackbacks.add(trackback);
1800                                    }
1801                            }
1802                            catch (Exception e) {
1803                                    _log.error("Error while sending trackback at " + trackback, e);
1804                            }
1805                    }
1806    
1807                    if (!validTrackbacks.isEmpty()) {
1808                            String newTrackbacks = StringUtil.merge(validTrackbacks);
1809    
1810                            if (Validator.isNotNull(entry.getTrackbacks())) {
1811                                    newTrackbacks += StringPool.COMMA + entry.getTrackbacks();
1812                            }
1813    
1814                            entry.setTrackbacks(newTrackbacks);
1815    
1816                            blogsEntryPersistence.update(entry);
1817                    }
1818            }
1819    
1820            protected BlogsEntry startWorkflowInstance(
1821                            long userId, BlogsEntry entry, ServiceContext serviceContext)
1822                    throws PortalException {
1823    
1824                    Map<String, Serializable> workflowContext =
1825                            new HashMap<String, Serializable>();
1826    
1827                    workflowContext.put(
1828                            WorkflowConstants.CONTEXT_URL, getEntryURL(entry, serviceContext));
1829    
1830                    String userPortraitURL = StringPool.BLANK;
1831                    String userURL = StringPool.BLANK;
1832    
1833                    if (serviceContext.getThemeDisplay() != null) {
1834                            User user = userPersistence.findByPrimaryKey(userId);
1835    
1836                            userPortraitURL = user.getPortraitURL(
1837                                    serviceContext.getThemeDisplay());
1838                            userURL = user.getDisplayURL(serviceContext.getThemeDisplay());
1839                    }
1840    
1841                    workflowContext.put(
1842                            WorkflowConstants.CONTEXT_USER_PORTRAIT_URL, userPortraitURL);
1843                    workflowContext.put(WorkflowConstants.CONTEXT_USER_URL, userURL);
1844    
1845                    return WorkflowHandlerRegistryUtil.startWorkflowInstance(
1846                            entry.getCompanyId(), entry.getGroupId(), userId,
1847                            BlogsEntry.class.getName(), entry.getEntryId(), entry,
1848                            serviceContext, workflowContext);
1849            }
1850    
1851            protected void validate(
1852                            String title, String content, long smallImageFileEntryId)
1853                    throws PortalException {
1854    
1855                    if (Validator.isNull(title)) {
1856                            throw new EntryTitleException();
1857                    }
1858                    else if (Validator.isNull(content)) {
1859                            throw new EntryContentException();
1860                    }
1861    
1862                    String[] imageExtensions = PrefsPropsUtil.getStringArray(
1863                            PropsKeys.BLOGS_IMAGE_EXTENSIONS, StringPool.COMMA);
1864    
1865                    if (smallImageFileEntryId != 0) {
1866                            FileEntry fileEntry = PortletFileRepositoryUtil.getPortletFileEntry(
1867                                    smallImageFileEntryId);
1868    
1869                            boolean validSmallImageExtension = false;
1870    
1871                            for (String _imageExtension : imageExtensions) {
1872                                    if (StringPool.STAR.equals(_imageExtension) ||
1873                                            _imageExtension.equals(
1874                                                    StringPool.PERIOD + fileEntry.getExtension())) {
1875    
1876                                            validSmallImageExtension = true;
1877    
1878                                            break;
1879                                    }
1880                            }
1881    
1882                            if (!validSmallImageExtension) {
1883                                    throw new EntrySmallImageNameException(
1884                                            "Invalid small image for file entry " +
1885                                                    smallImageFileEntryId);
1886                            }
1887    
1888                            long smallImageMaxSize = PrefsPropsUtil.getLong(
1889                                    PropsKeys.BLOGS_IMAGE_SMALL_MAX_SIZE);
1890    
1891                            if ((smallImageMaxSize > 0) &&
1892                                    (fileEntry.getSize() > smallImageMaxSize)) {
1893    
1894                                    throw new EntrySmallImageSizeException();
1895                            }
1896                    }
1897            }
1898    
1899            @BeanReference(type = CommentManager.class)
1900            protected CommentManager commentManager;
1901    
1902            private static Log _log = LogFactoryUtil.getLog(
1903                    BlogsEntryLocalServiceImpl.class);
1904    
1905    }