1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.verify;
16  
17  import com.liferay.portal.NoSuchRoleException;
18  import com.liferay.portal.model.Role;
19  import com.liferay.portal.model.RoleConstants;
20  import com.liferay.portal.service.RoleLocalServiceUtil;
21  import com.liferay.portal.util.PortalInstances;
22  
23  /**
24   * <a href="VerifyRole.java.html"><b><i>View Source</i></b></a>
25   *
26   * @author Brian Wing Shun Chan
27   */
28  public class VerifyRole extends VerifyProcess {
29  
30      protected void doVerify() throws Exception {
31          long[] companyIds = PortalInstances.getCompanyIdsBySQL();
32  
33          for (long companyId : companyIds) {
34              RoleLocalServiceUtil.checkSystemRoles(companyId);
35  
36              try {
37                  Role communityMemberRole = RoleLocalServiceUtil.getRole(
38                      companyId, RoleConstants.COMMUNITY_MEMBER);
39  
40                  deleteImplicitAssociations(communityMemberRole);
41              }
42              catch (NoSuchRoleException nsre) {
43              }
44  
45              try {
46                  Role organizationMemberRole = RoleLocalServiceUtil.getRole(
47                      companyId, RoleConstants.ORGANIZATION_MEMBER);
48  
49                  deleteImplicitAssociations(organizationMemberRole);
50              }
51              catch (NoSuchRoleException nsre) {
52              }
53          }
54      }
55  
56      protected void deleteImplicitAssociations(Role role) throws Exception {
57          runSQL(
58              "delete from UserGroupGroupRole where roleId = " +
59                  role.getRoleId());
60          runSQL(
61              "delete from UserGroupRole where roleId = " + role.getRoleId());
62      }
63  
64  }