1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.asset.service.impl;
16  
17  import com.liferay.portal.NoSuchGroupException;
18  import com.liferay.portal.kernel.dao.orm.QueryUtil;
19  import com.liferay.portal.kernel.exception.PortalException;
20  import com.liferay.portal.kernel.exception.SystemException;
21  import com.liferay.portal.kernel.log.Log;
22  import com.liferay.portal.kernel.log.LogFactoryUtil;
23  import com.liferay.portal.kernel.search.BooleanClauseOccur;
24  import com.liferay.portal.kernel.search.BooleanQuery;
25  import com.liferay.portal.kernel.search.BooleanQueryFactoryUtil;
26  import com.liferay.portal.kernel.search.Document;
27  import com.liferay.portal.kernel.search.Field;
28  import com.liferay.portal.kernel.search.Hits;
29  import com.liferay.portal.kernel.search.SearchEngineUtil;
30  import com.liferay.portal.kernel.search.TermQuery;
31  import com.liferay.portal.kernel.search.TermQueryFactoryUtil;
32  import com.liferay.portal.kernel.util.GetterUtil;
33  import com.liferay.portal.kernel.util.InstancePool;
34  import com.liferay.portal.kernel.util.ListUtil;
35  import com.liferay.portal.kernel.util.StringPool;
36  import com.liferay.portal.kernel.util.StringUtil;
37  import com.liferay.portal.kernel.util.Validator;
38  import com.liferay.portal.model.User;
39  import com.liferay.portal.service.ServiceContext;
40  import com.liferay.portal.util.PortalUtil;
41  import com.liferay.portal.util.PortletKeys;
42  import com.liferay.portal.util.PropsValues;
43  import com.liferay.portlet.asset.AssetRendererFactoryRegistryUtil;
44  import com.liferay.portlet.asset.NoSuchEntryException;
45  import com.liferay.portlet.asset.NoSuchTagException;
46  import com.liferay.portlet.asset.model.AssetCategory;
47  import com.liferay.portlet.asset.model.AssetEntry;
48  import com.liferay.portlet.asset.model.AssetEntryDisplay;
49  import com.liferay.portlet.asset.model.AssetLink;
50  import com.liferay.portlet.asset.model.AssetLinkConstants;
51  import com.liferay.portlet.asset.model.AssetRendererFactory;
52  import com.liferay.portlet.asset.model.AssetTag;
53  import com.liferay.portlet.asset.service.base.AssetEntryLocalServiceBaseImpl;
54  import com.liferay.portlet.asset.service.persistence.AssetEntryQuery;
55  import com.liferay.portlet.asset.util.AssetEntryValidator;
56  import com.liferay.portlet.blogs.model.BlogsEntry;
57  import com.liferay.portlet.bookmarks.model.BookmarksEntry;
58  import com.liferay.portlet.documentlibrary.model.DLFileEntry;
59  import com.liferay.portlet.documentlibrary.model.DLFolder;
60  import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
61  import com.liferay.portlet.imagegallery.model.IGImage;
62  import com.liferay.portlet.journal.model.JournalArticle;
63  import com.liferay.portlet.messageboards.model.MBMessage;
64  import com.liferay.portlet.wiki.model.WikiPage;
65  
66  import java.util.ArrayList;
67  import java.util.Date;
68  import java.util.List;
69  
70  /**
71   * <a href="AssetEntryLocalServiceImpl.java.html"><b><i>View Source</i></b></a>
72   *
73   * @author Brian Wing Shun Chan
74   * @author Bruno Farache
75   */
76  public class AssetEntryLocalServiceImpl extends AssetEntryLocalServiceBaseImpl {
77  
78      public void deleteEntry(AssetEntry entry) throws SystemException {
79  
80          // Entry
81  
82          assetEntryPersistence.remove(entry);
83  
84          // Links
85  
86          assetLinkLocalService.deleteLinks(entry.getEntryId());
87      }
88  
89      public void deleteEntry(long entryId)
90          throws PortalException, SystemException {
91  
92          AssetEntry entry = assetEntryPersistence.findByPrimaryKey(entryId);
93  
94          deleteEntry(entry);
95      }
96  
97      public void deleteEntry(String className, long classPK)
98          throws SystemException {
99  
100         long classNameId = PortalUtil.getClassNameId(className);
101 
102         AssetEntry entry = assetEntryPersistence.fetchByC_C(
103             classNameId, classPK);
104 
105         if (entry != null) {
106             deleteEntry(entry);
107         }
108     }
109 
110     public List<AssetEntry> getAncestorEntries(long entryId)
111         throws PortalException, SystemException {
112 
113         List<AssetEntry> entries = new ArrayList<AssetEntry>();
114 
115         AssetEntry parentEntry = getParentEntry(entryId);
116 
117         while (parentEntry != null) {
118             entries.add(parentEntry);
119 
120             parentEntry = getParentEntry(parentEntry.getEntryId());
121         }
122 
123         return entries;
124     }
125 
126     public List<AssetEntry> getChildEntries(long entryId)
127         throws PortalException, SystemException {
128 
129         List<AssetEntry> entries = new ArrayList<AssetEntry>();
130 
131         List<AssetLink> links = assetLinkLocalService.getLinks(
132             entryId, AssetLinkConstants.TYPE_CHILD);
133 
134         for (AssetLink link : links) {
135             AssetEntry curAsset = getEntry(link.getEntryId2());
136 
137             entries.add(curAsset);
138         }
139 
140         return entries;
141     }
142 
143     public List<AssetEntry> getCompanyEntries(
144             long companyId, int start, int end)
145         throws SystemException {
146 
147         return assetEntryPersistence.findByCompanyId(companyId, start, end);
148     }
149 
150     public int getCompanyEntriesCount(long companyId) throws SystemException {
151         return assetEntryPersistence.countByCompanyId(companyId);
152     }
153 
154     public AssetEntryDisplay[] getCompanyEntryDisplays(
155             long companyId, int start, int end, String languageId)
156         throws SystemException {
157 
158         return getEntryDisplays(
159             getCompanyEntries(companyId, start, end), languageId);
160     }
161 
162     public List<AssetEntry> getEntries(AssetEntryQuery entryQuery)
163         throws SystemException {
164 
165         return assetEntryFinder.findEntries(entryQuery);
166     }
167 
168     public int getEntriesCount(AssetEntryQuery entryQuery)
169         throws SystemException {
170 
171         return assetEntryFinder.countEntries(entryQuery);
172     }
173 
174     public AssetEntry getEntry(long entryId)
175         throws PortalException, SystemException {
176 
177         return assetEntryPersistence.findByPrimaryKey(entryId);
178     }
179 
180     public AssetEntry getEntry(String className, long classPK)
181         throws PortalException, SystemException {
182 
183         long classNameId = PortalUtil.getClassNameId(className);
184 
185         return assetEntryPersistence.findByC_C(classNameId, classPK);
186     }
187 
188     public AssetEntry getNextEntry(long entryId)
189         throws PortalException, SystemException {
190 
191         try {
192             getParentEntry(entryId);
193         }
194         catch (NoSuchEntryException nsee) {
195             List<AssetEntry> childEntries = getChildEntries(entryId);
196 
197             if (childEntries.isEmpty()) {
198                 throw new NoSuchEntryException();
199             }
200 
201             return childEntries.get(0);
202         }
203 
204         List<AssetLink> links = assetLinkLocalService.getLinks(
205             entryId, AssetLinkConstants.TYPE_CHILD);
206 
207         for (int i = 0; i < links.size(); i++) {
208             AssetLink link = links.get(i);
209 
210             if (link.getEntryId2() == entryId) {
211                 if ((i + 1) >= links.size()) {
212                     throw new NoSuchEntryException();
213                 }
214                 else {
215                     AssetLink nextLink = links.get(i + 1);
216 
217                     return getEntry(nextLink.getEntryId2());
218                 }
219             }
220         }
221 
222         throw new NoSuchEntryException();
223     }
224 
225     public AssetEntry getParentEntry(long entryId)
226         throws PortalException, SystemException {
227 
228         List<AssetLink> links = assetLinkLocalService.getReverseLinks(
229             entryId, AssetLinkConstants.TYPE_CHILD);
230 
231         if (links.isEmpty()) {
232             throw new NoSuchEntryException();
233         }
234 
235         AssetLink link = links.get(0);
236 
237         return getEntry(link.getEntryId1());
238     }
239 
240     public AssetEntry getPreviousEntry(long entryId)
241         throws PortalException, SystemException {
242 
243         getParentEntry(entryId);
244 
245         List<AssetLink> links = assetLinkLocalService.getLinks(
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 == 0) {
253                     throw new NoSuchEntryException();
254                 }
255                 else {
256                     AssetLink nextAssetLink = links.get(i - 1);
257 
258                     return getEntry(nextAssetLink.getEntryId2());
259                 }
260             }
261         }
262 
263         throw new NoSuchEntryException();
264     }
265 
266     public List<AssetEntry> getTopViewedEntries(
267             String className, boolean asc, int start, int end)
268         throws SystemException {
269 
270         return getTopViewedEntries(new String[] {className}, asc, start, end);
271     }
272 
273     public List<AssetEntry> getTopViewedEntries(
274             String[] className, boolean asc, int start, int end)
275         throws SystemException {
276 
277         long[] classNameIds = new long[className.length];
278 
279         for (int i = 0; i < className.length; i++) {
280             classNameIds[i] = PortalUtil.getClassNameId(className[i]);
281         }
282 
283         AssetEntryQuery entryQuery = new AssetEntryQuery();
284 
285         entryQuery.setClassNameIds(classNameIds);
286         entryQuery.setEnd(end);
287         entryQuery.setExcludeZeroViewCount(true);
288         entryQuery.setOrderByCol1("viewCount");
289         entryQuery.setOrderByType1(asc ? "ASC" : "DESC");
290         entryQuery.setStart(start);
291 
292         return assetEntryFinder.findEntries(entryQuery);
293     }
294 
295     public AssetEntry incrementViewCounter(String className, long classPK)
296         throws SystemException {
297 
298         if (classPK <= 0) {
299             return null;
300         }
301 
302         long classNameId = PortalUtil.getClassNameId(className);
303 
304         AssetEntry entry = assetEntryPersistence.fetchByC_C(
305             classNameId, classPK);
306 
307         if (entry != null) {
308             entry.setViewCount(entry.getViewCount() + 1);
309 
310             assetEntryPersistence.update(entry, false);
311         }
312 
313         return entry;
314     }
315 
316     public Hits search(
317             long companyId, String portletId, String keywords, int start,
318             int end)
319         throws SystemException {
320 
321         try {
322             BooleanQuery contextQuery = BooleanQueryFactoryUtil.create();
323 
324             if (Validator.isNotNull(portletId)) {
325                 contextQuery.addRequiredTerm(Field.PORTLET_ID, portletId);
326             }
327             else {
328                 BooleanQuery portletIdsQuery = BooleanQueryFactoryUtil.create();
329 
330                 List<AssetRendererFactory> rendererFactories =
331                     AssetRendererFactoryRegistryUtil.
332                         getAssetRendererFactories();
333 
334                 for (AssetRendererFactory rendererFactory : rendererFactories) {
335                     TermQuery termQuery = TermQueryFactoryUtil.create(
336                         Field.PORTLET_ID, rendererFactory.getPortletId());
337 
338                     portletIdsQuery.add(termQuery, BooleanClauseOccur.SHOULD);
339                 }
340 
341                 contextQuery.add(portletIdsQuery, BooleanClauseOccur.MUST);
342             }
343 
344             BooleanQuery searchQuery = BooleanQueryFactoryUtil.create();
345 
346             if (Validator.isNotNull(keywords)) {
347                 searchQuery.addTerm(Field.TITLE, keywords);
348                 searchQuery.addTerm(Field.CONTENT, keywords);
349                 searchQuery.addTerm(Field.DESCRIPTION, keywords);
350                 searchQuery.addTerm(Field.PROPERTIES, keywords);
351                 searchQuery.addTerm(Field.ASSET_TAG_NAMES, keywords, true);
352             }
353 
354             BooleanQuery fullQuery = BooleanQueryFactoryUtil.create();
355 
356             fullQuery.add(contextQuery, BooleanClauseOccur.MUST);
357 
358             if (searchQuery.clauses().size() > 0) {
359                 fullQuery.add(searchQuery, BooleanClauseOccur.MUST);
360             }
361 
362             return SearchEngineUtil.search(companyId, fullQuery, start, end);
363         }
364         catch (Exception e) {
365             throw new SystemException(e);
366         }
367     }
368 
369     public AssetEntryDisplay[] searchEntryDisplays(
370             long companyId, String portletId, String keywords,
371             String languageId, int start, int end)
372         throws SystemException {
373 
374         List<AssetEntry> entries = new ArrayList<AssetEntry>();
375 
376         Hits hits = search(companyId, portletId, keywords, start, end);
377 
378         List<Document> hitsList = hits.toList();
379 
380         for (Document doc : hitsList) {
381             try {
382                 AssetEntry entry = getEntry(doc);
383 
384                 if (entry != null) {
385                     entries.add(entry);
386                 }
387             }
388             catch (Exception e) {
389                 if (_log.isWarnEnabled()) {
390                     _log.warn(e);
391                 }
392             }
393         }
394 
395         return getEntryDisplays(entries, languageId);
396     }
397 
398     public int searchEntryDisplaysCount(
399             long companyId, String portletId, String keywords,
400             String languageId)
401         throws SystemException {
402 
403         Hits hits = search(
404             companyId, portletId, keywords, QueryUtil.ALL_POS,
405             QueryUtil.ALL_POS);
406 
407         return hits.getLength();
408     }
409 
410     public AssetEntry updateEntry(
411             long userId, long groupId, String className, long classPK,
412             long[] categoryIds, String[] tagNames)
413         throws PortalException, SystemException {
414 
415         return updateEntry(
416             userId, groupId, className, classPK, categoryIds, tagNames,
417             true, null, null, null, null, null, null, null, null, null, 0, 0,
418             null, false);
419     }
420 
421     public AssetEntry updateEntry(
422             long userId, long groupId, String className, long classPK,
423             long[] categoryIds, String[] tagNames, boolean visible,
424             Date startDate, Date endDate, Date publishDate, Date expirationDate,
425             String mimeType, String title, String description, String summary,
426             String url, int height, int width, Integer priority, boolean sync)
427         throws PortalException, SystemException {
428 
429         // Entry
430 
431         User user = userPersistence.findByPrimaryKey(userId);
432         long classNameId = PortalUtil.getClassNameId(className);
433 
434         title = StringUtil.shorten(title, 300, StringPool.BLANK);
435         Date now = new Date();
436 
437         validate(className, categoryIds, tagNames);
438 
439         AssetEntry entry = assetEntryPersistence.fetchByC_C(
440             classNameId, classPK);
441 
442         if (entry == null) {
443             long entryId = counterLocalService.increment();
444 
445             entry = assetEntryPersistence.create(entryId);
446 
447             entry.setCompanyId(user.getCompanyId());
448             entry.setUserId(user.getUserId());
449             entry.setUserName(user.getFullName());
450             entry.setCreateDate(now);
451             entry.setClassNameId(classNameId);
452             entry.setClassPK(classPK);
453             entry.setVisible(visible);
454             entry.setPublishDate(publishDate);
455             entry.setExpirationDate(expirationDate);
456 
457             if (priority == null) {
458                 entry.setPriority(0);
459             }
460 
461             entry.setViewCount(0);
462         }
463 
464         entry.setGroupId(groupId);
465         entry.setModifiedDate(now);
466         entry.setVisible(visible);
467         entry.setStartDate(startDate);
468         entry.setEndDate(endDate);
469         entry.setPublishDate(publishDate);
470         entry.setExpirationDate(expirationDate);
471         entry.setMimeType(mimeType);
472         entry.setTitle(title);
473         entry.setDescription(description);
474         entry.setSummary(summary);
475         entry.setUrl(url);
476         entry.setHeight(height);
477         entry.setWidth(width);
478 
479         if (priority != null) {
480             entry.setPriority(priority.intValue());
481         }
482 
483         // Categories
484 
485         if (categoryIds != null) {
486             assetEntryPersistence.setAssetCategories(
487                 entry.getEntryId(), categoryIds);
488         }
489 
490         // Tags
491 
492         if (tagNames != null) {
493             long parentGroupId = PortalUtil.getParentGroupId(groupId);
494 
495             List<AssetTag> tags = new ArrayList<AssetTag>(tagNames.length);
496 
497             for (String tagName : tagNames) {
498                 AssetTag tag = null;
499 
500                 try {
501                     tag = assetTagLocalService.getTag(parentGroupId, tagName);
502                 }
503                 catch (NoSuchTagException nste) {
504                     ServiceContext serviceContext = new ServiceContext();
505 
506                     serviceContext.setAddCommunityPermissions(true);
507                     serviceContext.setAddGuestPermissions(true);
508                     serviceContext.setScopeGroupId(parentGroupId);
509 
510                     tag = assetTagLocalService.addTag(
511                         user.getUserId(), tagName,
512                         PropsValues.ASSET_TAG_PROPERTIES_DEFAULT,
513                         serviceContext);
514                 }
515 
516                 if (tag != null) {
517                     tags.add(tag);
518                 }
519             }
520 
521             List<AssetTag> oldTags = assetEntryPersistence.getAssetTags(
522                 entry.getEntryId());
523 
524             assetEntryPersistence.setAssetTags(entry.getEntryId(), tags);
525 
526             if (entry.isNew()) {
527                 for (AssetTag tag : tags) {
528                     assetTagLocalService.incrementAssetCount(
529                         tag.getTagId(), classNameId);
530                 }
531             }
532             else {
533                 for (AssetTag oldTag : oldTags) {
534                     if (!tags.contains(oldTag)) {
535                         assetTagLocalService.decrementAssetCount(
536                             oldTag.getTagId(), classNameId);
537                     }
538                 }
539 
540                 for (AssetTag tag : tags) {
541                     if (!oldTags.contains(tag)) {
542                         assetTagLocalService.incrementAssetCount(
543                             tag.getTagId(), classNameId);
544                     }
545                 }
546             }
547         }
548 
549         // Update entry after tags so that entry listeners have access to the
550         // saved categories and tags
551 
552         assetEntryPersistence.update(entry, false);
553 
554         // Synchronize
555 
556         if (!sync) {
557             return entry;
558         }
559 
560         if (className.equals(BlogsEntry.class.getName())) {
561             BlogsEntry blogsEntry = blogsEntryPersistence.findByPrimaryKey(
562                 classPK);
563 
564             blogsEntry.setTitle(title);
565 
566             blogsEntryPersistence.update(blogsEntry, false);
567         }
568         else if (className.equals(BookmarksEntry.class.getName())) {
569             BookmarksEntry bookmarksEntry =
570                 bookmarksEntryPersistence.findByPrimaryKey(classPK);
571 
572             bookmarksEntry.setName(title);
573             bookmarksEntry.setComments(description);
574             bookmarksEntry.setUrl(url);
575 
576             bookmarksEntryPersistence.update(bookmarksEntry, false);
577         }
578         else if (className.equals(DLFileEntry.class.getName())) {
579             DLFileEntry dlFileEntry = dlFileEntryPersistence.findByPrimaryKey(
580                 classPK);
581 
582             dlFileEntry.setTitle(title);
583             dlFileEntry.setDescription(description);
584 
585             dlFileEntryPersistence.update(dlFileEntry, false);
586         }
587         else if (className.equals(JournalArticle.class.getName())) {
588             JournalArticle journalArticle =
589                 journalArticlePersistence.findByPrimaryKey(classPK);
590 
591             journalArticle.setTitle(title);
592             journalArticle.setDescription(description);
593 
594             journalArticlePersistence.update(journalArticle, false);
595         }
596         else if (className.equals(MBMessage.class.getName())) {
597             MBMessage mbMessage = mbMessagePersistence.findByPrimaryKey(
598                 classPK);
599 
600             mbMessage.setSubject(title);
601 
602             mbMessagePersistence.update(mbMessage, false);
603         }
604         else if (className.equals(WikiPage.class.getName())) {
605             WikiPage wikiPage = wikiPagePersistence.findByPrimaryKey(classPK);
606 
607             wikiPage.setTitle(title);
608 
609             wikiPagePersistence.update(wikiPage, false);
610         }
611 
612         return entry;
613     }
614 
615     public AssetEntry updateVisible(
616             String className, long classPK, boolean visible)
617         throws PortalException, SystemException {
618 
619         long classNameId = PortalUtil.getClassNameId(className);
620 
621         AssetEntry entry = assetEntryPersistence.findByC_C(
622             classNameId, classPK);
623 
624         entry.setVisible(visible);
625 
626         assetEntryPersistence.update(entry, false);
627 
628         return entry;
629     }
630 
631     public void validate(
632             String className, long[] categoryIds, String[] tagNames)
633         throws PortalException {
634 
635         AssetEntryValidator validator = (AssetEntryValidator)InstancePool.get(
636             PropsValues.ASSET_ENTRY_VALIDATOR);
637 
638         validator.validate(className, categoryIds, tagNames);
639     }
640 
641     protected AssetEntry getEntry(Document doc)
642         throws PortalException, SystemException {
643 
644         String portletId = GetterUtil.getString(doc.get(Field.PORTLET_ID));
645 
646         if (portletId.equals(PortletKeys.BLOGS)) {
647             long entryId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
648 
649             long classNameId = PortalUtil.getClassNameId(
650                 BlogsEntry.class.getName());
651             long classPK = entryId;
652 
653             return assetEntryPersistence.findByC_C(classNameId, classPK);
654         }
655         else if (portletId.equals(PortletKeys.BOOKMARKS)) {
656             long entryId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
657 
658             long classNameId = PortalUtil.getClassNameId(
659                 BookmarksEntry.class.getName());
660             long classPK = entryId;
661 
662             return assetEntryPersistence.findByC_C(classNameId, classPK);
663         }
664         else if (portletId.equals(PortletKeys.DOCUMENT_LIBRARY)) {
665             long repositoryId = GetterUtil.getLong(doc.get("repositoryId"));
666             String name = doc.get("path");
667 
668             long groupId = 0;
669             long folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
670 
671             try {
672                 groupPersistence.findByPrimaryKey(repositoryId);
673 
674                 groupId = repositoryId;
675             }
676             catch (NoSuchGroupException nsge) {
677                 DLFolder folder = dlFolderPersistence.findByPrimaryKey(
678                     repositoryId);
679 
680                 groupId = folder.getGroupId();
681                 folderId = folder.getFolderId();
682             }
683 
684             DLFileEntry fileEntry = dlFileEntryLocalService.getFileEntry(
685                 groupId, folderId, name);
686 
687             long classNameId = PortalUtil.getClassNameId(
688                 DLFileEntry.class.getName());
689             long classPK = fileEntry.getFileEntryId();
690 
691             return assetEntryPersistence.findByC_C(classNameId, classPK);
692         }
693         else if (portletId.equals(PortletKeys.IMAGE_GALLERY)) {
694             long imageId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
695 
696             long classNameId = PortalUtil.getClassNameId(
697                 IGImage.class.getName());
698             long classPK = imageId;
699 
700             return assetEntryPersistence.findByC_C(classNameId, classPK);
701         }
702         else if (portletId.equals(PortletKeys.JOURNAL)) {
703             long groupId = GetterUtil.getLong(doc.get(Field.GROUP_ID));
704             String articleId = doc.get(Field.ENTRY_CLASS_PK);
705             //double version = GetterUtil.getDouble(doc.get("version"));
706 
707             long articleResourcePrimKey =
708                 journalArticleResourceLocalService.getArticleResourcePrimKey(
709                     groupId, articleId);
710 
711             long classNameId = PortalUtil.getClassNameId(
712                 JournalArticle.class.getName());
713             long classPK = articleResourcePrimKey;
714 
715             return assetEntryPersistence.findByC_C(classNameId, classPK);
716         }
717         else if (portletId.equals(PortletKeys.MESSAGE_BOARDS)) {
718             long messageId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
719 
720             long classNameId = PortalUtil.getClassNameId(
721                 MBMessage.class.getName());
722             long classPK = messageId;
723 
724             return assetEntryPersistence.findByC_C(classNameId, classPK);
725         }
726         else if (portletId.equals(PortletKeys.WIKI)) {
727             long nodeId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
728             String title = doc.get(Field.TITLE);
729 
730             long pageResourcePrimKey =
731                 wikiPageResourceLocalService.getPageResourcePrimKey(
732                     nodeId, title);
733 
734             long classNameId = PortalUtil.getClassNameId(
735                 WikiPage.class.getName());
736             long classPK = pageResourcePrimKey;
737 
738             return assetEntryPersistence.findByC_C(classNameId, classPK);
739         }
740 
741         return null;
742     }
743 
744     protected AssetEntryDisplay[] getEntryDisplays(
745             List<AssetEntry> entries, String languageId)
746         throws SystemException {
747 
748         AssetEntryDisplay[] entryDisplays =
749             new AssetEntryDisplay[entries.size()];
750 
751         for (int i = 0; i < entries.size(); i++) {
752             AssetEntry entry = entries.get(i);
753 
754             String className = PortalUtil.getClassName(entry.getClassNameId());
755             String portletId = PortalUtil.getClassNamePortletId(className);
756             String portletTitle = PortalUtil.getPortletTitle(
757                 portletId, languageId);
758 
759             List<AssetCategory> categories =
760                 assetEntryPersistence.getAssetCategories(entry.getEntryId());
761 
762             String categoryIdsString = ListUtil.toString(
763                 categories, "assetCategoryId", StringPool.COMMA);
764             long[] categoryIds = StringUtil.split(
765                 categoryIdsString, StringPool.COMMA, 0L);
766 
767             List<AssetTag> tags = assetEntryPersistence.getAssetTags(
768                 entry.getEntryId());
769 
770             String tagNames = ListUtil.toString(tags, "name", ", ");
771 
772             AssetEntryDisplay entryDisplay = new AssetEntryDisplay();
773 
774             entryDisplay.setEntryId(entry.getEntryId());
775             entryDisplay.setCompanyId(entry.getCompanyId());
776             entryDisplay.setUserId(entry.getUserId());
777             entryDisplay.setUserName(entry.getUserName());
778             entryDisplay.setCreateDate(entry.getCreateDate());
779             entryDisplay.setModifiedDate(entry.getModifiedDate());
780             entryDisplay.setClassNameId(entry.getClassNameId());
781             entryDisplay.setClassName(className);
782             entryDisplay.setClassPK(entry.getClassPK());
783             entryDisplay.setPortletId(portletId);
784             entryDisplay.setPortletTitle(portletTitle);
785             entryDisplay.setStartDate(entry.getStartDate());
786             entryDisplay.setEndDate(entry.getEndDate());
787             entryDisplay.setPublishDate(entry.getPublishDate());
788             entryDisplay.setExpirationDate(entry.getExpirationDate());
789             entryDisplay.setMimeType(entry.getMimeType());
790             entryDisplay.setTitle(entry.getTitle());
791             entryDisplay.setDescription(entry.getDescription());
792             entryDisplay.setSummary(entry.getSummary());
793             entryDisplay.setUrl(entry.getUrl());
794             entryDisplay.setHeight(entry.getHeight());
795             entryDisplay.setWidth(entry.getWidth());
796             entryDisplay.setPriority(entry.getPriority());
797             entryDisplay.setViewCount(entry.getViewCount());
798             entryDisplay.setCategoryIds(categoryIds);
799             entryDisplay.setTagNames(tagNames);
800 
801             entryDisplays[i] = entryDisplay;
802         }
803 
804         return entryDisplays;
805     }
806 
807     private static Log _log = LogFactoryUtil.getLog(
808         AssetEntryLocalServiceImpl.class);
809 
810 }