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 String className = PortalUtil.getClassName(entry.getClassNameId());
402
403 Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(className);
404
405 indexer.reindex(className, entry.getClassPK());
406 }
407 }
408
409
413 @Override
414 public Hits search(
415 long companyId, long[] groupIds, long userId, String className,
416 String keywords, int start, int end)
417 throws SystemException {
418
419 return search(
420 companyId, groupIds, userId, className, keywords,
421 WorkflowConstants.STATUS_ANY, start, end);
422 }
423
424 @Override
425 public Hits search(
426 long companyId, long[] groupIds, long userId, String className,
427 String keywords, int status, int start, int end)
428 throws SystemException {
429
430 return search(
431 companyId, groupIds, userId, className, keywords, keywords,
432 keywords, null, null, status, false, start, end);
433 }
434
435
440 @Override
441 public Hits search(
442 long companyId, long[] groupIds, long userId, String className,
443 String userName, String title, String description,
444 String assetCategoryIds, String assetTagNames, boolean andSearch,
445 int start, int end)
446 throws SystemException {
447
448 return search(
449 companyId, groupIds, userId, className, userName, title,
450 description, assetCategoryIds, assetTagNames,
451 WorkflowConstants.STATUS_ANY, andSearch, start, end);
452 }
453
454 @Override
455 public Hits search(
456 long companyId, long[] groupIds, long userId, String className,
457 String userName, String title, String description,
458 String assetCategoryIds, String assetTagNames, int status,
459 boolean andSearch, int start, int end)
460 throws SystemException {
461
462 try {
463 Indexer searcher = AssetSearcher.getInstance();
464
465 AssetSearcher assetSearcher = (AssetSearcher)searcher;
466
467 AssetEntryQuery assetEntryQuery = new AssetEntryQuery();
468
469 assetEntryQuery.setClassNameIds(
470 getClassNameIds(companyId, className));
471
472 SearchContext searchContext = new SearchContext();
473
474 searchContext.setAndSearch(andSearch);
475 searchContext.setAssetCategoryIds(
476 StringUtil.split(assetCategoryIds, 0L));
477 searchContext.setAssetTagNames(StringUtil.split(assetTagNames));
478 searchContext.setAttribute(Field.DESCRIPTION, description);
479 searchContext.setAttribute(Field.TITLE, title);
480 searchContext.setAttribute(Field.USER_NAME, userName);
481 searchContext.setAttribute("paginationType", "regular");
482 searchContext.setAttribute("status", status);
483 searchContext.setCompanyId(companyId);
484 searchContext.setEnd(end);
485 searchContext.setGroupIds(groupIds);
486
487 QueryConfig queryConfig = new QueryConfig();
488
489 queryConfig.setHighlightEnabled(false);
490 queryConfig.setScoreEnabled(false);
491
492 searchContext.setQueryConfig(queryConfig);
493
494 searchContext.setStart(start);
495 searchContext.setUserId(userId);
496
497 assetSearcher.setAssetEntryQuery(assetEntryQuery);
498
499 return assetSearcher.search(searchContext);
500 }
501 catch (Exception e) {
502 throw new SystemException(e);
503 }
504 }
505
506
510 @Override
511 public Hits search(
512 long companyId, long[] groupIds, String className, String keywords,
513 int start, int end)
514 throws SystemException {
515
516 return search(
517 companyId, groupIds, 0, className, keywords,
518 WorkflowConstants.STATUS_ANY, start, end);
519 }
520
521 @Override
522 public AssetEntry updateEntry(
523 long userId, long groupId, Date createDate, Date modifiedDate,
524 String className, long classPK, String classUuid, long classTypeId,
525 long[] categoryIds, String[] tagNames, boolean visible,
526 Date startDate, Date endDate, Date expirationDate, String mimeType,
527 String title, String description, String summary, String url,
528 String layoutUuid, int height, int width, Integer priority,
529 boolean sync)
530 throws PortalException, SystemException {
531
532
533
534 long classNameId = PortalUtil.getClassNameId(className);
535
536 validate(groupId, className, categoryIds, tagNames);
537
538 AssetEntry entry = assetEntryPersistence.fetchByC_C(
539 classNameId, classPK);
540
541 boolean oldVisible = false;
542
543 if (entry != null) {
544 oldVisible = entry.isVisible();
545 }
546
547 if (modifiedDate == null) {
548 modifiedDate = new Date();
549 }
550
551 if (entry == null) {
552 long entryId = counterLocalService.increment();
553
554 entry = assetEntryPersistence.create(entryId);
555
556 Group group = groupLocalService.getGroup(groupId);
557
558 entry.setCompanyId(group.getCompanyId());
559
560 entry.setUserId(userId);
561
562 User user = userPersistence.fetchByPrimaryKey(userId);
563
564 if (user != null) {
565 entry.setUserName(user.getFullName());
566 }
567 else {
568 entry.setUserName(StringPool.BLANK);
569 }
570
571 if (createDate == null) {
572 createDate = new Date();
573 }
574
575 entry.setCreateDate(createDate);
576
577 entry.setModifiedDate(modifiedDate);
578 entry.setClassNameId(classNameId);
579 entry.setClassPK(classPK);
580 entry.setClassUuid(classUuid);
581 entry.setVisible(visible);
582 entry.setExpirationDate(expirationDate);
583
584 if (priority == null) {
585 entry.setPriority(0);
586 }
587
588 entry.setViewCount(0);
589 }
590
591 entry.setGroupId(groupId);
592 entry.setModifiedDate(modifiedDate);
593 entry.setClassTypeId(classTypeId);
594 entry.setVisible(visible);
595 entry.setStartDate(startDate);
596 entry.setEndDate(endDate);
597 entry.setExpirationDate(expirationDate);
598 entry.setMimeType(mimeType);
599 entry.setTitle(title);
600 entry.setDescription(description);
601 entry.setSummary(summary);
602 entry.setUrl(url);
603 entry.setLayoutUuid(layoutUuid);
604 entry.setHeight(height);
605 entry.setWidth(width);
606
607 if (priority != null) {
608 entry.setPriority(priority.intValue());
609 }
610
611
612
613 if (categoryIds != null) {
614 assetEntryPersistence.setAssetCategories(
615 entry.getEntryId(), categoryIds);
616 }
617
618
619
620 if (tagNames != null) {
621 long siteGroupId = PortalUtil.getSiteGroupId(groupId);
622
623 Group siteGroup = groupLocalService.getGroup(siteGroupId);
624
625 List<AssetTag> tags = assetTagLocalService.checkTags(
626 userId, siteGroup, tagNames);
627
628 List<AssetTag> oldTags = assetEntryPersistence.getAssetTags(
629 entry.getEntryId());
630
631 assetEntryPersistence.setAssetTags(entry.getEntryId(), tags);
632
633 if (entry.isVisible()) {
634 boolean isNew = entry.isNew();
635
636 assetEntryPersistence.updateImpl(entry);
637
638 if (isNew) {
639 for (AssetTag tag : tags) {
640 assetTagLocalService.incrementAssetCount(
641 tag.getTagId(), classNameId);
642 }
643 }
644 else {
645 for (AssetTag oldTag : oldTags) {
646 if (!tags.contains(oldTag)) {
647 assetTagLocalService.decrementAssetCount(
648 oldTag.getTagId(), classNameId);
649 }
650 }
651
652 for (AssetTag tag : tags) {
653 if (!oldTags.contains(tag)) {
654 assetTagLocalService.incrementAssetCount(
655 tag.getTagId(), classNameId);
656 }
657 }
658 }
659 }
660 else if (oldVisible) {
661 for (AssetTag oldTag : oldTags) {
662 assetTagLocalService.decrementAssetCount(
663 oldTag.getTagId(), classNameId);
664 }
665 }
666 }
667
668
669
670
671 assetEntryPersistence.update(entry);
672
673
674
675 if (!sync) {
676 return entry;
677 }
678
679 if (className.equals(BlogsEntry.class.getName())) {
680 BlogsEntry blogsEntry = blogsEntryPersistence.findByPrimaryKey(
681 classPK);
682
683 blogsEntry.setTitle(title);
684
685 blogsEntryPersistence.update(blogsEntry);
686 }
687 else if (className.equals(BookmarksEntry.class.getName())) {
688 BookmarksEntry bookmarksEntry =
689 bookmarksEntryPersistence.findByPrimaryKey(classPK);
690
691 bookmarksEntry.setName(title);
692 bookmarksEntry.setDescription(description);
693 bookmarksEntry.setUrl(url);
694
695 bookmarksEntryPersistence.update(bookmarksEntry);
696 }
697 else if (className.equals(DLFileEntry.class.getName())) {
698 DLFileEntry dlFileEntry = dlFileEntryPersistence.findByPrimaryKey(
699 classPK);
700
701 dlFileEntry.setTitle(title);
702 dlFileEntry.setDescription(description);
703
704 dlFileEntryPersistence.update(dlFileEntry);
705 }
706 else if (className.equals(JournalArticle.class.getName())) {
707 JournalArticle journalArticle =
708 journalArticlePersistence.findByPrimaryKey(classPK);
709
710 journalArticle.setTitle(title);
711 journalArticle.setDescription(description);
712
713 journalArticlePersistence.update(journalArticle);
714 }
715 else if (className.equals(MBMessage.class.getName())) {
716 MBMessage mbMessage = mbMessagePersistence.findByPrimaryKey(
717 classPK);
718
719 mbMessage.setSubject(title);
720
721 mbMessagePersistence.update(mbMessage);
722 }
723 else if (className.equals(WikiPage.class.getName())) {
724 WikiPage wikiPage = wikiPagePersistence.findByPrimaryKey(classPK);
725
726 wikiPage.setTitle(title);
727
728 wikiPagePersistence.update(wikiPage);
729 }
730
731 return entry;
732 }
733
734 @Override
735 public AssetEntry updateEntry(
736 long userId, long groupId, String className, long classPK,
737 long[] categoryIds, String[] tagNames)
738 throws PortalException, SystemException {
739
740 long classNameId = PortalUtil.getClassNameId(className);
741
742 AssetEntry entry = assetEntryPersistence.fetchByC_C(
743 classNameId, classPK);
744
745 if (entry != null) {
746 return updateEntry(
747 userId, groupId, entry.getCreateDate(), entry.getModifiedDate(),
748 className, classPK, entry.getClassUuid(),
749 entry.getClassTypeId(), categoryIds, tagNames,
750 entry.isVisible(), entry.getStartDate(), entry.getEndDate(),
751 entry.getExpirationDate(), entry.getMimeType(),
752 entry.getTitle(), entry.getDescription(), entry.getSummary(),
753 entry.getUrl(), entry.getLayoutUuid(), entry.getHeight(),
754 entry.getWidth(), GetterUtil.getInteger(entry.getPriority()),
755 false);
756 }
757
758 return updateEntry(
759 userId, groupId, null, null, className, classPK, null, 0,
760 categoryIds, tagNames, true, null, null, null, null, null, null,
761 null, null, null, 0, 0, null, false);
762 }
763
764
770 @Override
771 public AssetEntry updateEntry(
772 long userId, long groupId, String className, long classPK,
773 String classUuid, long classTypeId, long[] categoryIds,
774 String[] tagNames, boolean visible, Date startDate, Date endDate,
775 Date publishDate, Date expirationDate, String mimeType,
776 String title, String description, String summary, String url,
777 String layoutUuid, int height, int width, Integer priority,
778 boolean sync)
779 throws PortalException, SystemException {
780
781 return updateEntry(
782 userId, groupId, className, classPK, classUuid, classTypeId,
783 categoryIds, tagNames, visible, startDate, endDate, expirationDate,
784 mimeType, title, description, summary, url, layoutUuid, height,
785 width, priority, sync);
786 }
787
788
794 @Override
795 public AssetEntry updateEntry(
796 long userId, long groupId, String className, long classPK,
797 String classUuid, long classTypeId, long[] categoryIds,
798 String[] tagNames, boolean visible, Date startDate, Date endDate,
799 Date expirationDate, String mimeType, String title,
800 String description, String summary, String url, String layoutUuid,
801 int height, int width, Integer priority, boolean sync)
802 throws PortalException, SystemException {
803
804 return updateEntry(
805 userId, groupId, null, null, className, classPK, classUuid,
806 classTypeId, categoryIds, tagNames, visible, startDate, endDate,
807 expirationDate, mimeType, title, description, summary, url,
808 layoutUuid, height, width, priority, sync);
809 }
810
811 @Override
812 public AssetEntry updateEntry(
813 String className, long classPK, Date publishDate, boolean visible)
814 throws PortalException, SystemException {
815
816 long classNameId = PortalUtil.getClassNameId(className);
817
818 AssetEntry entry = assetEntryPersistence.findByC_C(
819 classNameId, classPK);
820
821 entry.setPublishDate(publishDate);
822
823 updateVisible(entry, visible);
824
825 assetEntryPersistence.update(entry);
826
827 return entry;
828 }
829
830 @Override
831 public AssetEntry updateEntry(
832 String className, long classPK, Date publishDate,
833 Date expirationDate, boolean visible)
834 throws PortalException, SystemException {
835
836 long classNameId = PortalUtil.getClassNameId(className);
837
838 AssetEntry entry = assetEntryPersistence.findByC_C(
839 classNameId, classPK);
840
841 entry.setExpirationDate(expirationDate);
842 entry.setPublishDate(publishDate);
843
844 updateVisible(entry, visible);
845
846 assetEntryPersistence.update(entry);
847
848 return entry;
849 }
850
851 @Override
852 public AssetEntry updateVisible(
853 String className, long classPK, boolean visible)
854 throws PortalException, SystemException {
855
856 long classNameId = PortalUtil.getClassNameId(className);
857
858 AssetEntry entry = assetEntryPersistence.findByC_C(
859 classNameId, classPK);
860
861 updateVisible(entry, visible);
862
863 assetEntryPersistence.update(entry);
864
865 return entry;
866 }
867
868 @Override
869 public void validate(
870 long groupId, String className, long[] categoryIds,
871 String[] tagNames)
872 throws PortalException, SystemException {
873
874 if (ExportImportThreadLocal.isImportInProcess()) {
875 return;
876 }
877
878 AssetEntryValidator validator = (AssetEntryValidator)InstancePool.get(
879 PropsValues.ASSET_ENTRY_VALIDATOR);
880
881 validator.validate(groupId, className, categoryIds, tagNames);
882 }
883
884 protected long[] getClassNameIds(long companyId, String className) {
885 if (Validator.isNotNull(className)) {
886 return new long[] {PortalUtil.getClassNameId(className)};
887 }
888
889 List<AssetRendererFactory> rendererFactories =
890 AssetRendererFactoryRegistryUtil.getAssetRendererFactories(
891 companyId);
892
893 long[] classNameIds = new long[rendererFactories.size()];
894
895 for (int i = 0; i < rendererFactories.size(); i++) {
896 AssetRendererFactory rendererFactory = rendererFactories.get(i);
897
898 classNameIds[i] = PortalUtil.getClassNameId(
899 rendererFactory.getClassName());
900 }
901
902 return classNameIds;
903 }
904
905 protected AssetEntry getEntry(Document document)
906 throws PortalException, SystemException {
907
908 String portletId = GetterUtil.getString(document.get(Field.PORTLET_ID));
909
910 if (portletId.equals(PortletKeys.BLOGS)) {
911 long entryId = GetterUtil.getLong(
912 document.get(Field.ENTRY_CLASS_PK));
913
914 long classNameId = PortalUtil.getClassNameId(
915 BlogsEntry.class.getName());
916 long classPK = entryId;
917
918 return assetEntryPersistence.findByC_C(classNameId, classPK);
919 }
920 else if (portletId.equals(PortletKeys.BOOKMARKS)) {
921 long entryId = GetterUtil.getLong(
922 document.get(Field.ENTRY_CLASS_PK));
923
924 long classNameId = PortalUtil.getClassNameId(
925 BookmarksEntry.class.getName());
926 long classPK = entryId;
927
928 return assetEntryPersistence.findByC_C(classNameId, classPK);
929 }
930 else if (portletId.equals(PortletKeys.DOCUMENT_LIBRARY)) {
931 long fileEntryId = GetterUtil.getLong(
932 document.get(Field.ENTRY_CLASS_PK));
933
934 long classNameId = PortalUtil.getClassNameId(
935 DLFileEntry.class.getName());
936 long classPK = fileEntryId;
937
938 return assetEntryPersistence.findByC_C(classNameId, classPK);
939 }
940 else if (portletId.equals(PortletKeys.JOURNAL)) {
941 long groupId = GetterUtil.getLong(document.get(Field.GROUP_ID));
942 String articleId = document.get("articleId");
943
944
945 long articleResourcePrimKey =
946 journalArticleResourceLocalService.getArticleResourcePrimKey(
947 groupId, articleId);
948
949 long classNameId = PortalUtil.getClassNameId(
950 JournalArticle.class.getName());
951 long classPK = articleResourcePrimKey;
952
953 return assetEntryPersistence.findByC_C(classNameId, classPK);
954 }
955 else if (portletId.equals(PortletKeys.MESSAGE_BOARDS)) {
956 long messageId = GetterUtil.getLong(
957 document.get(Field.ENTRY_CLASS_PK));
958
959 long classNameId = PortalUtil.getClassNameId(
960 MBMessage.class.getName());
961 long classPK = messageId;
962
963 return assetEntryPersistence.findByC_C(classNameId, classPK);
964 }
965 else if (portletId.equals(PortletKeys.WIKI)) {
966 long nodeId = GetterUtil.getLong(
967 document.get(Field.ENTRY_CLASS_PK));
968 String title = document.get(Field.TITLE);
969
970 long pageResourcePrimKey =
971 wikiPageResourceLocalService.getPageResourcePrimKey(
972 nodeId, title);
973
974 long classNameId = PortalUtil.getClassNameId(
975 WikiPage.class.getName());
976 long classPK = pageResourcePrimKey;
977
978 return assetEntryPersistence.findByC_C(classNameId, classPK);
979 }
980
981 return null;
982 }
983
984 protected void updateVisible(AssetEntry entry, boolean visible)
985 throws PortalException, SystemException {
986
987 if (visible == entry.isVisible()) {
988 return;
989 }
990
991 List<AssetTag> tags = assetEntryPersistence.getAssetTags(
992 entry.getEntryId());
993
994 if (visible) {
995 for (AssetTag tag : tags) {
996 assetTagLocalService.incrementAssetCount(
997 tag.getTagId(), entry.getClassNameId());
998 }
999
1000 socialActivityCounterLocalService.enableActivityCounters(
1001 entry.getClassNameId(), entry.getClassPK());
1002 }
1003 else {
1004 for (AssetTag tag : tags) {
1005 assetTagLocalService.decrementAssetCount(
1006 tag.getTagId(), entry.getClassNameId());
1007 }
1008
1009 socialActivityCounterLocalService.disableActivityCounters(
1010 entry.getClassNameId(), entry.getClassPK());
1011 }
1012
1013 entry.setVisible(visible);
1014 }
1015
1016 }