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 (classPK <= 0) {
314 return null;
315 }
316
317 long classNameId = PortalUtil.getClassNameId(className);
318
319 TagsAsset asset = tagsAssetPersistence.fetchByC_C(classNameId, classPK);
320
321 if (asset != null) {
322 asset.setViewCount(asset.getViewCount() + 1);
323
324 tagsAssetPersistence.update(asset, false);
325 }
326
327 return asset;
328 }
329
330 public Hits search(
331 long companyId, String portletId, String keywords, int start,
332 int end)
333 throws SystemException {
334
335 try {
336 BooleanQuery contextQuery = BooleanQueryFactoryUtil.create();
337
338 if (Validator.isNotNull(portletId)) {
339 contextQuery.addRequiredTerm(Field.PORTLET_ID, portletId);
340 }
341 else {
342 BooleanQuery portletIdsQuery = BooleanQueryFactoryUtil.create();
343
344 for (String assetTypePortletId :
345 TagsUtil.ASSET_TYPE_PORTLET_IDS) {
346
347 TermQuery termQuery = TermQueryFactoryUtil.create(
348 Field.PORTLET_ID, assetTypePortletId);
349
350 portletIdsQuery.add(termQuery, BooleanClauseOccur.SHOULD);
351 }
352
353 contextQuery.add(portletIdsQuery, BooleanClauseOccur.MUST);
354 }
355
356 BooleanQuery searchQuery = BooleanQueryFactoryUtil.create();
357
358 if (Validator.isNotNull(keywords)) {
359 searchQuery.addTerm(Field.TITLE, keywords);
360 searchQuery.addTerm(Field.CONTENT, keywords);
361 searchQuery.addTerm(Field.DESCRIPTION, keywords);
362 searchQuery.addTerm(Field.PROPERTIES, keywords);
363 searchQuery.addTerm(Field.TAGS_ENTRIES, keywords, true);
364 }
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 List<TagsEntry> entries = new ArrayList<TagsEntry>(
519 categoryNames.length + entryNames.length);
520
521 for (String categoryName : categoryNames) {
522 try {
523 TagsEntry entry = tagsEntryLocalService.getEntry(
524 groupId, categoryName,
525 TagsEntryConstants.FOLKSONOMY_CATEGORY);
526
527 entries.add(entry);
528 }
529 catch (NoSuchEntryException nsee) {
530 }
531 }
532
533
535 for (String entryName : entryNames) {
536 TagsEntry entry = null;
537
538 try {
539 entry = tagsEntryLocalService.getEntry(
540 groupId, entryName, TagsEntryConstants.FOLKSONOMY_TAG);
541 }
542 catch (NoSuchEntryException nsee) {
543 ServiceContext serviceContext = new ServiceContext();
544
545 serviceContext.setAddCommunityPermissions(true);
546 serviceContext.setAddGuestPermissions(true);
547 serviceContext.setScopeGroupId(groupId);
548
549 entry = tagsEntryLocalService.addEntry(
550 user.getUserId(), null, entryName, null,
551 PropsValues.TAGS_PROPERTIES_DEFAULT, serviceContext);
552 }
553
554 if (entry != null) {
555 entries.add(entry);
556 }
557 }
558
559 tagsAssetPersistence.setTagsEntries(asset.getAssetId(), entries);
560
561
564 tagsAssetPersistence.update(asset, false);
565
566
568 if (!sync) {
569 return asset;
570 }
571
572 if (className.equals(BlogsEntry.class.getName())) {
573 BlogsEntry entry = blogsEntryPersistence.findByPrimaryKey(classPK);
574
575 entry.setTitle(title);
576
577 blogsEntryPersistence.update(entry, false);
578 }
579 else if (className.equals(BookmarksEntry.class.getName())) {
580 BookmarksEntry entry = bookmarksEntryPersistence.findByPrimaryKey(
581 classPK);
582
583 entry.setName(title);
584 entry.setComments(description);
585 entry.setUrl(url);
586
587 bookmarksEntryPersistence.update(entry, false);
588 }
589 else if (className.equals(DLFileEntry.class.getName())) {
590 DLFileEntry fileEntry = dlFileEntryPersistence.findByPrimaryKey(
591 classPK);
592
593 fileEntry.setTitle(title);
594 fileEntry.setDescription(description);
595
596 dlFileEntryPersistence.update(fileEntry, false);
597 }
598 else if (className.equals(JournalArticle.class.getName())) {
599 JournalArticle article = journalArticlePersistence.findByPrimaryKey(
600 classPK);
601
602 article.setTitle(title);
603 article.setDescription(description);
604
605 journalArticlePersistence.update(article, false);
606 }
607 else if (className.equals(MBMessage.class.getName())) {
608 MBMessage message = mbMessagePersistence.findByPrimaryKey(classPK);
609
610 message.setSubject(title);
611
612 mbMessagePersistence.update(message, false);
613 }
614 else if (className.equals(WikiPage.class.getName())) {
615 WikiPage page = wikiPagePersistence.findByPrimaryKey(classPK);
616
617 page.setTitle(title);
618
619 wikiPagePersistence.update(page, false);
620 }
621
622 return asset;
623 }
624
625 public TagsAsset updateVisible(
626 String className, long classPK, boolean visible)
627 throws PortalException, SystemException {
628
629 long classNameId = PortalUtil.getClassNameId(className);
630
631 TagsAsset asset = tagsAssetPersistence.findByC_C(classNameId, classPK);
632
633 asset.setVisible(visible);
634
635 tagsAssetPersistence.update(asset, false);
636
637 return asset;
638 }
639
640 public void validate(String className, String[] entryNames)
641 throws PortalException {
642
643 TagsAssetValidator validator = (TagsAssetValidator)InstancePool.get(
644 PropsValues.TAGS_ASSET_VALIDATOR);
645
646 validator.validate(className, entryNames);
647 }
648
649 protected TagsAsset getAsset(Document doc)
650 throws PortalException, SystemException {
651
652 String portletId = GetterUtil.getString(doc.get(Field.PORTLET_ID));
653
654 if (portletId.equals(PortletKeys.BLOGS)) {
655 long entryId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
656
657 long classNameId = PortalUtil.getClassNameId(
658 BlogsEntry.class.getName());
659 long classPK = entryId;
660
661 return tagsAssetPersistence.findByC_C(classNameId, classPK);
662 }
663 else if (portletId.equals(PortletKeys.BOOKMARKS)) {
664 long entryId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
665
666 long classNameId = PortalUtil.getClassNameId(
667 BookmarksEntry.class.getName());
668 long classPK = entryId;
669
670 return tagsAssetPersistence.findByC_C(classNameId, classPK);
671 }
672 else if (portletId.equals(PortletKeys.DOCUMENT_LIBRARY)) {
673 long folderId = GetterUtil.getLong(doc.get("repositoryId"));
674 String name = doc.get("path");
675
676 DLFileEntry fileEntry = dlFileEntryLocalService.getFileEntry(
677 folderId, name);
678
679 long classNameId = PortalUtil.getClassNameId(
680 DLFileEntry.class.getName());
681 long classPK = fileEntry.getFileEntryId();
682
683 return tagsAssetPersistence.findByC_C(classNameId, classPK);
684 }
685 else if (portletId.equals(PortletKeys.IMAGE_GALLERY)) {
686 long imageId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
687
688 long classNameId = PortalUtil.getClassNameId(
689 IGImage.class.getName());
690 long classPK = imageId;
691
692 return tagsAssetPersistence.findByC_C(classNameId, classPK);
693 }
694 else if (portletId.equals(PortletKeys.JOURNAL)) {
695 long groupId = GetterUtil.getLong(doc.get(Field.GROUP_ID));
696 String articleId = doc.get(Field.ENTRY_CLASS_PK);
697
699 long articleResourcePrimKey =
700 journalArticleResourceLocalService.getArticleResourcePrimKey(
701 groupId, articleId);
702
703 long classNameId = PortalUtil.getClassNameId(
704 JournalArticle.class.getName());
705 long classPK = articleResourcePrimKey;
706
707 return tagsAssetPersistence.findByC_C(classNameId, classPK);
708 }
709 else if (portletId.equals(PortletKeys.MESSAGE_BOARDS)) {
710 long messageId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
711
712 long classNameId = PortalUtil.getClassNameId(
713 MBMessage.class.getName());
714 long classPK = messageId;
715
716 return tagsAssetPersistence.findByC_C(classNameId, classPK);
717 }
718 else if (portletId.equals(PortletKeys.WIKI)) {
719 long nodeId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
720 String title = doc.get(Field.TITLE);
721
722 long pageResourcePrimKey =
723 wikiPageResourceLocalService.getPageResourcePrimKey(
724 nodeId, title);
725
726 long classNameId = PortalUtil.getClassNameId(
727 WikiPage.class.getName());
728 long classPK = pageResourcePrimKey;
729
730 return tagsAssetPersistence.findByC_C(classNameId, classPK);
731 }
732
733 return null;
734 }
735
736 protected TagsAssetDisplay[] getAssetDisplays(
737 List<TagsAsset> assets, String languageId)
738 throws SystemException {
739
740 TagsAssetDisplay[] assetDisplays = new TagsAssetDisplay[assets.size()];
741
742 for (int i = 0; i < assets.size(); i++) {
743 TagsAsset asset = assets.get(i);
744
745 String className = PortalUtil.getClassName(asset.getClassNameId());
746 String portletId = PortalUtil.getClassNamePortletId(className);
747 String portletTitle = PortalUtil.getPortletTitle(
748 portletId, languageId);
749
750 List<TagsEntry> tagsEntriesList =
751 tagsAssetPersistence.getTagsEntries(asset.getAssetId());
752
753 String tagsEntries = ListUtil.toString(
754 tagsEntriesList, "name", ", ");
755
756 TagsAssetDisplay assetDisplay = new TagsAssetDisplay();
757
758 assetDisplay.setAssetId(asset.getAssetId());
759 assetDisplay.setCompanyId(asset.getCompanyId());
760 assetDisplay.setUserId(asset.getUserId());
761 assetDisplay.setUserName(asset.getUserName());
762 assetDisplay.setCreateDate(asset.getCreateDate());
763 assetDisplay.setModifiedDate(asset.getModifiedDate());
764 assetDisplay.setClassNameId(asset.getClassNameId());
765 assetDisplay.setClassName(className);
766 assetDisplay.setClassPK(asset.getClassPK());
767 assetDisplay.setPortletId(portletId);
768 assetDisplay.setPortletTitle(portletTitle);
769 assetDisplay.setStartDate(asset.getStartDate());
770 assetDisplay.setEndDate(asset.getEndDate());
771 assetDisplay.setPublishDate(asset.getPublishDate());
772 assetDisplay.setExpirationDate(asset.getExpirationDate());
773 assetDisplay.setMimeType(asset.getMimeType());
774 assetDisplay.setTitle(asset.getTitle());
775 assetDisplay.setDescription(asset.getDescription());
776 assetDisplay.setSummary(asset.getSummary());
777 assetDisplay.setUrl(asset.getUrl());
778 assetDisplay.setHeight(asset.getHeight());
779 assetDisplay.setWidth(asset.getWidth());
780 assetDisplay.setPriority(asset.getPriority());
781 assetDisplay.setViewCount(asset.getViewCount());
782 assetDisplay.setTagsEntries(tagsEntries);
783
784 assetDisplays[i] = assetDisplay;
785 }
786
787 return assetDisplays;
788 }
789
790 protected TagsAssetType getAssetType(String className, String languageId) {
791 long classNameId = PortalUtil.getClassNameId(className);
792
793 String portletId = PortalUtil.getClassNamePortletId(className);
794 String portletTitle = PortalUtil.getPortletTitle(portletId, languageId);
795
796 TagsAssetType assetType = new TagsAssetType();
797
798 assetType.setClassNameId(classNameId);
799 assetType.setClassName(className);
800 assetType.setPortletId(portletId);
801 assetType.setPortletTitle(portletTitle);
802
803 return assetType;
804 }
805
806 private static Log _log = LogFactoryUtil.getLog(
807 TagsAssetLocalServiceImpl.class);
808
809 }