Cognos Transfomer 权限自动化

最近一次偶然的机会,需要实现cognos mdl权限自动化,创建customer view ,赋权限,生成权限mdl,花了一点时间整理了一下,记录一下代码:主要参考 IBM Cognos Transfomer  Developer Guide.

主要用到的以下方法:

SecurityNameSpaceMake
ViewMake
UserClassMake
SecurityObjectMake

实现思路:从配制文件里读取mdlpath, db信息,实现可配制化,上代码:

import pymysql   #my sql 里存在所有的视图角色信息,权限维度等信息
import configparser
#读取文件内容
config = configparser.ConfigParser()  # 创建对象
config.read("mdlbatchfile", encoding='UTF-8')
# 读取db信息
host = config.get('dbconfig', 'host')
user = config.get('dbconfig', 'user')
pwd = config.get('dbconfig', 'pwd')
dbname = config.get('dbconfig', 'dbname')
port = int(config.get('dbconfig', 'port'))
# 读取 mdl 信息
mdlpath = config.get('mdlconfig', 'mdlpath')
mdlSavePath = config.get('mdlconfig', 'mdlSavePath')
mdl_batch_list = config.get('mdlconfig', 'mdl_batch_list')
SecurityNamespace = config.get('mdlconfig', 'SecurityNamespace')
# 取权限列表
agency_sql = config.get('sqlconfig', 'agency_sql')
#读取角色信息
role_sql = config.get('sqlconfig', 'role_sql')
#print(mdl_batch_list)
#读取transformer 所在路径
cogtrPath = config.get('cogtrPath', 'cogtrPath')

#连接数据库取相应的权限角色信息
db = pymysql.connect(host = host,user=user,password=pwd,port = port,database=dbname)
cursor = db.cursor()
cursor.execute(agency_sql)
results = cursor.fetchall()
cursor.execute(role_sql)
result_role = cursor.fetchall()
print(mdlSavePath+'/batchfile.bat')

fo_batch = open(mdlSavePath+'/batchfile.bat','w', encoding='UTF-8')
print('cd \"'+cogtrPath +'>\"')
fo_batch.writelines('cd \"'+cogtrPath +'>\"\n' )

for mdlname in mdl_batch_list.split(','):
    mdlfullpath_var=mdlSavePath+'/'+mdlname+'_s.mdl'
    mdlpath_var = mdlpath+'/'+mdlname+'.mdl'
    #print(mdlname)
    #print('mdlpath:',mdlpath)
    # 生成单独的文件
    print(mdlpath_var.replace('/','\\'))
    fo_batch.writelines('cogtr.exe  -c -n2 -s  -m \"' + mdlfullpath_var + '\"\n')  #生成刷新文件
    fo = open(mdlfullpath_var, 'w', encoding='UTF-8')
    fo.writelines("OpenMDL "+'"' +mdlpath_var.replace('/','\\') +'"' +'\n')
    fo.writelines('SecurityNameSpaceMake '+ '\"'+SecurityNamespace+ '\"'+' SecurityNamespaceCAMID '+ '\'CAMID (\"'+SecurityNamespace+'\")\''+'\n')
    fo.write('\n')
    #fo.writelines(mdlpath+'/'+mdlname+'.mdl'+'\n')
    concatstr = ''
    for row in results:
        row_str = 'ViewMake  \"ComcodeViewA' + str(row[0]) + '\"  Dimension "org" ViewUserClass ' + "\"" + str(row[0]) + "\" Apex \""+str(row[0])+'\"'
        row_str1 = 'UserClassMake \"' + str(row[0]) + '\"  DimensionView "org"  ' + "\"" + 'ComcodeViewA' + str(
            row[0]) + "\""
        fo.write(row_str + '\n')
        fo.write(row_str1 + '\n')
        fo.write('\n')
        concatstr = concatstr + "\""+str(row[0])+"\""+'  '
    for row in result_role:

        row_str ='SecurityObjectMake \'CAMID(\"'+SecurityNamespace+':r:'+str(row[0])+'\")\''\
                 +' SecurityNamespace \"' +SecurityNamespace+'\" SecurityObjectDisplayName \"'+str(row[1])\
                 +'\" SecurityObjectType'
        endstr ='SecurityType_Role CustomViewList \"'+str(row[1])+'\" EndList'
        fo.write(row_str+ '\n')
        fo.write(endstr+ '\n')
        fo.write('\n')

        #print(row_str)
        #print(endstr)
    fo.write('PowerCubeUserListUpdate Cube ' + "\"" + mdlname + "\"" + ' StartList  ' + concatstr + 'EndList \n')
    fo.write('SaveMDL' + '"' + mdlfullpath_var.replace('.mdl','_s.mdl')  + '"')
fo_batch.writelines('echo ok&pause')
fo_batch.close()
fo.close()
db.close()
print('success')

生成的结果图

第一次写代码,考虑不全,欢迎大家提意见。

Cognos Transformer是IBM Cognos Business Intelligence套件中的一个组件,用于创建和维护多维数据模型。它允许用户从各种数据源中提取、转换和加载数据,并将其组织成多维数据模型,以便进行复杂的分析和报表生成。 以下是Cognos Transformer的一些常见操作和功能: 1. 配置服务器地址:打开IBM Cognos Transformer Configuration,可以配置连接到Cognos服务器的地址。 2. 创建数据模型:使用Cognos Transformer可以从各种数据源中提取数据,并将其转换为多维数据模型。用户可以定义维度、层次结构、度量和计算等。 3. 定义维度和层次结构:在Cognos Transformer中,可以定义维度和层次结构,以便在多维数据模型中组织和分析数据。 4. 数据转换和加载:Cognos Transformer提供了强大的数据转换和加载功能,可以对数据进行清洗、转换和加载到多维数据模型中。 5. 条件格式:在Cognos Transformer中,可以使用条件格式来定义数据项的显示样式。可以根据特定的条件为数据项指定不同的格式,以便更好地展示数据。 6. 字符串变量:Cognos Transformer支持使用字符串变量来定义条件格式。可以创建字符串变量,并根据特定的条件为变量赋值和指定格式。 7. 报表生成:通过Cognos Transformer创建的多维数据模型可以用于生成复杂的报表和分析。用户可以使用Cognos Report Studio等工具来创建报表和分析。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值