今天是农历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<Department>   GetDepartment() 无参数 得到所有的部门,每一个部门对应一个custom view
public String GetFilterStr(int departid) departid-部门id 根据具体部门过滤掉其他部门的权限
public ArrayList<AccessTable>   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方法

  1. public String GetDepartForRole(int roleid) throws ClassNotFoundException, SQLException
  2. {
  3. Connection con=new GetCon().getcon_king();
  4. Statement stm=con.createStatement();
  5. ResultSet rs=stm.executeQuery("select * from access_table where role_id="+roleid);
  6. ArrayList<AccessTable> list=new ArrayList<AccessTable>();
  7. while(rs.next())
  8. {
  9. AccessTable at=new AccessTable();
  10. at.setRole_id(rs.getInt(1));
  11. at.setDepart_id(rs.getInt(2));
  12. at.setRole_name(rs.getString(3));
  13. at.setDepart_name(rs.getString(4));
  14. list.add(at);
  15. }
  16. System.out.println("lietsize:"+list.size());
  17. if(list.size()>0)
  18. {
  19. for(int i=0;i<list.size();i++)
  20. {
  21. for(int j=0;j<list.size()-1;j++)
  22. {
  23. if(list.get(j).getRole_id()==list.get(j+1).getRole_id())
  24. {
  25. list.get(j).setDepart_name(list.get(j).getDepart_name()+'"'+" "+'"'+list.get(j+1).getDepart_name());
  26. list.remove(j+1);
  27. }
  28. }
  29. }
  30.  
  31. }
  32.  
  33. return list.get(0).getDepart_name();
  34. }

