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