1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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.service.ServiceContext;
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.NoSuchEntryException;
57  import com.liferay.portlet.tags.model.TagsAsset;
58  import com.liferay.portlet.tags.model.TagsAssetDisplay;
59  import com.liferay.portlet.tags.model.TagsAssetType;
60  import com.liferay.portlet.tags.model.TagsEntry;
61  import com.liferay.portlet.tags.model.TagsEntryConstants;
62  import com.liferay.portlet.tags.service.base.TagsAssetLocalServiceBaseImpl;
63  import com.liferay.portlet.tags.util.TagsAssetValidator;
64  import com.liferay.portlet.tags.util.TagsUtil;
65  import com.liferay.portlet.wiki.model.WikiPage;
66  
67  import java.util.ArrayList;
68  import java.util.Date;
69  import java.util.List;
70  
71  /**
72   * <a href="TagsAssetLocalServiceImpl.java.html"><b><i>View Source</i></b></a>
73   *
74   * @author Brian Wing Shun Chan
75   * @author Bruno Farache
76   */
77  public class TagsAssetLocalServiceImpl extends TagsAssetLocalServiceBaseImpl {
78  
79      public void deleteAsset(long assetId)
80          throws PortalException, SystemException {
81  
82          TagsAsset asset = tagsAssetPersistence.findByPrimaryKey(assetId);
83  
84          deleteAsset(asset);
85      }
86  
87      public void deleteAsset(String className, long classPK)
88          throws SystemException {
89  
90          long classNameId = PortalUtil.getClassNameId(className);
91  
92          TagsAsset asset = tagsAssetPersistence.fetchByC_C(classNameId, classPK);
93  
94          if (asset != null) {
95              deleteAsset(asset);
96          }
97      }
98  
99      public void deleteAsset(TagsAsset asset) throws SystemException {
100         tagsAssetPersistence.remove(asset);
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 List<TagsAsset> getAssets(
118             long groupId, long[] classNameIds, long[] entryIds,
119             long[] notEntryIds, boolean andOperator,
120             boolean excludeZeroViewCount, Date publishDate, Date expirationDate,
121             int start, int end)
122         throws SystemException {
123 
124         if ((entryIds.length == 0) && (notEntryIds.length == 0)) {
125             return tagsAssetFinder.findAssets(
126                 groupId, classNameIds, null, null, null, null,
127                 excludeZeroViewCount, publishDate, expirationDate, start, end);
128         }
129         else if (andOperator) {
130             return tagsAssetFinder.findByAndEntryIds(
131                 groupId, classNameIds, entryIds, notEntryIds, null, null, null,
132                 null, excludeZeroViewCount, publishDate, expirationDate, start,
133                 end);
134         }
135         else {
136             return tagsAssetFinder.findByOrEntryIds(
137                 groupId, classNameIds, entryIds, notEntryIds, null, null, null,
138                 null, excludeZeroViewCount, publishDate, expirationDate, start,
139                 end);
140         }
141     }
142 
143     public List<TagsAsset> getAssets(
144             long groupId, long[] classNameIds, long[] entryIds,
145             long[] notEntryIds, boolean andOperator,
146             boolean excludeZeroViewCount, int start, int end)
147         throws SystemException {
148 
149         return getAssets(
150             groupId, classNameIds, entryIds, notEntryIds, andOperator,
151             excludeZeroViewCount, null, null, start, end);
152     }
153 
154     public List<TagsAsset> getAssets(
155             long groupId, long[] classNameIds, long[] entryIds,
156             long[] notEntryIds, boolean andOperator, String orderByCol1,
157             String orderByCol2, String orderByType1, String orderByType2,
158             boolean excludeZeroViewCount, Date publishDate, Date expirationDate,
159             int start, int end)
160         throws SystemException {
161 
162         if ((entryIds.length == 0) && (notEntryIds.length == 0)) {
163             return tagsAssetFinder.findAssets(
164                 groupId, classNameIds, orderByCol1, orderByCol2, orderByType1,
165                 orderByType2, excludeZeroViewCount, publishDate, expirationDate,
166                 start, end);
167         }
168         else if (andOperator) {
169             return tagsAssetFinder.findByAndEntryIds(
170                 groupId, classNameIds, entryIds, notEntryIds, orderByCol1,
171                 orderByCol2, orderByType1, orderByType2, excludeZeroViewCount,
172                 publishDate, expirationDate, start, end);
173         }
174         else {
175             return tagsAssetFinder.findByOrEntryIds(
176                 groupId, classNameIds, entryIds, notEntryIds, orderByCol1,
177                 orderByCol2, orderByType1, orderByType2, excludeZeroViewCount,
178                 publishDate, expirationDate, start, end);
179         }
180     }
181 
182     public List<TagsAsset> getAssets(
183             long[] entryIds, long[] notEntryIds, boolean andOperator,
184             boolean excludeZeroViewCount, Date publishDate, Date expirationDate,
185             int start, int end)
186         throws SystemException {
187 
188         return getAssets(
189             0, new long[0], entryIds, notEntryIds, andOperator,
190             excludeZeroViewCount, publishDate, expirationDate, start, end);
191     }
192 
193     public List<TagsAsset> getAssets(
194             long[] entryIds, long[] notEntryIds, boolean andOperator,
195             boolean excludeZeroViewCount, int start, int end)
196         throws SystemException {
197 
198         return getAssets(
199             0, new long[0], entryIds, notEntryIds, andOperator,
200             excludeZeroViewCount, null, null, start, end);
201     }
202 
203     public List<TagsAsset> getAssets(
204             long[] entryIds, long[] notEntryIds, boolean andOperator,
205             String orderByCol1, String orderByCol2, String orderByType1,
206             String orderByType2, boolean excludeZeroViewCount, Date publishDate,
207             Date expirationDate, int start, int end)
208         throws SystemException {
209 
210         return getAssets(
211             0, new long[0], entryIds, notEntryIds, andOperator,
212             excludeZeroViewCount, publishDate, expirationDate, start, end);
213     }
214 
215     public int getAssetsCount(
216             long groupId, long[] entryIds, long[] notEntryIds,
217             boolean andOperator, boolean excludeZeroViewCount)
218         throws SystemException {
219 
220         return getAssetsCount(
221             groupId, new long[0], entryIds, notEntryIds, andOperator,
222             excludeZeroViewCount, null, null);
223     }
224 
225     public int getAssetsCount(
226             long groupId, long[] classNameIds, long[] entryIds,
227             long[] notEntryIds, boolean andOperator,
228             boolean excludeZeroViewCount, Date publishDate, Date expirationDate)
229         throws SystemException {
230 
231         if ((entryIds.length == 0) && (notEntryIds.length == 0)) {
232             return tagsAssetFinder.countAssets(
233                 groupId, classNameIds, excludeZeroViewCount, publishDate,
234                 expirationDate);
235         }
236         else if (andOperator) {
237             return tagsAssetFinder.countByAndEntryIds(
238                 groupId, classNameIds, entryIds, notEntryIds,
239                 excludeZeroViewCount, publishDate, expirationDate);
240         }
241         else {
242             return tagsAssetFinder.countByOrEntryIds(
243                 groupId, classNameIds, entryIds, notEntryIds,
244                 excludeZeroViewCount, publishDate, expirationDate);
245         }
246     }
247 
248     public int getAssetsCount(
249             long[] entryIds, long[] notEntryIds, boolean andOperator,
250             boolean excludeZeroViewCount)
251         throws SystemException {
252 
253         return getAssetsCount(
254             0, new long[0], entryIds, notEntryIds, andOperator,
255             excludeZeroViewCount, null, null);
256     }
257 
258     public int getAssetsCount(
259             long[] entryIds, long[] notEntryIds, boolean andOperator,
260             boolean excludeZeroViewCount, Date publishDate, Date expirationDate)
261         throws SystemException {
262 
263         return getAssetsCount(
264             0, new long[0], entryIds, notEntryIds, andOperator,
265             excludeZeroViewCount, publishDate, expirationDate);
266     }
267 
268     public TagsAssetType[] getAssetTypes(String languageId) {
269         TagsAssetType[] assetTypes =
270             new TagsAssetType[TagsUtil.ASSET_TYPE_CLASS_NAMES.length];
271 
272         for (int i = 0; i < TagsUtil.ASSET_TYPE_CLASS_NAMES.length; i++) {
273             assetTypes[i] = getAssetType(
274                 TagsUtil.ASSET_TYPE_CLASS_NAMES[i], languageId);
275         }
276 
277         return assetTypes;
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, true);
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, QueryUtil.ALL_POS,
425             QueryUtil.ALL_POS);
426 
427         return hits.getLength();
428     }
429 
430     public TagsAsset updateAsset(
431             long userId, long groupId, String className, long classPK,
432             String[] categoryNames, String[] entryNames)
433         throws PortalException, SystemException {
434 
435         return updateAsset(
436             userId, groupId, className, classPK, categoryNames, entryNames,
437             true, null, null, null, null, null, null, null, null, null, 0, 0,
438             null);
439     }
440 
441     public TagsAsset updateAsset(
442             long userId, long groupId, String className, long classPK,
443             String[] categoryNames, String[] entryNames, boolean visible,
444             Date startDate, Date endDate, Date publishDate, Date expirationDate,
445             String mimeType, String title, String description, String summary,
446             String url, int height, int width, Integer priority)
447         throws PortalException, SystemException {
448 
449         return updateAsset(
450             userId, groupId, className, classPK, categoryNames, entryNames,
451             visible, startDate, endDate, publishDate, expirationDate, mimeType,
452             title, description, summary, url, height, width, priority, true);
453     }
454 
455     public TagsAsset updateAsset(
456             long userId, long groupId, String className, long classPK,
457             String[] categoryNames, String[] entryNames, boolean visible,
458             Date startDate, Date endDate, Date publishDate, Date expirationDate,
459             String mimeType, String title, String description, String summary,
460             String url, int height, int width, Integer priority, boolean sync)
461         throws PortalException, SystemException {
462 
463         // Asset
464 
465         User user = userPersistence.findByPrimaryKey(userId);
466         long classNameId = PortalUtil.getClassNameId(className);
467 
468         if (entryNames == null) {
469             entryNames = new String[0];
470         }
471 
472         if (categoryNames == null) {
473             categoryNames = new String[0];
474         }
475 
476         title = StringUtil.shorten(title, 300, StringPool.BLANK);
477         Date now = new Date();
478 
479         validate(className, entryNames);
480 
481         TagsAsset asset = tagsAssetPersistence.fetchByC_C(classNameId, classPK);
482 
483         if (asset == null) {
484             long assetId = counterLocalService.increment();
485 
486             asset = tagsAssetPersistence.create(assetId);
487 
488             asset.setCompanyId(user.getCompanyId());
489             asset.setUserId(user.getUserId());
490             asset.setUserName(user.getFullName());
491             asset.setCreateDate(now);
492             asset.setClassNameId(classNameId);
493             asset.setClassPK(classPK);
494             asset.setVisible(visible);
495             asset.setPublishDate(publishDate);
496             asset.setExpirationDate(expirationDate);
497 
498             if (priority == null) {
499                 asset.setPriority(0);
500             }
501 
502             asset.setViewCount(0);
503         }
504 
505         asset.setGroupId(groupId);
506         asset.setModifiedDate(now);
507         asset.setVisible(visible);
508         asset.setStartDate(startDate);
509         asset.setEndDate(endDate);
510         asset.setPublishDate(publishDate);
511         asset.setExpirationDate(expirationDate);
512         asset.setMimeType(mimeType);
513         asset.setTitle(title);
514         asset.setDescription(description);
515         asset.setSummary(summary);
516         asset.setUrl(url);
517         asset.setHeight(height);
518         asset.setWidth(width);
519 
520         if (priority != null) {
521             asset.setPriority(priority.intValue());
522         }
523 
524         // Categories
525 
526         List<TagsEntry> entries = new ArrayList<TagsEntry>(
527             categoryNames.length + entryNames.length);
528 
529         for (String categoryName : categoryNames) {
530             try {
531                 TagsEntry entry = tagsEntryLocalService.getEntry(
532                     groupId, categoryName,
533                     TagsEntryConstants.FOLKSONOMY_CATEGORY);
534 
535                 entries.add(entry);
536             }
537             catch (NoSuchEntryException nsee) {
538             }
539         }
540 
541         // Entries
542 
543         for (String entryName : entryNames) {
544             TagsEntry entry = null;
545 
546             try {
547                 entry = tagsEntryLocalService.getEntry(
548                     groupId, entryName, TagsEntryConstants.FOLKSONOMY_TAG);
549             }
550             catch (NoSuchEntryException nsee) {
551                 ServiceContext serviceContext = new ServiceContext();
552 
553                 serviceContext.setAddCommunityPermissions(true);
554                 serviceContext.setAddGuestPermissions(true);
555                 serviceContext.setScopeGroupId(groupId);
556 
557                 entry = tagsEntryLocalService.addEntry(
558                     user.getUserId(), null, entryName, null,
559                     PropsValues.TAGS_PROPERTIES_DEFAULT, serviceContext);
560             }
561 
562             if (entry != null) {
563                 entries.add(entry);
564             }
565         }
566 
567         tagsAssetPersistence.setTagsEntries(asset.getAssetId(), entries);
568 
569         // Update asset after entries so that asset listeners have access the
570         // saved entries
571 
572         tagsAssetPersistence.update(asset, false);
573 
574         // Synchronize
575 
576         if (!sync) {
577             return asset;
578         }
579 
580         if (className.equals(BlogsEntry.class.getName())) {
581             BlogsEntry entry = blogsEntryPersistence.findByPrimaryKey(classPK);
582 
583             entry.setTitle(title);
584 
585             blogsEntryPersistence.update(entry, false);
586         }
587         else if (className.equals(BookmarksEntry.class.getName())) {
588             BookmarksEntry entry = bookmarksEntryPersistence.findByPrimaryKey(
589                 classPK);
590 
591             entry.setName(title);
592             entry.setComments(description);
593             entry.setUrl(url);
594 
595             bookmarksEntryPersistence.update(entry, false);
596         }
597         else if (className.equals(DLFileEntry.class.getName())) {
598             DLFileEntry fileEntry = dlFileEntryPersistence.findByPrimaryKey(
599                 classPK);
600 
601             fileEntry.setTitle(title);
602             fileEntry.setDescription(description);
603 
604             dlFileEntryPersistence.update(fileEntry, false);
605         }
606         else if (className.equals(JournalArticle.class.getName())) {
607             JournalArticle article = journalArticlePersistence.findByPrimaryKey(
608                 classPK);
609 
610             article.setTitle(title);
611             article.setDescription(description);
612 
613             journalArticlePersistence.update(article, false);
614         }
615         else if (className.equals(MBMessage.class.getName())) {
616             MBMessage message = mbMessagePersistence.findByPrimaryKey(classPK);
617 
618             message.setSubject(title);
619 
620             mbMessagePersistence.update(message, false);
621         }
622         else if (className.equals(WikiPage.class.getName())) {
623             WikiPage page = wikiPagePersistence.findByPrimaryKey(classPK);
624 
625             page.setTitle(title);
626 
627             wikiPagePersistence.update(page, false);
628         }
629 
630         return asset;
631     }
632 
633     public TagsAsset updateVisible(
634             String className, long classPK, boolean visible)
635         throws PortalException, SystemException {
636 
637         long classNameId = PortalUtil.getClassNameId(className);
638 
639         TagsAsset asset = tagsAssetPersistence.findByC_C(classNameId, classPK);
640 
641         asset.setVisible(visible);
642 
643         tagsAssetPersistence.update(asset, false);
644 
645         return asset;
646     }
647 
648     public void validate(String className, String[] entryNames)
649         throws PortalException {
650 
651         TagsAssetValidator validator = (TagsAssetValidator)InstancePool.get(
652             PropsValues.TAGS_ASSET_VALIDATOR);
653 
654         validator.validate(className, entryNames);
655     }
656 
657     protected TagsAsset getAsset(Document doc)
658         throws PortalException, SystemException {
659 
660         String portletId = GetterUtil.getString(doc.get(Field.PORTLET_ID));
661 
662         if (portletId.equals(PortletKeys.BLOGS)) {
663             long entryId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
664 
665             long classNameId = PortalUtil.getClassNameId(
666                 BlogsEntry.class.getName());
667             long classPK = entryId;
668 
669             return tagsAssetPersistence.findByC_C(classNameId, classPK);
670         }
671         else if (portletId.equals(PortletKeys.BOOKMARKS)) {
672             long entryId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
673 
674             long classNameId = PortalUtil.getClassNameId(
675                 BookmarksEntry.class.getName());
676             long classPK = entryId;
677 
678             return tagsAssetPersistence.findByC_C(classNameId, classPK);
679         }
680         else if (portletId.equals(PortletKeys.DOCUMENT_LIBRARY)) {
681             long folderId = GetterUtil.getLong(doc.get("repositoryId"));
682             String name = doc.get("path");
683 
684             DLFileEntry fileEntry = dlFileEntryLocalService.getFileEntry(
685                 folderId, name);
686 
687             long classNameId = PortalUtil.getClassNameId(
688                 DLFileEntry.class.getName());
689             long classPK = fileEntry.getFileEntryId();
690 
691             return tagsAssetPersistence.findByC_C(classNameId, classPK);
692         }
693         else if (portletId.equals(PortletKeys.IMAGE_GALLERY)) {
694             long imageId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
695 
696             long classNameId = PortalUtil.getClassNameId(
697                 IGImage.class.getName());
698             long classPK = imageId;
699 
700             return tagsAssetPersistence.findByC_C(classNameId, classPK);
701         }
702         else if (portletId.equals(PortletKeys.JOURNAL)) {
703             long groupId = GetterUtil.getLong(doc.get(Field.GROUP_ID));
704             String articleId = doc.get(Field.ENTRY_CLASS_PK);
705             //double version = GetterUtil.getDouble(doc.get("version"));
706 
707             long articleResourcePrimKey =
708                 journalArticleResourceLocalService.getArticleResourcePrimKey(
709                     groupId, articleId);
710 
711             long classNameId = PortalUtil.getClassNameId(
712                 JournalArticle.class.getName());
713             long classPK = articleResourcePrimKey;
714 
715             return tagsAssetPersistence.findByC_C(classNameId, classPK);
716         }
717         else if (portletId.equals(PortletKeys.MESSAGE_BOARDS)) {
718             long messageId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
719 
720             long classNameId = PortalUtil.getClassNameId(
721                 MBMessage.class.getName());
722             long classPK = messageId;
723 
724             return tagsAssetPersistence.findByC_C(classNameId, classPK);
725         }
726         else if (portletId.equals(PortletKeys.WIKI)) {
727             long nodeId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
728             String title = doc.get(Field.TITLE);
729 
730             long pageResourcePrimKey =
731                 wikiPageResourceLocalService.getPageResourcePrimKey(
732                     nodeId, title);
733 
734             long classNameId = PortalUtil.getClassNameId(
735                 WikiPage.class.getName());
736             long classPK = pageResourcePrimKey;
737 
738             return tagsAssetPersistence.findByC_C(classNameId, classPK);
739         }
740 
741         return null;
742     }
743 
744     protected TagsAssetDisplay[] getAssetDisplays(
745             List<TagsAsset> assets, String languageId)
746         throws SystemException {
747 
748         TagsAssetDisplay[] assetDisplays = new TagsAssetDisplay[assets.size()];
749 
750         for (int i = 0; i < assets.size(); i++) {
751             TagsAsset asset = assets.get(i);
752 
753             String className = PortalUtil.getClassName(asset.getClassNameId());
754             String portletId = PortalUtil.getClassNamePortletId(className);
755             String portletTitle = PortalUtil.getPortletTitle(
756                 portletId, languageId);
757 
758             List<TagsEntry> tagsEntriesList =
759                 tagsAssetPersistence.getTagsEntries(asset.getAssetId());
760 
761             String tagsEntries = ListUtil.toString(
762                 tagsEntriesList, "name", ", ");
763 
764             TagsAssetDisplay assetDisplay = new TagsAssetDisplay();
765 
766             assetDisplay.setAssetId(asset.getAssetId());
767             assetDisplay.setCompanyId(asset.getCompanyId());
768             assetDisplay.setUserId(asset.getUserId());
769             assetDisplay.setUserName(asset.getUserName());
770             assetDisplay.setCreateDate(asset.getCreateDate());
771             assetDisplay.setModifiedDate(asset.getModifiedDate());
772             assetDisplay.setClassNameId(asset.getClassNameId());
773             assetDisplay.setClassName(className);
774             assetDisplay.setClassPK(asset.getClassPK());
775             assetDisplay.setPortletId(portletId);
776             assetDisplay.setPortletTitle(portletTitle);
777             assetDisplay.setStartDate(asset.getStartDate());
778             assetDisplay.setEndDate(asset.getEndDate());
779             assetDisplay.setPublishDate(asset.getPublishDate());
780             assetDisplay.setExpirationDate(asset.getExpirationDate());
781             assetDisplay.setMimeType(asset.getMimeType());
782             assetDisplay.setTitle(asset.getTitle());
783             assetDisplay.setDescription(asset.getDescription());
784             assetDisplay.setSummary(asset.getSummary());
785             assetDisplay.setUrl(asset.getUrl());
786             assetDisplay.setHeight(asset.getHeight());
787             assetDisplay.setWidth(asset.getWidth());
788             assetDisplay.setPriority(asset.getPriority());
789             assetDisplay.setViewCount(asset.getViewCount());
790             assetDisplay.setTagsEntries(tagsEntries);
791 
792             assetDisplays[i] = assetDisplay;
793         }
794 
795         return assetDisplays;
796     }
797 
798     protected TagsAssetType getAssetType(String className, String languageId) {
799         long classNameId = PortalUtil.getClassNameId(className);
800 
801         String portletId = PortalUtil.getClassNamePortletId(className);
802         String portletTitle = PortalUtil.getPortletTitle(portletId, languageId);
803 
804         TagsAssetType assetType = new TagsAssetType();
805 
806         assetType.setClassNameId(classNameId);
807         assetType.setClassName(className);
808         assetType.setPortletId(portletId);
809         assetType.setPortletTitle(portletTitle);
810 
811         return assetType;
812     }
813 
814     private static Log _log =
815         LogFactoryUtil.getLog(TagsAssetLocalServiceImpl.class);
816 
817 }