update_customview方法

  1. public void update_customview
  2. (String cubename,String targetmodel,String dimension,String filename,String namespacename,String namespaceid ) throws IOException, ClassNotFoundException, SQLException
  3. {
  4.  
  5. QueryUtil qu=new QueryUtil();//创建工具类
  6. FileOutputStream fos=new FileOutputStream(filename,true);//定义一个字符输出流,True表示在文件尾部追加
  7. qu.clearfile(filename);//先清空
  8. String mdlpath="OpenMDL"+" "+'"'+targetmodel+'"'; //定义一个要修改custom view 的mdl文件的位置
  9. String namespace="SecurityNameSpaceMake"+" "+'"'+namespacename+'"'+" "+"SecurityNamespaceCAMID"+" "+"'"+"CAMID"+"("+'"'+namespaceid+'"'+")"+"'";//指定第三方人中空间的名称和ID
  10. fos.write(mdlpath.getBytes());//输出到filename中,下文不再多说
  11. fos.write("\r\n".getBytes());//换行,下文不再多说
  12. fos.write(namespace.getBytes());
  13. fos.write("\r\n".getBytes());
  14. ArrayList<Department> list=qu.GetDepartment(); //从数据库中读出所有Department
  15. for(int i=0;i<list.size();i++)
  16. {
  17. Department d=new Department();
  18. d=list.get(i);
  19. //循环输出为每一个维度值创建custom view,同时采用Filter过滤掉其他维度值
  20. String str3="ViewMake"+" "+'"'+d.getDepart_name()+'"'+" "+"Dimension"+" "+'"'+dimension+'"'+" "+"ViewSecurity"+" "+
  21. '"'+d.getDepart_name()+'"'+" "+qu.GetFilterStr(d.getDepart_id());
  22. String str4="CustomViewMake"+" "+'"'+d.getDepart_name()+'"'+" "+"DimensionView"+" "+'"'+dimension+'"'+" "+
  23. '"'+d.getDepart_name()+'"';
  24. //对应的view写入文件
  25. fos.write(str3.getBytes());
  26. fos.write("\r\n".getBytes());
  27. fos.write(str4.getBytes());
  28. fos.write("\r\n".getBytes());
  29. }
  30. ArrayList<AccessTable> list1=qu.GetAccessRole(); //从数据库中读出所有Department
  31. for(int h=0;h<list1.size();h++)
  32. {
  33. AccessTable at=new AccessTable();
  34. at=list1.get(h);
  35. //循环把每一个角色添加到对应的custom view,一个角色可以对应多个custom view,建信需求是把部门作为角色来用
  36. String str5="SecurityObjectMake"+" "+"'CAMID("+'"'+namespaceid+":r:"+""+at.getRole_id()+'"'+")"+"'"+" "+"SecurityNamespace"+" "+'"'+namespaceid+'"';
  37. String str6="SecurityObjectDisplayName"+" "+'"'+at.getRole_name()+'"'+" "+"SecurityObjectType"+" "+"SecurityType_Role";
  38. String str7="CustomViewList"+" "+'"'+qu.GetDepartForRole(at.getRole_id())+'"'+" "+"EndList";
  39. fos.write(str5.getBytes());
  40. fos.write("\r\n".getBytes());
  41. fos.write(str6.getBytes());
  42. fos.write("\r\n".getBytes());
  43. fos.write(str7.getBytes());
  44. fos.write("\r\n".getBytes());
  45. }
  46.  
  47. String str8="PowerCubeCustomViewListUpdate"+" "+"Cube"+" "+'"'+cubename+'"';
  48. String str9="StartList";
  49. String str10="";
  50. String str11="ENDLIST";
  51.  
  52. //得到所有的viewname
  53. for(int k=0;k<list.size();k++)
  54. {
  55. Department d=new Department();
  56. d=list.get(k);
  57. str10=str10+'"'+d.getDepart_name()+'"'+" ";
  58. }
  59. fos.write(str8.getBytes());
  60. fos.write("\r\n".getBytes());
  61. fos.write(str9.getBytes());
  62. fos.write("\r\n".getBytes());
  63. fos.write(str10.getBytes());
  64. fos.write("\r\n".getBytes());
  65. fos.write(str11.getBytes());
  66. fos.write("\r\n".getBytes());
  67. fos.close();//流要及时关闭
  68. System.err.print("write is ok!");
  69. }

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文件效果

  1. OpenMDL "C:\Users\king\Documents\Transformer\Models\订单数据分析.mdl"
  2. SecurityNameSpaceMake "Intrust" SecurityNamespaceCAMID 'CAMID("Intrust")'
  3. ViewMake "信托一部" Dimension "部门维度" ViewSecurity "信托一部" Filter "" Filter ""
  4. CustomViewMake "信托一部" DimensionView "部门维度" "信托一部"
  5. ViewMake "信托二部" Dimension "部门维度" ViewSecurity "信托二部" Filter "" Filter ""
  6. CustomViewMake "信托二部" DimensionView "部门维度" "信托二部"
  7. ViewMake "信托三部" Dimension "部门维度" ViewSecurity "信托三部" Filter "" Filter ""
  8. CustomViewMake "信托三部" DimensionView "部门维度" "信托三部"
  9. SecurityObjectMake 'CAMID("Intrust:r:1")' SecurityNamespace "Intrust"
  10. SecurityObjectDisplayName "系统维护和管理人员" SecurityObjectType SecurityType_Role
  11. CustomViewList "信托一部" "信托二部" "信托三部" EndList
  12. SecurityObjectMake 'CAMID("Intrust:r:1")' SecurityNamespace "Intrust"
  13. SecurityObjectDisplayName "系统维护和管理人员" SecurityObjectType SecurityType_Role
  14. CustomViewList "信托一部" "信托二部" "信托三部" EndList
  15. SecurityObjectMake 'CAMID("Intrust:r:2")' SecurityNamespace "Intrust"
  16. SecurityObjectDisplayName "程序开发人员" SecurityObjectType SecurityType_Role
  17. CustomViewList "信托一部" "信托二部" "信托三部" EndList
  18. SecurityObjectMake 'CAMID("Intrust:r:2")' SecurityNamespace "Intrust"
  19. SecurityObjectDisplayName "程序开发人员" SecurityObjectType SecurityType_Role
  20. CustomViewList "信托一部" "信托二部" "信托三部" EndList
  21. SecurityObjectMake 'CAMID("Intrust:r:100")' SecurityNamespace "Intrust"
  22. SecurityObjectDisplayName "董事长" SecurityObjectType SecurityType_Role
  23. CustomViewList "信托一部" "信托二部" "信托三部" EndList
  24. SecurityObjectMake 'CAMID("Intrust:r:100")' SecurityNamespace "Intrust"
  25. SecurityObjectDisplayName "董事长" SecurityObjectType SecurityType_Role
  26. CustomViewList "信托一部" "信托二部" "信托三部" EndList
  27. SecurityObjectMake 'CAMID("Intrust:r:101")' SecurityNamespace "Intrust"
  28. SecurityObjectDisplayName "信托一部经理" SecurityObjectType SecurityType_Role
  29. CustomViewList "信托一部" EndList
  30. SecurityObjectMake 'CAMID("Intrust:r:102")' SecurityNamespace "Intrust"
  31. SecurityObjectDisplayName "信托二部经理" SecurityObjectType SecurityType_Role
  32. CustomViewList "信托二部" EndList
  33. SecurityObjectMake 'CAMID("Intrust:r:1")' SecurityNamespace "Intrust"
  34. SecurityObjectDisplayName "系统维护和管理人员" SecurityObjectType SecurityType_Role
  35. CustomViewList "信托一部" "信托二部" "信托三部" EndList
  36. SecurityObjectMake 'CAMID("Intrust:r:2")' SecurityNamespace "Intrust"
  37. SecurityObjectDisplayName "程序开发人员" SecurityObjectType SecurityType_Role
  38. CustomViewList "信托一部" "信托二部" "信托三部" EndList
  39. SecurityObjectMake 'CAMID("Intrust:r:100")' SecurityNamespace "Intrust"
  40. SecurityObjectDisplayName "董事长" SecurityObjectType SecurityType_Role
  41. CustomViewList "信托一部" "信托二部" "信托三部" EndList
  42. PowerCubeCustomViewListUpdate Cube "订单数据分析"
  43. StartList
  44. "信托一部" "信托二部" "信托三部"
  45. 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----------------------------------------------------------------------------------

