基于java语言的给cube添加custom view来实现权限控制

浏览: 3768

今天是农历2014年的最后一个工作日了,在这里提前祝大家新年快乐、羊年大吉!当然本人今天也拿出来点儿真东西,做为献给大家的新年礼物,依次共勉.

下文主要讲述的是使用Java代码来完成对cube基于部门维度创建custom view,实现角色级别的权限控制

第一部分:通用数据库设计

1:事实表(订单分析)--存放departkey关联部门

2:维度表(部门)

3:赋权表

role_id以及对应的role_name,来源于cognos cjap认证中的角色表
depart_id以及对应的depart_name来源于上面的部门维度表

第二部分:Java project详细设计步骤

2.1:整体架构

 

2.2:类功能详细描述

AddViewToCube.java主要是测试入口

GetCon得到oracle数据库的链接

QueryUtil查询工具类

AccessTable和Department是两个实例Bean,提供数据库字段值和set以及get方法

2.3:查询工具类代码解析

QueryUtil(类)
方法列表参数列表实现功能
public ArrayList   GetDepartment()无参数得到所有的部门,每一个部门对应一个custom view
public String GetFilterStr(int departid)departid-部门id根据具体部门过滤掉其他部门的权限
public ArrayList   GetAccessRole()无参数得到所有在access_table中已经授权的角色
public  String GetDepartForRole(int roleid)roleid-角色id根据具体角色得到该角色在access_table中所有的授权部门名称
public void clearfile(String filename)String filename生成mdl语句的文件路径清空一个文件
public void update_customview(String cubename,String targetmodel,String dimension,String filename,String namespacename,String namespaceid )cubename-mdl模型中生成cube的名称执行add view的主函数,必须传入足够的参数
targetmodel-需要增加权限的mdl文件路径
dimension-cube模型中需要增加权限的维度名称
filename-mdl语句的输出文件位置
namespacename-Cognos认证的空间名称
namespaceid-Cognos认证的空间ID 

2.4:主要代码实例

GetDepartForRole方法

