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.BooleanClauseOccur;
28  import com.liferay.portal.kernel.search.BooleanQuery;
29  import com.liferay.portal.kernel.search.BooleanQueryFactoryUtil;
30  import com.liferay.portal.kernel.search.Document;
31  import com.liferay.portal.kernel.search.Field;
32  import com.liferay.portal.kernel.search.Hits;
33  import com.liferay.portal.kernel.search.SearchEngineUtil;
34  import com.liferay.portal.kernel.search.TermQuery;
35  import com.liferay.portal.kernel.search.TermQueryFactoryUtil;
36  import com.liferay.portal.kernel.util.GetterUtil;
37  import com.liferay.portal.kernel.util.InstancePool;
38  import com.liferay.portal.kernel.util.ListUtil;
39  import com.liferay.portal.kernel.util.StringPool;
40  import com.liferay.portal.kernel.util.StringUtil;
41  import com.liferay.portal.kernel.util.Validator;
42  import com.liferay.portal.model.User;
43  import com.liferay.portal.util.PortalInstances;
44  import com.liferay.portal.util.PortalUtil;
45  import com.liferay.portal.util.PortletKeys;
46  import com.liferay.portal.util.PropsValues;
47  import com.liferay.portlet.blogs.model.BlogsEntry;
48  import com.liferay.portlet.bookmarks.model.BookmarksEntry;
49  import com.liferay.portlet.documentlibrary.model.DLFileEntry;
50  import com.liferay.portlet.imagegallery.model.IGImage;
51  import com.liferay.portlet.journal.model.JournalArticle;
52  import com.liferay.portlet.messageboards.model.MBMessage;
53  import com.liferay.portlet.tags.model.TagsAsset;
54  import com.liferay.portlet.tags.model.TagsAssetDisplay;
55  import com.liferay.portlet.tags.model.TagsAssetType;
56  import com.liferay.portlet.tags.model.TagsEntry;
57  import com.liferay.portlet.tags.service.base.TagsAssetLocalServiceBaseImpl;
58  import com.liferay.portlet.tags.util.TagsAssetValidator;
59  import com.liferay.portlet.tags.util.TagsUtil;
60  import com.liferay.portlet.wiki.model.WikiPage;
61  
62  import java.util.ArrayList;
63  import java.util.Date;
64  import java.util.List;
65  
66  import org.apache.commons.logging.Log;
67  import org.apache.commons.logging.LogFactory;
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 PortalException, 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)
98          throws PortalException, SystemException {
99  
100         tagsAssetPersistence.remove(asset.getAssetId());
101     }
102 
103     public TagsAsset getAsset(long assetId)
104         throws PortalException, SystemException {
105 
106         return tagsAssetPersistence.findByPrimaryKey(assetId);
107     }
108 
109     public TagsAsset getAsset(String className, long classPK)
110         throws PortalException, SystemException {
111 
112         long classNameId = PortalUtil.getClassNameId(className);
113 
114         return tagsAssetPersistence.findByC_C(classNameId, classPK);
115     }
116 
117     public TagsAssetType[] getAssetTypes(String languageId) {
118         TagsAssetType[] assetTypes =
119             new TagsAssetType[TagsUtil.ASSET_TYPE_CLASS_NAMES.length];
120 
121         for (int i = 0; i < TagsUtil.ASSET_TYPE_CLASS_NAMES.length; i++) {
122             assetTypes[i] = getAssetType(
123                 TagsUtil.ASSET_TYPE_CLASS_NAMES[i], languageId);
124         }
125 
126         return assetTypes;
127     }
128 
129     public List<TagsAsset> getAssets(
130             long[] entryIds, long[] notEntryIds, boolean andOperator,
131             boolean excludeZeroViewCount, int start, int end)
132         throws SystemException {
133 
134         return getAssets(
135             0, new long[0], entryIds, notEntryIds, andOperator,
136             excludeZeroViewCount, null, null, start, end);
137     }
138 
139     public List<TagsAsset> getAssets(
140             long groupId, long[] classNameIds, long[] entryIds,
141             long[] notEntryIds, boolean andOperator,
142             boolean excludeZeroViewCount, int start, int end)
143         throws SystemException {
144 
145         return getAssets(
146             groupId, classNameIds, entryIds, notEntryIds, andOperator,
147             excludeZeroViewCount, null, null, start, end);
148     }
149 
150     public List<TagsAsset> getAssets(
151             long[] entryIds, long[] notEntryIds, boolean andOperator,
152             boolean excludeZeroViewCount, Date publishDate, Date expirationDate,
153             int start, int end)
154         throws SystemException {
155 
156         return getAssets(
157             0, new long[0], entryIds, notEntryIds, andOperator,
158             excludeZeroViewCount, publishDate, expirationDate, start, end);
159     }
160 
161     public List<TagsAsset> getAssets(
162             long groupId, long[] classNameIds, long[] entryIds,
163             long[] notEntryIds, boolean andOperator,
164             boolean excludeZeroViewCount, Date publishDate, Date expirationDate,
165             int start, int end)
166         throws SystemException {
167 
168         if ((entryIds.length == 0) && (notEntryIds.length == 0)) {
169             return tagsAssetFinder.findAssets(
170                 groupId, classNameIds, null, null, null, null,
171                 excludeZeroViewCount, publishDate, expirationDate, start, end);
172         }
173         else if (andOperator) {
174             return tagsAssetFinder.findByAndEntryIds(
175                 groupId, classNameIds, entryIds, notEntryIds, null, null, null,
176                 null, excludeZeroViewCount, publishDate, expirationDate, start,
177                 end);
178         }
179         else {
180             return tagsAssetFinder.findByOrEntryIds(
181                 groupId, classNameIds, entryIds, notEntryIds, null, null, null,
182                 null, excludeZeroViewCount, publishDate, expirationDate, start,
183                 end);
184         }
185     }
186 
187     public List<TagsAsset> getAssets(
188             long[] entryIds, long[] notEntryIds, boolean andOperator,
189             String orderByCol1, String orderByCol2, String orderByType1,
190             String orderByType2, boolean excludeZeroViewCount, Date publishDate,
191             Date expirationDate, int start, int end)
192         throws SystemException {
193 
194         return getAssets(
195             0, new long[0], entryIds, notEntryIds, andOperator,
196             excludeZeroViewCount, publishDate, expirationDate, start, end);
197     }
198 
199     public List<TagsAsset> getAssets(
200             long groupId, long[] classNameIds, long[] entryIds,
201             long[] notEntryIds, boolean andOperator, String orderByCol1,
202             String orderByCol2, String orderByType1, String orderByType2,
203             boolean excludeZeroViewCount, Date publishDate, Date expirationDate,
204             int start, int end)
205         throws SystemException {
206 
207         if ((entryIds.length == 0) && (notEntryIds.length == 0)) {
208             return tagsAssetFinder.findAssets(
209                 groupId, classNameIds, orderByCol1, orderByCol2, orderByType1,
210                 orderByType2, excludeZeroViewCount, publishDate, expirationDate,
211                 start, end);
212         }
213         else if (andOperator) {
214             return tagsAssetFinder.findByAndEntryIds(
215                 groupId, classNameIds, entryIds, notEntryIds, orderByCol1,
216                 orderByCol2, orderByType1, orderByType2, excludeZeroViewCount,
217                 publishDate, expirationDate, start, end);
218         }
219         else {
220             return tagsAssetFinder.findByOrEntryIds(
221                 groupId, classNameIds, entryIds, notEntryIds, orderByCol1,
222                 orderByCol2, orderByType1, orderByType2, excludeZeroViewCount,
223                 publishDate, expirationDate, start, end);
224         }
225     }
226 
227     public int getAssetsCount(
228             long[] entryIds, long[] notEntryIds, boolean andOperator,
229             boolean excludeZeroViewCount)
230         throws SystemException {
231 
232         return getAssetsCount(
233             0, new long[0], entryIds, notEntryIds, andOperator,
234             excludeZeroViewCount, null, null);
235     }
236 
237     public int getAssetsCount(
238             long groupId, long[] entryIds, long[] notEntryIds,
239             boolean andOperator, boolean excludeZeroViewCount)
240         throws SystemException {
241 
242         return getAssetsCount(
243             groupId, new long[0], entryIds, notEntryIds, andOperator,
244             excludeZeroViewCount, null, null);
245     }
246 
247     public int getAssetsCount(
248             long[] entryIds, long[] notEntryIds, boolean andOperator,
249             boolean excludeZeroViewCount, Date publishDate, Date expirationDate)
250         throws SystemException {
251 
252         return getAssetsCount(
253             0, new long[0], entryIds, notEntryIds, andOperator,
254             excludeZeroViewCount, publishDate, expirationDate);
255     }
256 
257     public int getAssetsCount(
258             long groupId, long[] classNameIds, long[] entryIds,
259             long[] notEntryIds, boolean andOperator,
260             boolean excludeZeroViewCount, Date publishDate, Date expirationDate)
261         throws SystemException {
262 
263         if ((entryIds.length == 0) && (notEntryIds.length == 0)) {
264             return tagsAssetFinder.countAssets(
265                 groupId, classNameIds, excludeZeroViewCount, publishDate,
266                 expirationDate);
267         }
268         else if (andOperator) {
269             return tagsAssetFinder.countByAndEntryIds(
270                 groupId, classNameIds, entryIds, notEntryIds,
271                 excludeZeroViewCount, publishDate, expirationDate);
272         }
273         else {
274             return tagsAssetFinder.countByOrEntryIds(
275                 groupId, classNameIds, entryIds, notEntryIds,
276                 excludeZeroViewCount, publishDate, expirationDate);
277         }
278     }
279 
280     public TagsAssetDisplay[] getCompanyAssetDisplays(
281             long companyId, int start, int end, String languageId)
282         throws SystemException {
283 
284         return getAssetDisplays(
285             getCompanyAssets(companyId, start, end), languageId);
286     }
287 
288     public List<TagsAsset> getCompanyAssets(long companyId, int start, int end)
289         throws SystemException {
290 
291         return tagsAssetPersistence.findByCompanyId(companyId, start, end);
292     }
293 
294     public int getCompanyAssetsCount(long companyId) throws SystemException {
295         return tagsAssetPersistence.countByCompanyId(companyId);
296     }
297 
298     public List<TagsAsset> getTopViewedAssets(
299             String className, boolean asc, int start, int end)
300         throws SystemException {
301 
302         return getTopViewedAssets(new String[] {className}, asc, start, end);
303     }
304 
305     public List<TagsAsset> getTopViewedAssets(
306             String[] className, boolean asc, int start, int end)
307         throws SystemException {
308 
309         long[] classNameIds = new long[className.length];
310 
311         for (int i = 0; i < className.length; i++) {
312             classNameIds[i] = PortalUtil.getClassNameId(className[i]);
313         }
314 
315         return tagsAssetFinder.findByViewCount(classNameIds, asc, start, end);
316     }
317 
318     public TagsAsset incrementViewCounter(String className, long classPK)
319         throws SystemException {
320 
321         if (classPK <= 0) {
322             return null;
323         }
324 
325         long classNameId = PortalUtil.getClassNameId(className);
326 
327         TagsAsset asset = tagsAssetPersistence.fetchByC_C(classNameId, classPK);
328 
329         if (asset != null) {
330             asset.setViewCount(asset.getViewCount() + 1);
331 
332             tagsAssetPersistence.update(asset, false);
333         }
334 
335         return asset;
336     }
337 
338     public Hits search(
339             long companyId, String portletId, String keywords, int start,
340             int end)
341         throws SystemException {
342 
343         try {
344             BooleanQuery contextQuery = BooleanQueryFactoryUtil.create();
345 
346             if (Validator.isNotNull(portletId)) {
347                 contextQuery.addRequiredTerm(Field.PORTLET_ID, portletId);
348             }
349             else {
350                 BooleanQuery portletIdsQuery = BooleanQueryFactoryUtil.create();
351 
352                 for (String assetTypePortletId :
353                         TagsUtil.ASSET_TYPE_PORTLET_IDS) {
354 
355                     TermQuery termQuery = TermQueryFactoryUtil.create(
356                         Field.PORTLET_ID, assetTypePortletId);
357 
358                     portletIdsQuery.add(termQuery, BooleanClauseOccur.SHOULD);
359                 }
360 
361                 contextQuery.add(portletIdsQuery, BooleanClauseOccur.MUST);
362             }
363 
364             BooleanQuery searchQuery = BooleanQueryFactoryUtil.create();
365 
366             if (Validator.isNotNull(keywords)) {
367                 searchQuery.addTerm(Field.TITLE, keywords);
368                 searchQuery.addTerm(Field.CONTENT, keywords);
369                 searchQuery.addTerm(Field.DESCRIPTION, keywords);
370                 searchQuery.addTerm(Field.PROPERTIES, keywords);
371                 searchQuery.addTerm(Field.TAGS_ENTRIES, keywords);
372             }
373 
374             BooleanQuery fullQuery = BooleanQueryFactoryUtil.create();
375 
376             fullQuery.add(contextQuery, BooleanClauseOccur.MUST);
377 
378             if (searchQuery.clauses().size() > 0) {
379                 fullQuery.add(searchQuery, BooleanClauseOccur.MUST);
380             }
381 
382             return SearchEngineUtil.search(companyId, fullQuery, start, end);
383         }
384         catch (Exception e) {
385             throw new SystemException(e);
386         }
387     }
388 
389     public TagsAssetDisplay[] searchAssetDisplays(
390             long companyId, String portletId, String keywords,
391             String languageId, int start, int end)
392         throws SystemException {
393 
394         List<TagsAsset> assets = new ArrayList<TagsAsset>();
395 
396         Hits hits = search(companyId, portletId, keywords, start, end);
397 
398         List<Document> hitsList = hits.toList();
399 
400         for (Document doc : hitsList) {
401             try {
402                 TagsAsset asset = getAsset(doc);
403 
404                 if (asset != null) {
405                     assets.add(asset);
406                 }
407             }
408             catch (Exception e) {
409                 if (_log.isWarnEnabled()) {
410                     _log.warn(e);
411                 }
412             }
413         }
414 
415         return getAssetDisplays(assets, languageId);
416     }
417 
418     public int searchAssetDisplaysCount(
419             long companyId, String portletId, String keywords,
420             String languageId)
421         throws SystemException {
422 
423         Hits hits = search(
424             companyId, portletId, keywords, SearchEngineUtil.ALL_POS,
425             SearchEngineUtil.ALL_POS);
426 
427         return hits.getLength();
428     }
429 
430     public TagsAsset updateAsset(
431             long userId, long groupId, String className, long classPK,
432             String[] entryNames)
433         throws PortalException, SystemException {
434 
435         return updateAsset(
436             userId, groupId, className, classPK, entryNames, null, null, null,
437             null, null, null, null, null, null, 0, 0, null);
438     }
439 
440     public TagsAsset updateAsset(
441             long userId, long groupId, String className, long classPK,
442             String[] entryNames, Date startDate, Date endDate, Date publishDate,
443             Date expirationDate, String mimeType, String title,
444             String description, String summary, String url, int height,
445             int width, Integer priority)
446         throws PortalException, SystemException {
447 
448         return updateAsset(
449             userId, groupId, className, classPK, entryNames, startDate,
450             endDate, publishDate, expirationDate, mimeType, title, description,
451             summary, url, height, width, priority, true);
452     }
453 
454     public TagsAsset updateAsset(
455             long userId, long groupId, String className, long classPK,
456             String[] entryNames, Date startDate, Date endDate, Date publishDate,
457             Date expirationDate, String mimeType, String title,
458             String description, String summary, String url, int height,
459             int width, Integer priority, boolean sync)
460         throws PortalException, SystemException {
461 
462         // Asset
463 
464         User user = userPersistence.findByPrimaryKey(userId);
465         long classNameId = PortalUtil.getClassNameId(className);
466 
467         if (entryNames == null) {
468             entryNames = new String[0];
469         }
470 
471         title = StringUtil.shorten(title, 300, StringPool.BLANK);
472         Date now = new Date();
473 
474         validate(className, entryNames);
475 
476         TagsAsset asset = tagsAssetPersistence.fetchByC_C(classNameId, classPK);
477 
478         if (asset == null) {
479             long assetId = counterLocalService.increment();
480 
481             asset = tagsAssetPersistence.create(assetId);
482 
483             asset.setCompanyId(user.getCompanyId());
484             asset.setUserId(user.getUserId());
485             asset.setUserName(user.getFullName());
486             asset.setCreateDate(now);
487             asset.setClassNameId(classNameId);
488             asset.setClassPK(classPK);
489             asset.setPublishDate(publishDate);
490             asset.setExpirationDate(expirationDate);
491 
492             if (priority == null) {
493                 asset.setPriority(0);
494             }
495 
496             asset.setViewCount(0);
497         }
498 
499         asset.setGroupId(groupId);
500         asset.setModifiedDate(now);
501         asset.setStartDate(startDate);
502         asset.setEndDate(endDate);
503         asset.setPublishDate(publishDate);
504         asset.setExpirationDate(expirationDate);
505         asset.setMimeType(mimeType);
506         asset.setTitle(title);
507         asset.setDescription(description);
508         asset.setSummary(summary);
509         asset.setUrl(url);
510         asset.setHeight(height);
511         asset.setWidth(width);
512 
513         if (priority != null) {
514             asset.setPriority(priority.intValue());
515         }
516 
517         tagsAssetPersistence.update(asset, false);
518 
519         // Entries
520 
521         List<TagsEntry> entries = new ArrayList<TagsEntry>(entryNames.length);
522 
523         for (int i = 0; i < entryNames.length; i++) {
524             String name = entryNames[i].trim().toLowerCase();
525 
526             TagsEntry entry = tagsEntryPersistence.fetchByC_N(
527                 user.getCompanyId(), name);
528 
529             if (entry == null) {
530                 entry = tagsEntryLocalService.addEntry(
531                     user.getUserId(), entryNames[i],
532                     TagsEntryLocalServiceImpl.DEFAULT_PROPERTIES);
533             }
534 
535             entries.add(entry);
536         }
537 
538         tagsAssetPersistence.setTagsEntries(asset.getAssetId(), entries);
539 
540         // Synchronize
541 
542         if (!sync) {
543             return asset;
544         }
545 
546         if (className.equals(BlogsEntry.class.getName())) {
547             BlogsEntry entry = blogsEntryPersistence.findByPrimaryKey(classPK);
548 
549             entry.setTitle(title);
550 
551             blogsEntryPersistence.update(entry, false);
552         }
553         else if (className.equals(BookmarksEntry.class.getName())) {
554             BookmarksEntry entry = bookmarksEntryPersistence.findByPrimaryKey(
555                 classPK);
556 
557             entry.setName(title);
558             entry.setComments(description);
559             entry.setUrl(url);
560 
561             bookmarksEntryPersistence.update(entry, false);
562         }
563         else if (className.equals(DLFileEntry.class.getName())) {
564             DLFileEntry fileEntry = dlFileEntryPersistence.findByPrimaryKey(
565                 classPK);
566 
567             fileEntry.setTitle(title);
568             fileEntry.setDescription(description);
569 
570             dlFileEntryPersistence.update(fileEntry, false);
571         }
572         else if (className.equals(JournalArticle.class.getName())) {
573             JournalArticle article = journalArticlePersistence.findByPrimaryKey(
574                 classPK);
575 
576             article.setTitle(title);
577             article.setDescription(description);
578 
579             journalArticlePersistence.update(article, false);
580         }
581         else if (className.equals(MBMessage.class.getName())) {
582             MBMessage message = mbMessagePersistence.findByPrimaryKey(classPK);
583 
584             message.setSubject(title);
585 
586             mbMessagePersistence.update(message, false);
587         }
588         else if (className.equals(WikiPage.class.getName())) {
589             WikiPage page = wikiPagePersistence.findByPrimaryKey(classPK);
590 
591             page.setTitle(title);
592 
593             wikiPagePersistence.update(page, false);
594         }
595 
596         return asset;
597     }
598 
599     public void validate(String className, String[] entryNames)
600         throws PortalException {
601 
602         TagsAssetValidator validator = (TagsAssetValidator)InstancePool.get(
603             PropsValues.TAGS_ASSET_VALIDATOR);
604 
605         validator.validate(className, entryNames);
606     }
607 
608     protected TagsAsset getAsset(Document doc)
609         throws PortalException, SystemException {
610 
611         String portletId = GetterUtil.getString(doc.get(Field.PORTLET_ID));
612 
613         if (portletId.equals(PortletKeys.BLOGS)) {
614             long entryId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
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(Field.ENTRY_CLASS_PK));
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(Field.ENTRY_CLASS_PK));
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(doc.get(Field.GROUP_ID));
655             String articleId = doc.get(Field.ENTRY_CLASS_PK);
656             //double version = GetterUtil.getDouble(doc.get("version"));
657 
658             long articleResourcePrimKey =
659                 journalArticleResourceLocalService.getArticleResourcePrimKey(
660                     groupId, articleId);
661 
662             long classNameId = PortalUtil.getClassNameId(
663                 JournalArticle.class.getName());
664             long classPK = articleResourcePrimKey;
665 
666             return tagsAssetPersistence.findByC_C(classNameId, classPK);
667         }
668         else if (portletId.equals(PortletKeys.MESSAGE_BOARDS)) {
669             long messageId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
670 
671             long classNameId = PortalUtil.getClassNameId(
672                 MBMessage.class.getName());
673             long classPK = messageId;
674 
675             return tagsAssetPersistence.findByC_C(classNameId, classPK);
676         }
677         else if (portletId.equals(PortletKeys.WIKI)) {
678             long nodeId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
679             String title = doc.get(Field.TITLE);
680 
681             long pageResourcePrimKey =
682                 wikiPageResourceLocalService.getPageResourcePrimKey(
683                     nodeId, title);
684 
685             long classNameId = PortalUtil.getClassNameId(
686                 WikiPage.class.getName());
687             long classPK = pageResourcePrimKey;
688 
689             return tagsAssetPersistence.findByC_C(classNameId, classPK);
690         }
691 
692         return null;
693     }
694 
695     protected TagsAssetDisplay[] getAssetDisplays(
696             List<TagsAsset> assets, String languageId)
697         throws SystemException {
698 
699         TagsAssetDisplay[] assetDisplays = new TagsAssetDisplay[assets.size()];
700 
701         for (int i = 0; i < assets.size(); i++) {
702             TagsAsset asset = assets.get(i);
703 
704             String className = PortalUtil.getClassName(asset.getClassNameId());
705             String portletId = PortalUtil.getClassNamePortletId(className);
706             String portletTitle = PortalUtil.getPortletTitle(
707                 portletId, asset.getCompanyId(), languageId);
708 
709             List<TagsEntry> tagsEntriesList =
710                 tagsAssetPersistence.getTagsEntries(asset.getAssetId());
711 
712             String tagsEntries = ListUtil.toString(
713                 tagsEntriesList, "name", ", ");
714 
715             TagsAssetDisplay assetDisplay = new TagsAssetDisplay();
716 
717             assetDisplay.setAssetId(asset.getAssetId());
718             assetDisplay.setCompanyId(asset.getCompanyId());
719             assetDisplay.setUserId(asset.getUserId());
720             assetDisplay.setUserName(asset.getUserName());
721             assetDisplay.setCreateDate(asset.getCreateDate());
722             assetDisplay.setModifiedDate(asset.getModifiedDate());
723             assetDisplay.setClassNameId(asset.getClassNameId());
724             assetDisplay.setClassName(className);
725             assetDisplay.setClassPK(asset.getClassPK());
726             assetDisplay.setPortletId(portletId);
727             assetDisplay.setPortletTitle(portletTitle);
728             assetDisplay.setStartDate(asset.getStartDate());
729             assetDisplay.setEndDate(asset.getEndDate());
730             assetDisplay.setPublishDate(asset.getPublishDate());
731             assetDisplay.setExpirationDate(asset.getExpirationDate());
732             assetDisplay.setMimeType(asset.getMimeType());
733             assetDisplay.setTitle(asset.getTitle());
734             assetDisplay.setDescription(asset.getDescription());
735             assetDisplay.setSummary(asset.getSummary());
736             assetDisplay.setUrl(asset.getUrl());
737             assetDisplay.setHeight(asset.getHeight());
738             assetDisplay.setWidth(asset.getWidth());
739             assetDisplay.setPriority(asset.getPriority());
740             assetDisplay.setViewCount(asset.getViewCount());
741             assetDisplay.setTagsEntries(tagsEntries);
742 
743             assetDisplays[i] = assetDisplay;
744         }
745 
746         return assetDisplays;
747     }
748 
749     protected TagsAssetType getAssetType(String className, String languageId) {
750         long companyId = PortalInstances.getDefaultCompanyId();
751 
752         long classNameId = PortalUtil.getClassNameId(className);
753 
754         String portletId = PortalUtil.getClassNamePortletId(className);
755         String portletTitle = PortalUtil.getPortletTitle(
756             portletId, companyId, languageId);
757 
758         TagsAssetType assetType = new TagsAssetType();
759 
760         assetType.setClassNameId(classNameId);
761         assetType.setClassName(className);
762         assetType.setPortletId(portletId);
763         assetType.setPortletTitle(portletTitle);
764 
765         return assetType;
766     }
767 
768     private static Log _log =
769         LogFactory.getLog(TagsAssetLocalServiceImpl.class);
770 
771 }