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