001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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.getConnection();
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    }