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.orm.ActionableDynamicQuery;
018    import com.liferay.portal.kernel.log.Log;
019    import com.liferay.portal.kernel.log.LogFactoryUtil;
020    import com.liferay.portal.model.Organization;
021    import com.liferay.portal.service.OrganizationLocalServiceUtil;
022    import com.liferay.portal.service.persistence.OrganizationActionableDynamicQuery;
023    import com.liferay.portal.util.PortalInstances;
024    import com.liferay.portlet.asset.model.AssetEntry;
025    import com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     * @author Daniel Kocsis
030     */
031    public class VerifyOrganization extends VerifyProcess {
032    
033            @Override
034            protected void doVerify() throws Exception {
035                    rebuildTree();
036                    updateOrganizationAssetEntries();
037            }
038    
039            protected void rebuildTree() throws Exception {
040                    long[] companyIds = PortalInstances.getCompanyIdsBySQL();
041    
042                    for (long companyId : companyIds) {
043                            OrganizationLocalServiceUtil.rebuildTree(companyId);
044                    }
045            }
046    
047            protected void updateOrganizationAssetEntries() throws Exception {
048                    ActionableDynamicQuery actionableDynamicQuery =
049                            new OrganizationActionableDynamicQuery() {
050    
051                            @Override
052                            protected void performAction(Object object) {
053                                    Organization organization = (Organization)object;
054    
055                                    try {
056                                            AssetEntry assetEntry = AssetEntryLocalServiceUtil.getEntry(
057                                                    Organization.class.getName(),
058                                                    organization.getOrganizationId());
059    
060                                            assetEntry.setClassUuid(organization.getUuid());
061    
062                                            AssetEntryLocalServiceUtil.updateAssetEntry(assetEntry);
063                                    }
064                                    catch (Exception e) {
065                                            if (_log.isWarnEnabled()) {
066                                                    _log.warn(
067                                                            "Unable to update asset entry for organization " +
068                                                                    organization.getOrganizationId(),
069                                                            e);
070                                            }
071                                    }
072                            }
073    
074                    };
075    
076                    actionableDynamicQuery.performActions();
077            }
078    
079            private static Log _log = LogFactoryUtil.getLog(VerifyOrganization.class);
080    
081    }