1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.tags.service.impl;
24  
25  import com.liferay.portal.PortalException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.kernel.dao.orm.QueryUtil;
28  import com.liferay.portal.kernel.log.Log;
29  import com.liferay.portal.kernel.log.LogFactoryUtil;
30  import com.liferay.portal.kernel.search.BooleanClauseOccur;
31  import com.liferay.portal.kernel.search.BooleanQuery;
32  import com.liferay.portal.kernel.search.BooleanQueryFactoryUtil;
33  import com.liferay.portal.kernel.search.Document;
34  import com.liferay.portal.kernel.search.Field;
35  import com.liferay.portal.kernel.search.Hits;
36  import com.liferay.portal.kernel.search.SearchEngineUtil;
37  import com.liferay.portal.kernel.search.TermQuery;
38  import com.liferay.portal.kernel.search.TermQueryFactoryUtil;
39  import com.liferay.portal.kernel.util.GetterUtil;
40  import com.liferay.portal.kernel.util.InstancePool;
41  import com.liferay.portal.kernel.util.ListUtil;
42  import com.liferay.portal.kernel.util.StringPool;
43  import com.liferay.portal.kernel.util.StringUtil;
44  import com.liferay.portal.kernel.util.Validator;
45  import com.liferay.portal.model.User;
46  import com.liferay.portal.util.PortalInstances;
47  import com.liferay.portal.util.PortalUtil;
48  import com.liferay.portal.util.PortletKeys;
49  import com.liferay.portal.util.PropsValues;
50  import com.liferay.portlet.blogs.model.BlogsEntry;
51  import com.liferay.portlet.bookmarks.model.BookmarksEntry;
52  import com.liferay.portlet.documentlibrary.model.DLFileEntry;
53  import com.liferay.portlet.imagegallery.model.IGImage;
54  import com.liferay.portlet.journal.model.JournalArticle;
55  import com.liferay.portlet.messageboards.model.MBMessage;
56  import com.liferay.portlet.tags.model.TagsAsset;
57  import com.liferay.portlet.tags.model.TagsAssetDisplay;
58  import com.liferay.portlet.tags.model.TagsAssetType;
59  import com.liferay.portlet.tags.model.TagsEntry;
60  import com.liferay.portlet.tags.service.base.TagsAssetLocalServiceBaseImpl;
61  import com.liferay.portlet.tags.util.TagsAssetValidator;
62  import com.liferay.portlet.tags.util.TagsUtil;
63  import com.liferay.portlet.wiki.model.WikiPage;
64  
65  import java.util.ArrayList;
66  import java.util.Date;
67  import java.util.List;
68  
69  /**
70   * <a href="TagsAssetLocalServiceImpl.java.html"><b><i>View Source</i></b></a>
71   *
72   * @author Brian Wing Shun Chan
73   *
74   */
75  public class TagsAssetLocalServiceImpl extends TagsAssetLocalServiceBaseImpl {
76  
77      public void deleteAsset(long assetId)
78          throws PortalException, SystemException {
79  
80          TagsAsset asset = tagsAssetPersistence.findByPrimaryKey(assetId);
81  
82          deleteAsset(asset);
83      }
84  
85      public void deleteAsset(String className, long classPK)
86          throws SystemException {
87  
88          long classNameId = PortalUtil.getClassNameId(className);
89  
90          TagsAsset asset = tagsAssetPersistence.fetchByC_C(classNameId, classPK);
91  
92          if (asset != null) {
93              deleteAsset(asset);
94          }
95      }
96  
97      public void deleteAsset(TagsAsset asset) throws SystemException {
98          tagsAssetPersistence.remove(asset);
99      }
100 
101     public TagsAsset getAsset(long assetId)
102         throws PortalException, SystemException {
103 
104         return tagsAssetPersistence.findByPrimaryKey(assetId);
105     }
106 
107     public TagsAsset getAsset(String className, long classPK)
108         throws PortalException, SystemException {
109 
110         long classNameId = PortalUtil.getClassNameId(className);
111 
112         return tagsAssetPersistence.findByC_C(classNameId, classPK);
113     }
114 
115     public TagsAssetType[] getAssetTypes(String languageId) {
116         TagsAssetType[] assetTypes =
117             new TagsAssetType[TagsUtil.ASSET_TYPE_CLASS_NAMES.length];
118 
119         for (int i = 0; i < TagsUtil.ASSET_TYPE_CLASS_NAMES.length; i++) {
120             assetTypes[i] = getAssetType(
121                 TagsUtil.ASSET_TYPE_CLASS_NAMES[i], languageId);
122         }
123 
124         return assetTypes;
125     }
126 
127     public List<TagsAsset> getAssets(
128             long[] entryIds, long[] notEntryIds, boolean andOperator,
129             boolean excludeZeroViewCount, int start, int end)
130         throws SystemException {
131 
132         return getAssets(
133             0, new long[0], entryIds, notEntryIds, andOperator,
134             excludeZeroViewCount, null, null, start, end);
135     }
136 
137     public List<TagsAsset> getAssets(
138             long groupId, long[] classNameIds, long[] entryIds,
139             long[] notEntryIds, boolean andOperator,
140             boolean excludeZeroViewCount, int start, int end)
141         throws SystemException {
142 
143         return getAssets(
144             groupId, classNameIds, entryIds, notEntryIds, andOperator,
145             excludeZeroViewCount, null, null, start, end);
146     }
147 
148     public List<TagsAsset> getAssets(
149             long[] entryIds, long[] notEntryIds, boolean andOperator,
150             boolean excludeZeroViewCount, Date publishDate, Date expirationDate,
151             int start, int end)
152         throws SystemException {
153 
154         return getAssets(
155             0, new long[0], entryIds, notEntryIds, andOperator,
156             excludeZeroViewCount, publishDate, expirationDate, start, end);
157     }
158 
159     public List<TagsAsset> getAssets(
160             long groupId, long[] classNameIds, long[] entryIds,
161             long[] notEntryIds, boolean andOperator,
162             boolean excludeZeroViewCount, Date publishDate, Date expirationDate,
163             int start, int end)
164         throws SystemException {
165 
166         if ((entryIds.length == 0) && (notEntryIds.length == 0)) {
167             return tagsAssetFinder.findAssets(
168                 groupId, classNameIds, null, null, null, null,
169                 excludeZeroViewCount, publishDate, expirationDate, start, end);
170         }
171         else if (andOperator) {
172             return tagsAssetFinder.findByAndEntryIds(
173                 groupId, classNameIds, entryIds, notEntryIds, null, null, null,
174                 null, excludeZeroViewCount, publishDate, expirationDate, start,
175                 end);
176         }
177         else {
178             return tagsAssetFinder.findByOrEntryIds(
179                 groupId, classNameIds, entryIds, notEntryIds, null, null, null,
180                 null, excludeZeroViewCount, publishDate, expirationDate, start,
181                 end);
182         }
183     }
184 
185     public List<TagsAsset> getAssets(
186             long[] entryIds, long[] notEntryIds, boolean andOperator,
187             String orderByCol1, String orderByCol2, String orderByType1,
188             String orderByType2, boolean excludeZeroViewCount, Date publishDate,
189             Date expirationDate, int start, int end)
190         throws SystemException {
191 
192         return getAssets(
193             0, new long[0], entryIds, notEntryIds, andOperator,
194             excludeZeroViewCount, publishDate, expirationDate, start, end);
195     }
196 
197     public List<TagsAsset> getAssets(
198             long groupId, long[] classNameIds, long[] entryIds,
199             long[] notEntryIds, boolean andOperator, String orderByCol1,
200             String orderByCol2, String orderByType1, String orderByType2,
201             boolean excludeZeroViewCount, Date publishDate, Date expirationDate,
202             int start, int end)
203         throws SystemException {
204 
205         if ((entryIds.length == 0) && (notEntryIds.length == 0)) {
206             return tagsAssetFinder.findAssets(
207                 groupId, classNameIds, orderByCol1, orderByCol2, orderByType1,
208                 orderByType2, excludeZeroViewCount, publishDate, expirationDate,
209                 start, end);
210         }
211         else if (andOperator) {
212             return tagsAssetFinder.findByAndEntryIds(
213                 groupId, classNameIds, entryIds, notEntryIds, orderByCol1,
214                 orderByCol2, orderByType1, orderByType2, excludeZeroViewCount,
215                 publishDate, expirationDate, start, end);
216         }
217         else {
218             return tagsAssetFinder.findByOrEntryIds(
219                 groupId, classNameIds, entryIds, notEntryIds, orderByCol1,
220                 orderByCol2, orderByType1, orderByType2, excludeZeroViewCount,
221                 publishDate, expirationDate, start, end);
222         }
223     }
224 
225     public int getAssetsCount(
226             long[] entryIds, long[] notEntryIds, boolean andOperator,
227             boolean excludeZeroViewCount)
228         throws SystemException {
229 
230         return getAssetsCount(
231             0, new long[0], entryIds, notEntryIds, andOperator,
232             excludeZeroViewCount, null, null);
233     }
234 
235     public int getAssetsCount(
236             long groupId, long[] entryIds, long[] notEntryIds,
237             boolean andOperator, boolean excludeZeroViewCount)
238         throws SystemException {
239 
240         return getAssetsCount(
241             groupId, new long[0], entryIds, notEntryIds, andOperator,
242             excludeZeroViewCount, null, null);
243     }
244 
245     public int getAssetsCount(
246             long[] entryIds, long[] notEntryIds, boolean andOperator,
247             boolean excludeZeroViewCount, Date publishDate, Date expirationDate)
248         throws SystemException {
249 
250         return getAssetsCount(
251             0, new long[0], entryIds, notEntryIds, andOperator,
252             excludeZeroViewCount, publishDate, expirationDate);
253     }
254 
255     public int getAssetsCount(
256             long groupId, long[] classNameIds, long[] entryIds,
257             long[] notEntryIds, boolean andOperator,
258             boolean excludeZeroViewCount, Date publishDate, Date expirationDate)
259         throws SystemException {
260 
261         if ((entryIds.length == 0) && (notEntryIds.length == 0)) {
262             return tagsAssetFinder.countAssets(
263                 groupId, classNameIds, excludeZeroViewCount, publishDate,
264                 expirationDate);
265         }
266         else if (andOperator) {
267             return tagsAssetFinder.countByAndEntryIds(
268                 groupId, classNameIds, entryIds, notEntryIds,
269                 excludeZeroViewCount, publishDate, expirationDate);
270         }
271         else {
272             return tagsAssetFinder.countByOrEntryIds(
273                 groupId, classNameIds, entryIds, notEntryIds,
274                 excludeZeroViewCount, publishDate, expirationDate);
275         }
276     }
277 
278     public TagsAssetDisplay[] getCompanyAssetDisplays(
279             long companyId, int start, int end, String languageId)
280         throws SystemException {
281 
282         return getAssetDisplays(
283             getCompanyAssets(companyId, start, end), languageId);
284     }
285 
286     public List<TagsAsset> getCompanyAssets(long companyId, int start, int end)
287         throws SystemException {
288 
289         return tagsAssetPersistence.findByCompanyId(companyId, start, end);
290     }
291 
292     public int getCompanyAssetsCount(long companyId) throws SystemException {
293         return tagsAssetPersistence.countByCompanyId(companyId);
294     }
295 
296     public List<TagsAsset> getTopViewedAssets(
297             String className, boolean asc, int start, int end)
298         throws SystemException {
299 
300         return getTopViewedAssets(new String[] {className}, asc, start, end);
301     }
302 
303     public List<TagsAsset> getTopViewedAssets(
304             String[] className, boolean asc, int start, int end)
305         throws SystemException {
306 
307         long[] classNameIds = new long[className.length];
308 
309         for (int i = 0; i < className.length; i++) {
310             classNameIds[i] = PortalUtil.getClassNameId(className[i]);
311         }
312 
313         return tagsAssetFinder.findByViewCount(classNameIds, asc, start, end);
314     }
315 
316     public TagsAsset incrementViewCounter(String className, long classPK)
317         throws SystemException {
318 
319         if (classPK <= 0) {
320             return null;
321         }
322 
323         long classNameId = PortalUtil.getClassNameId(className);
324 
325         TagsAsset asset = tagsAssetPersistence.fetchByC_C(classNameId, classPK);
326 
327         if (asset != null) {
328             asset.setViewCount(asset.getViewCount() + 1);
329 
330             tagsAssetPersistence.update(asset, false);
331         }
332 
333         return asset;
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             BooleanQuery contextQuery = BooleanQueryFactoryUtil.create();
343 
344             if (Validator.isNotNull(portletId)) {
345                 contextQuery.addRequiredTerm(Field.PORTLET_ID, portletId);
346             }
347             else {
348                 BooleanQuery portletIdsQuery = BooleanQueryFactoryUtil.create();
349 
350                 for (String assetTypePortletId :
351                         TagsUtil.ASSET_TYPE_PORTLET_IDS) {
352 
353                     TermQuery termQuery = TermQueryFactoryUtil.create(
354                         Field.PORTLET_ID, assetTypePortletId);
355 
356                     portletIdsQuery.add(termQuery, BooleanClauseOccur.SHOULD);
357                 }
358 
359                 contextQuery.add(portletIdsQuery, BooleanClauseOccur.MUST);
360             }
361 
362             BooleanQuery searchQuery = BooleanQueryFactoryUtil.create();
363 
364             if (Validator.isNotNull(keywords)) {
365                 searchQuery.addTerm(Field.TITLE, keywords);
366                 searchQuery.addTerm(Field.CONTENT, keywords);
367                 searchQuery.addTerm(Field.DESCRIPTION, keywords);
368                 searchQuery.addTerm(Field.PROPERTIES, keywords);
369                 searchQuery.addTerm(Field.TAGS_ENTRIES, keywords);
370             }
371 
372             BooleanQuery fullQuery = BooleanQueryFactoryUtil.create();
373 
374             fullQuery.add(contextQuery, BooleanClauseOccur.MUST);
375 
376             if (searchQuery.clauses().size() > 0) {
377                 fullQuery.add(searchQuery, BooleanClauseOccur.MUST);
378             }
379 
380             return SearchEngineUtil.search(companyId, fullQuery, start, end);
381         }
382         catch (Exception e) {
383             throw new SystemException(e);
384         }
385     }
386 
387     public TagsAssetDisplay[] searchAssetDisplays(
388             long companyId, String portletId, String keywords,
389             String languageId, int start, int end)
390         throws SystemException {
391 
392         List<TagsAsset> assets = new ArrayList<TagsAsset>();
393 
394         Hits hits = search(companyId, portletId, keywords, start, end);
395 
396         List<Document> hitsList = hits.toList();
397 
398         for (Document doc : hitsList) {
399             try {
400                 TagsAsset asset = getAsset(doc);
401 
402                 if (asset != null) {
403                     assets.add(asset);
404                 }
405             }
406             catch (Exception e) {
407                 if (_log.isWarnEnabled()) {
408                     _log.warn(e);
409                 }
410             }
411         }
412 
413         return getAssetDisplays(assets, languageId);
414     }
415 
416     public int searchAssetDisplaysCount(
417             long companyId, String portletId, String keywords,
418             String languageId)
419         throws SystemException {
420 
421         Hits hits = search(
422             companyId, portletId, keywords, QueryUtil.ALL_POS,
423             QueryUtil.ALL_POS);
424 
425         return hits.getLength();
426     }
427 
428     public TagsAsset updateAsset(
429             long userId, long groupId, String className, long classPK,
430             String[] entryNames)
431         throws PortalException, SystemException {
432 
433         return updateAsset(
434             userId, groupId, className, classPK, entryNames, null, null, null,
435             null, null, null, null, null, null, 0, 0, null);
436     }
437 
438     public TagsAsset updateAsset(
439             long userId, long groupId, String className, long classPK,
440             String[] entryNames, Date startDate, Date endDate, Date publishDate,
441             Date expirationDate, String mimeType, String title,
442             String description, String summary, String url, int height,
443             int width, Integer priority)
444         throws PortalException, SystemException {
445 
446         return updateAsset(
447             userId, groupId, className, classPK, entryNames, startDate,
448             endDate, publishDate, expirationDate, mimeType, title, description,
449             summary, url, height, width, priority, true);
450     }
451 
452     public TagsAsset updateAsset(
453             long userId, long groupId, String className, long classPK,
454             String[] entryNames, Date startDate, Date endDate, Date publishDate,
455             Date expirationDate, String mimeType, String title,
456             String description, String summary, String url, int height,
457             int width, Integer priority, boolean sync)
458         throws PortalException, SystemException {
459 
460         // Asset
461 
462         User user = userPersistence.findByPrimaryKey(userId);
463         long classNameId = PortalUtil.getClassNameId(className);
464 
465         if (entryNames == null) {
466             entryNames = new String[0];
467         }
468 
469         title = StringUtil.shorten(title, 300, StringPool.BLANK);
470         Date now = new Date();
471 
472         validate(className, entryNames);
473 
474         TagsAsset asset = tagsAssetPersistence.fetchByC_C(classNameId, classPK);
475 
476         if (asset == null) {
477             long assetId = counterLocalService.increment();
478 
479             asset = tagsAssetPersistence.create(assetId);
480 
481             asset.setCompanyId(user.getCompanyId());
482             asset.setUserId(user.getUserId());
483             asset.setUserName(user.getFullName());
484             asset.setCreateDate(now);
485             asset.setClassNameId(classNameId);
486             asset.setClassPK(classPK);
487             asset.setPublishDate(publishDate);
488             asset.setExpirationDate(expirationDate);
489 
490             if (priority == null) {
491                 asset.setPriority(0);
492             }
493 
494             asset.setViewCount(0);
495         }
496 
497         asset.setGroupId(groupId);
498         asset.setModifiedDate(now);
499         asset.setStartDate(startDate);
500         asset.setEndDate(endDate);
501         asset.setPublishDate(publishDate);
502         asset.setExpirationDate(expirationDate);
503         asset.setMimeType(mimeType);
504         asset.setTitle(title);
505         asset.setDescription(description);
506         asset.setSummary(summary);
507         asset.setUrl(url);
508         asset.setHeight(height);
509         asset.setWidth(width);
510 
511         if (priority != null) {
512             asset.setPriority(priority.intValue());
513         }
514 
515         // Entries
516 
517         List<TagsEntry> entries = new ArrayList<TagsEntry>(entryNames.length);
518 
519         for (int i = 0; i < entryNames.length; i++) {
520             String name = entryNames[i].trim().toLowerCase();
521 
522             TagsEntry entry = tagsEntryPersistence.fetchByC_N(
523                 user.getCompanyId(), name);
524 
525             if (entry == null) {
526                 entry = tagsEntryLocalService.addEntry(
527                     user.getUserId(), entryNames[i],
528                     TagsEntryLocalServiceImpl.DEFAULT_PROPERTIES);
529             }
530 
531             entries.add(entry);
532         }
533 
534         tagsAssetPersistence.setTagsEntries(asset.getAssetId(), entries);
535 
536         // Update asset after entries so that asset listeners have access the
537         // saved entries
538 
539         tagsAssetPersistence.update(asset, false);
540 
541         // Synchronize
542 
543         if (!sync) {
544             return asset;
545         }
546 
547         if (className.equals(BlogsEntry.class.getName())) {
548             BlogsEntry entry = blogsEntryPersistence.findByPrimaryKey(classPK);
549 
550             entry.setTitle(title);
551 
552             blogsEntryPersistence.update(entry, false);
553         }
554         else if (className.equals(BookmarksEntry.class.getName())) {
555             BookmarksEntry entry = bookmarksEntryPersistence.findByPrimaryKey(
556                 classPK);
557 
558             entry.setName(title);
559             entry.setComments(description);
560             entry.setUrl(url);
561 
562             bookmarksEntryPersistence.update(entry, false);
563         }
564         else if (className.equals(DLFileEntry.class.getName())) {
565             DLFileEntry fileEntry = dlFileEntryPersistence.findByPrimaryKey(
566                 classPK);
567 
568             fileEntry.setTitle(title);
569             fileEntry.setDescription(description);
570 
571             dlFileEntryPersistence.update(fileEntry, false);
572         }
573         else if (className.equals(JournalArticle.class.getName())) {
574             JournalArticle article = journalArticlePersistence.findByPrimaryKey(
575                 classPK);
576 
577             article.setTitle(title);
578             article.setDescription(description);
579 
580             journalArticlePersistence.update(article, false);
581         }
582         else if (className.equals(MBMessage.class.getName())) {
583             MBMessage message = mbMessagePersistence.findByPrimaryKey(classPK);
584 
585             message.setSubject(title);
586 
587             mbMessagePersistence.update(message, false);
588         }
589         else if (className.equals(WikiPage.class.getName())) {
590             WikiPage page = wikiPagePersistence.findByPrimaryKey(classPK);
591 
592             page.setTitle(title);
593 
594             wikiPagePersistence.update(page, false);
595         }
596 
597         return asset;
598     }
599 
600     public void validate(String className, String[] entryNames)
601         throws PortalException {
602 
603         TagsAssetValidator validator = (TagsAssetValidator)InstancePool.get(
604             PropsValues.TAGS_ASSET_VALIDATOR);
605 
606         validator.validate(className, entryNames);
607     }
608 
609     protected TagsAsset getAsset(Document doc)
610         throws PortalException, SystemException {
611 
612         String portletId = GetterUtil.getString(doc.get(Field.PORTLET_ID));
613 
614         if (portletId.equals(PortletKeys.BLOGS)) {
615             long entryId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
616 
617             long classNameId = PortalUtil.getClassNameId(
618                 BlogsEntry.class.getName());
619             long classPK = entryId;
620 
621             return tagsAssetPersistence.findByC_C(classNameId, classPK);
622         }
623         else if (portletId.equals(PortletKeys.BOOKMARKS)) {
624             long entryId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
625 
626             long classNameId = PortalUtil.getClassNameId(
627                 BookmarksEntry.class.getName());
628             long classPK = entryId;
629 
630             return tagsAssetPersistence.findByC_C(classNameId, classPK);
631         }
632         else if (portletId.equals(PortletKeys.DOCUMENT_LIBRARY)) {
633             long folderId = GetterUtil.getLong(doc.get("repositoryId"));
634             String name = doc.get("path");
635 
636             DLFileEntry fileEntry = dlFileEntryLocalService.getFileEntry(
637                 folderId, name);
638 
639             long classNameId = PortalUtil.getClassNameId(
640                 DLFileEntry.class.getName());
641             long classPK = fileEntry.getFileEntryId();
642 
643             return tagsAssetPersistence.findByC_C(classNameId, classPK);
644         }
645         else if (portletId.equals(PortletKeys.IMAGE_GALLERY)) {
646             long imageId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
647 
648             long classNameId = PortalUtil.getClassNameId(
649                 IGImage.class.getName());
650             long classPK = imageId;
651 
652             return tagsAssetPersistence.findByC_C(classNameId, classPK);
653         }
654         else if (portletId.equals(PortletKeys.JOURNAL)) {
655             long groupId = GetterUtil.getLong(doc.get(Field.GROUP_ID));
656             String articleId = doc.get(Field.ENTRY_CLASS_PK);
657             //double version = GetterUtil.getDouble(doc.get("version"));
658 
659             long articleResourcePrimKey =
660                 journalArticleResourceLocalService.getArticleResourcePrimKey(
661                     groupId, articleId);
662 
663             long classNameId = PortalUtil.getClassNameId(
664                 JournalArticle.class.getName());
665             long classPK = articleResourcePrimKey;
666 
667             return tagsAssetPersistence.findByC_C(classNameId, classPK);
668         }
669         else if (portletId.equals(PortletKeys.MESSAGE_BOARDS)) {
670             long messageId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
671 
672             long classNameId = PortalUtil.getClassNameId(
673                 MBMessage.class.getName());
674             long classPK = messageId;
675 
676             return tagsAssetPersistence.findByC_C(classNameId, classPK);
677         }
678         else if (portletId.equals(PortletKeys.WIKI)) {
679             long nodeId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
680             String title = doc.get(Field.TITLE);
681 
682             long pageResourcePrimKey =
683                 wikiPageResourceLocalService.getPageResourcePrimKey(
684                     nodeId, title);
685 
686             long classNameId = PortalUtil.getClassNameId(
687                 WikiPage.class.getName());
688             long classPK = pageResourcePrimKey;
689 
690             return tagsAssetPersistence.findByC_C(classNameId, classPK);
691         }
692 
693         return null;
694     }
695 
696     protected TagsAssetDisplay[] getAssetDisplays(
697             List<TagsAsset> assets, String languageId)
698         throws SystemException {
699 
700         TagsAssetDisplay[] assetDisplays = new TagsAssetDisplay[assets.size()];
701 
702         for (int i = 0; i < assets.size(); i++) {
703             TagsAsset asset = assets.get(i);
704 
705             String className = PortalUtil.getClassName(asset.getClassNameId());
706             String portletId = PortalUtil.getClassNamePortletId(className);
707             String portletTitle = PortalUtil.getPortletTitle(
708                 portletId, asset.getCompanyId(), languageId);
709 
710             List<TagsEntry> tagsEntriesList =
711                 tagsAssetPersistence.getTagsEntries(asset.getAssetId());
712 
713             String tagsEntries = ListUtil.toString(
714                 tagsEntriesList, "name", ", ");
715 
716             TagsAssetDisplay assetDisplay = new TagsAssetDisplay();
717 
718             assetDisplay.setAssetId(asset.getAssetId());
719             assetDisplay.setCompanyId(asset.getCompanyId());
720             assetDisplay.setUserId(asset.getUserId());
721             assetDisplay.setUserName(asset.getUserName());
722             assetDisplay.setCreateDate(asset.getCreateDate());
723             assetDisplay.setModifiedDate(asset.getModifiedDate());
724             assetDisplay.setClassNameId(asset.getClassNameId());
725             assetDisplay.setClassName(className);
726             assetDisplay.setClassPK(asset.getClassPK());
727             assetDisplay.setPortletId(portletId);
728             assetDisplay.setPortletTitle(portletTitle);
729             assetDisplay.setStartDate(asset.getStartDate());
730             assetDisplay.setEndDate(asset.getEndDate());
731             assetDisplay.setPublishDate(asset.getPublishDate());
732             assetDisplay.setExpirationDate(asset.getExpirationDate());
733             assetDisplay.setMimeType(asset.getMimeType());
734             assetDisplay.setTitle(asset.getTitle());
735             assetDisplay.setDescription(asset.getDescription());
736             assetDisplay.setSummary(asset.getSummary());
737             assetDisplay.setUrl(asset.getUrl());
738             assetDisplay.setHeight(asset.getHeight());
739             assetDisplay.setWidth(asset.getWidth());
740             assetDisplay.setPriority(asset.getPriority());
741             assetDisplay.setViewCount(asset.getViewCount());
742             assetDisplay.setTagsEntries(tagsEntries);
743 
744             assetDisplays[i] = assetDisplay;
745         }
746 
747         return assetDisplays;
748     }
749 
750     protected TagsAssetType getAssetType(String className, String languageId) {
751         long companyId = PortalInstances.getDefaultCompanyId();
752 
753         long classNameId = PortalUtil.getClassNameId(className);
754 
755         String portletId = PortalUtil.getClassNamePortletId(className);
756         String portletTitle = PortalUtil.getPortletTitle(
757             portletId, companyId, languageId);
758 
759         TagsAssetType assetType = new TagsAssetType();
760 
761         assetType.setClassNameId(classNameId);
762         assetType.setClassName(className);
763         assetType.setPortletId(portletId);
764         assetType.setPortletTitle(portletTitle);
765 
766         return assetType;
767     }
768 
769     private static Log _log =
770         LogFactoryUtil.getLog(TagsAssetLocalServiceImpl.class);
771 
772 }