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.ExportImportThreadLocal;
022 import com.liferay.portal.kernel.search.Document;
023 import com.liferay.portal.kernel.search.Field;
024 import com.liferay.portal.kernel.search.Hits;
025 import com.liferay.portal.kernel.search.Indexer;
026 import com.liferay.portal.kernel.search.IndexerRegistryUtil;
027 import com.liferay.portal.kernel.search.QueryConfig;
028 import com.liferay.portal.kernel.search.SearchContext;
029 import com.liferay.portal.kernel.util.GetterUtil;
030 import com.liferay.portal.kernel.util.InstancePool;
031 import com.liferay.portal.kernel.util.StringPool;
032 import com.liferay.portal.kernel.util.StringUtil;
033 import com.liferay.portal.kernel.util.Validator;
034 import com.liferay.portal.kernel.workflow.WorkflowConstants;
035 import com.liferay.portal.model.Group;
036 import com.liferay.portal.model.SystemEventConstants;
037 import com.liferay.portal.model.User;
038 import com.liferay.portal.util.PortalUtil;
039 import com.liferay.portal.util.PortletKeys;
040 import com.liferay.portal.util.PropsValues;
041 import com.liferay.portlet.asset.AssetRendererFactoryRegistryUtil;
042 import com.liferay.portlet.asset.NoSuchEntryException;
043 import com.liferay.portlet.asset.model.AssetEntry;
044 import com.liferay.portlet.asset.model.AssetLink;
045 import com.liferay.portlet.asset.model.AssetLinkConstants;
046 import com.liferay.portlet.asset.model.AssetRendererFactory;
047 import com.liferay.portlet.asset.model.AssetTag;
048 import com.liferay.portlet.asset.service.base.AssetEntryLocalServiceBaseImpl;
049 import com.liferay.portlet.asset.service.persistence.AssetEntryQuery;
050 import com.liferay.portlet.asset.util.AssetEntryValidator;
051 import com.liferay.portlet.assetpublisher.util.AssetSearcher;
052 import com.liferay.portlet.blogs.model.BlogsEntry;
053 import com.liferay.portlet.bookmarks.model.BookmarksEntry;
054 import com.liferay.portlet.documentlibrary.model.DLFileEntry;
055 import com.liferay.portlet.journal.model.JournalArticle;
056 import com.liferay.portlet.messageboards.model.MBMessage;
057 import com.liferay.portlet.social.model.SocialActivityConstants;
058 import com.liferay.portlet.wiki.model.WikiPage;
059
060 import java.util.ArrayList;
061 import java.util.Date;
062 import java.util.List;
063
064
072 public class AssetEntryLocalServiceImpl extends AssetEntryLocalServiceBaseImpl {
073
074 @Override
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 systemEventLocalService.addSystemEvent(
088 0, entry.getGroupId(), entry.getClassName(), entry.getClassPK(),
089 entry.getClassUuid(), null, SystemEventConstants.TYPE_DELETE, null);
090
091
092
093 assetLinkLocalService.deleteLinks(entry.getEntryId());
094
095
096
097 for (AssetTag tag : tags) {
098 if (entry.isVisible()) {
099 assetTagLocalService.decrementAssetCount(
100 tag.getTagId(), entry.getClassNameId());
101 }
102 }
103
104
105
106 socialActivityLocalService.deleteActivities(entry);
107 }
108
109 @Override
110 public void deleteEntry(long entryId)
111 throws PortalException, SystemException {
112
113 AssetEntry entry = assetEntryPersistence.findByPrimaryKey(entryId);
114
115 deleteEntry(entry);
116 }
117
118 @Override
119 public void deleteEntry(String className, long classPK)
120 throws PortalException, SystemException {
121
122 long classNameId = PortalUtil.getClassNameId(className);
123
124 AssetEntry entry = assetEntryPersistence.fetchByC_C(
125 classNameId, classPK);
126
127 if (entry != null) {
128 deleteEntry(entry);
129 }
130 }
131
132 @Override
133 public AssetEntry fetchEntry(long entryId) throws SystemException {
134 return assetEntryPersistence.fetchByPrimaryKey(entryId);
135 }
136
137 @Override
138 public AssetEntry fetchEntry(long groupId, String classUuid)
139 throws SystemException {
140
141 return assetEntryPersistence.fetchByG_CU(groupId, classUuid);
142 }
143
144 @Override
145 public AssetEntry fetchEntry(String className, long classPK)
146 throws SystemException {
147
148 long classNameId = PortalUtil.getClassNameId(className);
149
150 return assetEntryPersistence.fetchByC_C(classNameId, classPK);
151 }
152
153 @Override
154 public List<AssetEntry> getAncestorEntries(long entryId)
155 throws PortalException, SystemException {
156
157 List<AssetEntry> entries = new ArrayList<AssetEntry>();
158
159 AssetEntry parentEntry = getParentEntry(entryId);
160
161 while (parentEntry != null) {
162 entries.add(parentEntry);
163
164 parentEntry = getParentEntry(parentEntry.getEntryId());
165 }
166
167 return entries;
168 }
169
170 @Override
171 public List<AssetEntry> getChildEntries(long entryId)
172 throws PortalException, SystemException {
173
174 List<AssetEntry> entries = new ArrayList<AssetEntry>();
175
176 List<AssetLink> links = assetLinkLocalService.getDirectLinks(
177 entryId, AssetLinkConstants.TYPE_CHILD);
178
179 for (AssetLink link : links) {
180 AssetEntry curAsset = getEntry(link.getEntryId2());
181
182 entries.add(curAsset);
183 }
184
185 return entries;
186 }
187
188 @Override
189 public List<AssetEntry> getCompanyEntries(
190 long companyId, int start, int end)
191 throws SystemException {
192
193 return assetEntryPersistence.findByCompanyId(companyId, start, end);
194 }
195
196 @Override
197 public int getCompanyEntriesCount(long companyId) throws SystemException {
198 return assetEntryPersistence.countByCompanyId(companyId);
199 }
200
201 @Override
202 public List<AssetEntry> getEntries(AssetEntryQuery entryQuery)
203 throws SystemException {
204
205 return assetEntryFinder.findEntries(entryQuery);
206 }
207
208 @Override
209 public int getEntriesCount(AssetEntryQuery entryQuery)
210 throws SystemException {
211
212 return assetEntryFinder.countEntries(entryQuery);
213 }
214
215 @Override
216 public AssetEntry getEntry(long entryId)
217 throws PortalException, SystemException {
218
219 return assetEntryPersistence.findByPrimaryKey(entryId);
220 }
221
222 @Override
223 public AssetEntry getEntry(long groupId, String classUuid)
224 throws PortalException, SystemException {
225
226 return assetEntryPersistence.findByG_CU(groupId, classUuid);
227 }
228
229 @Override
230 public AssetEntry getEntry(String className, long classPK)
231 throws PortalException, SystemException {
232
233 long classNameId = PortalUtil.getClassNameId(className);
234
235 return assetEntryPersistence.findByC_C(classNameId, classPK);
236 }
237
238 @Override
239 public AssetEntry getNextEntry(long entryId)
240 throws PortalException, SystemException {
241
242 try {
243 getParentEntry(entryId);
244 }
245 catch (NoSuchEntryException nsee) {
246 List<AssetEntry> childEntries = getChildEntries(entryId);
247
248 if (childEntries.isEmpty()) {
249 throw new NoSuchEntryException("{entryId=" + entryId + "}");
250 }
251
252 return childEntries.get(0);
253 }
254
255 List<AssetLink> links = assetLinkLocalService.getDirectLinks(
256 entryId, AssetLinkConstants.TYPE_CHILD);
257
258 for (int i = 0; i < links.size(); i++) {
259 AssetLink link = links.get(i);
260
261 if (link.getEntryId2() == entryId) {
262 if ((i + 1) >= links.size()) {
263 throw new NoSuchEntryException("{entryId=" + entryId + "}");
264 }
265 else {
266 AssetLink nextLink = links.get(i + 1);
267
268 return getEntry(nextLink.getEntryId2());
269 }
270 }
271 }
272
273 throw new NoSuchEntryException("{entryId=" + entryId + "}");
274 }
275
276 @Override
277 public AssetEntry getParentEntry(long entryId)
278 throws PortalException, SystemException {
279
280 List<AssetLink> links = assetLinkLocalService.getReverseLinks(
281 entryId, AssetLinkConstants.TYPE_CHILD);
282
283 if (links.isEmpty()) {
284 throw new NoSuchEntryException("{entryId=" + entryId + "}");
285 }
286
287 AssetLink link = links.get(0);
288
289 return getEntry(link.getEntryId1());
290 }
291
292 @Override
293 public AssetEntry getPreviousEntry(long entryId)
294 throws PortalException, SystemException {
295
296 getParentEntry(entryId);
297
298 List<AssetLink> links = assetLinkLocalService.getDirectLinks(
299 entryId, AssetLinkConstants.TYPE_CHILD);
300
301 for (int i = 0; i < links.size(); i++) {
302 AssetLink link = links.get(i);
303
304 if (link.getEntryId2() == entryId) {
305 if (i == 0) {
306 throw new NoSuchEntryException("{entryId=" + entryId + "}");
307 }
308 else {
309 AssetLink nextAssetLink = links.get(i - 1);
310
311 return getEntry(nextAssetLink.getEntryId2());
312 }
313 }
314 }
315
316 throw new NoSuchEntryException("{entryId=" + entryId + "}");
317 }
318
319 @Override
320 public List<AssetEntry> getTopViewedEntries(
321 String className, boolean asc, int start, int end)
322 throws SystemException {
323
324 return getTopViewedEntries(new String[] {className}, asc, start, end);
325 }
326
327 @Override
328 public List<AssetEntry> getTopViewedEntries(
329 String[] className, boolean asc, int start, int end)
330 throws SystemException {
331
332 long[] classNameIds = new long[className.length];
333
334 for (int i = 0; i < className.length; i++) {
335 classNameIds[i] = PortalUtil.getClassNameId(className[i]);
336 }
337
338 AssetEntryQuery entryQuery = new AssetEntryQuery();
339
340 entryQuery.setClassNameIds(classNameIds);
341 entryQuery.setEnd(end);
342 entryQuery.setExcludeZeroViewCount(true);
343 entryQuery.setOrderByCol1("viewCount");
344 entryQuery.setOrderByType1(asc ? "ASC" : "DESC");
345 entryQuery.setStart(start);
346
347 return assetEntryFinder.findEntries(entryQuery);
348 }
349
350 @Override
351 public AssetEntry incrementViewCounter(
352 long userId, String className, long classPK)
353 throws PortalException, SystemException {
354
355 User user = userPersistence.findByPrimaryKey(userId);
356
357 assetEntryLocalService.incrementViewCounter(
358 user.getUserId(), className, classPK, 1);
359
360 AssetEntry assetEntry = getEntry(className, classPK);
361
362 if (!user.isDefaultUser()) {
363 socialActivityLocalService.addActivity(
364 user.getUserId(), assetEntry.getGroupId(), className, classPK,
365 SocialActivityConstants.TYPE_VIEW, StringPool.BLANK, 0);
366 }
367
368 return assetEntry;
369 }
370
371 @BufferedIncrement(
372 configuration = "AssetEntry", incrementClass = NumberIncrement.class)
373 @Override
374 public AssetEntry incrementViewCounter(
375 long userId, String className, long classPK, int increment)
376 throws SystemException {
377
378 if (ExportImportThreadLocal.isImportInProcess() || (classPK <= 0)) {
379 return null;
380 }
381
382 long classNameId = PortalUtil.getClassNameId(className);
383
384 AssetEntry entry = assetEntryPersistence.fetchByC_C(
385 classNameId, classPK);
386
387 if (entry == null) {
388 return null;
389 }
390
391 entry.setViewCount(entry.getViewCount() + increment);
392
393 assetEntryPersistence.update(entry);
394
395 return entry;
396 }
397
398 @Override
399 public void reindex(List<AssetEntry> entries) throws PortalException {
400 for (AssetEntry entry : entries) {
401 reindex(entry);
402 }
403 }
404
405
409 @Override
410 public Hits search(
411 long companyId, long[] groupIds, long userId, String className,
412 String keywords, int start, int end)
413 throws SystemException {
414
415 return search(
416 companyId, groupIds, userId, className, keywords,
417 WorkflowConstants.STATUS_ANY, start, end);
418 }
419
420 @Override
421 public Hits search(
422 long companyId, long[] groupIds, long userId, String className,
423 String keywords, int status, int start, int end)
424 throws SystemException {
425
426 return search(
427 companyId, groupIds, userId, className, keywords, keywords,
428 keywords, null, null, status, false, start, end);
429 }
430
431
436 @Override
437 public Hits search(
438 long companyId, long[] groupIds, long userId, String className,
439 String userName, String title, String description,
440 String assetCategoryIds, String assetTagNames, boolean andSearch,
441 int start, int end)
442 throws SystemException {
443
444 return search(
445 companyId, groupIds, userId, className, userName, title,
446 description, assetCategoryIds, assetTagNames,
447 WorkflowConstants.STATUS_ANY, andSearch, start, end);
448 }
449
450 @Override
451 public Hits search(
452 long companyId, long[] groupIds, long userId, String className,
453 String userName, String title, String description,
454 String assetCategoryIds, String assetTagNames, int status,
455 boolean andSearch, int start, int end)
456 throws SystemException {
457
458 try {
459 Indexer searcher = AssetSearcher.getInstance();
460
461 AssetSearcher assetSearcher = (AssetSearcher)searcher;
462
463 AssetEntryQuery assetEntryQuery = new AssetEntryQuery();
464
465 assetEntryQuery.setClassNameIds(
466 getClassNameIds(companyId, className));
467
468 SearchContext searchContext = new SearchContext();
469
470 searchContext.setAndSearch(andSearch);
471 searchContext.setAssetCategoryIds(
472 StringUtil.split(assetCategoryIds, 0L));
473 searchContext.setAssetTagNames(StringUtil.split(assetTagNames));
474 searchContext.setAttribute(Field.DESCRIPTION, description);
475 searchContext.setAttribute(Field.TITLE, title);
476 searchContext.setAttribute(Field.USER_NAME, userName);
477 searchContext.setAttribute("paginationType", "regular");
478 searchContext.setAttribute("status", status);
479 searchContext.setCompanyId(companyId);
480 searchContext.setEnd(end);
481 searchContext.setGroupIds(groupIds);
482
483 QueryConfig queryConfig = new QueryConfig();
484
485 queryConfig.setHighlightEnabled(false);
486 queryConfig.setScoreEnabled(false);
487
488 searchContext.setQueryConfig(queryConfig);
489
490 searchContext.setStart(start);
491 searchContext.setUserId(userId);
492
493 assetSearcher.setAssetEntryQuery(assetEntryQuery);
494
495 return assetSearcher.search(searchContext);
496 }
497 catch (Exception e) {
498 throw new SystemException(e);
499 }
500 }
501
502
506 @Override
507 public Hits search(
508 long companyId, long[] groupIds, String className, String keywords,
509 int start, int end)
510 throws SystemException {
511
512 return search(
513 companyId, groupIds, 0, className, keywords,
514 WorkflowConstants.STATUS_ANY, start, end);
515 }
516
517 @Override
518 public AssetEntry updateEntry(
519 long userId, long groupId, Date createDate, Date modifiedDate,
520 String className, long classPK, String classUuid, long classTypeId,
521 long[] categoryIds, String[] tagNames, boolean visible,
522 Date startDate, Date endDate, Date expirationDate, String mimeType,
523 String title, String description, String summary, String url,
524 String layoutUuid, int height, int width, Integer priority,
525 boolean sync)
526 throws PortalException, SystemException {
527
528
529
530 long classNameId = PortalUtil.getClassNameId(className);
531
532 validate(groupId, className, categoryIds, tagNames);
533
534 AssetEntry entry = assetEntryPersistence.fetchByC_C(
535 classNameId, classPK);
536
537 boolean oldVisible = false;
538
539 if (entry != null) {
540 oldVisible = entry.isVisible();
541 }
542
543 if (modifiedDate == null) {
544 modifiedDate = new Date();
545 }
546
547 if (entry == null) {
548 long entryId = counterLocalService.increment();
549
550 entry = assetEntryPersistence.create(entryId);
551
552 Group group = groupLocalService.getGroup(groupId);
553
554 entry.setCompanyId(group.getCompanyId());
555
556 entry.setUserId(userId);
557
558 User user = userPersistence.fetchByPrimaryKey(userId);
559
560 if (user != null) {
561 entry.setUserName(user.getFullName());
562 }
563 else {
564 entry.setUserName(StringPool.BLANK);
565 }
566
567 if (createDate == null) {
568 createDate = new Date();
569 }
570
571 entry.setCreateDate(createDate);
572
573 entry.setModifiedDate(modifiedDate);
574 entry.setClassNameId(classNameId);
575 entry.setClassPK(classPK);
576 entry.setClassUuid(classUuid);
577 entry.setVisible(visible);
578 entry.setExpirationDate(expirationDate);
579
580 if (priority == null) {
581 entry.setPriority(0);
582 }
583
584 entry.setViewCount(0);
585 }
586
587 entry.setGroupId(groupId);
588 entry.setModifiedDate(modifiedDate);
589 entry.setClassTypeId(classTypeId);
590 entry.setVisible(visible);
591 entry.setStartDate(startDate);
592 entry.setEndDate(endDate);
593 entry.setExpirationDate(expirationDate);
594 entry.setMimeType(mimeType);
595 entry.setTitle(title);
596 entry.setDescription(description);
597 entry.setSummary(summary);
598 entry.setUrl(url);
599 entry.setLayoutUuid(layoutUuid);
600 entry.setHeight(height);
601 entry.setWidth(width);
602
603 if (priority != null) {
604 entry.setPriority(priority.intValue());
605 }
606
607
608
609 if (categoryIds != null) {
610 assetEntryPersistence.setAssetCategories(
611 entry.getEntryId(), categoryIds);
612 }
613
614
615
616 if (tagNames != null) {
617 long siteGroupId = PortalUtil.getSiteGroupId(groupId);
618
619 Group siteGroup = groupLocalService.getGroup(siteGroupId);
620
621 List<AssetTag> tags = assetTagLocalService.checkTags(
622 userId, siteGroup, tagNames);
623
624 List<AssetTag> oldTags = assetEntryPersistence.getAssetTags(
625 entry.getEntryId());
626
627 assetEntryPersistence.setAssetTags(entry.getEntryId(), tags);
628
629 if (entry.isVisible()) {
630 boolean isNew = entry.isNew();
631
632 assetEntryPersistence.updateImpl(entry);
633
634 if (isNew) {
635 for (AssetTag tag : tags) {
636 assetTagLocalService.incrementAssetCount(
637 tag.getTagId(), classNameId);
638 }
639 }
640 else {
641 for (AssetTag oldTag : oldTags) {
642 if (!tags.contains(oldTag)) {
643 assetTagLocalService.decrementAssetCount(
644 oldTag.getTagId(), classNameId);
645 }
646 }
647
648 for (AssetTag tag : tags) {
649 if (!oldTags.contains(tag)) {
650 assetTagLocalService.incrementAssetCount(
651 tag.getTagId(), classNameId);
652 }
653 }
654 }
655 }
656 else if (oldVisible) {
657 for (AssetTag oldTag : oldTags) {
658 assetTagLocalService.decrementAssetCount(
659 oldTag.getTagId(), classNameId);
660 }
661 }
662 }
663
664
665
666
667 assetEntryPersistence.update(entry);
668
669
670
671 if (sync) {
672 if (className.equals(BlogsEntry.class.getName())) {
673 BlogsEntry blogsEntry = blogsEntryPersistence.findByPrimaryKey(
674 classPK);
675
676 blogsEntry.setTitle(title);
677
678 blogsEntryPersistence.update(blogsEntry);
679 }
680 else if (className.equals(BookmarksEntry.class.getName())) {
681 BookmarksEntry bookmarksEntry =
682 bookmarksEntryPersistence.findByPrimaryKey(classPK);
683
684 bookmarksEntry.setName(title);
685 bookmarksEntry.setDescription(description);
686 bookmarksEntry.setUrl(url);
687
688 bookmarksEntryPersistence.update(bookmarksEntry);
689 }
690 else if (className.equals(DLFileEntry.class.getName())) {
691 DLFileEntry dlFileEntry =
692 dlFileEntryPersistence.findByPrimaryKey(classPK);
693
694 dlFileEntry.setTitle(title);
695 dlFileEntry.setDescription(description);
696
697 dlFileEntryPersistence.update(dlFileEntry);
698 }
699 else if (className.equals(JournalArticle.class.getName())) {
700 JournalArticle journalArticle =
701 journalArticlePersistence.findByPrimaryKey(classPK);
702
703 journalArticle.setTitle(title);
704 journalArticle.setDescription(description);
705
706 journalArticlePersistence.update(journalArticle);
707 }
708 else if (className.equals(MBMessage.class.getName())) {
709 MBMessage mbMessage = mbMessagePersistence.findByPrimaryKey(
710 classPK);
711
712 mbMessage.setSubject(title);
713
714 mbMessagePersistence.update(mbMessage);
715 }
716 else if (className.equals(WikiPage.class.getName())) {
717 WikiPage wikiPage = wikiPagePersistence.findByPrimaryKey(
718 classPK);
719
720 wikiPage.setTitle(title);
721
722 wikiPagePersistence.update(wikiPage);
723 }
724 }
725
726
727
728 reindex(entry);
729
730 return entry;
731 }
732
733 @Override
734 public AssetEntry updateEntry(
735 long userId, long groupId, String className, long classPK,
736 long[] categoryIds, String[] tagNames)
737 throws PortalException, SystemException {
738
739 long classNameId = PortalUtil.getClassNameId(className);
740
741 AssetEntry entry = assetEntryPersistence.fetchByC_C(
742 classNameId, classPK);
743
744 if (entry != null) {
745 return updateEntry(
746 userId, groupId, entry.getCreateDate(), entry.getModifiedDate(),
747 className, classPK, entry.getClassUuid(),
748 entry.getClassTypeId(), categoryIds, tagNames,
749 entry.isVisible(), entry.getStartDate(), entry.getEndDate(),
750 entry.getExpirationDate(), entry.getMimeType(),
751 entry.getTitle(), entry.getDescription(), entry.getSummary(),
752 entry.getUrl(), entry.getLayoutUuid(), entry.getHeight(),
753 entry.getWidth(), GetterUtil.getInteger(entry.getPriority()),
754 false);
755 }
756
757 return updateEntry(
758 userId, groupId, null, null, className, classPK, null, 0,
759 categoryIds, tagNames, true, null, null, null, null, null, null,
760 null, null, null, 0, 0, null, false);
761 }
762
763
769 @Override
770 public AssetEntry updateEntry(
771 long userId, long groupId, String className, long classPK,
772 String classUuid, long classTypeId, long[] categoryIds,
773 String[] tagNames, boolean visible, Date startDate, Date endDate,
774 Date publishDate, Date expirationDate, String mimeType,
775 String title, String description, String summary, String url,
776 String layoutUuid, int height, int width, Integer priority,
777 boolean sync)
778 throws PortalException, SystemException {
779
780 return updateEntry(
781 userId, groupId, className, classPK, classUuid, classTypeId,
782 categoryIds, tagNames, visible, startDate, endDate, expirationDate,
783 mimeType, title, description, summary, url, layoutUuid, height,
784 width, priority, sync);
785 }
786
787
793 @Override
794 public AssetEntry updateEntry(
795 long userId, long groupId, String className, long classPK,
796 String classUuid, long classTypeId, long[] categoryIds,
797 String[] tagNames, boolean visible, Date startDate, Date endDate,
798 Date expirationDate, String mimeType, String title,
799 String description, String summary, String url, String layoutUuid,
800 int height, int width, Integer priority, boolean sync)
801 throws PortalException, SystemException {
802
803 return updateEntry(
804 userId, groupId, null, null, className, classPK, classUuid,
805 classTypeId, categoryIds, tagNames, visible, startDate, endDate,
806 expirationDate, mimeType, title, description, summary, url,
807 layoutUuid, height, width, priority, sync);
808 }
809
810 @Override
811 public AssetEntry updateEntry(
812 String className, long classPK, Date publishDate, boolean visible)
813 throws PortalException, SystemException {
814
815 long classNameId = PortalUtil.getClassNameId(className);
816
817 AssetEntry entry = assetEntryPersistence.findByC_C(
818 classNameId, classPK);
819
820 entry.setPublishDate(publishDate);
821
822 return updateVisible(entry, visible);
823 }
824
825 @Override
826 public AssetEntry updateEntry(
827 String className, long classPK, Date publishDate,
828 Date expirationDate, boolean visible)
829 throws PortalException, SystemException {
830
831 long classNameId = PortalUtil.getClassNameId(className);
832
833 AssetEntry entry = assetEntryPersistence.findByC_C(
834 classNameId, classPK);
835
836 entry.setExpirationDate(expirationDate);
837 entry.setPublishDate(publishDate);
838
839 return updateVisible(entry, visible);
840 }
841
842 @Override
843 public AssetEntry updateVisible(
844 String className, long classPK, boolean visible)
845 throws PortalException, SystemException {
846
847 long classNameId = PortalUtil.getClassNameId(className);
848
849 AssetEntry entry = assetEntryPersistence.findByC_C(
850 classNameId, classPK);
851
852 return updateVisible(entry, visible);
853 }
854
855 @Override
856 public void validate(
857 long groupId, String className, long[] categoryIds,
858 String[] tagNames)
859 throws PortalException, SystemException {
860
861 if (ExportImportThreadLocal.isImportInProcess()) {
862 return;
863 }
864
865 AssetEntryValidator validator = (AssetEntryValidator)InstancePool.get(
866 PropsValues.ASSET_ENTRY_VALIDATOR);
867
868 validator.validate(groupId, className, categoryIds, tagNames);
869 }
870
871 protected long[] getClassNameIds(long companyId, String className) {
872 if (Validator.isNotNull(className)) {
873 return new long[] {PortalUtil.getClassNameId(className)};
874 }
875
876 List<AssetRendererFactory> rendererFactories =
877 AssetRendererFactoryRegistryUtil.getAssetRendererFactories(
878 companyId);
879
880 long[] classNameIds = new long[rendererFactories.size()];
881
882 for (int i = 0; i < rendererFactories.size(); i++) {
883 AssetRendererFactory rendererFactory = rendererFactories.get(i);
884
885 classNameIds[i] = PortalUtil.getClassNameId(
886 rendererFactory.getClassName());
887 }
888
889 return classNameIds;
890 }
891
892 protected AssetEntry getEntry(Document document)
893 throws PortalException, SystemException {
894
895 String portletId = GetterUtil.getString(document.get(Field.PORTLET_ID));
896
897 if (portletId.equals(PortletKeys.BLOGS)) {
898 long entryId = GetterUtil.getLong(
899 document.get(Field.ENTRY_CLASS_PK));
900
901 long classNameId = PortalUtil.getClassNameId(
902 BlogsEntry.class.getName());
903 long classPK = entryId;
904
905 return assetEntryPersistence.findByC_C(classNameId, classPK);
906 }
907 else if (portletId.equals(PortletKeys.BOOKMARKS)) {
908 long entryId = GetterUtil.getLong(
909 document.get(Field.ENTRY_CLASS_PK));
910
911 long classNameId = PortalUtil.getClassNameId(
912 BookmarksEntry.class.getName());
913 long classPK = entryId;
914
915 return assetEntryPersistence.findByC_C(classNameId, classPK);
916 }
917 else if (portletId.equals(PortletKeys.DOCUMENT_LIBRARY)) {
918 long fileEntryId = GetterUtil.getLong(
919 document.get(Field.ENTRY_CLASS_PK));
920
921 long classNameId = PortalUtil.getClassNameId(
922 DLFileEntry.class.getName());
923 long classPK = fileEntryId;
924
925 return assetEntryPersistence.findByC_C(classNameId, classPK);
926 }
927 else if (portletId.equals(PortletKeys.JOURNAL)) {
928 long groupId = GetterUtil.getLong(document.get(Field.GROUP_ID));
929 String articleId = document.get("articleId");
930
931
932 long articleResourcePrimKey =
933 journalArticleResourceLocalService.getArticleResourcePrimKey(
934 groupId, articleId);
935
936 long classNameId = PortalUtil.getClassNameId(
937 JournalArticle.class.getName());
938 long classPK = articleResourcePrimKey;
939
940 return assetEntryPersistence.findByC_C(classNameId, classPK);
941 }
942 else if (portletId.equals(PortletKeys.MESSAGE_BOARDS)) {
943 long messageId = GetterUtil.getLong(
944 document.get(Field.ENTRY_CLASS_PK));
945
946 long classNameId = PortalUtil.getClassNameId(
947 MBMessage.class.getName());
948 long classPK = messageId;
949
950 return assetEntryPersistence.findByC_C(classNameId, classPK);
951 }
952 else if (portletId.equals(PortletKeys.WIKI)) {
953 long nodeId = GetterUtil.getLong(
954 document.get(Field.ENTRY_CLASS_PK));
955 String title = document.get(Field.TITLE);
956
957 long pageResourcePrimKey =
958 wikiPageResourceLocalService.getPageResourcePrimKey(
959 nodeId, title);
960
961 long classNameId = PortalUtil.getClassNameId(
962 WikiPage.class.getName());
963 long classPK = pageResourcePrimKey;
964
965 return assetEntryPersistence.findByC_C(classNameId, classPK);
966 }
967
968 return null;
969 }
970
971 protected void reindex(AssetEntry entry) throws PortalException {
972 String className = PortalUtil.getClassName(entry.getClassNameId());
973
974 Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(className);
975
976 indexer.reindex(className, entry.getClassPK());
977 }
978
979 protected AssetEntry updateVisible(AssetEntry entry, boolean visible)
980 throws PortalException, SystemException {
981
982 if (visible == entry.isVisible()) {
983 return assetEntryPersistence.update(entry);
984 }
985
986 entry.setVisible(visible);
987
988 assetEntryPersistence.update(entry);
989
990 List<AssetTag> tags = assetEntryPersistence.getAssetTags(
991 entry.getEntryId());
992
993 if (visible) {
994 for (AssetTag tag : tags) {
995 assetTagLocalService.incrementAssetCount(
996 tag.getTagId(), entry.getClassNameId());
997 }
998
999 socialActivityCounterLocalService.enableActivityCounters(
1000 entry.getClassNameId(), entry.getClassPK());
1001 }
1002 else {
1003 for (AssetTag tag : tags) {
1004 assetTagLocalService.decrementAssetCount(
1005 tag.getTagId(), entry.getClassNameId());
1006 }
1007
1008 socialActivityCounterLocalService.disableActivityCounters(
1009 entry.getClassNameId(), entry.getClassPK());
1010 }
1011
1012 return entry;
1013 }
1014
1015 }