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              try {
35                  Role communityMemberRole = RoleLocalServiceUtil.getRole(
36                      companyId, RoleConstants.COMMUNITY_MEMBER);
37  
38                  deleteImplicitAssociations(communityMemberRole);
39              }
40              catch (NoSuchRoleException nsre) {
41              }
42  
43              try {
44                  Role organizationMemberRole = RoleLocalServiceUtil.getRole(
45                      companyId, RoleConstants.ORGANIZATION_MEMBER);
46  
47                  deleteImplicitAssociations(organizationMemberRole);
48              }
49              catch (NoSuchRoleException nsre) {
50              }
51          }
52      }
53  
54      protected void deleteImplicitAssociations(Role role) throws Exception {
55          runSQL(
56              "delete from UserGroupGroupRole where roleId = " +
57                  role.getRoleId());
58          runSQL(
59              "delete from UserGroupRole where roleId = " + role.getRoleId());
60      }
61  
62  }