12345678910111213141516171819202122232425262728293031323334public  String GetDepartForRole(int roleid) throws ClassNotFoundException, SQLException        {            Connection con=new GetCon().getcon_king();            Statement stm=con.createStatement();            ResultSet rs=stm.executeQuery("select  * from access_table where role_id="+roleid);            ArrayList list=new ArrayList();            while(rs.next())            {                AccessTable at=new AccessTable();                at.setRole_id(rs.getInt(1));                at.setDepart_id(rs.getInt(2));                at.setRole_name(rs.getString(3));                at.setDepart_name(rs.getString(4));                list.add(at);            }            System.out.println("lietsize:"+list.size());            if(list.size()>0)            {                for(int i=0;i

update_customview方法

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869public void update_customview        (String cubename,String targetmodel,String dimension,String filename,String namespacename,String namespaceid ) throws IOException, ClassNotFoundException, SQLException        {                         QueryUtil  qu=new QueryUtil();//创建工具类            FileOutputStream fos=new FileOutputStream(filename,true);//定义一个字符输出流,True表示在文件尾部追加             qu.clearfile(filename);//先清空            String mdlpath="OpenMDL"+" "+'"'+targetmodel+'"'; //定义一个要修改custom view 的mdl文件的位置            String namespace="SecurityNameSpaceMake"+" "+'"'+namespacename+'"'+" "+"SecurityNamespaceCAMID"+" "+"'"+"CAMID"+"("+'"'+namespaceid+'"'+")"+"'";//指定第三方人中空间的名称和ID            fos.write(mdlpath.getBytes());//输出到filename中,下文不再多说            fos.write("\r\n".getBytes());//换行,下文不再多说            fos.write(namespace.getBytes());            fos.write("\r\n".getBytes());            ArrayList  list=qu.GetDepartment(); //从数据库中读出所有Department            for(int i=0;i  list1=qu.GetAccessRole(); //从数据库中读出所有Department            for(int h=0;h

2.5:方法入口

public static void main(String args[]) throws ClassNotFoundException, SQLException, IOException
{
QueryUtil qu=new QueryUtil();
String filename="C:\\Users\\king\\Documents\\Transformer\\Models\\订单数据分析_update.mdl";
String cubename="订单数据分析";
String updatemdl="C:\\Users\\king\\Documents\\Transformer\\Models\\订单数据分析.mdl";
String dimension="部门维度";
String namespacename="Intrust";
String namespaceid="Intrust";
qu.update_customview(cubename,updatemdl,dimension,filename,namespacename,namespaceid);
//System.out.print(qu.GetDepartForRole(1));
}

三:生产的mdl文件效果

复制代码

OpenMDL "C:\Users\king\Documents\Transformer\Models\订单数据分析.mdl"
SecurityNameSpaceMake
"Intrust" SecurityNamespaceCAMID 'CAMID("Intrust")'
ViewMake
"信托一部" Dimension "部门维度" ViewSecurity "信托一部" Filter "2" Filter "3"
CustomViewMake
"信托一部" DimensionView "部门维度" "信托一部"
ViewMake
"信托二部" Dimension "部门维度" ViewSecurity "信托二部" Filter "1" Filter "3"
CustomViewMake
"信托二部" DimensionView "部门维度" "信托二部"
ViewMake
"信托三部" Dimension "部门维度" ViewSecurity "信托三部" Filter "1" Filter "2"
CustomViewMake
"信托三部" DimensionView "部门维度" "信托三部"
SecurityObjectMake
'CAMID("Intrust:r:1")' SecurityNamespace "Intrust"
SecurityObjectDisplayName
"系统维护和管理人员" SecurityObjectType SecurityType_Role
CustomViewList
"信托一部" "信托二部" "信托三部" EndList
SecurityObjectMake
'CAMID("Intrust:r:1")' SecurityNamespace "Intrust"
SecurityObjectDisplayName
"系统维护和管理人员" SecurityObjectType SecurityType_Role
CustomViewList
"信托一部" "信托二部" "信托三部" EndList
SecurityObjectMake
'CAMID("Intrust:r:2")' SecurityNamespace "Intrust"
SecurityObjectDisplayName
"程序开发人员" SecurityObjectType SecurityType_Role
CustomViewList
"信托一部" "信托二部" "信托三部" EndList
SecurityObjectMake
'CAMID("Intrust:r:2")' SecurityNamespace "Intrust"
SecurityObjectDisplayName
"程序开发人员" SecurityObjectType SecurityType_Role
CustomViewList
"信托一部" "信托二部" "信托三部" EndList
SecurityObjectMake
'CAMID("Intrust:r:100")' SecurityNamespace "Intrust"
SecurityObjectDisplayName
"董事长" SecurityObjectType SecurityType_Role
CustomViewList
"信托一部" "信托二部" "信托三部" EndList
SecurityObjectMake
'CAMID("Intrust:r:100")' SecurityNamespace "Intrust"
SecurityObjectDisplayName
"董事长" SecurityObjectType SecurityType_Role
CustomViewList
"信托一部" "信托二部" "信托三部" EndList
SecurityObjectMake
'CAMID("Intrust:r:101")' SecurityNamespace "Intrust"
SecurityObjectDisplayName
"信托一部经理" SecurityObjectType SecurityType_Role
CustomViewList
"信托一部" EndList
SecurityObjectMake
'CAMID("Intrust:r:102")' SecurityNamespace "Intrust"
SecurityObjectDisplayName
"信托二部经理" SecurityObjectType SecurityType_Role
CustomViewList
"信托二部" EndList
SecurityObjectMake
'CAMID("Intrust:r:1")' SecurityNamespace "Intrust"
SecurityObjectDisplayName
"系统维护和管理人员" SecurityObjectType SecurityType_Role
CustomViewList
"信托一部" "信托二部" "信托三部" EndList
SecurityObjectMake
'CAMID("Intrust:r:2")' SecurityNamespace "Intrust"
SecurityObjectDisplayName
"程序开发人员" SecurityObjectType SecurityType_Role
CustomViewList
"信托一部" "信托二部" "信托三部" EndList
SecurityObjectMake
'CAMID("Intrust:r:100")' SecurityNamespace "Intrust"
SecurityObjectDisplayName
"董事长" SecurityObjectType SecurityType_Role
CustomViewList
"信托一部" "信托二部" "信托三部" EndList
PowerCubeCustomViewListUpdate Cube
"订单数据分析"
StartList
"信托一部" "信托二部" "信托三部"
ENDLIST

复制代码

四:操作步骤

1:使用Transform打开已经生成mdl命令的文件C:\\Users\\king\\Documents\\Transformer\\Models\\订单数据分析_update.mdl

2:如果报错如下

那么查看是否维度层级还没生成,部门下面无内容

Generate categories

再次查看,维度层级已经生成

再次打开

可以看到已经OK了,效果如下图,cube下面有对应custom view ,cust view中有access_table中每一个部门对应的所有角色

 

 

五:查看展示效果

5.1:用管理员登陆可以查看所有部门数据

5.2:用张三登陆可以查看其对应的信托一部的数据

六:思路概述

1:利用程序读出数据库中部门数量 ,生成对应个数的custom view,每一个custom view只给对应的部门ID授权

ViewMake "信托一部" Dimension "部门维度" ViewSecurity "信托一部" Filter "2" Filter "3" 
CustomViewMake "信托一部" DimensionView "部门维度" "信托一部"

2:根据每一个roleid的到所有授权的depart_name把所有已授权的depart都放到该角色的下面

SecurityObjectMake 'CAMID("Intrust:r:1")' SecurityNamespace "Intrust"
SecurityObjectDisplayName "系统维护和管理人员" SecurityObjectType SecurityType_Role
CustomViewList "信托一部" "信托二部" "信托三部" EndList

3:把所有custom view加入到cube中

PowerCubeCustomViewListUpdate Cube "订单数据分析"
StartList
"信托一部" "信托二部" "信托三部" 
ENDLIST

------------------------------------------------------------终,写于2015-2-13 17:20:59----------------------------------------------------------------------------------

推荐 7
本文由 kingwang 创作,采用 知识共享署名-相同方式共享 3.0 中国大陆许可协议 进行许可。
转载、引用前需联系作者,并署名作者且注明文章出处。
本站文章版权归原作者及原出处所有 。内容为作者个人观点, 并不代表本站赞同其观点和对其真实性负责。本站是一个个人学习交流的平台,并不用于任何商业目的,如果有任何问题,请及时联系我们,我们将根据著作权人的要求,立即更正或者删除有关内容。本站拥有对此声明的最终解释权。

1 个评论

写的好详细,图文并茂的,最近也在学习Cube这块,以后多多指教。

要回复文章请先登录注册