001
014
015 package com.liferay.portlet.asset.service.impl;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.kernel.increment.BufferedIncrement;
020 import com.liferay.portal.kernel.increment.NumberIncrement;
021 import com.liferay.portal.kernel.lar.ImportExportThreadLocal;
022 import com.liferay.portal.kernel.search.Document;
023 import com.liferay.portal.kernel.search.FacetedSearcher;
024 import com.liferay.portal.kernel.search.Field;
025 import com.liferay.portal.kernel.search.Hits;
026 import com.liferay.portal.kernel.search.Indexer;
027 import com.liferay.portal.kernel.search.IndexerRegistryUtil;
028 import com.liferay.portal.kernel.search.QueryConfig;
029 import com.liferay.portal.kernel.search.SearchContext;
030 import com.liferay.portal.kernel.search.facet.AssetEntriesFacet;
031 import com.liferay.portal.kernel.search.facet.Facet;
032 import com.liferay.portal.kernel.search.facet.ScopeFacet;
033 import com.liferay.portal.kernel.util.GetterUtil;
034 import com.liferay.portal.kernel.util.InstancePool;
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.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.AssetEntry;
046 import com.liferay.portlet.asset.model.AssetLink;
047 import com.liferay.portlet.asset.model.AssetLinkConstants;
048 import com.liferay.portlet.asset.model.AssetRendererFactory;
049 import com.liferay.portlet.asset.model.AssetTag;
050 import com.liferay.portlet.asset.service.base.AssetEntryLocalServiceBaseImpl;
051 import com.liferay.portlet.asset.service.persistence.AssetEntryQuery;
052 import com.liferay.portlet.asset.util.AssetEntryValidator;
053 import com.liferay.portlet.blogs.model.BlogsEntry;
054 import com.liferay.portlet.bookmarks.model.BookmarksEntry;
055 import com.liferay.portlet.documentlibrary.model.DLFileEntry;
056 import com.liferay.portlet.journal.model.JournalArticle;
057 import com.liferay.portlet.messageboards.model.MBMessage;
058 import com.liferay.portlet.wiki.model.WikiPage;
059
060 import java.io.Serializable;
061
062 import java.util.ArrayList;
063 import java.util.Date;
064 import java.util.HashMap;
065 import java.util.List;
066 import java.util.Map;
067
068
073 public class AssetEntryLocalServiceImpl extends AssetEntryLocalServiceBaseImpl {
074
075 public void deleteEntry(AssetEntry entry)
076 throws PortalException, SystemException {
077
078
079
080 List<AssetTag> tags = assetEntryPersistence.getAssetTags(
081 entry.getEntryId());
082
083 assetEntryPersistence.remove(entry);
084
085
086
087 assetLinkLocalService.deleteLinks(entry.getEntryId());
088
089
090
091 for (AssetTag tag : tags) {
092 if (entry.isVisible()) {
093 assetTagLocalService.decrementAssetCount(
094 tag.getTagId(), entry.getClassNameId());
095 }
096 }
097
098
099
100 socialActivityLocalService.deleteActivities(entry);
101 }
102
103 public void deleteEntry(long entryId)
104 throws PortalException, SystemException {
105
106 AssetEntry entry = assetEntryPersistence.findByPrimaryKey(entryId);
107
108 deleteEntry(entry);
109 }
110
111 public void deleteEntry(String className, long classPK)
112 throws PortalException, SystemException {
113
114 long classNameId = PortalUtil.getClassNameId(className);
115
116 AssetEntry entry = assetEntryPersistence.fetchByC_C(
117 classNameId, classPK);
118
119 if (entry != null) {
120 deleteEntry(entry);
121 }
122 }
123
124 public AssetEntry fetchEntry(long entryId) throws SystemException {
125 return assetEntryPersistence.fetchByPrimaryKey(entryId);
126 }
127
128 public AssetEntry fetchEntry(String className, long classPK)
129 throws SystemException {
130
131 long classNameId = PortalUtil.getClassNameId(className);
132
133 return assetEntryPersistence.fetchByC_C(classNameId, classPK);
134 }
135
136 public List<AssetEntry> getAncestorEntries(long entryId)
137 throws PortalException, SystemException {
138
139 List<AssetEntry> entries = new ArrayList<AssetEntry>();
140
141 AssetEntry parentEntry = getParentEntry(entryId);
142
143 while (parentEntry != null) {
144 entries.add(parentEntry);
145
146 parentEntry = getParentEntry(parentEntry.getEntryId());
147 }
148
149 return entries;
150 }
151
152 public List<AssetEntry> getChildEntries(long entryId)
153 throws PortalException, SystemException {
154
155 List<AssetEntry> entries = new ArrayList<AssetEntry>();
156
157 List<AssetLink> links = assetLinkLocalService.getDirectLinks(
158 entryId, AssetLinkConstants.TYPE_CHILD);
159
160 for (AssetLink link : links) {
161 AssetEntry curAsset = getEntry(link.getEntryId2());
162
163 entries.add(curAsset);
164 }
165
166 return entries;
167 }
168
169 public List<AssetEntry> getCompanyEntries(
170 long companyId, int start, int end)
171 throws SystemException {
172
173 return assetEntryPersistence.findByCompanyId(companyId, start, end);
174 }
175
176 public int getCompanyEntriesCount(long companyId) throws SystemException {
177 return assetEntryPersistence.countByCompanyId(companyId);
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.getDirectLinks(
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.getDirectLinks(
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 @BufferedIncrement(incrementClass = NumberIncrement.class)
320 public AssetEntry incrementViewCounter(
321 long userId, String className, long classPK, int increment)
322 throws SystemException {
323
324 if (!PropsValues.ASSET_ENTRY_INCREMENT_VIEW_COUNTER_ENABLED) {
325 return null;
326 }
327
328 if (classPK <= 0) {
329 return null;
330 }
331
332 long classNameId = PortalUtil.getClassNameId(className);
333
334 AssetEntry entry = assetEntryPersistence.fetchByC_C(
335 classNameId, classPK);
336
337 if (entry == null) {
338 return null;
339 }
340
341 entry.setViewCount(entry.getViewCount() + increment);
342
343 assetEntryPersistence.update(entry, false);
344
345 return entry;
346 }
347
348 public void reindex(List<AssetEntry> entries) throws PortalException {
349 for (AssetEntry entry : entries) {
350 String className = PortalUtil.getClassName(entry.getClassNameId());
351
352 Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(className);
353
354 indexer.reindex(className, entry.getClassPK());
355 }
356 }
357
358 public Hits search(
359 long companyId, long[] groupIds, long userId, String className,
360 String keywords, int start, int end)
361 throws SystemException {
362
363 try {
364 SearchContext searchContext = new SearchContext();
365
366 Facet assetEntriesFacet = new AssetEntriesFacet(searchContext);
367
368 assetEntriesFacet.setStatic(true);
369
370 searchContext.addFacet(assetEntriesFacet);
371
372 Facet scopeFacet = new ScopeFacet(searchContext);
373
374 scopeFacet.setStatic(true);
375
376 searchContext.addFacet(scopeFacet);
377
378 searchContext.setAttribute("paginationType", "regular");
379 searchContext.setCompanyId(companyId);
380 searchContext.setEnd(end);
381 searchContext.setEntryClassNames(getClassNames(className));
382 searchContext.setGroupIds(groupIds);
383 searchContext.setKeywords(keywords);
384
385 QueryConfig queryConfig = new QueryConfig();
386
387 queryConfig.setHighlightEnabled(false);
388 queryConfig.setScoreEnabled(false);
389
390 searchContext.setQueryConfig(queryConfig);
391
392 searchContext.setStart(start);
393 searchContext.setUserId(userId);
394
395 Indexer indexer = FacetedSearcher.getInstance();
396
397 return indexer.search(searchContext);
398 }
399 catch (Exception e) {
400 throw new SystemException(e);
401 }
402 }
403
404 public Hits search(
405 long companyId, long[] groupIds, long userId, String className,
406 String userName, String title, String description,
407 String assetCategoryIds, String assetTagNames, boolean andSearch,
408 int start, int end)
409 throws SystemException {
410
411 try {
412 Map<String, Serializable> attributes =
413 new HashMap<String, Serializable>();
414
415 attributes.put(Field.DESCRIPTION, description);
416 attributes.put(Field.TITLE, title);
417 attributes.put(Field.USER_NAME, userName);
418 attributes.put("paginationType", "regular");
419
420 SearchContext searchContext = new SearchContext();
421
422 Facet assetEntriesFacet = new AssetEntriesFacet(searchContext);
423
424 assetEntriesFacet.setStatic(true);
425
426 searchContext.addFacet(assetEntriesFacet);
427
428 Facet scopeFacet = new ScopeFacet(searchContext);
429
430 scopeFacet.setStatic(true);
431
432 searchContext.addFacet(scopeFacet);
433
434 searchContext.setAndSearch(andSearch);
435 searchContext.setAssetCategoryIds(
436 StringUtil.split(assetCategoryIds, 0L));
437 searchContext.setAssetTagNames(StringUtil.split(assetTagNames));
438 searchContext.setAttributes(attributes);
439 searchContext.setCompanyId(companyId);
440 searchContext.setEnd(end);
441 searchContext.setEntryClassNames(getClassNames(className));
442 searchContext.setGroupIds(groupIds);
443
444 QueryConfig queryConfig = new QueryConfig();
445
446 queryConfig.setHighlightEnabled(false);
447 queryConfig.setScoreEnabled(false);
448
449 searchContext.setQueryConfig(queryConfig);
450
451 searchContext.setStart(start);
452 searchContext.setUserId(userId);
453
454 Indexer indexer = FacetedSearcher.getInstance();
455
456 return indexer.search(searchContext);
457 }
458 catch (Exception e) {
459 throw new SystemException(e);
460 }
461 }
462
463 public Hits search(
464 long companyId, long[] groupIds, String className, String keywords,
465 int start, int end)
466 throws SystemException {
467
468 return search(companyId, groupIds, 0, className, keywords, start, end);
469 }
470
471 public AssetEntry updateEntry(
472 long userId, long groupId, String className, long classPK,
473 long[] categoryIds, String[] tagNames)
474 throws PortalException, SystemException {
475
476 long classNameId = PortalUtil.getClassNameId(className);
477
478 AssetEntry entry = assetEntryPersistence.fetchByC_C(
479 classNameId, classPK);
480
481 if (entry != null) {
482 return updateEntry(
483 userId, groupId, className, classPK, entry.getClassUuid(),
484 entry.getClassTypeId(), categoryIds, tagNames,
485 entry.isVisible(), entry.getStartDate(), entry.getEndDate(),
486 entry.getPublishDate(), entry.getExpirationDate(),
487 entry.getMimeType(), entry.getTitle(), entry.getDescription(),
488 entry.getSummary(), entry.getUrl(), entry.getLayoutUuid(),
489 entry.getHeight(), entry.getWidth(),
490 GetterUtil.getInteger(entry.getPriority()), false);
491 }
492
493 return updateEntry(
494 userId, groupId, className, classPK, null, 0, categoryIds, tagNames,
495 true, null, null, null, null, null, null, null, null, null, null, 0,
496 0, null, false);
497 }
498
499 public AssetEntry updateEntry(
500 long userId, long groupId, String className, long classPK,
501 String classUuid, long classTypeId, long[] categoryIds,
502 String[] tagNames, boolean visible, Date startDate, Date endDate,
503 Date publishDate, Date expirationDate, String mimeType,
504 String title, String description, String summary, String url,
505 String layoutUuid, int height, int width, Integer priority,
506 boolean sync)
507 throws PortalException, SystemException {
508
509
510
511 User user = userPersistence.findByPrimaryKey(userId);
512 long classNameId = PortalUtil.getClassNameId(className);
513 Date now = new Date();
514
515 validate(groupId, className, categoryIds, tagNames);
516
517 AssetEntry entry = assetEntryPersistence.fetchByC_C(
518 classNameId, classPK);
519
520 boolean oldVisible = false;
521
522 if (entry != null) {
523 oldVisible = entry.isVisible();
524 }
525
526 if (entry == null) {
527 long entryId = counterLocalService.increment();
528
529 entry = assetEntryPersistence.create(entryId);
530
531 entry.setCompanyId(user.getCompanyId());
532 entry.setUserId(user.getUserId());
533 entry.setUserName(user.getFullName());
534 entry.setCreateDate(now);
535 entry.setClassNameId(classNameId);
536 entry.setClassPK(classPK);
537 entry.setClassUuid(classUuid);
538 entry.setVisible(visible);
539 entry.setPublishDate(publishDate);
540 entry.setExpirationDate(expirationDate);
541
542 if (priority == null) {
543 entry.setPriority(0);
544 }
545
546 entry.setViewCount(0);
547 }
548
549 entry.setGroupId(groupId);
550 entry.setModifiedDate(now);
551 entry.setClassTypeId(classTypeId);
552 entry.setVisible(visible);
553 entry.setStartDate(startDate);
554 entry.setEndDate(endDate);
555 entry.setPublishDate(publishDate);
556 entry.setExpirationDate(expirationDate);
557 entry.setMimeType(mimeType);
558 entry.setTitle(title);
559 entry.setDescription(description);
560 entry.setSummary(summary);
561 entry.setUrl(url);
562 entry.setLayoutUuid(layoutUuid);
563 entry.setHeight(height);
564 entry.setWidth(width);
565
566 if (priority != null) {
567 entry.setPriority(priority.intValue());
568 }
569
570
571
572 if (categoryIds != null) {
573 assetEntryPersistence.setAssetCategories(
574 entry.getEntryId(), categoryIds);
575 }
576
577
578
579 if (tagNames != null) {
580 long parentGroupId = PortalUtil.getParentGroupId(groupId);
581
582 List<AssetTag> tags = new ArrayList<AssetTag>(tagNames.length);
583
584 for (String tagName : tagNames) {
585 AssetTag tag = null;
586
587 try {
588 tag = assetTagLocalService.getTag(parentGroupId, tagName);
589 }
590 catch (NoSuchTagException nste) {
591 ServiceContext serviceContext = new ServiceContext();
592
593 serviceContext.setAddGroupPermissions(true);
594 serviceContext.setAddGuestPermissions(true);
595 serviceContext.setScopeGroupId(parentGroupId);
596
597 tag = assetTagLocalService.addTag(
598 user.getUserId(), tagName,
599 PropsValues.ASSET_TAG_PROPERTIES_DEFAULT,
600 serviceContext);
601 }
602
603 if (tag != null) {
604 tags.add(tag);
605 }
606 }
607
608 List<AssetTag> oldTags = assetEntryPersistence.getAssetTags(
609 entry.getEntryId());
610
611 assetEntryPersistence.setAssetTags(entry.getEntryId(), tags);
612
613 if (entry.isVisible()) {
614 boolean isNew = entry.isNew();
615
616 assetEntryPersistence.updateImpl(entry, false);
617
618 if (isNew) {
619 for (AssetTag tag : tags) {
620 assetTagLocalService.incrementAssetCount(
621 tag.getTagId(), classNameId);
622 }
623 }
624 else {
625 for (AssetTag oldTag : oldTags) {
626 if (!tags.contains(oldTag)) {
627 assetTagLocalService.decrementAssetCount(
628 oldTag.getTagId(), classNameId);
629 }
630 }
631
632 for (AssetTag tag : tags) {
633 if (!oldTags.contains(tag)) {
634 assetTagLocalService.incrementAssetCount(
635 tag.getTagId(), classNameId);
636 }
637 }
638 }
639 }
640 else if (oldVisible) {
641 for (AssetTag oldTag : oldTags) {
642 assetTagLocalService.decrementAssetCount(
643 oldTag.getTagId(), classNameId);
644 }
645 }
646 }
647
648
649
650
651 assetEntryPersistence.update(entry, false);
652
653
654
655 if (!sync) {
656 return entry;
657 }
658
659 if (className.equals(BlogsEntry.class.getName())) {
660 BlogsEntry blogsEntry = blogsEntryPersistence.findByPrimaryKey(
661 classPK);
662
663 blogsEntry.setTitle(title);
664
665 blogsEntryPersistence.update(blogsEntry, false);
666 }
667 else if (className.equals(BookmarksEntry.class.getName())) {
668 BookmarksEntry bookmarksEntry =
669 bookmarksEntryPersistence.findByPrimaryKey(classPK);
670
671 bookmarksEntry.setName(title);
672 bookmarksEntry.setDescription(description);
673 bookmarksEntry.setUrl(url);
674
675 bookmarksEntryPersistence.update(bookmarksEntry, false);
676 }
677 else if (className.equals(DLFileEntry.class.getName())) {
678 DLFileEntry dlFileEntry = dlFileEntryPersistence.findByPrimaryKey(
679 classPK);
680
681 dlFileEntry.setTitle(title);
682 dlFileEntry.setDescription(description);
683
684 dlFileEntryPersistence.update(dlFileEntry, false);
685 }
686 else if (className.equals(JournalArticle.class.getName())) {
687 JournalArticle journalArticle =
688 journalArticlePersistence.findByPrimaryKey(classPK);
689
690 journalArticle.setTitle(title);
691 journalArticle.setDescription(description);
692
693 journalArticlePersistence.update(journalArticle, false);
694 }
695 else if (className.equals(MBMessage.class.getName())) {
696 MBMessage mbMessage = mbMessagePersistence.findByPrimaryKey(
697 classPK);
698
699 mbMessage.setSubject(title);
700
701 mbMessagePersistence.update(mbMessage, false);
702 }
703 else if (className.equals(WikiPage.class.getName())) {
704 WikiPage wikiPage = wikiPagePersistence.findByPrimaryKey(classPK);
705
706 wikiPage.setTitle(title);
707
708 wikiPagePersistence.update(wikiPage, false);
709 }
710
711 return entry;
712 }
713
714 public AssetEntry updateEntry(
715 String className, long classPK, Date publishDate,
716 Date expirationDate, boolean visible)
717 throws PortalException, SystemException {
718
719 long classNameId = PortalUtil.getClassNameId(className);
720
721 AssetEntry entry = assetEntryPersistence.findByC_C(
722 classNameId, classPK);
723
724 entry.setExpirationDate(expirationDate);
725 entry.setPublishDate(publishDate);
726
727 updateVisible(entry, visible);
728
729 assetEntryPersistence.update(entry, false);
730
731 return entry;
732 }
733
734 public AssetEntry updateVisible(
735 String className, long classPK, boolean visible)
736 throws PortalException, SystemException {
737
738 long classNameId = PortalUtil.getClassNameId(className);
739
740 AssetEntry entry = assetEntryPersistence.findByC_C(
741 classNameId, classPK);
742
743 List<AssetTag> tags = assetEntryPersistence.getAssetTags(
744 entry.getEntryId());
745
746 if (visible && !entry.isVisible()) {
747 for (AssetTag tag : tags) {
748 assetTagLocalService.incrementAssetCount(
749 tag.getTagId(), classNameId);
750 }
751 }
752 else if (!visible && entry.isVisible()) {
753 for (AssetTag tag : tags) {
754 assetTagLocalService.decrementAssetCount(
755 tag.getTagId(), classNameId);
756 }
757 }
758
759 entry.setVisible(visible);
760
761 assetEntryPersistence.update(entry, false);
762
763 return entry;
764 }
765
766 public void validate(
767 long groupId, String className, long[] categoryIds,
768 String[] tagNames)
769 throws PortalException, SystemException {
770
771 if (ImportExportThreadLocal.isImportInProcess()) {
772 return;
773 }
774
775 AssetEntryValidator validator = (AssetEntryValidator)InstancePool.get(
776 PropsValues.ASSET_ENTRY_VALIDATOR);
777
778 validator.validate(groupId, className, categoryIds, tagNames);
779 }
780
781 protected String[] getClassNames(String className) {
782 if (Validator.isNotNull(className)) {
783 return new String[] {className};
784 }
785 else {
786 List<AssetRendererFactory> rendererFactories =
787 AssetRendererFactoryRegistryUtil.getAssetRendererFactories();
788
789 String[] classNames = new String[rendererFactories.size()];
790
791 for (int i = 0; i < rendererFactories.size(); i++) {
792 AssetRendererFactory rendererFactory = rendererFactories.get(i);
793
794 classNames[i] = rendererFactory.getClassName();
795 }
796
797 return classNames;
798 }
799 }
800
801 protected AssetEntry getEntry(Document document)
802 throws PortalException, SystemException {
803
804 String portletId = GetterUtil.getString(document.get(Field.PORTLET_ID));
805
806 if (portletId.equals(PortletKeys.BLOGS)) {
807 long entryId = GetterUtil.getLong(
808 document.get(Field.ENTRY_CLASS_PK));
809
810 long classNameId = PortalUtil.getClassNameId(
811 BlogsEntry.class.getName());
812 long classPK = entryId;
813
814 return assetEntryPersistence.findByC_C(classNameId, classPK);
815 }
816 else if (portletId.equals(PortletKeys.BOOKMARKS)) {
817 long entryId = GetterUtil.getLong(
818 document.get(Field.ENTRY_CLASS_PK));
819
820 long classNameId = PortalUtil.getClassNameId(
821 BookmarksEntry.class.getName());
822 long classPK = entryId;
823
824 return assetEntryPersistence.findByC_C(classNameId, classPK);
825 }
826 else if (portletId.equals(PortletKeys.DOCUMENT_LIBRARY)) {
827 long fileEntryId = GetterUtil.getLong(
828 document.get(Field.ENTRY_CLASS_PK));
829
830 long classNameId = PortalUtil.getClassNameId(
831 DLFileEntry.class.getName());
832 long classPK = fileEntryId;
833
834 return assetEntryPersistence.findByC_C(classNameId, classPK);
835 }
836 else if (portletId.equals(PortletKeys.JOURNAL)) {
837 long groupId = GetterUtil.getLong(document.get(Field.GROUP_ID));
838 String articleId = document.get("articleId");
839
840
841 long articleResourcePrimKey =
842 journalArticleResourceLocalService.getArticleResourcePrimKey(
843 groupId, articleId);
844
845 long classNameId = PortalUtil.getClassNameId(
846 JournalArticle.class.getName());
847 long classPK = articleResourcePrimKey;
848
849 return assetEntryPersistence.findByC_C(classNameId, classPK);
850 }
851 else if (portletId.equals(PortletKeys.MESSAGE_BOARDS)) {
852 long messageId = GetterUtil.getLong(
853 document.get(Field.ENTRY_CLASS_PK));
854
855 long classNameId = PortalUtil.getClassNameId(
856 MBMessage.class.getName());
857 long classPK = messageId;
858
859 return assetEntryPersistence.findByC_C(classNameId, classPK);
860 }
861 else if (portletId.equals(PortletKeys.WIKI)) {
862 long nodeId = GetterUtil.getLong(
863 document.get(Field.ENTRY_CLASS_PK));
864 String title = document.get(Field.TITLE);
865
866 long pageResourcePrimKey =
867 wikiPageResourceLocalService.getPageResourcePrimKey(
868 nodeId, title);
869
870 long classNameId = PortalUtil.getClassNameId(
871 WikiPage.class.getName());
872 long classPK = pageResourcePrimKey;
873
874 return assetEntryPersistence.findByC_C(classNameId, classPK);
875 }
876
877 return null;
878 }
879
880 protected void updateVisible(AssetEntry entry, boolean visible)
881 throws PortalException, SystemException {
882
883 if (visible == entry.isVisible()) {
884 return;
885 }
886
887 List<AssetTag> tags = assetEntryPersistence.getAssetTags(
888 entry.getEntryId());
889
890 if (visible) {
891 for (AssetTag tag : tags) {
892 assetTagLocalService.incrementAssetCount(
893 tag.getTagId(), entry.getClassNameId());
894 }
895 }
896 else {
897 for (AssetTag tag : tags) {
898 assetTagLocalService.decrementAssetCount(
899 tag.getTagId(), entry.getClassNameId());
900 }
901 }
902
903 entry.setVisible(visible);
904 }
905
906 }