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.asset.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.increment.BufferedIncrement;
020    import com.liferay.portal.kernel.increment.NumberIncrement;
021    import com.liferay.portal.kernel.lar.ExportImportThreadLocal;
022    import com.liferay.portal.kernel.search.Field;
023    import com.liferay.portal.kernel.search.Hits;
024    import com.liferay.portal.kernel.search.Indexer;
025    import com.liferay.portal.kernel.search.IndexerRegistryUtil;
026    import com.liferay.portal.kernel.search.QueryConfig;
027    import com.liferay.portal.kernel.search.SearchContext;
028    import com.liferay.portal.kernel.util.GetterUtil;
029    import com.liferay.portal.kernel.util.InstancePool;
030    import com.liferay.portal.kernel.util.StringPool;
031    import com.liferay.portal.kernel.util.StringUtil;
032    import com.liferay.portal.kernel.util.Validator;
033    import com.liferay.portal.kernel.workflow.WorkflowConstants;
034    import com.liferay.portal.model.Group;
035    import com.liferay.portal.model.User;
036    import com.liferay.portal.util.PortalUtil;
037    import com.liferay.portal.util.PropsValues;
038    import com.liferay.portlet.asset.AssetRendererFactoryRegistryUtil;
039    import com.liferay.portlet.asset.NoSuchEntryException;
040    import com.liferay.portlet.asset.model.AssetCategoryConstants;
041    import com.liferay.portlet.asset.model.AssetEntry;
042    import com.liferay.portlet.asset.model.AssetLink;
043    import com.liferay.portlet.asset.model.AssetLinkConstants;
044    import com.liferay.portlet.asset.model.AssetRendererFactory;
045    import com.liferay.portlet.asset.model.AssetTag;
046    import com.liferay.portlet.asset.service.base.AssetEntryLocalServiceBaseImpl;
047    import com.liferay.portlet.asset.service.persistence.AssetEntryQuery;
048    import com.liferay.portlet.asset.util.AssetEntryValidator;
049    import com.liferay.portlet.assetpublisher.util.AssetSearcher;
050    import com.liferay.portlet.blogs.model.BlogsEntry;
051    import com.liferay.portlet.documentlibrary.model.DLFileEntry;
052    import com.liferay.portlet.documentlibrary.util.DLUtil;
053    import com.liferay.portlet.journal.model.JournalArticle;
054    import com.liferay.portlet.messageboards.model.MBMessage;
055    import com.liferay.portlet.social.model.SocialActivityConstants;
056    import com.liferay.portlet.wiki.model.WikiPage;
057    
058    import java.util.ArrayList;
059    import java.util.Date;
060    import java.util.List;
061    
062    /**
063     * Provides the local service for accessing, deleting, updating, and validating
064     * asset entries.
065     *
066     * @author Brian Wing Shun Chan
067     * @author Bruno Farache
068     * @author Zsolt Berentey
069     */
070    public class AssetEntryLocalServiceImpl extends AssetEntryLocalServiceBaseImpl {
071    
072            @Override
073            public void deleteEntry(AssetEntry entry) throws PortalException {
074    
075                    // Entry
076    
077                    List<AssetTag> tags = assetEntryPersistence.getAssetTags(
078                            entry.getEntryId());
079    
080                    assetEntryPersistence.remove(entry);
081    
082                    // Links
083    
084                    assetLinkLocalService.deleteLinks(entry.getEntryId());
085    
086                    // Tags
087    
088                    for (AssetTag tag : tags) {
089                            if (entry.isVisible()) {
090                                    assetTagLocalService.decrementAssetCount(
091                                            tag.getTagId(), entry.getClassNameId());
092                            }
093                    }
094    
095                    // Social
096    
097                    socialActivityLocalService.deleteActivities(entry);
098            }
099    
100            @Override
101            public void deleteEntry(long entryId) throws PortalException {
102                    AssetEntry entry = assetEntryPersistence.findByPrimaryKey(entryId);
103    
104                    deleteEntry(entry);
105            }
106    
107            @Override
108            public void deleteEntry(String className, long classPK)
109                    throws PortalException {
110    
111                    long classNameId = classNameLocalService.getClassNameId(className);
112    
113                    AssetEntry entry = assetEntryPersistence.fetchByC_C(
114                            classNameId, classPK);
115    
116                    if (entry != null) {
117                            deleteEntry(entry);
118                    }
119            }
120    
121            @Override
122            public void deleteGroupEntries(long groupId) throws PortalException {
123                    List<AssetEntry> assetEntries = getGroupEntries(groupId);
124    
125                    for (AssetEntry assetEntry : assetEntries) {
126                            deleteEntry(assetEntry);
127                    }
128            }
129    
130            @Override
131            public AssetEntry fetchEntry(long entryId) {
132                    return assetEntryPersistence.fetchByPrimaryKey(entryId);
133            }
134    
135            @Override
136            public AssetEntry fetchEntry(long groupId, String classUuid) {
137                    return assetEntryPersistence.fetchByG_CU(groupId, classUuid);
138            }
139    
140            @Override
141            public AssetEntry fetchEntry(String className, long classPK) {
142                    long classNameId = classNameLocalService.getClassNameId(className);
143    
144                    return assetEntryPersistence.fetchByC_C(classNameId, classPK);
145            }
146    
147            @Override
148            public List<AssetEntry> getAncestorEntries(long entryId)
149                    throws PortalException {
150    
151                    List<AssetEntry> entries = new ArrayList<AssetEntry>();
152    
153                    AssetEntry parentEntry = getParentEntry(entryId);
154    
155                    while (parentEntry != null) {
156                            entries.add(parentEntry);
157    
158                            parentEntry = getParentEntry(parentEntry.getEntryId());
159                    }
160    
161                    return entries;
162            }
163    
164            @Override
165            public List<AssetEntry> getChildEntries(long entryId)
166                    throws PortalException {
167    
168                    List<AssetEntry> entries = new ArrayList<AssetEntry>();
169    
170                    List<AssetLink> links = assetLinkLocalService.getDirectLinks(
171                            entryId, AssetLinkConstants.TYPE_CHILD);
172    
173                    for (AssetLink link : links) {
174                            AssetEntry curAsset = getEntry(link.getEntryId2());
175    
176                            entries.add(curAsset);
177                    }
178    
179                    return entries;
180            }
181    
182            @Override
183            public List<AssetEntry> getCompanyEntries(
184                    long companyId, int start, int end) {
185    
186                    return assetEntryPersistence.findByCompanyId(companyId, start, end);
187            }
188    
189            @Override
190            public int getCompanyEntriesCount(long companyId) {
191                    return assetEntryPersistence.countByCompanyId(companyId);
192            }
193    
194            @Override
195            public List<AssetEntry> getEntries(AssetEntryQuery entryQuery) {
196                    return assetEntryFinder.findEntries(entryQuery);
197            }
198    
199            @Override
200            public int getEntriesCount(AssetEntryQuery entryQuery) {
201                    return assetEntryFinder.countEntries(entryQuery);
202            }
203    
204            @Override
205            public AssetEntry getEntry(long entryId) throws PortalException {
206                    return assetEntryPersistence.findByPrimaryKey(entryId);
207            }
208    
209            @Override
210            public AssetEntry getEntry(long groupId, String classUuid)
211                    throws PortalException {
212    
213                    return assetEntryPersistence.findByG_CU(groupId, classUuid);
214            }
215    
216            @Override
217            public AssetEntry getEntry(String className, long classPK)
218                    throws PortalException {
219    
220                    long classNameId = classNameLocalService.getClassNameId(className);
221    
222                    return assetEntryPersistence.findByC_C(classNameId, classPK);
223            }
224    
225            @Override
226            public List<AssetEntry> getGroupEntries(long groupId) {
227                    return assetEntryPersistence.findByGroupId(groupId);
228            }
229    
230            @Override
231            public AssetEntry getNextEntry(long entryId) throws PortalException {
232                    try {
233                            getParentEntry(entryId);
234                    }
235                    catch (NoSuchEntryException nsee) {
236                            List<AssetEntry> childEntries = getChildEntries(entryId);
237    
238                            if (childEntries.isEmpty()) {
239                                    throw new NoSuchEntryException("{entryId=" + entryId + "}");
240                            }
241    
242                            return childEntries.get(0);
243                    }
244    
245                    List<AssetLink> links = assetLinkLocalService.getDirectLinks(
246                            entryId, AssetLinkConstants.TYPE_CHILD);
247    
248                    for (int i = 0; i < links.size(); i++) {
249                            AssetLink link = links.get(i);
250    
251                            if (link.getEntryId2() == entryId) {
252                                    if ((i + 1) >= links.size()) {
253                                            throw new NoSuchEntryException("{entryId=" + entryId + "}");
254                                    }
255                                    else {
256                                            AssetLink nextLink = links.get(i + 1);
257    
258                                            return getEntry(nextLink.getEntryId2());
259                                    }
260                            }
261                    }
262    
263                    throw new NoSuchEntryException("{entryId=" + entryId + "}");
264            }
265    
266            @Override
267            public AssetEntry getParentEntry(long entryId) throws PortalException {
268                    List<AssetLink> links = assetLinkLocalService.getReverseLinks(
269                            entryId, AssetLinkConstants.TYPE_CHILD);
270    
271                    if (links.isEmpty()) {
272                            throw new NoSuchEntryException("{entryId=" + entryId + "}");
273                    }
274    
275                    AssetLink link = links.get(0);
276    
277                    return getEntry(link.getEntryId1());
278            }
279    
280            @Override
281            public AssetEntry getPreviousEntry(long entryId) throws PortalException {
282                    getParentEntry(entryId);
283    
284                    List<AssetLink> links = assetLinkLocalService.getDirectLinks(
285                            entryId, AssetLinkConstants.TYPE_CHILD);
286    
287                    for (int i = 0; i < links.size(); i++) {
288                            AssetLink link = links.get(i);
289    
290                            if (link.getEntryId2() == entryId) {
291                                    if (i == 0) {
292                                            throw new NoSuchEntryException("{entryId=" + entryId + "}");
293                                    }
294                                    else {
295                                            AssetLink nextAssetLink = links.get(i - 1);
296    
297                                            return getEntry(nextAssetLink.getEntryId2());
298                                    }
299                            }
300                    }
301    
302                    throw new NoSuchEntryException("{entryId=" + entryId + "}");
303            }
304    
305            @Override
306            public List<AssetEntry> getTopViewedEntries(
307                    String className, boolean asc, int start, int end) {
308    
309                    return getTopViewedEntries(new String[] {className}, asc, start, end);
310            }
311    
312            @Override
313            public List<AssetEntry> getTopViewedEntries(
314                    String[] className, boolean asc, int start, int end) {
315    
316                    long[] classNameIds = new long[className.length];
317    
318                    for (int i = 0; i < className.length; i++) {
319                            classNameIds[i] = classNameLocalService.getClassNameId(
320                                    className[i]);
321                    }
322    
323                    AssetEntryQuery entryQuery = new AssetEntryQuery();
324    
325                    entryQuery.setClassNameIds(classNameIds);
326                    entryQuery.setEnd(end);
327                    entryQuery.setExcludeZeroViewCount(true);
328                    entryQuery.setOrderByCol1("viewCount");
329                    entryQuery.setOrderByType1(asc ? "ASC" : "DESC");
330                    entryQuery.setStart(start);
331    
332                    return assetEntryFinder.findEntries(entryQuery);
333            }
334    
335            @Override
336            public AssetEntry incrementViewCounter(
337                            long userId, String className, long classPK)
338                    throws PortalException {
339    
340                    User user = userPersistence.findByPrimaryKey(userId);
341    
342                    assetEntryLocalService.incrementViewCounter(
343                            user.getUserId(), className, classPK, 1);
344    
345                    AssetEntry assetEntry = getEntry(className, classPK);
346    
347                    if (!user.isDefaultUser()) {
348                            socialActivityLocalService.addActivity(
349                                    user.getUserId(), assetEntry.getGroupId(), className, classPK,
350                                    SocialActivityConstants.TYPE_VIEW, StringPool.BLANK, 0);
351                    }
352    
353                    return assetEntry;
354            }
355    
356            @BufferedIncrement(
357                    configuration = "AssetEntry", incrementClass = NumberIncrement.class)
358            @Override
359            public void incrementViewCounter(
360                    long userId, String className, long classPK, int increment) {
361    
362                    if (ExportImportThreadLocal.isImportInProcess() || (classPK <= 0)) {
363                            return;
364                    }
365    
366                    long classNameId = classNameLocalService.getClassNameId(className);
367    
368                    AssetEntry entry = assetEntryPersistence.fetchByC_C(
369                            classNameId, classPK);
370    
371                    if (entry == null) {
372                            return;
373                    }
374    
375                    entry.setViewCount(entry.getViewCount() + increment);
376    
377                    assetEntryPersistence.update(entry);
378            }
379    
380            @Override
381            public void reindex(List<AssetEntry> entries) throws PortalException {
382                    for (AssetEntry entry : entries) {
383                            String className = PortalUtil.getClassName(entry.getClassNameId());
384    
385                            Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(className);
386    
387                            indexer.reindex(className, entry.getClassPK());
388                    }
389            }
390    
391            @Override
392            public Hits search(
393                    long companyId, long[] groupIds, long userId, String className,
394                    long classTypeId, String keywords, int status, int start, int end) {
395    
396                    return search(
397                            companyId, groupIds, userId, className, classTypeId, null, null,
398                            null, null, null, status, false, start, end);
399            }
400    
401            @Override
402            public Hits search(
403                    long companyId, long[] groupIds, long userId, String className,
404                    long classTypeId, String userName, String title, String description,
405                    String assetCategoryIds, String assetTagNames, int status,
406                    boolean andSearch, int start, int end) {
407    
408                    try {
409                            Indexer indexer = AssetSearcher.getInstance();
410    
411                            AssetSearcher assetSearcher = (AssetSearcher)indexer;
412    
413                            AssetEntryQuery assetEntryQuery = new AssetEntryQuery();
414    
415                            assetEntryQuery.setClassNameIds(
416                                    getClassNameIds(companyId, className));
417    
418                            SearchContext searchContext = new SearchContext();
419    
420                            searchContext.setAndSearch(andSearch);
421                            searchContext.setAssetCategoryIds(
422                                    StringUtil.split(assetCategoryIds, 0L));
423                            searchContext.setAssetTagNames(StringUtil.split(assetTagNames));
424                            searchContext.setAttribute(Field.DESCRIPTION, description);
425                            searchContext.setAttribute(Field.TITLE, title);
426                            searchContext.setAttribute(Field.USER_NAME, userName);
427                            searchContext.setAttribute("paginationType", "regular");
428                            searchContext.setAttribute("status", status);
429    
430                            if (classTypeId > 0) {
431                                    searchContext.setClassTypeIds(new long[] {classTypeId});
432                            }
433    
434                            searchContext.setCompanyId(companyId);
435                            searchContext.setEnd(end);
436                            searchContext.setGroupIds(groupIds);
437                            searchContext.setStart(start);
438                            searchContext.setUserId(userId);
439    
440                            QueryConfig queryConfig = searchContext.getQueryConfig();
441    
442                            queryConfig.setHighlightEnabled(false);
443                            queryConfig.setScoreEnabled(false);
444    
445                            assetSearcher.setAssetEntryQuery(assetEntryQuery);
446    
447                            return assetSearcher.search(searchContext);
448                    }
449                    catch (Exception e) {
450                            throw new SystemException(e);
451                    }
452            }
453    
454            /**
455             * @deprecated As of 6.2.0, replaced by {@link #search(long, long[], long,
456             *             String, String, int, int, int)}
457             */
458            @Deprecated
459            @Override
460            public Hits search(
461                    long companyId, long[] groupIds, long userId, String className,
462                    String keywords, int start, int end) {
463    
464                    return search(
465                            companyId, groupIds, userId, className, keywords,
466                            WorkflowConstants.STATUS_ANY, start, end);
467            }
468    
469            @Override
470            public Hits search(
471                    long companyId, long[] groupIds, long userId, String className,
472                    String keywords, int status, int start, int end) {
473    
474                    return search(
475                            companyId, groupIds, userId, className, 0, keywords, status, start,
476                            end);
477            }
478    
479            /**
480             * @deprecated As of 6.2.0, replaced by {@link #search(long, long[], long,
481             *             String, String, String, String, String, String, int, boolean,
482             *             int, int)}
483             */
484            @Deprecated
485            @Override
486            public Hits search(
487                    long companyId, long[] groupIds, long userId, String className,
488                    String userName, String title, String description,
489                    String assetCategoryIds, String assetTagNames, boolean andSearch,
490                    int start, int end) {
491    
492                    return search(
493                            companyId, groupIds, userId, className, userName, title,
494                            description, assetCategoryIds, assetTagNames,
495                            WorkflowConstants.STATUS_ANY, andSearch, start, end);
496            }
497    
498            @Override
499            public Hits search(
500                    long companyId, long[] groupIds, long userId, String className,
501                    String userName, String title, String description,
502                    String assetCategoryIds, String assetTagNames, int status,
503                    boolean andSearch, int start, int end) {
504    
505                    return search(
506                            companyId, groupIds, userId, className, 0, userName, title,
507                            description, assetCategoryIds, assetTagNames, status, andSearch,
508                            start, end);
509            }
510    
511            /**
512             * @deprecated As of 6.2.0, replaced by {@link #search(long, long[], long,
513             *             String, String, int, int, int)}
514             */
515            @Deprecated
516            @Override
517            public Hits search(
518                    long companyId, long[] groupIds, String className, String keywords,
519                    int start, int end) {
520    
521                    return search(
522                            companyId, groupIds, 0, className, keywords,
523                            WorkflowConstants.STATUS_ANY, start, end);
524            }
525    
526            @Override
527            public AssetEntry updateEntry(
528                            long userId, long groupId, Date createDate, Date modifiedDate,
529                            String className, long classPK, String classUuid, long classTypeId,
530                            long[] categoryIds, String[] tagNames, boolean visible,
531                            Date startDate, Date endDate, Date expirationDate, String mimeType,
532                            String title, String description, String summary, String url,
533                            String layoutUuid, int height, int width, Integer priority,
534                            boolean sync)
535                    throws PortalException {
536    
537                    // Entry
538    
539                    long classNameId = classNameLocalService.getClassNameId(className);
540    
541                    validate(groupId, className, classTypeId, categoryIds, tagNames);
542    
543                    AssetEntry entry = assetEntryPersistence.fetchByC_C(
544                            classNameId, classPK);
545    
546                    boolean oldVisible = false;
547    
548                    if (entry != null) {
549                            oldVisible = entry.isVisible();
550                    }
551    
552                    if (modifiedDate == null) {
553                            modifiedDate = new Date();
554                    }
555    
556                    if (entry == null) {
557                            long entryId = counterLocalService.increment();
558    
559                            entry = assetEntryPersistence.create(entryId);
560    
561                            Group group = groupLocalService.getGroup(groupId);
562    
563                            entry.setCompanyId(group.getCompanyId());
564    
565                            entry.setUserId(userId);
566    
567                            User user = userPersistence.fetchByPrimaryKey(userId);
568    
569                            if (user != null) {
570                                    entry.setUserName(user.getFullName());
571                            }
572                            else {
573                                    entry.setUserName(StringPool.BLANK);
574                            }
575    
576                            if (createDate == null) {
577                                    createDate = new Date();
578                            }
579    
580                            entry.setCreateDate(createDate);
581    
582                            entry.setModifiedDate(modifiedDate);
583                            entry.setClassNameId(classNameId);
584                            entry.setClassPK(classPK);
585                            entry.setClassUuid(classUuid);
586                            entry.setVisible(visible);
587                            entry.setExpirationDate(expirationDate);
588    
589                            if (priority == null) {
590                                    entry.setPriority(0);
591                            }
592    
593                            entry.setViewCount(0);
594                    }
595    
596                    entry.setGroupId(groupId);
597                    entry.setModifiedDate(modifiedDate);
598                    entry.setClassTypeId(classTypeId);
599                    entry.setVisible(visible);
600                    entry.setStartDate(startDate);
601                    entry.setEndDate(endDate);
602                    entry.setExpirationDate(expirationDate);
603                    entry.setMimeType(mimeType);
604                    entry.setTitle(title);
605                    entry.setDescription(description);
606                    entry.setSummary(summary);
607                    entry.setUrl(url);
608                    entry.setLayoutUuid(layoutUuid);
609                    entry.setHeight(height);
610                    entry.setWidth(width);
611    
612                    if (priority != null) {
613                            entry.setPriority(priority.intValue());
614                    }
615    
616                    // Categories
617    
618                    if (categoryIds != null) {
619                            assetEntryPersistence.setAssetCategories(
620                                    entry.getEntryId(), categoryIds);
621                    }
622    
623                    // Tags
624    
625                    if (tagNames != null) {
626                            long siteGroupId = PortalUtil.getSiteGroupId(groupId);
627    
628                            Group siteGroup = groupLocalService.getGroup(siteGroupId);
629    
630                            List<AssetTag> tags = assetTagLocalService.checkTags(
631                                    userId, siteGroup, tagNames);
632    
633                            List<AssetTag> oldTags = assetEntryPersistence.getAssetTags(
634                                    entry.getEntryId());
635    
636                            assetEntryPersistence.setAssetTags(entry.getEntryId(), tags);
637    
638                            if (entry.isVisible()) {
639                                    boolean isNew = entry.isNew();
640    
641                                    assetEntryPersistence.updateImpl(entry);
642    
643                                    if (isNew) {
644                                            for (AssetTag tag : tags) {
645                                                    assetTagLocalService.incrementAssetCount(
646                                                            tag.getTagId(), classNameId);
647                                            }
648                                    }
649                                    else {
650                                            for (AssetTag oldTag : oldTags) {
651                                                    if (!tags.contains(oldTag)) {
652                                                            assetTagLocalService.decrementAssetCount(
653                                                                    oldTag.getTagId(), classNameId);
654                                                    }
655                                            }
656    
657                                            for (AssetTag tag : tags) {
658                                                    if (!oldTags.contains(tag)) {
659                                                            assetTagLocalService.incrementAssetCount(
660                                                                    tag.getTagId(), classNameId);
661                                                    }
662                                            }
663                                    }
664                            }
665                            else if (oldVisible) {
666                                    for (AssetTag oldTag : oldTags) {
667                                            assetTagLocalService.decrementAssetCount(
668                                                    oldTag.getTagId(), classNameId);
669                                    }
670                            }
671                    }
672    
673                    // Update entry after tags so that entry listeners have access to the
674                    // saved categories and tags
675    
676                    assetEntryPersistence.update(entry);
677    
678                    // Synchronize
679    
680                    if (!sync) {
681                            return entry;
682                    }
683    
684                    if (className.equals(BlogsEntry.class.getName())) {
685                            BlogsEntry blogsEntry = blogsEntryPersistence.findByPrimaryKey(
686                                    classPK);
687    
688                            blogsEntry.setTitle(title);
689    
690                            blogsEntryPersistence.update(blogsEntry);
691                    }
692                    else if (className.equals(DLFileEntry.class.getName())) {
693                            DLFileEntry dlFileEntry = dlFileEntryPersistence.findByPrimaryKey(
694                                    classPK);
695    
696                            String fileName = DLUtil.getSanitizedFileName(
697                                    title, dlFileEntry.getExtension());
698    
699                            dlFileEntry.setFileName(fileName);
700    
701                            dlFileEntry.setTitle(title);
702                            dlFileEntry.setDescription(description);
703    
704                            dlFileEntryPersistence.update(dlFileEntry);
705                    }
706                    else if (className.equals(JournalArticle.class.getName())) {
707                            JournalArticle journalArticle =
708                                    journalArticlePersistence.findByPrimaryKey(classPK);
709    
710                            journalArticle.setTitle(title);
711                            journalArticle.setDescription(description);
712    
713                            journalArticlePersistence.update(journalArticle);
714                    }
715                    else if (className.equals(MBMessage.class.getName())) {
716                            MBMessage mbMessage = mbMessagePersistence.findByPrimaryKey(
717                                    classPK);
718    
719                            mbMessage.setSubject(title);
720    
721                            mbMessagePersistence.update(mbMessage);
722                    }
723                    else if (className.equals(WikiPage.class.getName())) {
724                            WikiPage wikiPage = wikiPagePersistence.findByPrimaryKey(classPK);
725    
726                            wikiPage.setTitle(title);
727    
728                            wikiPagePersistence.update(wikiPage);
729                    }
730    
731                    return entry;
732            }
733    
734            @Override
735            public AssetEntry updateEntry(
736                            long userId, long groupId, String className, long classPK,
737                            long[] categoryIds, String[] tagNames)
738                    throws PortalException {
739    
740                    long classNameId = classNameLocalService.getClassNameId(className);
741    
742                    AssetEntry entry = assetEntryPersistence.fetchByC_C(
743                            classNameId, classPK);
744    
745                    if (entry != null) {
746                            return updateEntry(
747                                    userId, groupId, entry.getCreateDate(), entry.getModifiedDate(),
748                                    className, classPK, entry.getClassUuid(),
749                                    entry.getClassTypeId(), categoryIds, tagNames,
750                                    entry.isVisible(), entry.getStartDate(), entry.getEndDate(),
751                                    entry.getExpirationDate(), entry.getMimeType(),
752                                    entry.getTitle(), entry.getDescription(), entry.getSummary(),
753                                    entry.getUrl(), entry.getLayoutUuid(), entry.getHeight(),
754                                    entry.getWidth(), GetterUtil.getInteger(entry.getPriority()),
755                                    false);
756                    }
757    
758                    return updateEntry(
759                            userId, groupId, null, null, className, classPK, null, 0,
760                            categoryIds, tagNames, true, null, null, null, null, null, null,
761                            null, null, null, 0, 0, null, false);
762            }
763    
764            /**
765             * @deprecated As of 6.2.0, replaced by {@link #updateEntry(long, long,
766             *             String, long, String, long, long[], String[], boolean, Date,
767             *             Date, Date, String, String, String, String, String, String,
768             *             int, int, Integer, boolean)}
769             */
770            @Deprecated
771            @Override
772            public AssetEntry updateEntry(
773                            long userId, long groupId, String className, long classPK,
774                            String classUuid, long classTypeId, long[] categoryIds,
775                            String[] tagNames, boolean visible, Date startDate, Date endDate,
776                            Date publishDate, Date expirationDate, String mimeType,
777                            String title, String description, String summary, String url,
778                            String layoutUuid, int height, int width, Integer priority,
779                            boolean sync)
780                    throws PortalException {
781    
782                    return updateEntry(
783                            userId, groupId, className, classPK, classUuid, classTypeId,
784                            categoryIds, tagNames, visible, startDate, endDate, expirationDate,
785                            mimeType, title, description, summary, url, layoutUuid, height,
786                            width, priority, sync);
787            }
788    
789            /**
790             * @deprecated As of 6.2.0, replaced by {@link #updateEntry(long, long,
791             *             Date, Date, String, long, String, long, long[], String[],
792             *             boolean, Date, Date, Date, String, String, String, String,
793             *             String, String, int, int, Integer, boolean)}
794             */
795            @Deprecated
796            @Override
797            public AssetEntry updateEntry(
798                            long userId, long groupId, String className, long classPK,
799                            String classUuid, long classTypeId, long[] categoryIds,
800                            String[] tagNames, boolean visible, Date startDate, Date endDate,
801                            Date expirationDate, String mimeType, String title,
802                            String description, String summary, String url, String layoutUuid,
803                            int height, int width, Integer priority, boolean sync)
804                    throws PortalException {
805    
806                    return updateEntry(
807                            userId, groupId, null, null, className, classPK, classUuid,
808                            classTypeId, categoryIds, tagNames, visible, startDate, endDate,
809                            expirationDate, mimeType, title, description, summary, url,
810                            layoutUuid, height, width, priority, sync);
811            }
812    
813            @Override
814            public AssetEntry updateEntry(
815                            String className, long classPK, Date publishDate, boolean visible)
816                    throws PortalException {
817    
818                    long classNameId = classNameLocalService.getClassNameId(className);
819    
820                    AssetEntry entry = assetEntryPersistence.findByC_C(
821                            classNameId, classPK);
822    
823                    entry.setPublishDate(publishDate);
824    
825                    return updateVisible(entry, visible);
826            }
827    
828            @Override
829            public AssetEntry updateEntry(
830                            String className, long classPK, Date publishDate,
831                            Date expirationDate, boolean visible)
832                    throws PortalException {
833    
834                    long classNameId = classNameLocalService.getClassNameId(className);
835    
836                    AssetEntry entry = assetEntryPersistence.findByC_C(
837                            classNameId, classPK);
838    
839                    entry.setExpirationDate(expirationDate);
840                    entry.setPublishDate(publishDate);
841    
842                    return updateVisible(entry, visible);
843            }
844    
845            @Override
846            public AssetEntry updateVisible(
847                            String className, long classPK, boolean visible)
848                    throws PortalException {
849    
850                    long classNameId = classNameLocalService.getClassNameId(className);
851    
852                    AssetEntry entry = assetEntryPersistence.findByC_C(
853                            classNameId, classPK);
854    
855                    return updateVisible(entry, visible);
856            }
857    
858            @Override
859            public void validate(
860                            long groupId, String className, long classTypePK,
861                            long[] categoryIds, String[] tagNames)
862                    throws PortalException {
863    
864                    if (ExportImportThreadLocal.isImportInProcess()) {
865                            return;
866                    }
867    
868                    AssetEntryValidator validator = (AssetEntryValidator)InstancePool.get(
869                            PropsValues.ASSET_ENTRY_VALIDATOR);
870    
871                    validator.validate(
872                            groupId, className, classTypePK, categoryIds, tagNames);
873            }
874    
875            /**
876             * @deprecated As of 7.0.0, replaced by {@link #validate(long, String, long,
877             *             long[], String[])}
878             */
879            @Deprecated
880            @Override
881            public void validate(
882                            long groupId, String className, long[] categoryIds,
883                            String[] tagNames)
884                    throws PortalException {
885    
886                    validate(
887                            groupId, className, AssetCategoryConstants.ALL_CLASS_TYPE_PK,
888                            categoryIds, tagNames);
889            }
890    
891            protected long[] getClassNameIds(long companyId, String className) {
892                    if (Validator.isNotNull(className)) {
893                            return new long[] {classNameLocalService.getClassNameId(className)};
894                    }
895    
896                    List<AssetRendererFactory> rendererFactories =
897                            AssetRendererFactoryRegistryUtil.getAssetRendererFactories(
898                                    companyId);
899    
900                    long[] classNameIds = new long[rendererFactories.size()];
901    
902                    for (int i = 0; i < rendererFactories.size(); i++) {
903                            AssetRendererFactory rendererFactory = rendererFactories.get(i);
904    
905                            classNameIds[i] = classNameLocalService.getClassNameId(
906                                    rendererFactory.getClassName());
907                    }
908    
909                    return classNameIds;
910            }
911    
912            protected AssetEntry updateVisible(AssetEntry entry, boolean visible)
913                    throws PortalException {
914    
915                    if (visible == entry.isVisible()) {
916                            return assetEntryPersistence.update(entry);
917                    }
918    
919                    entry.setVisible(visible);
920    
921                    assetEntryPersistence.update(entry);
922    
923                    List<AssetTag> tags = assetEntryPersistence.getAssetTags(
924                            entry.getEntryId());
925    
926                    if (visible) {
927                            for (AssetTag tag : tags) {
928                                    assetTagLocalService.incrementAssetCount(
929                                            tag.getTagId(), entry.getClassNameId());
930                            }
931    
932                            socialActivityCounterLocalService.enableActivityCounters(
933                                    entry.getClassNameId(), entry.getClassPK());
934                    }
935                    else {
936                            for (AssetTag tag : tags) {
937                                    assetTagLocalService.decrementAssetCount(
938                                            tag.getTagId(), entry.getClassNameId());
939                            }
940    
941                            socialActivityCounterLocalService.disableActivityCounters(
942                                    entry.getClassNameId(), entry.getClassPK());
943                    }
944    
945                    return entry;
946            }
947    
948    }