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