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.dao.jdbc.DataAccess;
018    import com.liferay.portal.upgrade.util.UpgradeAssetPublisherManualEntries;
019    import com.liferay.portlet.asset.service.AssetCategoryLocalServiceUtil;
020    
021    import java.sql.Connection;
022    import java.sql.PreparedStatement;
023    import java.sql.ResultSet;
024    
025    /**
026     * @author Douglas Wong
027     */
028    public class VerifyAsset extends VerifyProcess {
029    
030            @Override
031            protected void doVerify() throws Exception {
032                    rebuildTree();
033    
034                    upgradeAssetPublisherManualEntries();
035            }
036    
037            protected void rebuildTree() throws Exception {
038                    Connection con = null;
039                    PreparedStatement ps = null;
040                    ResultSet rs = null;
041    
042                    try {
043                            con = DataAccess.getUpgradeOptimizedConnection();
044    
045                            ps = con.prepareStatement(
046                                    "select distinct groupId from AssetCategory where " +
047                                            "(leftCategoryId is null) or (rightCategoryId is null)");
048    
049                            rs = ps.executeQuery();
050    
051                            while (rs.next()) {
052                                    long groupId = rs.getLong("groupId");
053    
054                                    AssetCategoryLocalServiceUtil.rebuildTree(groupId, true);
055                            }
056                    }
057                    finally {
058                            DataAccess.cleanUp(con, ps, rs);
059                    }
060            }
061    
062            protected void upgradeAssetPublisherManualEntries() throws Exception {
063                    UpgradeAssetPublisherManualEntries upgradeAssetPublisherManualEntries =
064                            new UpgradeAssetPublisherManualEntries();
065    
066                    upgradeAssetPublisherManualEntries.upgrade();
067            }
068    
069    }