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