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