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.StringUtil;
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="PermissionView.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Alexander Chow
37   *
38   */
39  public class PermissionView extends Table {
40  
41      public static String getActionId(String[] values) {
42          return values[values.length - 4];
43      }
44  
45      public static long getCompanyId(String[] values) {
46          return Long.parseLong(values[values.length - 5]);
47      }
48  
49      public static String getNameId(String[] values) {
50          return values[values.length - 2];
51      }
52  
53      public static long getPermissionId(String[] values) {
54          return Long.parseLong(values[values.length - 6]);
55      }
56  
57      public static long getPrimaryKey(String[] values) {
58          return Long.parseLong(values[0]);
59      }
60  
61      public static long getResourceId(String[] values) {
62          return Long.parseLong(values[values.length - 3]);
63      }
64  
65      public static int getScopeId(String[] values) {
66          return Integer.parseInt(values[values.length - 1]);
67      }
68  
69      public PermissionView(String tableName, String[] primKeys) {
70          super(tableName);
71  
72          List<Object[]> columns = new ArrayList<Object[]>();
73  
74          for (String primKey : primKeys) {
75              columns.add(new Object[] {primKey, Types.BIGINT});
76          }
77  
78          columns.add(new Object[] {"permissionId", Types.BIGINT});
79          columns.add(new Object[] {"companyId", Types.BIGINT});
80          columns.add(new Object[] {"actionId", Types.VARCHAR});
81          columns.add(new Object[] {"resourceId", Types.BIGINT});
82          columns.add(new Object[] {"name", Types.VARCHAR});
83          columns.add(new Object[] {"scope", Types.INTEGER});
84  
85          setColumns(columns.toArray(new Object[0][]));
86      }
87  
88      public String getSelectSQL() throws Exception {
89          return StringUtil.replace(_SELECT_SQL, "_OLD_TABLE_", getTableName());
90      }
91  
92      private static final String _SELECT_SQL =
93          "SELECT _OLD_TABLE_.*, Permission_.companyId, Permission_.actionId, " +
94          "Resource_.resourceId, ResourceCode.name, ResourceCode.scope FROM " +
95          "_OLD_TABLE_, Permission_, Resource_, ResourceCode WHERE " +
96          "_OLD_TABLE_.permissionId = Permission_.permissionId AND " +
97          "Permission_.resourceId = Resource_.resourceId AND " +
98          "Resource_.codeId = ResourceCode.codeId ORDER BY " +
99          "Resource_.resourceId";
100 
101 }