1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.convert.util;
24  
25  import com.liferay.portal.kernel.util.StringPool;
26  import com.liferay.portal.upgrade.util.Table;
27  
28  import java.sql.Types;
29  
30  import java.util.ArrayList;
31  import java.util.List;
32  
33  /**
34   * <a href="ResourcePermissionView.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Alexander Chow
37   *
38   */
39  public class ResourcePermissionView extends Table {
40  
41      public static String getActionId(String[] values) {
42          return values[4];
43      }
44  
45      public static long getCompanyId(String[] values) {
46          return Long.parseLong(values[0]);
47      }
48  
49      public static String getPrimaryKey(String[] values) {
50          return values[2];
51      }
52  
53      public static long getRoleId(String[] values) {
54          return Long.parseLong(values[3]);
55      }
56  
57      public static int getScope(String[] values) {
58          return Integer.parseInt(values[1]);
59      }
60  
61      public ResourcePermissionView(String name) {
62          super("ResourcePermissionView");
63  
64          List<Object[]> columns = new ArrayList<Object[]>();
65  
66          columns.add(new Object[] {"companyId", Types.BIGINT});
67          columns.add(new Object[] {"scope", Types.INTEGER});
68          columns.add(new Object[] {"primKey", Types.VARCHAR});
69          columns.add(new Object[] {"roleId", Types.BIGINT});
70          columns.add(new Object[] {"actionId", Types.VARCHAR});
71  
72          setColumns(columns.toArray(new Object[0][]));
73  
74          _name = name;
75      }
76  
77      public String getSelectSQL() throws Exception {
78          return _SELECT_SQL + StringPool.QUOTE + _name + StringPool.QUOTE;
79      }
80  
81      private String _name = StringPool.BLANK;
82  
83      private static final String _SELECT_SQL =
84          "SELECT Permission_.companyId, ResourceCode.scope, " +
85          "Resource_.primKey, Roles_Permissions.roleId, Permission_.actionId " +
86          "FROM Roles_Permissions, Permission_, Resource_, ResourceCode WHERE " +
87          "Permission_.permissionId = Roles_Permissions.permissionId AND " +
88          "Permission_.resourceId = Resource_.resourceId AND " +
89          "Resource_.codeId = ResourceCode.codeId AND ResourceCode.name = ";
90  
91  }