1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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  public class ResourcePermissionView extends Table {
39  
40      public static String getActionId(String[] values) {
41          return values[4];
42      }
43  
44      public static long getCompanyId(String[] values) {
45          return Long.parseLong(values[0]);
46      }
47  
48      public static String getPrimaryKey(String[] values) {
49          return values[2];
50      }
51  
52      public static long getRoleId(String[] values) {
53          return Long.parseLong(values[3]);
54      }
55  
56      public static int getScope(String[] values) {
57          return Integer.parseInt(values[1]);
58      }
59  
60      public ResourcePermissionView(String name) {
61          super("ResourcePermissionView");
62  
63          List<Object[]> columns = new ArrayList<Object[]>();
64  
65          columns.add(new Object[] {"companyId", Types.BIGINT});
66          columns.add(new Object[] {"scope", Types.INTEGER});
67          columns.add(new Object[] {"primKey", Types.VARCHAR});
68          columns.add(new Object[] {"roleId", Types.BIGINT});
69          columns.add(new Object[] {"actionId", Types.VARCHAR});
70  
71          setColumns(columns.toArray(new Object[0][]));
72  
73          _name = name;
74      }
75  
76      public String getSelectSQL() throws Exception {
77          StringBuilder sb = new StringBuilder();
78  
79          sb.append(_SELECT_SQL);
80          sb.append(StringPool.APOSTROPHE);
81          sb.append(_name);
82          sb.append(StringPool.APOSTROPHE);
83  
84          return sb.toString();
85      }
86  
87      private String _name = StringPool.BLANK;
88  
89      private static final String _SELECT_SQL =
90          "SELECT Permission_.companyId, ResourceCode.scope, " +
91          "Resource_.primKey, Roles_Permissions.roleId, Permission_.actionId " +
92          "FROM Roles_Permissions, Permission_, Resource_, ResourceCode WHERE " +
93          "Permission_.permissionId = Roles_Permissions.permissionId AND " +
94          "Permission_.resourceId = Resource_.resourceId AND " +
95          "Resource_.codeId = ResourceCode.codeId AND ResourceCode.name = ";
96  
97  }