1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.convert.util;
21  
22  import com.liferay.portal.kernel.util.StringPool;
23  import com.liferay.portal.upgrade.util.Table;
24  
25  import java.sql.Types;
26  
27  import java.util.ArrayList;
28  import java.util.List;
29  
30  /**
31   * <a href="ResourcePermissionView.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Alexander Chow
34   *
35   */
36  public class ResourcePermissionView extends Table {
37  
38      public static String getActionId(String[] values) {
39          return values[4];
40      }
41  
42      public static long getCompanyId(String[] values) {
43          return Long.parseLong(values[0]);
44      }
45  
46      public static String getPrimaryKey(String[] values) {
47          return values[2];
48      }
49  
50      public static long getRoleId(String[] values) {
51          return Long.parseLong(values[3]);
52      }
53  
54      public static int getScope(String[] values) {
55          return Integer.parseInt(values[1]);
56      }
57  
58      public ResourcePermissionView(String name) {
59          super("ResourcePermissionView");
60  
61          List<Object[]> columns = new ArrayList<Object[]>();
62  
63          columns.add(new Object[] {"companyId", Types.BIGINT});
64          columns.add(new Object[] {"scope", Types.INTEGER});
65          columns.add(new Object[] {"primKey", Types.VARCHAR});
66          columns.add(new Object[] {"roleId", Types.BIGINT});
67          columns.add(new Object[] {"actionId", Types.VARCHAR});
68  
69          setColumns(columns.toArray(new Object[0][]));
70  
71          _name = name;
72      }
73  
74      public String getSelectSQL() throws Exception {
75          return _SELECT_SQL + StringPool.QUOTE + _name + StringPool.QUOTE;
76      }
77  
78      private String _name = StringPool.BLANK;
79  
80      private static final String _SELECT_SQL =
81          "SELECT Permission_.companyId, ResourceCode.scope, " +
82          "Resource_.primKey, Roles_Permissions.roleId, Permission_.actionId " +
83          "FROM Roles_Permissions, Permission_, Resource_, ResourceCode WHERE " +
84          "Permission_.permissionId = Roles_Permissions.permissionId AND " +
85          "Permission_.resourceId = Resource_.resourceId AND " +
86          "Resource_.codeId = ResourceCode.codeId AND ResourceCode.name = ";
87  
88  }