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