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.portal.verify;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portlet.bookmarks.model.BookmarksEntry;
020    import com.liferay.portlet.bookmarks.model.BookmarksFolder;
021    import com.liferay.portlet.bookmarks.service.BookmarksEntryLocalServiceUtil;
022    import com.liferay.portlet.bookmarks.service.BookmarksFolderLocalServiceUtil;
023    
024    import java.util.List;
025    
026    /**
027     * @author Raymond Aug??
028     * @author Alexander Chow
029     */
030    public class VerifyBookmarks extends VerifyProcess {
031    
032            @Override
033            protected void doVerify() throws Exception {
034                    updateEntryAssets();
035                    updateFolderAssets();
036            }
037    
038            protected void updateEntryAssets() throws Exception {
039                    List<BookmarksEntry> entries =
040                            BookmarksEntryLocalServiceUtil.getNoAssetEntries();
041    
042                    if (_log.isDebugEnabled()) {
043                            _log.debug(
044                                    "Processing " + entries.size() + " entries with no asset");
045                    }
046    
047                    for (BookmarksEntry entry : entries) {
048                            try {
049                                    BookmarksEntryLocalServiceUtil.updateAsset(
050                                            entry.getUserId(), entry, null, null, null);
051                            }
052                            catch (Exception e) {
053                                    if (_log.isWarnEnabled()) {
054                                            _log.warn(
055                                                    "Unable to update asset for entry " +
056                                                            entry.getEntryId() + ": " + e.getMessage());
057                                    }
058                            }
059                    }
060    
061                    if (_log.isDebugEnabled()) {
062                            _log.debug("Assets verified for entries");
063                    }
064            }
065    
066            protected void updateFolderAssets() throws Exception {
067                    List<BookmarksFolder> folders =
068                            BookmarksFolderLocalServiceUtil.getNoAssetFolders();
069    
070                    if (_log.isDebugEnabled()) {
071                            _log.debug(
072                                    "Processing " + folders.size() + " folders with no asset");
073                    }
074    
075                    for (BookmarksFolder folder : folders) {
076                            try {
077                                    BookmarksFolderLocalServiceUtil.updateAsset(
078                                            folder.getUserId(), folder, null, null, null);
079                            }
080                            catch (Exception e) {
081                                    if (_log.isWarnEnabled()) {
082                                            _log.warn(
083                                                    "Unable to update asset for folder " +
084                                                            folder.getFolderId() + ": " + e.getMessage());
085                                    }
086                            }
087                    }
088    
089                    if (_log.isDebugEnabled()) {
090                            _log.debug("Assets verified for folders");
091                    }
092            }
093    
094            private static Log _log = LogFactoryUtil.getLog(VerifyBookmarks.class);
095    
096    }