基于java语言的给cube添加custom view来实现权限控制的更多相关文章

  1. JFinal -基于Java 语言的MVC极速 web 开发框架

    JFinal概述 JFinal 是基于Java 语言的极速 web 开发框架,其核心设计目标是开发迅速.代码量少.学习简单.功能强大.轻量级.易扩展.Restful.在拥有Java语言所有优势的同时再 ...

  2. 基于JAVA语言的多线程技术

    1.简介 多线程技术属于操作系统范围内的知识: 进程与线程 可以这么理解,一个应用程序就是一个进程,在一个进程中包含至少一个线程:进程就是线程的容器,真正工作.处理任务的是线程. 进程是操作系统分配资 ...

  3. 基于Java语言开发jt808、jt809技术文章精华索引

    很多技术开发人员喜欢追逐最新的技术,如Node.js, go等语言,这些语言只是解决了某一个方面,如只是擅长异步高并发等等,却在企业管理后台开发方面提供的支持非常不够,造成项目团队技术选项失败,开发后 ...

  4. 单循环链表(基于java语言)

    public class CircleSinglyLinkList { private Node head; CircleSinglyLinkList(){ this.head = null; } C ...

  5. 【SpringSecurity系列1】基于SpringSecurity实现前后端分离无状态Rest API的权限控制

    源码传送门: https://github.com/ningzuoxin/zxning-springsecurity-demos/tree/master/01-springsecurity-state ...

  6. 《神经网络算法与实现-基于Java语言》的读书笔记

    文章提纲 全书总评 读书笔记 C1.初识神经网络 C2.神经网络是如何学习的 C3.有监督学习(运用感知机) C4.无监督学习(自组织映射) Rreferences(参考文献) 全书总评 书本印刷质量 ...

  7. Selenium(基于JAVA语言)-》在eclipse上运行web项目在Mac系统上启动时提示nodename nor servname provided解决办法

    最近使用eclipse进行自动化测试时,遇到一种情况,无法调起浏览器,且有报错,如下: org.openqa.selenium.WebDriverException: failed to lookup ...

  8. 基于JAVA语言的selenium测试基础总结

    目录一.基本语句1.循环控制(break,continue)3.字符的替换(replace,repalceFirst,replaceAll,regex)4.字符串的连接("+",a ...

  9. 基于JAVA语言的selenium总结

    目录一.基本语句 1.循环控制(break,continue) 3.字符的替换(replace,repalceFirst,replaceAll,regex) 4.字符串的连接("+" ...

随机推荐

  1. 2017年浙江中医药大学大学生程序设计竞赛(重现赛)D - CC的神奇背包

    题目描述 cc最近收到了好多礼物,对着满地大小不一的礼物,她想要一个包来装,于是dd就掏出了一个会说话的神奇背包给cc装礼物.cc为了一次性装尽可能多的礼物,于是跟这个背包定下了一个规则,对每个礼物, ...

  2. 初识GeneXus产品

    本人由于工作原因接触了GeneXus产品,从使用到现在也有些年头了.从刚开始的不熟悉到现在使用GeneXus开发了很多项目,慢慢也总结了一些经验,当然中间也走了很多的弯路.对于在国内同样使用GeneX ...

  3. Django 如何实现 如下 联表 JOIN 查询?

    SQL语句: select distinct a.device_hash, sum(b.cmn_merge_count) from (select distinct device_hash from ...

  4. 【BZOJ 4031】 4031: [HEOI2015]小Z的房间 (Matrix-Tree Theorem)

    4031: [HEOI2015]小Z的房间 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 1089  Solved: 533 Description ...

  5. 前缀和:CodeForces 932B Recursive Queries

    Description Let us define two functions f and g on positive integer numbers. You need to process Q q ...

  6. 【树形DP】BZOJ1040-[ZJOI2008]骑士

    [题目大意] 有n个骑士,给出他们的能力值和最痛恨的一位骑士.选出一个骑士军团,使得军团内没有矛盾的两人(不存在一个骑士与他最痛恨的人一同被选入骑士军团的情况),并且,使得这支骑士军团最具有战斗力,求 ...

  7. 升级到php7和安装拓展(mac centos)

    Mac升级到php7 使用homebrew安装php7 brew update #更新源 brew search php #查找源中的php,发现有php7.1版本,安装最新的php7.1 brew ...

  8. java开发_mysql中获取数据库表描述_源码下载

    功能描述: 在mysql数据库中,有两张表: data_element_config , test_table 我们需要获取表:test_table表的描述信息,然后把描述信息插入到表:data_el ...

  9. asp.net url传值,弹窗

    一,<a>标签链接式传值 1, <a href="News_list.aspx?ClassID=<%#((DataRowView)Container.DataItem ...

  10. Codeforces Round #303 (Div. 2) A. Toy Cars 水题

     A. Toy Cars Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/545/problem ...