1   /**
2    * Copyright (c) 2000-2008 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.search.Document;
28  import com.liferay.portal.kernel.search.Hits;
29  import com.liferay.portal.kernel.util.GetterUtil;
30  import com.liferay.portal.kernel.util.InstancePool;
31  import com.liferay.portal.kernel.util.StringPool;
32  import com.liferay.portal.kernel.util.StringUtil;
33  import com.liferay.portal.kernel.util.Validator;
34  import com.liferay.portal.lucene.LuceneFields;
35  import com.liferay.portal.lucene.LuceneUtil;
36  import com.liferay.portal.model.User;
37  import com.liferay.portal.util.PortalInstances;
38  import com.liferay.portal.util.PortalUtil;
39  import com.liferay.portal.util.PortletKeys;
40  import com.liferay.portal.util.PropsValues;
41  import com.liferay.portlet.blogs.model.BlogsEntry;
42  import com.liferay.portlet.bookmarks.model.BookmarksEntry;
43  import com.liferay.portlet.documentlibrary.model.DLFileEntry;
44  import com.liferay.portlet.imagegallery.model.IGImage;
45  import com.liferay.portlet.journal.model.JournalArticle;
46  import com.liferay.portlet.messageboards.model.MBMessage;
47  import com.liferay.portlet.tags.model.TagsAsset;
48  import com.liferay.portlet.tags.model.TagsAssetDisplay;
49  import com.liferay.portlet.tags.model.TagsAssetType;
50  import com.liferay.portlet.tags.model.TagsEntry;
51  import com.liferay.portlet.tags.service.base.TagsAssetLocalServiceBaseImpl;
52  import com.liferay.portlet.tags.util.TagsAssetValidator;
53  import com.liferay.portlet.tags.util.TagsUtil;
54  import com.liferay.portlet.wiki.model.WikiPage;
55  import com.liferay.util.ListUtil;
56  import com.liferay.util.lucene.HitsImpl;
57  
58  import java.util.ArrayList;
59  import java.util.Date;
60  import java.util.List;
61  
62  import org.apache.commons.logging.Log;
63  import org.apache.commons.logging.LogFactory;
64  import org.apache.lucene.index.Term;
65  import org.apache.lucene.search.BooleanClause;
66  import org.apache.lucene.search.BooleanQuery;
67  import org.apache.lucene.search.Searcher;
68  import org.apache.lucene.search.TermQuery;
69  
70  /**
71   * <a href="TagsAssetLocalServiceImpl.java.html"><b><i>View Source</i></b></a>
72   *
73   * @author Brian Wing Shun Chan
74   *
75   */
76  public class TagsAssetLocalServiceImpl extends TagsAssetLocalServiceBaseImpl {
77  
78      public void deleteAsset(long assetId)
79          throws PortalException, SystemException {
80  
81          TagsAsset asset = tagsAssetPersistence.findByPrimaryKey(assetId);
82  
83          deleteAsset(asset);
84      }
85  
86      public void deleteAsset(String className, long classPK)
87          throws PortalException, SystemException {
88  
89          long classNameId = PortalUtil.getClassNameId(className);
90  
91          TagsAsset asset = tagsAssetPersistence.fetchByC_C(classNameId, classPK);
92  
93          if (asset != null) {
94              deleteAsset(asset);
95          }
96      }
97  
98      public void deleteAsset(TagsAsset asset)
99          throws PortalException, SystemException {
100 
101         tagsAssetPersistence.remove(asset.getAssetId());
102     }
103 
104     public TagsAsset getAsset(long assetId)
105         throws PortalException, SystemException {
106 
107         return tagsAssetPersistence.findByPrimaryKey(assetId);
108     }
109 
110     public TagsAsset getAsset(String className, long classPK)
111         throws PortalException, SystemException {
112 
113         long classNameId = PortalUtil.getClassNameId(className);
114 
115         return tagsAssetPersistence.findByC_C(classNameId, classPK);
116     }
117 
118     public TagsAssetType[] getAssetTypes(String languageId) {
119         TagsAssetType[] assetTypes =
120             new TagsAssetType[TagsUtil.ASSET_TYPE_CLASS_NAMES.length];
121 
122         for (int i = 0; i < TagsUtil.ASSET_TYPE_CLASS_NAMES.length; i++) {
123             assetTypes[i] = getAssetType(
124                 TagsUtil.ASSET_TYPE_CLASS_NAMES[i], languageId);
125         }
126 
127         return assetTypes;
128     }
129 
130     public List getAssets(
131             long[] entryIds, long[] notEntryIds, boolean andOperator,
132             boolean excludeZeroViewCount, int begin, int end)
133         throws SystemException {
134 
135         return getAssets(
136             0, new long[0], entryIds, notEntryIds, andOperator,
137             excludeZeroViewCount, null, null, begin, end);
138     }
139 
140     public List getAssets(
141             long groupId, long[] classNameIds, long[] entryIds,
142             long[] notEntryIds, boolean andOperator,
143             boolean excludeZeroViewCount, int begin, int end)
144         throws SystemException {
145 
146         return getAssets(
147             groupId, classNameIds, entryIds, notEntryIds, andOperator,
148             excludeZeroViewCount, null, null, begin, end);
149     }
150 
151     public List getAssets(
152             long[] entryIds, long[] notEntryIds, boolean andOperator,
153             boolean excludeZeroViewCount, Date publishDate, Date expirationDate,
154             int begin, int end)
155         throws SystemException {
156 
157         return getAssets(
158             0, new long[0], entryIds, notEntryIds, andOperator,
159             excludeZeroViewCount, null, null, begin, end);
160     }
161 
162     public List getAssets(
163             long groupId, long[] classNameIds, long[] entryIds,
164             long[] notEntryIds, boolean andOperator,
165             boolean excludeZeroViewCount, Date publishDate, Date expirationDate,
166             int begin, int end)
167         throws SystemException {
168 
169         if (andOperator) {
170             return tagsAssetFinder.findByAndEntryIds(
171                 groupId, classNameIds, entryIds, notEntryIds, null, null, null,
172                 null, excludeZeroViewCount, publishDate, expirationDate, begin,
173                 end);
174         }
175         else {
176             return tagsAssetFinder.findByOrEntryIds(
177                 groupId, classNameIds, entryIds, notEntryIds, null, null, null,
178                 null, excludeZeroViewCount, publishDate, expirationDate, begin,
179                 end);
180         }
181     }
182 
183     public List getAssets(
184             long[] entryIds, long[] notEntryIds, boolean andOperator,
185             String orderByCol1, String orderByCol2, String orderByType1,
186             String orderByType2, boolean excludeZeroViewCount, Date publishDate,
187             Date expirationDate, int begin, int end)
188         throws SystemException {
189 
190         return getAssets(
191             0, new long[0], entryIds, notEntryIds, andOperator,
192             excludeZeroViewCount, publishDate, expirationDate, begin, end);
193     }
194 
195     public List getAssets(
196             long groupId, long[] classNameIds, long[] entryIds,
197             long[] notEntryIds, boolean andOperator, String orderByCol1,
198             String orderByCol2, String orderByType1, String orderByType2,
199             boolean excludeZeroViewCount, Date publishDate, Date expirationDate,
200             int begin, int end)
201         throws SystemException {
202 
203         if (andOperator) {
204             return tagsAssetFinder.findByAndEntryIds(
205                 groupId, classNameIds, entryIds, notEntryIds, orderByCol1,
206                 orderByCol2, orderByType1, orderByType2, excludeZeroViewCount,
207                 publishDate, expirationDate, begin, end);
208         }
209         else {
210             return tagsAssetFinder.findByOrEntryIds(
211                 groupId, classNameIds, entryIds, notEntryIds, orderByCol1,
212                 orderByCol2, orderByType1, orderByType2, excludeZeroViewCount,
213                 publishDate, expirationDate, begin, end);
214         }
215     }
216 
217     public int getAssetsCount(
218             long[] entryIds, long[] notEntryIds, boolean andOperator,
219             boolean excludeZeroViewCount)
220         throws SystemException {
221 
222         return getAssetsCount(
223             0, new long[0], entryIds, notEntryIds, andOperator,
224             excludeZeroViewCount, null, null);
225     }
226 
227     public int getAssetsCount(
228             long groupId, long[] entryIds, long[] notEntryIds,
229             boolean andOperator, boolean excludeZeroViewCount)
230         throws SystemException {
231 
232         return getAssetsCount(
233             groupId, new long[0], entryIds, notEntryIds, andOperator,
234             excludeZeroViewCount, null, null);
235     }
236 
237     public int getAssetsCount(
238             long[] entryIds, long[] notEntryIds, boolean andOperator,
239             boolean excludeZeroViewCount, Date publishDate, Date expirationDate)
240         throws SystemException {
241 
242         return getAssetsCount(
243             0, new long[0], entryIds, notEntryIds, andOperator,
244             excludeZeroViewCount, publishDate, expirationDate);
245     }
246 
247     public int getAssetsCount(
248             long groupId, long[] classNameIds, long[] entryIds,
249             long[] notEntryIds, boolean andOperator,
250             boolean excludeZeroViewCount, Date publishDate, Date expirationDate)
251         throws SystemException {
252 
253         if (andOperator) {
254             return tagsAssetFinder.countByAndEntryIds(
255                 groupId, classNameIds, entryIds, notEntryIds,
256                 excludeZeroViewCount, publishDate, expirationDate);
257         }
258         else {
259             return tagsAssetFinder.countByOrEntryIds(
260                 groupId, classNameIds, entryIds, notEntryIds,
261                 excludeZeroViewCount, publishDate, expirationDate);
262         }
263     }
264 
265     public TagsAssetDisplay[] getCompanyAssetDisplays(
266             long companyId, int begin, int end, String languageId)
267         throws PortalException, SystemException {
268 
269         return getAssetDisplays(
270             getCompanyAssets(companyId, begin, end), languageId);
271     }
272 
273     public List getCompanyAssets(long companyId, int begin, int end)
274         throws SystemException {
275 
276         return tagsAssetPersistence.findByCompanyId(companyId, begin, end);
277     }
278 
279     public int getCompanyAssetsCount(long companyId) throws SystemException {
280         return tagsAssetPersistence.countByCompanyId(companyId);
281     }
282 
283     public List getTopViewedAssets(
284             String className, boolean asc, int begin, int end)
285         throws SystemException {
286 
287         return getTopViewedAssets(new String[] {className}, asc, begin, end);
288     }
289 
290     public List getTopViewedAssets(
291             String[] className, boolean asc, int begin, int end)
292         throws SystemException {
293 
294         long[] classNameIds = new long[className.length];
295 
296         for (int i = 0; i < className.length; i++) {
297             classNameIds[i] = PortalUtil.getClassNameId(className[i]);
298         }
299 
300         return tagsAssetFinder.findByViewCount(classNameIds, asc, begin, end);
301     }
302 
303     public TagsAsset incrementViewCounter(String className, long classPK)
304         throws PortalException, SystemException {
305 
306         if (classPK <= 0) {
307             return null;
308         }
309 
310         long classNameId = PortalUtil.getClassNameId(className);
311 
312         TagsAsset asset = tagsAssetPersistence.fetchByC_C(classNameId, classPK);
313 
314         if (asset != null) {
315             asset.setViewCount(asset.getViewCount() + 1);
316 
317             tagsAssetPersistence.update(asset);
318         }
319 
320         return asset;
321     }
322 
323     public Hits search(long companyId, String portletId, String keywords)
324         throws SystemException {
325 
326         Searcher searcher = null;
327 
328         try {
329             HitsImpl hits = new HitsImpl();
330 
331             BooleanQuery contextQuery = new BooleanQuery();
332 
333             if (Validator.isNotNull(portletId)) {
334                 LuceneUtil.addRequiredTerm(
335                     contextQuery, LuceneFields.PORTLET_ID, portletId);
336             }
337             else {
338                 BooleanQuery portletIdsQuery = new BooleanQuery();
339 
340                 for (int i = 0; i < TagsUtil.ASSET_TYPE_PORTLET_IDS.length;
341                         i++) {
342 
343                     Term term = new Term(
344                         LuceneFields.PORTLET_ID,
345                         TagsUtil.ASSET_TYPE_PORTLET_IDS[i]);
346                     TermQuery termQuery = new TermQuery(term);
347 
348                     portletIdsQuery.add(termQuery, BooleanClause.Occur.SHOULD);
349                 }
350 
351                 contextQuery.add(portletIdsQuery, BooleanClause.Occur.MUST);
352             }
353 
354             BooleanQuery searchQuery = new BooleanQuery();
355 
356             if (Validator.isNotNull(keywords)) {
357                 LuceneUtil.addTerm(searchQuery, LuceneFields.TITLE, keywords);
358                 LuceneUtil.addTerm(searchQuery, LuceneFields.CONTENT, keywords);
359                 LuceneUtil.addTerm(
360                     searchQuery, LuceneFields.DESCRIPTION, keywords);
361                 LuceneUtil.addTerm(
362                     searchQuery, LuceneFields.PROPERTIES, keywords);
363                 LuceneUtil.addTerm(
364                     searchQuery, LuceneFields.TAG_ENTRY, keywords);
365             }
366 
367             BooleanQuery fullQuery = new BooleanQuery();
368 
369             fullQuery.add(contextQuery, BooleanClause.Occur.MUST);
370 
371             if (searchQuery.clauses().size() > 0) {
372                 fullQuery.add(searchQuery, BooleanClause.Occur.MUST);
373             }
374 
375             searcher = LuceneUtil.getSearcher(companyId);
376 
377             hits.recordHits(searcher.search(fullQuery), searcher);
378 
379             return hits;
380         }
381         catch (Exception e) {
382             return LuceneUtil.closeSearcher(searcher, keywords, e);
383         }
384     }
385 
386     public TagsAssetDisplay[] searchAssetDisplays(
387             long companyId, String portletId, String keywords,
388             String languageId, int begin, int end)
389         throws PortalException, SystemException {
390 
391         List assets = new ArrayList();
392 
393         Hits hits = search(companyId, portletId, keywords);
394 
395         hits = hits.subset(begin, end);
396 
397         List hitsList = hits.toList();
398 
399         for (int i = 0; i < hitsList.size(); i++) {
400             Document doc = (Document)hitsList.get(i);
401 
402             try {
403                 TagsAsset asset = getAsset(doc);
404 
405                 if (asset != null) {
406                     assets.add(asset);
407                 }
408             }
409             catch (Exception e) {
410                 if (_log.isWarnEnabled()) {
411                     _log.warn(e);
412                 }
413             }
414         }
415 
416         return getAssetDisplays(assets, languageId);
417     }
418 
419     public int searchAssetDisplaysCount(
420             long companyId, String portletId, String keywords,
421             String languageId)
422         throws SystemException {
423 
424         Hits hits = search(companyId, portletId, keywords);
425 
426         return hits.getLength();
427     }
428 
429     public TagsAsset updateAsset(
430             long userId, long groupId, String className, long classPK,
431             String[] entryNames)
432         throws PortalException, SystemException {
433 
434         return updateAsset(
435             userId, groupId, className, classPK, entryNames, null, null, null,
436             null, null, null, null, null, null, 0, 0, null);
437     }
438 
439     public TagsAsset updateAsset(
440             long userId, long groupId, String className, long classPK,
441             String[] entryNames, Date startDate, Date endDate, Date publishDate,
442             Date expirationDate, String mimeType, String title,
443             String description, String summary, String url, int height,
444             int width, Integer priority)
445         throws PortalException, SystemException {
446 
447         return updateAsset(
448             userId, groupId, className, classPK, entryNames, startDate,
449             endDate, publishDate, expirationDate, mimeType, title, description,
450             summary, url, height, width, priority, true);
451     }
452 
453     public TagsAsset updateAsset(
454             long userId, long groupId, String className, long classPK,
455             String[] entryNames, Date startDate, Date endDate, Date publishDate,
456             Date expirationDate, String mimeType, String title,
457             String description, String summary, String url, int height,
458             int width, Integer priority, boolean sync)
459         throws PortalException, SystemException {
460 
461         // Asset
462 
463         User user = userPersistence.findByPrimaryKey(userId);
464         long classNameId = PortalUtil.getClassNameId(className);
465 
466         if (entryNames == null) {
467             entryNames = new String[0];
468         }
469 
470         title = StringUtil.shorten(title, 300, StringPool.BLANK);
471         Date now = new Date();
472 
473         validate(className, entryNames);
474 
475         TagsAsset asset = tagsAssetPersistence.fetchByC_C(classNameId, classPK);
476 
477         if (asset == null) {
478             long assetId = counterLocalService.increment();
479 
480             asset = tagsAssetPersistence.create(assetId);
481 
482             asset.setCompanyId(user.getCompanyId());
483             asset.setUserId(user.getUserId());
484             asset.setUserName(user.getFullName());
485             asset.setCreateDate(now);
486             asset.setClassNameId(classNameId);
487             asset.setClassPK(classPK);
488             asset.setPublishDate(publishDate);
489             asset.setExpirationDate(expirationDate);
490 
491             if (priority == null) {
492                 asset.setPriority(0);
493             }
494 
495             asset.setViewCount(0);
496         }
497 
498         asset.setGroupId(groupId);
499         asset.setModifiedDate(now);
500         asset.setStartDate(startDate);
501         asset.setEndDate(endDate);
502         asset.setPublishDate(publishDate);
503         asset.setExpirationDate(expirationDate);
504         asset.setMimeType(mimeType);
505         asset.setTitle(title);
506         asset.setDescription(description);
507         asset.setSummary(summary);
508         asset.setUrl(url);
509         asset.setHeight(height);
510         asset.setWidth(width);
511 
512         if (priority != null) {
513             asset.setPriority(priority.intValue());
514         }
515 
516         tagsAssetPersistence.update(asset);
517 
518         // Entries
519 
520         List entries = new ArrayList(entryNames.length);
521 
522         for (int i = 0; i < entryNames.length; i++) {
523             String name = entryNames[i].trim().toLowerCase();
524 
525             TagsEntry entry = tagsEntryPersistence.fetchByC_N(
526                 user.getCompanyId(), name);
527 
528             if (entry == null) {
529                 entry = tagsEntryLocalService.addEntry(
530                     user.getUserId(), entryNames[i],
531                     TagsEntryLocalServiceImpl.DEFAULT_PROPERTIES);
532             }
533 
534             entries.add(entry);
535         }
536 
537         tagsAssetPersistence.setTagsEntries(asset.getAssetId(), entries);
538 
539         // Synchronize
540 
541         if (!sync) {
542             return asset;
543         }
544 
545         if (className.equals(BlogsEntry.class.getName())) {
546             BlogsEntry entry = blogsEntryPersistence.findByPrimaryKey(classPK);
547 
548             entry.setTitle(title);
549 
550             blogsEntryPersistence.update(entry);
551         }
552         else if (className.equals(BookmarksEntry.class.getName())) {
553             BookmarksEntry entry = bookmarksEntryPersistence.findByPrimaryKey(
554                 classPK);
555 
556             entry.setName(title);
557             entry.setComments(description);
558             entry.setUrl(url);
559 
560             bookmarksEntryPersistence.update(entry);
561         }
562         else if (className.equals(DLFileEntry.class.getName())) {
563             DLFileEntry fileEntry = dlFileEntryPersistence.findByPrimaryKey(
564                 classPK);
565 
566             fileEntry.setTitle(title);
567             fileEntry.setDescription(description);
568 
569             dlFileEntryPersistence.update(fileEntry);
570         }
571         else if (className.equals(JournalArticle.class.getName())) {
572             JournalArticle article = journalArticlePersistence.findByPrimaryKey(
573                 classPK);
574 
575             article.setTitle(title);
576             article.setDescription(description);
577 
578             journalArticlePersistence.update(article);
579         }
580         else if (className.equals(MBMessage.class.getName())) {
581             MBMessage message = mbMessagePersistence.findByPrimaryKey(classPK);
582 
583             message.setSubject(title);
584 
585             mbMessagePersistence.update(message);
586         }
587         else if (className.equals(WikiPage.class.getName())) {
588             WikiPage page = wikiPagePersistence.findByPrimaryKey(classPK);
589 
590             page.setTitle(title);
591 
592             wikiPagePersistence.update(page);
593         }
594 
595         return asset;
596     }
597 
598     public void validate(String className, String[] entryNames)
599         throws PortalException {
600 
601         TagsAssetValidator validator = (TagsAssetValidator)InstancePool.get(
602             PropsValues.TAGS_ASSET_VALIDATOR);
603 
604         validator.validate(className, entryNames);
605     }
606 
607     protected TagsAsset getAsset(Document doc)
608         throws PortalException, SystemException {
609 
610         String portletId = GetterUtil.getString(
611             doc.get(LuceneFields.PORTLET_ID));
612 
613         if (portletId.equals(PortletKeys.BLOGS)) {
614             long entryId = GetterUtil.getLong(doc.get("entryId"));
615 
616             long classNameId = PortalUtil.getClassNameId(
617                 BlogsEntry.class.getName());
618             long classPK = entryId;
619 
620             return tagsAssetPersistence.findByC_C(classNameId, classPK);
621         }
622         else if (portletId.equals(PortletKeys.BOOKMARKS)) {
623             long entryId = GetterUtil.getLong(doc.get("entryId"));
624 
625             long classNameId = PortalUtil.getClassNameId(
626                 BookmarksEntry.class.getName());
627             long classPK = entryId;
628 
629             return tagsAssetPersistence.findByC_C(classNameId, classPK);
630         }
631         else if (portletId.equals(PortletKeys.DOCUMENT_LIBRARY)) {
632             long folderId = GetterUtil.getLong(doc.get("repositoryId"));
633             String name = doc.get("path");
634 
635             DLFileEntry fileEntry = dlFileEntryLocalService.getFileEntry(
636                 folderId, name);
637 
638             long classNameId = PortalUtil.getClassNameId(
639                 DLFileEntry.class.getName());
640             long classPK = fileEntry.getFileEntryId();
641 
642             return tagsAssetPersistence.findByC_C(classNameId, classPK);
643         }
644         else if (portletId.equals(PortletKeys.IMAGE_GALLERY)) {
645             long imageId = GetterUtil.getLong(doc.get("imageId"));
646 
647             long classNameId = PortalUtil.getClassNameId(
648                 IGImage.class.getName());
649             long classPK = imageId;
650 
651             return tagsAssetPersistence.findByC_C(classNameId, classPK);
652         }
653         else if (portletId.equals(PortletKeys.JOURNAL)) {
654             long groupId = GetterUtil.getLong(
655                 doc.get(LuceneFields.GROUP_ID));
656             String articleId = doc.get("articleId");
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("messageId"));
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("nodeId"));
680             String title = doc.get(LuceneFields.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 assets, String languageId)
698         throws PortalException, SystemException {
699 
700         TagsAssetDisplay[] assetDisplays = new TagsAssetDisplay[assets.size()];
701 
702         for (int i = 0; i < assets.size(); i++) {
703             TagsAsset asset = (TagsAsset)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 tagsEntriesList = tagsAssetPersistence.getTagsEntries(
711                 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         LogFactory.getLog(TagsAssetLocalServiceImpl.class);
771 
772 }