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