001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.bookmarks.service.impl;
016    
017    import com.liferay.portal.kernel.dao.orm.QueryDefinition;
018    import com.liferay.portal.kernel.exception.PortalException;
019    import com.liferay.portal.kernel.exception.SystemException;
020    import com.liferay.portal.kernel.search.Indexable;
021    import com.liferay.portal.kernel.search.IndexableType;
022    import com.liferay.portal.kernel.search.Indexer;
023    import com.liferay.portal.kernel.search.IndexerRegistryUtil;
024    import com.liferay.portal.kernel.util.ContentTypes;
025    import com.liferay.portal.kernel.util.StringPool;
026    import com.liferay.portal.kernel.util.Validator;
027    import com.liferay.portal.kernel.workflow.WorkflowConstants;
028    import com.liferay.portal.model.ResourceConstants;
029    import com.liferay.portal.model.User;
030    import com.liferay.portal.service.ServiceContext;
031    import com.liferay.portlet.asset.model.AssetEntry;
032    import com.liferay.portlet.asset.model.AssetLinkConstants;
033    import com.liferay.portlet.bookmarks.FolderNameException;
034    import com.liferay.portlet.bookmarks.model.BookmarksEntry;
035    import com.liferay.portlet.bookmarks.model.BookmarksFolder;
036    import com.liferay.portlet.bookmarks.model.BookmarksFolderConstants;
037    import com.liferay.portlet.bookmarks.service.base.BookmarksFolderLocalServiceBaseImpl;
038    import com.liferay.portlet.social.model.SocialActivityConstants;
039    import com.liferay.portlet.trash.model.TrashEntry;
040    
041    import java.util.ArrayList;
042    import java.util.Date;
043    import java.util.List;
044    
045    /**
046     * @author Brian Wing Shun Chan
047     * @author Wesley Gong
048     */
049    public class BookmarksFolderLocalServiceImpl
050            extends BookmarksFolderLocalServiceBaseImpl {
051    
052            public BookmarksFolder addFolder(
053                            long userId, long parentFolderId, String name, String description,
054                            ServiceContext serviceContext)
055                    throws PortalException, SystemException {
056    
057                    // Folder
058    
059                    User user = userPersistence.findByPrimaryKey(userId);
060                    long groupId = serviceContext.getScopeGroupId();
061                    parentFolderId = getParentFolderId(groupId, parentFolderId);
062                    Date now = new Date();
063    
064                    validate(name);
065    
066                    long folderId = counterLocalService.increment();
067    
068                    BookmarksFolder folder = bookmarksFolderPersistence.create(folderId);
069    
070                    folder.setUuid(serviceContext.getUuid());
071                    folder.setGroupId(groupId);
072                    folder.setCompanyId(user.getCompanyId());
073                    folder.setUserId(user.getUserId());
074                    folder.setUserName(user.getFullName());
075                    folder.setCreateDate(serviceContext.getCreateDate(now));
076                    folder.setModifiedDate(serviceContext.getModifiedDate(now));
077                    folder.setParentFolderId(parentFolderId);
078                    folder.setName(name);
079                    folder.setDescription(description);
080                    folder.setExpandoBridgeAttributes(serviceContext);
081    
082                    bookmarksFolderPersistence.update(folder);
083    
084                    // Resources
085    
086                    resourceLocalService.addModelResources(folder, serviceContext);
087    
088                    // Asset
089    
090                    updateAsset(
091                            userId, folder, serviceContext.getAssetCategoryIds(),
092                            serviceContext.getAssetTagNames(),
093                            serviceContext.getAssetLinkEntryIds());
094    
095                    return folder;
096            }
097    
098            @Indexable(type = IndexableType.DELETE)
099            public BookmarksFolder deleteFolder(BookmarksFolder folder)
100                    throws PortalException, SystemException {
101    
102                    return deleteFolder(folder, true);
103            }
104    
105            @Indexable(type = IndexableType.DELETE)
106            public BookmarksFolder deleteFolder(
107                            BookmarksFolder folder, boolean includeTrashedEntries)
108                    throws PortalException, SystemException {
109    
110                    // Folders
111    
112                    List<BookmarksFolder> folders = bookmarksFolderPersistence.findByG_P_S(
113                            folder.getGroupId(), folder.getFolderId(),
114                            WorkflowConstants.STATUS_ANY);
115    
116                    for (BookmarksFolder curFolder : folders) {
117                            if (includeTrashedEntries || !curFolder.isInTrash()) {
118                                    deleteFolder(curFolder);
119                            }
120                    }
121    
122                    // Folder
123    
124                    bookmarksFolderPersistence.remove(folder);
125    
126                    // Resources
127    
128                    resourceLocalService.deleteResource(
129                            folder, ResourceConstants.SCOPE_INDIVIDUAL);
130    
131                    // Entries
132    
133                    bookmarksEntryLocalService.deleteEntries(
134                            folder.getGroupId(), folder.getFolderId(), includeTrashedEntries);
135    
136                    // Asset
137    
138                    assetEntryLocalService.deleteEntry(
139                            BookmarksFolder.class.getName(), folder.getFolderId());
140    
141                    // Expando
142    
143                    expandoValueLocalService.deleteValues(
144                            BookmarksFolder.class.getName(), folder.getFolderId());
145    
146                    // Subscriptions
147    
148                    subscriptionLocalService.deleteSubscriptions(
149                            folder.getCompanyId(), BookmarksFolder.class.getName(),
150                            folder.getFolderId());
151    
152                    // Trash
153    
154                    trashEntryLocalService.deleteEntry(
155                            BookmarksFolder.class.getName(), folder.getFolderId());
156    
157                    return folder;
158            }
159    
160            @Indexable(type = IndexableType.DELETE)
161            public BookmarksFolder deleteFolder(long folderId)
162                    throws PortalException, SystemException {
163    
164                    BookmarksFolder folder = bookmarksFolderPersistence.findByPrimaryKey(
165                            folderId);
166    
167                    return deleteFolder(folder);
168            }
169    
170            @Indexable(type = IndexableType.DELETE)
171            public BookmarksFolder deleteFolder(
172                            long folderId, boolean includeTrashedEntries)
173                    throws PortalException, SystemException {
174    
175                    BookmarksFolder folder = bookmarksFolderLocalService.getFolder(
176                            folderId);
177    
178                    return deleteFolder(folder, includeTrashedEntries);
179            }
180    
181            public void deleteFolders(long groupId)
182                    throws PortalException, SystemException {
183    
184                    List<BookmarksFolder> folders = bookmarksFolderPersistence.findByG_P(
185                            groupId, BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID);
186    
187                    for (BookmarksFolder folder : folders) {
188                            bookmarksFolderLocalService.deleteFolder(folder);
189                    }
190            }
191    
192            public List<BookmarksFolder> getCompanyFolders(
193                            long companyId, int start, int end)
194                    throws SystemException {
195    
196                    return bookmarksFolderPersistence.findByCompanyId(
197                            companyId, start, end);
198            }
199    
200            public int getCompanyFoldersCount(long companyId) throws SystemException {
201                    return bookmarksFolderPersistence.countByCompanyId(companyId);
202            }
203    
204            public BookmarksFolder getFolder(long folderId)
205                    throws PortalException, SystemException {
206    
207                    return bookmarksFolderPersistence.findByPrimaryKey(folderId);
208            }
209    
210            public List<BookmarksFolder> getFolders(long groupId)
211                    throws SystemException {
212    
213                    return bookmarksFolderPersistence.findByGroupId(groupId);
214            }
215    
216            public List<BookmarksFolder> getFolders(long groupId, long parentFolderId)
217                    throws SystemException {
218    
219                    return bookmarksFolderPersistence.findByG_P(groupId, parentFolderId);
220            }
221    
222            public List<BookmarksFolder> getFolders(
223                            long groupId, long parentFolderId, int start, int end)
224                    throws SystemException {
225    
226                    return getFolders(
227                            groupId, parentFolderId, WorkflowConstants.STATUS_APPROVED, start,
228                            end);
229            }
230    
231            public List<BookmarksFolder> getFolders(
232                            long groupId, long parentFolderId, int status, int start, int end)
233                    throws SystemException {
234    
235                    return bookmarksFolderPersistence.findByG_P_S(
236                            groupId, parentFolderId, status, start, end);
237            }
238    
239            public List<Object> getFoldersAndEntries(long groupId, long folderId)
240                    throws SystemException {
241    
242                    return getFoldersAndEntries(
243                            groupId, folderId, WorkflowConstants.STATUS_ANY);
244            }
245    
246            public List<Object> getFoldersAndEntries(
247                            long groupId, long folderId, int status)
248                    throws SystemException {
249    
250                    QueryDefinition queryDefinition = new QueryDefinition(status);
251    
252                    return bookmarksFolderFinder.findF_E_ByG_F(
253                            groupId, folderId, queryDefinition);
254            }
255    
256            public List<Object> getFoldersAndEntries(
257                            long groupId, long folderId, int status, int start, int end)
258                    throws SystemException {
259    
260                    QueryDefinition queryDefinition = new QueryDefinition(
261                            status, start, end, null);
262    
263                    return bookmarksFolderFinder.findF_E_ByG_F(
264                            groupId, folderId, queryDefinition);
265            }
266    
267            public int getFoldersAndEntriesCount(
268                            long groupId, long folderId, int status)
269                    throws SystemException {
270    
271                    QueryDefinition queryDefinition = new QueryDefinition(status);
272    
273                    return bookmarksFolderFinder.countF_E_ByG_F(
274                            groupId, folderId, queryDefinition);
275            }
276    
277            public int getFoldersCount(long groupId, long parentFolderId)
278                    throws SystemException {
279    
280                    return getFoldersCount(
281                            groupId, parentFolderId, WorkflowConstants.STATUS_APPROVED);
282            }
283    
284            public int getFoldersCount(long groupId, long parentFolderId, int status)
285                    throws SystemException {
286    
287                    return bookmarksFolderPersistence.countByG_P_S(
288                            groupId, parentFolderId, status);
289            }
290    
291            public List<BookmarksFolder> getNoAssetFolders() throws SystemException {
292                    return bookmarksFolderFinder.findByNoAssets();
293            }
294    
295            public void getSubfolderIds(
296                            List<Long> folderIds, long groupId, long folderId)
297                    throws SystemException {
298    
299                    List<BookmarksFolder> folders = bookmarksFolderPersistence.findByG_P(
300                            groupId, folderId);
301    
302                    for (BookmarksFolder folder : folders) {
303                            folderIds.add(folder.getFolderId());
304    
305                            getSubfolderIds(
306                                    folderIds, folder.getGroupId(), folder.getFolderId());
307                    }
308            }
309    
310            @Indexable(type = IndexableType.REINDEX)
311            public BookmarksFolder moveFolder(long folderId, long parentFolderId)
312                    throws PortalException, SystemException {
313    
314                    BookmarksFolder folder = bookmarksFolderPersistence.findByPrimaryKey(
315                            folderId);
316    
317                    folder.setParentFolderId(parentFolderId);
318    
319                    bookmarksFolderPersistence.update(folder);
320    
321                    return folder;
322            }
323    
324            public BookmarksFolder moveFolderFromTrash(
325                            long userId, long folderId, long parentFolderId)
326                    throws PortalException, SystemException {
327    
328                    BookmarksFolder folder = bookmarksFolderPersistence.findByPrimaryKey(
329                            folderId);
330    
331                    if (folder.isInTrash()) {
332                            restoreFolderFromTrash(userId, folderId);
333                    }
334                    else {
335                            updateStatus(userId, folder, WorkflowConstants.STATUS_APPROVED);
336                    }
337    
338                    return bookmarksFolderLocalService.moveFolder(folderId, parentFolderId);
339            }
340    
341            @Indexable(type = IndexableType.REINDEX)
342            public void moveFolderToTrash(long userId, long folderId)
343                    throws PortalException, SystemException {
344    
345                    // Folder
346    
347                    BookmarksFolder folder = bookmarksFolderPersistence.findByPrimaryKey(
348                            folderId);
349    
350                    updateStatus(userId, folder, WorkflowConstants.STATUS_IN_TRASH);
351    
352                    // Social
353    
354                    socialActivityCounterLocalService.enableActivityCounters(
355                            BookmarksFolder.class.getName(), folder.getFolderId());
356    
357                    socialActivityLocalService.addActivity(
358                            userId, folder.getGroupId(), BookmarksFolder.class.getName(),
359                            folder.getFolderId(), SocialActivityConstants.TYPE_MOVE_TO_TRASH,
360                            StringPool.BLANK, 0);
361            }
362    
363            @Indexable(type = IndexableType.REINDEX)
364            public void restoreFolderFromTrash(long userId, long folderId)
365                    throws PortalException, SystemException {
366    
367                    // Folder
368    
369                    BookmarksFolder folder = bookmarksFolderPersistence.findByPrimaryKey(
370                            folderId);
371    
372                    TrashEntry trashEntry = trashEntryLocalService.getEntry(
373                            BookmarksFolder.class.getName(), folderId);
374    
375                    updateStatus(userId, folder, trashEntry.getStatus());
376    
377                    // Social
378    
379                    socialActivityCounterLocalService.enableActivityCounters(
380                            BookmarksFolder.class.getName(), folder.getFolderId());
381    
382                    socialActivityLocalService.addActivity(
383                            userId, folder.getGroupId(), BookmarksFolder.class.getName(),
384                            folder.getFolderId(),
385                            SocialActivityConstants.TYPE_RESTORE_FROM_TRASH, StringPool.BLANK,
386                            0);
387            }
388    
389            public void subscribeFolder(long userId, long groupId, long folderId)
390                    throws PortalException, SystemException {
391    
392                    if (folderId == BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
393                            folderId = groupId;
394                    }
395    
396                    subscriptionLocalService.addSubscription(
397                            userId, groupId, BookmarksFolder.class.getName(), folderId);
398            }
399    
400            public void unsubscribeFolder(long userId, long groupId, long folderId)
401                    throws PortalException, SystemException {
402    
403                    if (folderId == BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
404                            folderId = groupId;
405                    }
406    
407                    subscriptionLocalService.deleteSubscription(
408                            userId, BookmarksFolder.class.getName(), folderId);
409            }
410    
411            public void updateAsset(
412                            long userId, BookmarksFolder folder, long[] assetCategoryIds,
413                            String[] assetTagNames, long[] assetLinkEntryIds)
414                    throws PortalException, SystemException {
415    
416                    AssetEntry assetEntry = assetEntryLocalService.updateEntry(
417                            userId, folder.getGroupId(), folder.getCreateDate(),
418                            folder.getModifiedDate(), BookmarksFolder.class.getName(),
419                            folder.getFolderId(), folder.getUuid(), 0, assetCategoryIds,
420                            assetTagNames, true, null, null, null, ContentTypes.TEXT_PLAIN,
421                            folder.getName(), folder.getDescription(), null, null, null, 0, 0,
422                            null, false);
423    
424                    assetLinkLocalService.updateLinks(
425                            userId, assetEntry.getEntryId(), assetLinkEntryIds,
426                            AssetLinkConstants.TYPE_RELATED);
427            }
428    
429            @Indexable(type = IndexableType.REINDEX)
430            public BookmarksFolder updateFolder(
431                            long userId, long folderId, long parentFolderId, String name,
432                            String description, boolean mergeWithParentFolder,
433                            ServiceContext serviceContext)
434                    throws PortalException, SystemException {
435    
436                    // Merge folders
437    
438                    BookmarksFolder folder = bookmarksFolderPersistence.findByPrimaryKey(
439                            folderId);
440    
441                    parentFolderId = getParentFolderId(folder, parentFolderId);
442    
443                    if (mergeWithParentFolder && (folderId != parentFolderId)) {
444                            mergeFolders(folder, parentFolderId);
445    
446                            return folder;
447                    }
448    
449                    // Folder
450    
451                    validate(name);
452    
453                    folder.setModifiedDate(serviceContext.getModifiedDate(null));
454                    folder.setParentFolderId(parentFolderId);
455                    folder.setName(name);
456                    folder.setDescription(description);
457                    folder.setExpandoBridgeAttributes(serviceContext);
458    
459                    bookmarksFolderPersistence.update(folder);
460    
461                    // Asset
462    
463                    updateAsset(
464                            userId, folder, serviceContext.getAssetCategoryIds(),
465                            serviceContext.getAssetTagNames(),
466                            serviceContext.getAssetLinkEntryIds());
467    
468                    return folder;
469            }
470    
471            public BookmarksFolder updateStatus(
472                            long userId, BookmarksFolder folder, int status)
473                    throws PortalException, SystemException {
474    
475                    // Folder
476    
477                    User user = userPersistence.findByPrimaryKey(userId);
478    
479                    int oldStatus = folder.getStatus();
480    
481                    folder.setStatus(status);
482                    folder.setStatusByUserId(userId);
483                    folder.setStatusByUserName(user.getFullName());
484                    folder.setStatusDate(new Date());
485    
486                    bookmarksFolderPersistence.update(folder);
487    
488                    // Folders and entries
489    
490                    List<Object> foldersAndEntries =
491                            bookmarksFolderLocalService.getFoldersAndEntries(
492                                    folder.getGroupId(), folder.getFolderId());
493    
494                    updateDependentStatus(foldersAndEntries, status);
495    
496                    if (status == WorkflowConstants.STATUS_APPROVED) {
497    
498                            // Asset
499    
500                            assetEntryLocalService.updateVisible(
501                                    BookmarksFolder.class.getName(), folder.getFolderId(), true);
502    
503                            // Social
504    
505                            socialActivityCounterLocalService.enableActivityCounters(
506                                    BookmarksFolder.class.getName(), folder.getFolderId());
507                    }
508                    else if (status == WorkflowConstants.STATUS_IN_TRASH) {
509    
510                            // Asset
511    
512                            assetEntryLocalService.updateVisible(
513                                    BookmarksFolder.class.getName(), folder.getFolderId(), false);
514    
515                            // Social
516    
517                            socialActivityCounterLocalService.disableActivityCounters(
518                                    BookmarksFolder.class.getName(), folder.getFolderId());
519                    }
520    
521                    // Trash
522    
523                    if (oldStatus == WorkflowConstants.STATUS_IN_TRASH) {
524                            trashEntryLocalService.deleteEntry(
525                                    BookmarksFolder.class.getName(), folder.getFolderId());
526                    }
527                    else if (status == WorkflowConstants.STATUS_IN_TRASH) {
528                            trashEntryLocalService.addTrashEntry(
529                                    userId, folder.getGroupId(), BookmarksFolder.class.getName(),
530                                    folder.getFolderId(), oldStatus, null, null);
531                    }
532    
533                    // Index
534    
535                    Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(
536                            BookmarksFolder.class);
537    
538                    indexer.reindex(folder);
539    
540                    return folder;
541            }
542    
543            protected long getParentFolderId(
544                            BookmarksFolder folder, long parentFolderId)
545                    throws SystemException {
546    
547                    if (parentFolderId ==
548                                    BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
549    
550                            return parentFolderId;
551                    }
552    
553                    if (folder.getFolderId() == parentFolderId) {
554                            return folder.getParentFolderId();
555                    }
556                    else {
557                            BookmarksFolder parentFolder =
558                                    bookmarksFolderPersistence.fetchByPrimaryKey(parentFolderId);
559    
560                            if ((parentFolder == null) ||
561                                    (folder.getGroupId() != parentFolder.getGroupId())) {
562    
563                                    return folder.getParentFolderId();
564                            }
565    
566                            List<Long> subfolderIds = new ArrayList<Long>();
567    
568                            getSubfolderIds(
569                                    subfolderIds, folder.getGroupId(), folder.getFolderId());
570    
571                            if (subfolderIds.contains(parentFolderId)) {
572                                    return folder.getParentFolderId();
573                            }
574    
575                            return parentFolderId;
576                    }
577            }
578    
579            protected long getParentFolderId(long groupId, long parentFolderId)
580                    throws SystemException {
581    
582                    if (parentFolderId !=
583                                    BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
584    
585                            BookmarksFolder parentFolder =
586                                    bookmarksFolderPersistence.fetchByPrimaryKey(parentFolderId);
587    
588                            if ((parentFolder == null) ||
589                                    (groupId != parentFolder.getGroupId())) {
590    
591                                    parentFolderId =
592                                            BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID;
593                            }
594                    }
595    
596                    return parentFolderId;
597            }
598    
599            protected void mergeFolders(BookmarksFolder fromFolder, long toFolderId)
600                    throws PortalException, SystemException {
601    
602                    List<BookmarksFolder> folders = bookmarksFolderPersistence.findByG_P(
603                            fromFolder.getGroupId(), fromFolder.getFolderId());
604    
605                    for (BookmarksFolder folder : folders) {
606                            mergeFolders(folder, toFolderId);
607                    }
608    
609                    List<BookmarksEntry> entries = bookmarksEntryPersistence.findByG_F(
610                            fromFolder.getGroupId(), fromFolder.getFolderId());
611    
612                    for (BookmarksEntry entry : entries) {
613                            entry.setFolderId(toFolderId);
614    
615                            bookmarksEntryPersistence.update(entry);
616    
617                            Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(
618                                    BookmarksEntry.class);
619    
620                            indexer.reindex(entry);
621                    }
622    
623                    bookmarksFolderLocalService.deleteFolder(fromFolder);
624            }
625    
626            protected void updateDependentStatus(
627                            List<Object> foldersAndEntries, int status)
628                    throws PortalException, SystemException {
629    
630                    for (Object object : foldersAndEntries) {
631                            if (object instanceof BookmarksEntry) {
632                                    BookmarksEntry entry = (BookmarksEntry)object;
633    
634                                    if (status == WorkflowConstants.STATUS_IN_TRASH) {
635    
636                                            // Asset
637    
638                                            assetEntryLocalService.updateVisible(
639                                                    BookmarksEntry.class.getName(), entry.getEntryId(),
640                                                    false);
641    
642                                            // Social
643    
644                                            socialActivityCounterLocalService.disableActivityCounters(
645                                                    BookmarksEntry.class.getName(), entry.getEntryId());
646    
647                                            if (entry.getStatus() == WorkflowConstants.STATUS_PENDING) {
648                                                    entry.setStatus(WorkflowConstants.STATUS_DRAFT);
649    
650                                                    bookmarksEntryPersistence.update(entry);
651                                            }
652                                    }
653                                    else {
654    
655                                            // Asset
656    
657                                            if (entry.getStatus() ==
658                                                            WorkflowConstants.STATUS_APPROVED) {
659    
660                                                    assetEntryLocalService.updateVisible(
661                                                            BookmarksEntry.class.getName(), entry.getEntryId(),
662                                                            true);
663                                            }
664    
665                                            // Social
666    
667                                            socialActivityCounterLocalService.enableActivityCounters(
668                                                    BookmarksEntry.class.getName(), entry.getEntryId());
669                                    }
670    
671                                    // Indexer
672    
673                                    Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(
674                                            BookmarksEntry.class);
675    
676                                    indexer.reindex(entry);
677                            }
678                            else if (object instanceof BookmarksFolder) {
679                                    BookmarksFolder folder = (BookmarksFolder)object;
680    
681                                    if (folder.isInTrash()) {
682                                            continue;
683                                    }
684    
685                                    // Folders and entries
686    
687                                    List<Object> curFoldersAndEntries = getFoldersAndEntries(
688                                            folder.getGroupId(), folder.getFolderId());
689    
690                                    updateDependentStatus(curFoldersAndEntries, status);
691    
692                                    if (status == WorkflowConstants.STATUS_IN_TRASH) {
693    
694                                            // Asset
695    
696                                            assetEntryLocalService.updateVisible(
697                                                    BookmarksFolder.class.getName(), folder.getFolderId(),
698                                                    false);
699    
700                                            // Social
701    
702                                            socialActivityCounterLocalService.disableActivityCounters(
703                                                    BookmarksFolder.class.getName(), folder.getFolderId());
704                                    }
705                                    else {
706    
707                                            // Asset
708    
709                                            assetEntryLocalService.updateVisible(
710                                                    BookmarksFolder.class.getName(), folder.getFolderId(),
711                                                    true);
712    
713                                            // Social
714    
715                                            socialActivityCounterLocalService.enableActivityCounters(
716                                                    BookmarksFolder.class.getName(), folder.getFolderId());
717                                    }
718    
719                                    // Index
720    
721                                    Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(
722                                            BookmarksFolder.class);
723    
724                                    indexer.reindex(folder);
725                            }
726                    }
727            }
728    
729            protected void validate(String name) throws PortalException {
730                    if (Validator.isNull(name) || name.contains("\\\\") ||
731                            name.contains("//")) {
732    
733                            throw new FolderNameException();
734                    }
735            }
736    
737    }