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