001
014
015 package com.liferay.portlet.asset.service.impl;
016
017 import com.liferay.portal.NoSuchGroupException;
018 import com.liferay.portal.kernel.dao.orm.QueryUtil;
019 import com.liferay.portal.kernel.exception.PortalException;
020 import com.liferay.portal.kernel.exception.SystemException;
021 import com.liferay.portal.kernel.increment.BufferedIncrement;
022 import com.liferay.portal.kernel.increment.NumberIncrement;
023 import com.liferay.portal.kernel.log.Log;
024 import com.liferay.portal.kernel.log.LogFactoryUtil;
025 import com.liferay.portal.kernel.search.Document;
026 import com.liferay.portal.kernel.search.Field;
027 import com.liferay.portal.kernel.search.Hits;
028 import com.liferay.portal.kernel.search.Indexer;
029 import com.liferay.portal.kernel.search.IndexerRegistryUtil;
030 import com.liferay.portal.kernel.search.SearchContext;
031 import com.liferay.portal.kernel.util.GetterUtil;
032 import com.liferay.portal.kernel.util.InstancePool;
033 import com.liferay.portal.kernel.util.ListUtil;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.kernel.util.Validator;
037 import com.liferay.portal.model.User;
038 import com.liferay.portal.security.permission.ActionKeys;
039 import com.liferay.portal.service.ServiceContext;
040 import com.liferay.portal.util.PortalUtil;
041 import com.liferay.portal.util.PortletKeys;
042 import com.liferay.portal.util.PropsValues;
043 import com.liferay.portlet.asset.AssetRendererFactoryRegistryUtil;
044 import com.liferay.portlet.asset.NoSuchEntryException;
045 import com.liferay.portlet.asset.NoSuchTagException;
046 import com.liferay.portlet.asset.model.AssetCategory;
047 import com.liferay.portlet.asset.model.AssetEntry;
048 import com.liferay.portlet.asset.model.AssetEntryDisplay;
049 import com.liferay.portlet.asset.model.AssetLink;
050 import com.liferay.portlet.asset.model.AssetLinkConstants;
051 import com.liferay.portlet.asset.model.AssetRendererFactory;
052 import com.liferay.portlet.asset.model.AssetTag;
053 import com.liferay.portlet.asset.service.base.AssetEntryLocalServiceBaseImpl;
054 import com.liferay.portlet.asset.service.persistence.AssetEntryQuery;
055 import com.liferay.portlet.asset.util.AssetEntryValidator;
056 import com.liferay.portlet.blogs.model.BlogsEntry;
057 import com.liferay.portlet.bookmarks.model.BookmarksEntry;
058 import com.liferay.portlet.documentlibrary.model.DLFileEntry;
059 import com.liferay.portlet.documentlibrary.model.DLFolder;
060 import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
061 import com.liferay.portlet.imagegallery.model.IGImage;
062 import com.liferay.portlet.journal.model.JournalArticle;
063 import com.liferay.portlet.messageboards.model.MBMessage;
064 import com.liferay.portlet.wiki.model.WikiPage;
065
066 import java.io.Serializable;
067
068 import java.util.ArrayList;
069 import java.util.Date;
070 import java.util.HashMap;
071 import java.util.List;
072 import java.util.Map;
073
074
079 public class AssetEntryLocalServiceImpl extends AssetEntryLocalServiceBaseImpl {
080
081 public void deleteEntry(AssetEntry entry)
082 throws PortalException, SystemException {
083
084
085
086 List<AssetTag> tags = assetEntryPersistence.getAssetTags(
087 entry.getEntryId());
088
089 assetEntryPersistence.remove(entry);
090
091
092
093 assetLinkLocalService.deleteLinks(entry.getEntryId());
094
095
096
097 for (AssetTag tag : tags) {
098 assetTagLocalService.decrementAssetCount(
099 tag.getTagId(), entry.getClassNameId());
100 }
101
102
103
104 socialEquityLogLocalService.deactivateEquityLogs(entry.getEntryId());
105 }
106
107 public void deleteEntry(long entryId)
108 throws PortalException, SystemException {
109
110 AssetEntry entry = assetEntryPersistence.findByPrimaryKey(entryId);
111
112 deleteEntry(entry);
113 }
114
115 public void deleteEntry(String className, long classPK)
116 throws PortalException, SystemException {
117
118 long classNameId = PortalUtil.getClassNameId(className);
119
120 AssetEntry entry = assetEntryPersistence.fetchByC_C(
121 classNameId, classPK);
122
123 if (entry != null) {
124 deleteEntry(entry);
125 }
126 }
127
128 public List<AssetEntry> getAncestorEntries(long entryId)
129 throws PortalException, SystemException {
130
131 List<AssetEntry> entries = new ArrayList<AssetEntry>();
132
133 AssetEntry parentEntry = getParentEntry(entryId);
134
135 while (parentEntry != null) {
136 entries.add(parentEntry);
137
138 parentEntry = getParentEntry(parentEntry.getEntryId());
139 }
140
141 return entries;
142 }
143
144 public List<AssetEntry> getChildEntries(long entryId)
145 throws PortalException, SystemException {
146
147 List<AssetEntry> entries = new ArrayList<AssetEntry>();
148
149 List<AssetLink> links = assetLinkLocalService.getLinks(
150 entryId, AssetLinkConstants.TYPE_CHILD);
151
152 for (AssetLink link : links) {
153 AssetEntry curAsset = getEntry(link.getEntryId2());
154
155 entries.add(curAsset);
156 }
157
158 return entries;
159 }
160
161 public List<AssetEntry> getCompanyEntries(
162 long companyId, int start, int end)
163 throws SystemException {
164
165 return assetEntryPersistence.findByCompanyId(companyId, start, end);
166 }
167
168 public int getCompanyEntriesCount(long companyId) throws SystemException {
169 return assetEntryPersistence.countByCompanyId(companyId);
170 }
171
172 public AssetEntryDisplay[] getCompanyEntryDisplays(
173 long companyId, int start, int end, String languageId)
174 throws SystemException {
175
176 return getEntryDisplays(
177 getCompanyEntries(companyId, start, end), languageId);
178 }
179
180 public List<AssetEntry> getEntries(AssetEntryQuery entryQuery)
181 throws SystemException {
182
183 return assetEntryFinder.findEntries(entryQuery);
184 }
185
186 public int getEntriesCount(AssetEntryQuery entryQuery)
187 throws SystemException {
188
189 return assetEntryFinder.countEntries(entryQuery);
190 }
191
192 public AssetEntry getEntry(long entryId)
193 throws PortalException, SystemException {
194
195 return assetEntryPersistence.findByPrimaryKey(entryId);
196 }
197
198 public AssetEntry getEntry(long groupId, String classUuid)
199 throws PortalException, SystemException {
200
201 return assetEntryPersistence.findByG_CU(groupId, classUuid);
202 }
203
204 public AssetEntry getEntry(String className, long classPK)
205 throws PortalException, SystemException {
206
207 long classNameId = PortalUtil.getClassNameId(className);
208
209 return assetEntryPersistence.findByC_C(classNameId, classPK);
210 }
211
212 public AssetEntry getNextEntry(long entryId)
213 throws PortalException, SystemException {
214
215 try {
216 getParentEntry(entryId);
217 }
218 catch (NoSuchEntryException nsee) {
219 List<AssetEntry> childEntries = getChildEntries(entryId);
220
221 if (childEntries.isEmpty()) {
222 throw new NoSuchEntryException();
223 }
224
225 return childEntries.get(0);
226 }
227
228 List<AssetLink> links = assetLinkLocalService.getLinks(
229 entryId, AssetLinkConstants.TYPE_CHILD);
230
231 for (int i = 0; i < links.size(); i++) {
232 AssetLink link = links.get(i);
233
234 if (link.getEntryId2() == entryId) {
235 if ((i + 1) >= links.size()) {
236 throw new NoSuchEntryException();
237 }
238 else {
239 AssetLink nextLink = links.get(i + 1);
240
241 return getEntry(nextLink.getEntryId2());
242 }
243 }
244 }
245
246 throw new NoSuchEntryException();
247 }
248
249 public AssetEntry getParentEntry(long entryId)
250 throws PortalException, SystemException {
251
252 List<AssetLink> links = assetLinkLocalService.getReverseLinks(
253 entryId, AssetLinkConstants.TYPE_CHILD);
254
255 if (links.isEmpty()) {
256 throw new NoSuchEntryException();
257 }
258
259 AssetLink link = links.get(0);
260
261 return getEntry(link.getEntryId1());
262 }
263
264 public AssetEntry getPreviousEntry(long entryId)
265 throws PortalException, SystemException {
266
267 getParentEntry(entryId);
268
269 List<AssetLink> links = assetLinkLocalService.getLinks(
270 entryId, AssetLinkConstants.TYPE_CHILD);
271
272 for (int i = 0; i < links.size(); i++) {
273 AssetLink link = links.get(i);
274
275 if (link.getEntryId2() == entryId) {
276 if (i == 0) {
277 throw new NoSuchEntryException();
278 }
279 else {
280 AssetLink nextAssetLink = links.get(i - 1);
281
282 return getEntry(nextAssetLink.getEntryId2());
283 }
284 }
285 }
286
287 throw new NoSuchEntryException();
288 }
289
290 public List<AssetEntry> getTopViewedEntries(
291 String className, boolean asc, int start, int end)
292 throws SystemException {
293
294 return getTopViewedEntries(new String[] {className}, asc, start, end);
295 }
296
297 public List<AssetEntry> getTopViewedEntries(
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 AssetEntryQuery entryQuery = new AssetEntryQuery();
308
309 entryQuery.setClassNameIds(classNameIds);
310 entryQuery.setEnd(end);
311 entryQuery.setExcludeZeroViewCount(true);
312 entryQuery.setOrderByCol1("viewCount");
313 entryQuery.setOrderByType1(asc ? "ASC" : "DESC");
314 entryQuery.setStart(start);
315
316 return assetEntryFinder.findEntries(entryQuery);
317 }
318
319 public void incrementViewCounter(
320 long userId, String className, long classPK)
321 throws PortalException, SystemException {
322
323 assetEntryLocalService.incrementViewCounter(
324 userId, className, classPK, 1);
325 }
326
327 @BufferedIncrement(incrementClass = NumberIncrement.class)
328 public void incrementViewCounter(
329 long userId, String className, long classPK, int increment)
330 throws PortalException, SystemException {
331
332 if (!PropsValues.ASSET_ENTRY_INCREMENT_VIEW_COUNTER_ENABLED) {
333 return;
334 }
335
336 if (classPK <= 0) {
337 return;
338 }
339
340 long classNameId = PortalUtil.getClassNameId(className);
341
342 AssetEntry entry = assetEntryPersistence.fetchByC_C(
343 classNameId, classPK);
344
345 if (entry != null) {
346 entry.setViewCount(entry.getViewCount() + increment);
347
348 assetEntryPersistence.update(entry, false);
349
350
351
352 if ((userId > 0) && (entry.getUserId() != userId)) {
353 socialEquityLogLocalService.addEquityLogs(
354 userId, entry.getEntryId(), ActionKeys.VIEW);
355 }
356 }
357 }
358
359 public Hits search(
360 long companyId, String portletId, String keywords, int start,
361 int end)
362 throws SystemException {
363
364 try {
365 SearchContext searchContext = new SearchContext();
366
367 searchContext.setCompanyId(companyId);
368 searchContext.setEnd(end);
369 searchContext.setKeywords(keywords);
370 searchContext.setPortletIds(getPortletIds(portletId));
371 searchContext.setStart(start);
372
373 Indexer indexer = IndexerRegistryUtil.getIndexer(AssetEntry.class);
374
375 return indexer.search(searchContext);
376 }
377 catch (Exception e) {
378 throw new SystemException(e);
379 }
380 }
381
382 public Hits search(
383 long companyId, long[] groupIds, String portletId, String userName,
384 String title, String description, String assetCategoryIds,
385 String assetTagNames, boolean andSearch, int start, int end)
386 throws SystemException {
387
388 try {
389 Map<String, Serializable> attributes =
390 new HashMap<String, Serializable>();
391
392 attributes.put(Field.DESCRIPTION, description);
393 attributes.put(Field.TITLE, title);
394 attributes.put(Field.USER_NAME, userName);
395
396 SearchContext searchContext = new SearchContext();
397
398 searchContext.setAndSearch(andSearch);
399 searchContext.setAttributes(attributes);
400 searchContext.setCompanyId(companyId);
401 searchContext.setEnd(end);
402 searchContext.setGroupIds(groupIds);
403 searchContext.setPortletIds(getPortletIds(portletId));
404 searchContext.setStart(start);
405
406 Indexer indexer = IndexerRegistryUtil.getIndexer(AssetEntry.class);
407
408 return indexer.search(searchContext);
409 }
410 catch (Exception e) {
411 throw new SystemException(e);
412 }
413 }
414
415 public AssetEntryDisplay[] searchEntryDisplays(
416 long companyId, String portletId, String keywords,
417 String languageId, int start, int end)
418 throws SystemException {
419
420 List<AssetEntry> entries = new ArrayList<AssetEntry>();
421
422 Hits hits = search(companyId, portletId, keywords, start, end);
423
424 List<Document> hitsList = hits.toList();
425
426 for (Document doc : hitsList) {
427 try {
428 AssetEntry entry = getEntry(doc);
429
430 if (entry != null) {
431 entries.add(entry);
432 }
433 }
434 catch (Exception e) {
435 if (_log.isWarnEnabled()) {
436 _log.warn(e);
437 }
438 }
439 }
440
441 return getEntryDisplays(entries, languageId);
442 }
443
444 public int searchEntryDisplaysCount(
445 long companyId, String portletId, String keywords,
446 String languageId)
447 throws SystemException {
448
449 Hits hits = search(
450 companyId, portletId, keywords, QueryUtil.ALL_POS,
451 QueryUtil.ALL_POS);
452
453 return hits.getLength();
454 }
455
456 public AssetEntry updateEntry(
457 long userId, long groupId, String className, long classPK,
458 long[] categoryIds, String[] tagNames)
459 throws PortalException, SystemException {
460
461 return updateEntry(
462 userId, groupId, className, classPK, null, categoryIds, tagNames,
463 true, null, null, null, null, null, null, null, null, null, 0, 0,
464 null, false);
465 }
466
467 public AssetEntry updateEntry(
468 long userId, long groupId, String className, long classPK,
469 String classUuid, long[] categoryIds, String[] tagNames,
470 boolean visible, Date startDate, Date endDate, Date publishDate,
471 Date expirationDate, String mimeType, String title,
472 String description, String summary, String url, int height,
473 int width, Integer priority, boolean sync)
474 throws PortalException, SystemException {
475
476
477
478 User user = userPersistence.findByPrimaryKey(userId);
479 long classNameId = PortalUtil.getClassNameId(className);
480
481 title = StringUtil.shorten(title, 300, StringPool.BLANK);
482 Date now = new Date();
483
484 validate(className, categoryIds, tagNames);
485
486 AssetEntry entry = assetEntryPersistence.fetchByC_C(
487 classNameId, classPK);
488
489 if (entry == null) {
490 long entryId = counterLocalService.increment();
491
492 entry = assetEntryPersistence.create(entryId);
493
494 entry.setCompanyId(user.getCompanyId());
495 entry.setUserId(user.getUserId());
496 entry.setUserName(user.getFullName());
497 entry.setCreateDate(now);
498 entry.setClassNameId(classNameId);
499 entry.setClassPK(classPK);
500 entry.setClassUuid(classUuid);
501 entry.setVisible(visible);
502 entry.setPublishDate(publishDate);
503 entry.setExpirationDate(expirationDate);
504
505 if (priority == null) {
506 entry.setPriority(0);
507 }
508
509 entry.setViewCount(0);
510 }
511
512 entry.setGroupId(groupId);
513 entry.setModifiedDate(now);
514 entry.setVisible(visible);
515 entry.setStartDate(startDate);
516 entry.setEndDate(endDate);
517 entry.setPublishDate(publishDate);
518 entry.setExpirationDate(expirationDate);
519 entry.setMimeType(mimeType);
520 entry.setTitle(title);
521 entry.setDescription(description);
522 entry.setSummary(summary);
523 entry.setUrl(url);
524 entry.setHeight(height);
525 entry.setWidth(width);
526
527 if (priority != null) {
528 entry.setPriority(priority.intValue());
529 }
530
531
532
533 if (categoryIds != null) {
534 assetEntryPersistence.setAssetCategories(
535 entry.getEntryId(), categoryIds);
536 }
537
538
539
540 if (tagNames != null) {
541 long parentGroupId = PortalUtil.getParentGroupId(groupId);
542
543 List<AssetTag> tags = new ArrayList<AssetTag>(tagNames.length);
544
545 for (String tagName : tagNames) {
546 AssetTag tag = null;
547
548 try {
549 tag = assetTagLocalService.getTag(parentGroupId, tagName);
550 }
551 catch (NoSuchTagException nste) {
552 ServiceContext serviceContext = new ServiceContext();
553
554 serviceContext.setAddCommunityPermissions(true);
555 serviceContext.setAddGuestPermissions(true);
556 serviceContext.setScopeGroupId(parentGroupId);
557
558 tag = assetTagLocalService.addTag(
559 user.getUserId(), tagName,
560 PropsValues.ASSET_TAG_PROPERTIES_DEFAULT,
561 serviceContext);
562 }
563
564 if (tag != null) {
565 tags.add(tag);
566 }
567 }
568
569 List<AssetTag> oldTags = assetEntryPersistence.getAssetTags(
570 entry.getEntryId());
571
572 assetEntryPersistence.setAssetTags(entry.getEntryId(), tags);
573
574 if (entry.isNew()) {
575 for (AssetTag tag : tags) {
576 assetTagLocalService.incrementAssetCount(
577 tag.getTagId(), classNameId);
578 }
579 }
580 else {
581 for (AssetTag oldTag : oldTags) {
582 if (!tags.contains(oldTag)) {
583 assetTagLocalService.decrementAssetCount(
584 oldTag.getTagId(), classNameId);
585 }
586 }
587
588 for (AssetTag tag : tags) {
589 if (!oldTags.contains(tag)) {
590 assetTagLocalService.incrementAssetCount(
591 tag.getTagId(), classNameId);
592 }
593 }
594 }
595 }
596
597
598
599
600 assetEntryPersistence.update(entry, false);
601
602
603
604 if (!sync) {
605 return entry;
606 }
607
608 if (className.equals(BlogsEntry.class.getName())) {
609 BlogsEntry blogsEntry = blogsEntryPersistence.findByPrimaryKey(
610 classPK);
611
612 blogsEntry.setTitle(title);
613
614 blogsEntryPersistence.update(blogsEntry, false);
615 }
616 else if (className.equals(BookmarksEntry.class.getName())) {
617 BookmarksEntry bookmarksEntry =
618 bookmarksEntryPersistence.findByPrimaryKey(classPK);
619
620 bookmarksEntry.setName(title);
621 bookmarksEntry.setComments(description);
622 bookmarksEntry.setUrl(url);
623
624 bookmarksEntryPersistence.update(bookmarksEntry, false);
625 }
626 else if (className.equals(DLFileEntry.class.getName())) {
627 DLFileEntry dlFileEntry = dlFileEntryPersistence.findByPrimaryKey(
628 classPK);
629
630 dlFileEntry.setTitle(title);
631 dlFileEntry.setDescription(description);
632
633 dlFileEntryPersistence.update(dlFileEntry, false);
634 }
635 else if (className.equals(JournalArticle.class.getName())) {
636 JournalArticle journalArticle =
637 journalArticlePersistence.findByPrimaryKey(classPK);
638
639 journalArticle.setTitle(title);
640 journalArticle.setDescription(description);
641
642 journalArticlePersistence.update(journalArticle, false);
643 }
644 else if (className.equals(MBMessage.class.getName())) {
645 MBMessage mbMessage = mbMessagePersistence.findByPrimaryKey(
646 classPK);
647
648 mbMessage.setSubject(title);
649
650 mbMessagePersistence.update(mbMessage, false);
651 }
652 else if (className.equals(WikiPage.class.getName())) {
653 WikiPage wikiPage = wikiPagePersistence.findByPrimaryKey(classPK);
654
655 wikiPage.setTitle(title);
656
657 wikiPagePersistence.update(wikiPage, false);
658 }
659
660 return entry;
661 }
662
663 public AssetEntry updateVisible(
664 String className, long classPK, boolean visible)
665 throws PortalException, SystemException {
666
667 long classNameId = PortalUtil.getClassNameId(className);
668
669 AssetEntry entry = assetEntryPersistence.findByC_C(
670 classNameId, classPK);
671
672 entry.setVisible(visible);
673
674 assetEntryPersistence.update(entry, false);
675
676 return entry;
677 }
678
679 public void validate(
680 String className, long[] categoryIds, String[] tagNames)
681 throws PortalException {
682
683 AssetEntryValidator validator = (AssetEntryValidator)InstancePool.get(
684 PropsValues.ASSET_ENTRY_VALIDATOR);
685
686 validator.validate(className, categoryIds, tagNames);
687 }
688
689 protected AssetEntry getEntry(Document doc)
690 throws PortalException, SystemException {
691
692 String portletId = GetterUtil.getString(doc.get(Field.PORTLET_ID));
693
694 if (portletId.equals(PortletKeys.BLOGS)) {
695 long entryId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
696
697 long classNameId = PortalUtil.getClassNameId(
698 BlogsEntry.class.getName());
699 long classPK = entryId;
700
701 return assetEntryPersistence.findByC_C(classNameId, classPK);
702 }
703 else if (portletId.equals(PortletKeys.BOOKMARKS)) {
704 long entryId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
705
706 long classNameId = PortalUtil.getClassNameId(
707 BookmarksEntry.class.getName());
708 long classPK = entryId;
709
710 return assetEntryPersistence.findByC_C(classNameId, classPK);
711 }
712 else if (portletId.equals(PortletKeys.DOCUMENT_LIBRARY)) {
713 long repositoryId = GetterUtil.getLong(doc.get("repositoryId"));
714 String name = doc.get("path");
715
716 long groupId = 0;
717 long folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
718
719 try {
720 groupPersistence.findByPrimaryKey(repositoryId);
721
722 groupId = repositoryId;
723 }
724 catch (NoSuchGroupException nsge) {
725 DLFolder folder = dlFolderPersistence.findByPrimaryKey(
726 repositoryId);
727
728 groupId = folder.getGroupId();
729 folderId = folder.getFolderId();
730 }
731
732 DLFileEntry fileEntry = dlFileEntryLocalService.getFileEntry(
733 groupId, folderId, name);
734
735 long classNameId = PortalUtil.getClassNameId(
736 DLFileEntry.class.getName());
737 long classPK = fileEntry.getFileEntryId();
738
739 return assetEntryPersistence.findByC_C(classNameId, classPK);
740 }
741 else if (portletId.equals(PortletKeys.IMAGE_GALLERY)) {
742 long imageId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
743
744 long classNameId = PortalUtil.getClassNameId(
745 IGImage.class.getName());
746 long classPK = imageId;
747
748 return assetEntryPersistence.findByC_C(classNameId, classPK);
749 }
750 else if (portletId.equals(PortletKeys.JOURNAL)) {
751 long groupId = GetterUtil.getLong(doc.get(Field.GROUP_ID));
752 String articleId = doc.get(Field.ENTRY_CLASS_PK);
753
754
755 long articleResourcePrimKey =
756 journalArticleResourceLocalService.getArticleResourcePrimKey(
757 groupId, articleId);
758
759 long classNameId = PortalUtil.getClassNameId(
760 JournalArticle.class.getName());
761 long classPK = articleResourcePrimKey;
762
763 return assetEntryPersistence.findByC_C(classNameId, classPK);
764 }
765 else if (portletId.equals(PortletKeys.MESSAGE_BOARDS)) {
766 long messageId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
767
768 long classNameId = PortalUtil.getClassNameId(
769 MBMessage.class.getName());
770 long classPK = messageId;
771
772 return assetEntryPersistence.findByC_C(classNameId, classPK);
773 }
774 else if (portletId.equals(PortletKeys.WIKI)) {
775 long nodeId = GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
776 String title = doc.get(Field.TITLE);
777
778 long pageResourcePrimKey =
779 wikiPageResourceLocalService.getPageResourcePrimKey(
780 nodeId, title);
781
782 long classNameId = PortalUtil.getClassNameId(
783 WikiPage.class.getName());
784 long classPK = pageResourcePrimKey;
785
786 return assetEntryPersistence.findByC_C(classNameId, classPK);
787 }
788
789 return null;
790 }
791
792 protected AssetEntryDisplay[] getEntryDisplays(
793 List<AssetEntry> entries, String languageId)
794 throws SystemException {
795
796 AssetEntryDisplay[] entryDisplays =
797 new AssetEntryDisplay[entries.size()];
798
799 for (int i = 0; i < entries.size(); i++) {
800 AssetEntry entry = entries.get(i);
801
802 String className = PortalUtil.getClassName(entry.getClassNameId());
803 String portletId = PortalUtil.getClassNamePortletId(className);
804 String portletTitle = PortalUtil.getPortletTitle(
805 portletId, languageId);
806
807 List<AssetCategory> categories =
808 assetEntryPersistence.getAssetCategories(entry.getEntryId());
809
810 String categoryIdsString = ListUtil.toString(
811 categories, "assetCategoryId", StringPool.COMMA);
812 long[] categoryIds = StringUtil.split(
813 categoryIdsString, StringPool.COMMA, 0L);
814
815 List<AssetTag> tags = assetEntryPersistence.getAssetTags(
816 entry.getEntryId());
817
818 String tagNames = ListUtil.toString(tags, "name", ", ");
819
820 AssetEntryDisplay entryDisplay = new AssetEntryDisplay();
821
822 entryDisplay.setEntryId(entry.getEntryId());
823 entryDisplay.setCompanyId(entry.getCompanyId());
824 entryDisplay.setUserId(entry.getUserId());
825 entryDisplay.setUserName(entry.getUserName());
826 entryDisplay.setCreateDate(entry.getCreateDate());
827 entryDisplay.setModifiedDate(entry.getModifiedDate());
828 entryDisplay.setClassNameId(entry.getClassNameId());
829 entryDisplay.setClassName(className);
830 entryDisplay.setClassPK(entry.getClassPK());
831 entryDisplay.setPortletId(portletId);
832 entryDisplay.setPortletTitle(portletTitle);
833 entryDisplay.setStartDate(entry.getStartDate());
834 entryDisplay.setEndDate(entry.getEndDate());
835 entryDisplay.setPublishDate(entry.getPublishDate());
836 entryDisplay.setExpirationDate(entry.getExpirationDate());
837 entryDisplay.setMimeType(entry.getMimeType());
838 entryDisplay.setTitle(entry.getTitle());
839 entryDisplay.setDescription(entry.getDescription());
840 entryDisplay.setSummary(entry.getSummary());
841 entryDisplay.setUrl(entry.getUrl());
842 entryDisplay.setHeight(entry.getHeight());
843 entryDisplay.setWidth(entry.getWidth());
844 entryDisplay.setPriority(entry.getPriority());
845 entryDisplay.setViewCount(entry.getViewCount());
846 entryDisplay.setCategoryIds(categoryIds);
847 entryDisplay.setTagNames(tagNames);
848
849 entryDisplays[i] = entryDisplay;
850 }
851
852 return entryDisplays;
853 }
854
855 private String[] getPortletIds(String portletId) {
856 if (Validator.isNotNull(portletId)) {
857 return new String[] {portletId};
858 }
859 else {
860 List<AssetRendererFactory> rendererFactories =
861 AssetRendererFactoryRegistryUtil.getAssetRendererFactories();
862
863 String[] portletIds = new String[rendererFactories.size()];
864
865 for (int i = 0; i < rendererFactories.size(); i++) {
866 AssetRendererFactory rendererFactory = rendererFactories.get(i);
867
868 portletIds[i] = rendererFactory.getPortletId();
869 }
870
871 return portletIds;
872 }
873 }
874
875 private static Log _log = LogFactoryUtil.getLog(
876 AssetEntryLocalServiceImpl.class);
877
878 }