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