1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.convert.util;
16  
17  import com.liferay.portal.kernel.util.StringUtil;
18  import com.liferay.portal.upgrade.util.Table;
19  
20  import java.sql.Types;
21  
22  import java.util.ArrayList;
23  import java.util.List;
24  
25  /**
26   * <a href="PermissionView.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Alexander Chow
29   */
30  public class PermissionView extends Table {
31  
32      public static String getActionId(String[] values) {
33          return values[values.length - 4];
34      }
35  
36      public static long getCompanyId(String[] values) {
37          return Long.parseLong(values[values.length - 5]);
38      }
39  
40      public static String getNameId(String[] values) {
41          return values[values.length - 2];
42      }
43  
44      public static long getPermissionId(String[] values) {
45          return Long.parseLong(values[values.length - 6]);
46      }
47  
48      public static long getPrimaryKey(String[] values) {
49          return Long.parseLong(values[0]);
50      }
51  
52      public static long getResourceId(String[] values) {
53          return Long.parseLong(values[values.length - 3]);
54      }
55  
56      public static int getScopeId(String[] values) {
57          return Integer.parseInt(values[values.length - 1]);
58      }
59  
60      public PermissionView(String tableName, String[] primKeys) {
61          super(tableName);
62  
63          List<Object[]> columns = new ArrayList<Object[]>();
64  
65          for (String primKey : primKeys) {
66              columns.add(new Object[] {primKey, Types.BIGINT});
67          }
68  
69          columns.add(new Object[] {"permissionId", Types.BIGINT});
70          columns.add(new Object[] {"companyId", Types.BIGINT});
71          columns.add(new Object[] {"actionId", Types.VARCHAR});
72          columns.add(new Object[] {"resourceId", Types.BIGINT});
73          columns.add(new Object[] {"name", Types.VARCHAR});
74          columns.add(new Object[] {"scope", Types.INTEGER});
75  
76          setColumns(columns.toArray(new Object[0][]));
77      }
78  
79      public String getSelectSQL() throws Exception {
80          return StringUtil.replace(_SELECT_SQL, "_OLD_TABLE_", getTableName());
81      }
82  
83      private static final String _SELECT_SQL =
84          "SELECT _OLD_TABLE_.*, Permission_.companyId, Permission_.actionId, " +
85          "Resource_.resourceId, ResourceCode.name, ResourceCode.scope FROM " +
86          "_OLD_TABLE_, Permission_, Resource_, ResourceCode WHERE " +
87          "_OLD_TABLE_.permissionId = Permission_.permissionId AND " +
88          "Permission_.resourceId = Resource_.resourceId AND " +
89          "Resource_.codeId = ResourceCode.codeId ORDER BY " +
90          "Resource_.resourceId";
91  
92  }