001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.convert.util;
016    
017    import com.liferay.portal.kernel.util.GetterUtil;
018    import com.liferay.portal.kernel.util.StringBundler;
019    import com.liferay.portal.kernel.util.StringPool;
020    import com.liferay.portal.upgrade.util.Table;
021    
022    import java.sql.Types;
023    
024    import java.util.ArrayList;
025    import java.util.List;
026    
027    /**
028     * @author Alexander Chow
029     */
030    public class ResourcePermissionView extends Table {
031    
032            public static String getActionId(String[] values) {
033                    return values[4];
034            }
035    
036            public static long getCompanyId(String[] values) {
037                    return GetterUtil.getLong(values[0]);
038            }
039    
040            public static String getPrimaryKey(String[] values) {
041                    return values[2];
042            }
043    
044            public static long getRoleId(String[] values) {
045                    return GetterUtil.getLong(values[3]);
046            }
047    
048            public static int getScope(String[] values) {
049                    return GetterUtil.getInteger(values[1]);
050            }
051    
052            public ResourcePermissionView(String name) {
053                    super("ResourcePermissionView");
054    
055                    List<Object[]> columns = new ArrayList<Object[]>();
056    
057                    columns.add(new Object[] {"companyId", Types.BIGINT});
058                    columns.add(new Object[] {"scope", Types.INTEGER});
059                    columns.add(new Object[] {"primKey", Types.VARCHAR});
060                    columns.add(new Object[] {"roleId", Types.BIGINT});
061                    columns.add(new Object[] {"actionId", Types.VARCHAR});
062    
063                    setColumns(columns.toArray(new Object[0][]));
064    
065                    _name = name;
066            }
067    
068            @Override
069            public String getSelectSQL() throws Exception {
070                    StringBundler sb = new StringBundler(4);
071    
072                    sb.append(_SELECT_SQL);
073                    sb.append(StringPool.APOSTROPHE);
074                    sb.append(_name);
075                    sb.append(StringPool.APOSTROPHE);
076    
077                    return sb.toString();
078            }
079    
080            private static final String _SELECT_SQL =
081                    "SELECT Permission_.companyId, ResourceCode.scope, " +
082                    "Resource_.primKey, Roles_Permissions.roleId, Permission_.actionId " +
083                    "FROM Roles_Permissions, Permission_, Resource_, ResourceCode WHERE " +
084                    "Permission_.permissionId = Roles_Permissions.permissionId AND " +
085                    "Permission_.resourceId = Resource_.resourceId AND " +
086                    "Resource_.codeId = ResourceCode.codeId AND ResourceCode.name = ";
087    
088            private String _name = StringPool.BLANK;
089    
090    }