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