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
78 public class TagsAssetLocalServiceImpl extends TagsAssetLocalServiceBaseImpl {
79
80 public void deleteAsset(long assetId)
81 throws PortalException, SystemException {
82
83 TagsAsset asset = tagsAssetPersistence.findByPrimaryKey(assetId);
84
85 deleteAsset(asset);
86 }
87
88 public void deleteAsset(String className, long classPK)
89 throws SystemException {
90
91 long classNameId = PortalUtil.getClassNameId(className);
92
93 TagsAsset asset = tagsAssetPersistence.fetchByC_C(classNameId, classPK);
94
95 if (asset != null) {
96 deleteAsset(asset);
97 }
98 }
99
100 public void deleteAsset(TagsAsset asset) throws SystemException {
101 tagsAssetPersistence.remove(asset);
102 }
103
104 public TagsAsset getAsset(long assetId)
105 throws PortalException, SystemException {
106
107 return tagsAssetPersistence.findByPrimaryKey(assetId);
108 }
109
110 public TagsAsset getAsset(String className, long classPK)
111 throws PortalException, SystemException {
112
113 long classNameId = PortalUtil.getClassNameId(className);
114
115 return tagsAssetPersistence.findByC_C(classNameId, classPK);
116 }
117
118 public TagsAssetType[] getAssetTypes(String languageId) {
119 TagsAssetType[] assetTypes =
120 new TagsAssetType[TagsUtil.ASSET_TYPE_CLASS_NAMES.length];
121
122 for (int i = 0; i < TagsUtil.ASSET_TYPE_CLASS_NAMES.length; i++) {
123 assetTypes[i] = getAssetType(
124 TagsUtil.ASSET_TYPE_CLASS_NAMES[i], languageId);
125 }
126
127 return assetTypes;
128 }
129
130 public List<TagsAsset> getAssets(
131 long[] entryIds, long[] notEntryIds, boolean andOperator,
132 boolean excludeZeroViewCount, int start, int end)
133 throws SystemException {
134
135 return getAssets(
136 0, new long[0], entryIds, notEntryIds, andOperator,
137 excludeZeroViewCount, null, null, start, end);
138 }
139
140 public List<TagsAsset> getAssets(
141 long groupId, long[] classNameIds, long[] entryIds,
142 long[] notEntryIds, boolean andOperator,
143 boolean excludeZeroViewCount, int start, int end)
144 throws SystemException {
145
146 return getAssets(
147 groupId, classNameIds, entryIds, notEntryIds, andOperator,
148 excludeZeroViewCount, null, null, start, end);
149 }
150
151 public List<TagsAsset> getAssets(
152 long[] entryIds, long[] notEntryIds, boolean andOperator,
153 boolean excludeZeroViewCount, Date publishDate, Date expirationDate,
154 int start, int end)
155 throws SystemException {
156
157 return getAssets(
158 0, new long[0], entryIds, notEntryIds, andOperator,
159 excludeZeroViewCount, publishDate, expirationDate, start, end);
160 }
161
162 public List<TagsAsset> getAssets(
163 long groupId, long[] classNameIds, long[] entryIds,
164 long[] notEntryIds, boolean andOperator,
165 boolean excludeZeroViewCount, Date publishDate, Date expirationDate,
166 int start, int end)
167 throws SystemException {
168
169 if ((entryIds.length == 0) && (notEntryIds.length == 0)) {
170 return tagsAssetFinder.findAssets(
171 groupId, classNameIds, null, null, null, null,
172 excludeZeroViewCount, publishDate, expirationDate, start, end);
173 }
174 else if (andOperator) {
175 return tagsAssetFinder.findByAndEntryIds(
176 groupId, classNameIds, entryIds, notEntryIds, null, null, null,
177 null, excludeZeroViewCount, publishDate, expirationDate, start,
178 end);
179 }
180 else {
181 return tagsAssetFinder.findByOrEntryIds(
182 groupId, classNameIds, entryIds, notEntryIds, null, null, null,
183 null, excludeZeroViewCount, publishDate, expirationDate, start,
184 end);
185 }
186 }
187
188 public List<TagsAsset> getAssets(
189 long[] entryIds, long[] notEntryIds, boolean andOperator,
190 String orderByCol1, String orderByCol2, String orderByType1,
191 String orderByType2, boolean excludeZeroViewCount, Date publishDate,
192 Date expirationDate, int start, int end)
193 throws SystemException {
194
195 return getAssets(
196 0, new long[0], entryIds, notEntryIds, andOperator,
197 excludeZeroViewCount, publishDate, expirationDate, start, end);
198 }
199
200 public List<TagsAsset> getAssets(
201 long groupId, long[] classNameIds, long[] entryIds,
202 long[] notEntryIds, boolean andOperator, String orderByCol1,
203 String orderByCol2, String orderByType1, String orderByType2,
204 boolean excludeZeroViewCount, Date publishDate, Date expirationDate,
205 int start, int end)
206 throws SystemException {
207
208 if ((entryIds.length == 0) && (notEntryIds.length == 0)) {
209 return tagsAssetFinder.findAssets(
210 groupId, classNameIds, orderByCol1, orderByCol2, orderByType1,
211 orderByType2, excludeZeroViewCount, publishDate, expirationDate,
212 start, end);
213 }
214 else if (andOperator) {
215 return tagsAssetFinder.findByAndEntryIds(
216 groupId, classNameIds, entryIds, notEntryIds, orderByCol1,
217 orderByCol2, orderByType1, orderByType2, excludeZeroViewCount,
218 publishDate, expirationDate, start, end);
219 }
220 else {
221 return tagsAssetFinder.findByOrEntryIds(
222 groupId, classNameIds, entryIds, notEntryIds, orderByCol1,
223 orderByCol2, orderByType1, orderByType2, excludeZeroViewCount,
224 publishDate, expirationDate, start, end);
225 }
226 }
227
228 public int getAssetsCount(
229 long[] entryIds, long[] notEntryIds, boolean andOperator,
230 boolean excludeZeroViewCount)
231 throws SystemException {
232
233 return getAssetsCount(
234 0, new long[0], entryIds, notEntryIds, andOperator,
235 excludeZeroViewCount, null, null);
236 }
237
238 public int getAssetsCount(
239 long groupId, long[] entryIds, long[] notEntryIds,
240 boolean andOperator, boolean excludeZeroViewCount)
241 throws SystemException {
242
243 return getAssetsCount(
244 groupId, new long[0], entryIds, notEntryIds, andOperator,
245 excludeZeroViewCount, null, null);
246 }
247
248 public int getAssetsCount(
249 long[] entryIds, long[] notEntryIds, boolean andOperator,
250 boolean excludeZeroViewCount, Date publishDate, Date expirationDate)
251 throws SystemException {
252
253 return getAssetsCount(
254 0, new long[0], entryIds, notEntryIds, andOperator,
255 excludeZeroViewCount, publishDate, expirationDate);
256 }
257
258 public int getAssetsCount(
259 long groupId, long[] classNameIds, long[] entryIds,
260 long[] notEntryIds, boolean andOperator,
261 boolean excludeZeroViewCount, Date publishDate, Date expirationDate)
262 throws SystemException {
263
264 if ((entryIds.length == 0) && (notEntryIds.length == 0)) {
265 return tagsAssetFinder.countAssets(
266 groupId, classNameIds, excludeZeroViewCount, publishDate,
267 expirationDate);
268 }
269 else if (andOperator) {
270 return tagsAssetFinder.countByAndEntryIds(
271 groupId, classNameIds, entryIds, notEntryIds,
272 excludeZeroViewCount, publishDate, expirationDate);
273 }
274 else {
275 return tagsAssetFinder.countByOrEntryIds(
276 groupId, classNameIds, entryIds, notEntryIds,
277 excludeZeroViewCount, publishDate, expirationDate);
278 }
279 }
280
281 public TagsAssetDisplay[] getCompanyAssetDisplays(
282 long companyId, int start, int end, String languageId)
283 throws SystemException {
284
285 return getAssetDisplays(
286 getCompanyAssets(companyId, start, end), languageId);
287 }
288
289 public List<TagsAsset> getCompanyAssets(long companyId, int start, int end)
290 throws SystemException {
291
292 return tagsAssetPersistence.findByCompanyId(companyId, start, end);
293 }
294
295 public int getCompanyAssetsCount(long companyId) throws SystemException {
296 return tagsAssetPersistence.countByCompanyId(companyId);
297 }
298
299 public List<TagsAsset> getTopViewedAssets(
300 String className, boolean asc, int start, int end)
301 throws SystemException {
302
303 return getTopViewedAssets(new String[] {className}, asc, start, end);
304 }
305
306 public List<TagsAsset> getTopViewedAssets(
307 String[] className, boolean asc, int start, int end)
308 throws SystemException {
309
310 long[] classNameIds = new long[className.length];
311
312 for (int i = 0; i < className.length; i++) {
313 classNameIds[i] = PortalUtil.getClassNameId(className[i]);
314 }
315
316 return tagsAssetFinder.findByViewCount(classNameIds, asc, start, end);
317 }
318
319 public TagsAsset incrementViewCounter(String className, long classPK)
320 throws SystemException {
321
322 if (classPK <= 0) {
323 return null;
324 }
325
326 long classNameId = PortalUtil.getClassNameId(className);
327
328 TagsAsset asset = tagsAssetPersistence.fetchByC_C(classNameId, classPK);
329
330 if (asset != null) {
331 asset.setViewCount(asset.getViewCount() + 1);
332
333 tagsAssetPersistence.update(asset, false);
334 }
335
336 return asset;
337 }
338
339 public Hits search(
340 long companyId, String portletId, String keywords, int start,
341 int end)
342 throws SystemException {
343
344 try {
345 BooleanQuery contextQuery = BooleanQueryFactoryUtil.create();
346
347 if (Validator.isNotNull(portletId)) {
348 contextQuery.addRequiredTerm(Field.PORTLET_ID, portletId);
349 }
350 else {
351 BooleanQuery portletIdsQuery = BooleanQueryFactoryUtil.create();
352
353 for (String assetTypePortletId :
354 TagsUtil.ASSET_TYPE_PORTLET_IDS) {
355
356 TermQuery termQuery = TermQueryFactoryUtil.create(
357 Field.PORTLET_ID, assetTypePortletId);
358
359 portletIdsQuery.add(termQuery, BooleanClauseOccur.SHOULD);
360 }
361
362 contextQuery.add(portletIdsQuery, BooleanClauseOccur.MUST);
363 }
364
365 BooleanQuery searchQuery = BooleanQueryFactoryUtil.create();
366
367 if (Validator.isNotNull(keywords)) {
368 searchQuery.addTerm(Field.TITLE, keywords);
369 searchQuery.addTerm(Field.CONTENT, keywords);
370 searchQuery.addTerm(Field.DESCRIPTION, keywords);
371 searchQuery.addTerm(Field.PROPERTIES, keywords);
372 searchQuery.addTerm(Field.TAGS_ENTRIES, keywords, true);
373 }
374
375 BooleanQuery fullQuery = BooleanQueryFactoryUtil.create();
376
377 fullQuery.add(contextQuery, BooleanClauseOccur.MUST);
378
379 if (searchQuery.clauses().size() > 0) {
380 fullQuery.add(searchQuery, BooleanClauseOccur.MUST);
381 }
382
383 return SearchEngineUtil.search(companyId, fullQuery, start, end);
384 }
385 catch (Exception e) {
386 throw new SystemException(e);
387 }
388 }
389
390 public TagsAssetDisplay[] searchAssetDisplays(
391 long companyId, String portletId, String keywords,
392 String languageId, int start, int end)
393 throws SystemException {
394
395 List<TagsAsset> assets = new ArrayList<TagsAsset>();
396
397 Hits hits = search(companyId, portletId, keywords, start, end);
398
399 List<Document> hitsList = hits.toList();
400
401 for (Document doc : hitsList) {
402 try {
403 TagsAsset asset = getAsset(doc);
404
405 if (asset != null) {
406 assets.add(asset);
407 }
408 }
409 catch (Exception e) {
410 if (_log.isWarnEnabled()) {
411 _log.warn(e);
412 }
413 }
414 }
415
416 return getAssetDisplays(assets, languageId);
417 }
418
419 public int searchAssetDisplaysCount(
420 long companyId, String portletId, String keywords,
421 String languageId)
422 throws SystemException {
423
424 Hits hits = search(
425 companyId, portletId, keywords, QueryUtil.ALL_POS,
426 QueryUtil.ALL_POS);
427
428 return hits.getLength();
429 }
430
431 public TagsAsset updateAsset(
432 long userId, long groupId, String className, long classPK,
433 String[] categoryNames, String[] entryNames)
434 throws PortalException, SystemException {
435
436 return updateAsset(
437 userId, groupId, className, classPK, categoryNames, entryNames,
438 true, null, null, null, null, null, null, null, null, null, 0, 0,
439 null);
440 }
441
442 public TagsAsset updateAsset(
443 long userId, long groupId, String className, long classPK,
444 String[] categoryNames, String[] entryNames, boolean visible,
445 Date startDate, Date endDate, Date publishDate, Date expirationDate,
446 String mimeType, String title, String description, String summary,
447 String url, int height, int width, Integer priority)
448 throws PortalException, SystemException {
449
450 return updateAsset(
451 userId, groupId, className, classPK, categoryNames, entryNames,
452 visible, startDate, endDate, publishDate, expirationDate, mimeType,
453 title, description, summary, url, height, width, priority, true);
454 }
455
456 public TagsAsset updateAsset(
457 long userId, long groupId, String className, long classPK,
458 String[] categoryNames, String[] entryNames, boolean visible,
459 Date startDate, Date endDate, Date publishDate, Date expirationDate,
460 String mimeType, String title, String description, String summary,
461 String url, int height, int width, Integer priority, boolean sync)
462 throws PortalException, SystemException {
463
464
466 User user = userPersistence.findByPrimaryKey(userId);
467 long classNameId = PortalUtil.getClassNameId(className);
468
469 if (entryNames == null) {
470 entryNames = new String[0];
471 }
472
473 if (categoryNames == null) {
474 categoryNames = new String[0];
475 }
476
477 title = StringUtil.shorten(title, 300, StringPool.BLANK);
478 Date now = new Date();
479
480 validate(className, entryNames);
481
482 TagsAsset asset = tagsAssetPersistence.fetchByC_C(classNameId, classPK);
483
484 if (asset == null) {
485 long assetId = counterLocalService.increment();
486
487 asset = tagsAssetPersistence.create(assetId);
488
489 asset.setCompanyId(user.getCompanyId());
490 asset.setUserId(user.getUserId());
491 asset.setUserName(user.getFullName());
492 asset.setCreateDate(now);
493 asset.setClassNameId(classNameId);
494 asset.setClassPK(classPK);
495 asset.setVisible(visible);
496 asset.setPublishDate(publishDate);
497 asset.setExpirationDate(expirationDate);
498
499 if (priority == null) {
500 asset.setPriority(0);
501 }
502
503 asset.setViewCount(0);
504 }
505
506 asset.setGroupId(groupId);
507 asset.setModifiedDate(now);
508 asset.setVisible(visible);
509 asset.setStartDate(startDate);
510 asset.setEndDate(endDate);
511 asset.setPublishDate(publishDate);
512 asset.setExpirationDate(expirationDate);
513 asset.setMimeType(mimeType);
514 asset.setTitle(title);
515 asset.setDescription(description);
516 asset.setSummary(summary);
517 asset.setUrl(url);
518 asset.setHeight(height);
519 asset.setWidth(width);
520
521 if (priority != null) {
522 asset.setPriority(priority.intValue());
523 }
524
525
527 List<TagsEntry> entries = new ArrayList<TagsEntry>(entryNames.length);
528
529 for (int i = 0; i < entryNames.length; i++) {
530 TagsEntry entry = null;
531
532 try {
533 entry = tagsEntryLocalService.getEntry(
534 groupId, entryNames[i], TagsEntryConstants.FOLKSONOMY_TAG);
535 }
536 catch (NoSuchEntryException nsee) {
537 ServiceContext serviceContext = new ServiceContext();
538
539 serviceContext.setAddCommunityPermissions(true);
540 serviceContext.setAddGuestPermissions(true);
541 serviceContext.setScopeGroupId(groupId);
542
543 entry = tagsEntryLocalService.addEntry(
544 user.getUserId(), null, entryNames[i], null,
545 PropsValues.TAGS_PROPERTIES_DEFAULT, serviceContext);
546 }
547
548 if (entry != null) {
549 entries.add(entry);
550 }
551 }
552
553
555 for (int i = 0; i < categoryNames.length; i++) {
556 try {
557 TagsEntry entry = tagsEntryLocalService.getEntry(
558 groupId, categoryNames[i],
559 TagsEntryConstants.FOLKSONOMY_CATEGORY);
560
561 entries.add(entry);
562 }
563 catch (NoSuchEntryException nsee) {
564 }
565 }
566
567 tagsAssetPersistence.setTagsEntries(asset.getAssetId(), entries);
568
569
572 tagsAssetPersistence.update(asset, false);
573
574
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
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, asset.getCompanyId(), 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 companyId = PortalInstances.getDefaultCompanyId();
800
801 long classNameId = PortalUtil.getClassNameId(className);
802
803 String portletId = PortalUtil.getClassNamePortletId(className);
804 String portletTitle = PortalUtil.getPortletTitle(
805 portletId, companyId, languageId);
806
807 TagsAssetType assetType = new TagsAssetType();
808
809 assetType.setClassNameId(classNameId);
810 assetType.setClassName(className);
811 assetType.setPortletId(portletId);
812 assetType.setPortletTitle(portletTitle);
813
814 return assetType;
815 }
816
817 private static Log _log =
818 LogFactoryUtil.getLog(TagsAssetLocalServiceImpl.class);
819
820 }