[saiku] 系统登录成功后查询Cubes
一、系统启动时初始化ds和conn
1、查询出目前系统拥有的Datasources和Connections放入内存中
2、比对saiku-datasources中的ds是否有新增的,如果有,创建新的ds
二、登陆授权成功后获取全部的Connections
1、查询OLAP数据连接(cubesConnectionList)列表 http://localhost:8080/saiku/rest/saiku/a1/discover OlapDiscoverResource - getConnections() 2、根据单个 connection 解析出 catalog schema cube【SessionWorkspace.js】 var connection = this.connections[i]; var catalog = connection.catalogs[j]; var schema = catalog.schemas[k]; var cube = schema.cubes[l]; 3、拼凑成交互ID - key 根据这个ID去 new Cube({ key: key })【SessionWorkspace.js】 var key = connection.name + "/" + catalog.name + "/" + ((schema.name === "" || schema.name === null) ? "null" : schema.name) + "/" + encodeURIComponent(cube.name); 至此就完成了获取connections的操作
三、获取repositoryList(仓库列表)
http://localhost:8080/saiku/rest/saiku/api/repository?type=saiku,sdb BasicRepositoryResource2 - getRepository()
返回的 repositoryList 如下:
ID NAME TYPE ACL #/datasources datasources FOLDER [READ, WRITE] #/etc etc FOLDER [READ, WRITE] #/etc/legacyreports legacyreports FOLDER [READ, WRITE] #/etc/theme theme FOLDER [READ, WRITE] #/etc/theme/legacyreports legacyreports FOLDER [READ, WRITE] #/homes homes FOLDER [READ] #/homes/home:a1 home:a1 FOLDER [READ, WRITE, GRANT]
四、获取license
http://localhost:8080/saiku/rest/saiku/api/license
五、查询Cube
查询思路剖析:
通过第二步可知已经得到了connection的信息和拼凑了key[交互ID] 执行 new Cube({key:key}) 调用接口获取Cube内容 前端请求url : Saiku.session.username + "/discover/" + args.key + "/metadata"; 后端处理的方法: OlapDiscoverResource - getMetadata() 后端rest接口所需参数 : @Path("/saiku/{username}/discover") + @Path("/{connection}/{catalog}/{schema}/{cube}/metadata") + key参数 调用成功后返回的Model: SaikuCubeMetadata |-dimensions |-measures |-properties
附后台处理代码: @GET @Produces({"application/json" }) @Path("/{connection}/{catalog}/{schema}/{cube}/metadata") public SaikuCubeMetadata getMetadata( @PathParam("connection") String connectionName, @PathParam("catalog") String catalogName, @PathParam("schema") String schemaName, @PathParam("cube") String cubeName) { if ("null".equals(schemaName)) { schemaName = ""; } //获取Cube SaikuCube cube = new SaikuCube(connectionName, cubeName,cubeName,cubeName, catalogName, schemaName); try { //根据Cube获取 dimensions/measures/properties List<SaikuDimension> dimensions = olapDiscoverService.getAllDimensions(cube); List<SaikuMember> measures = olapDiscoverService.getMeasures(cube); Map<String, Object> properties = olapDiscoverService.getProperties(cube); return new SaikuCubeMetadata(dimensions, measures, properties); } catch (Exception e) { log.error(this.getClass().getName(),e); } return new SaikuCubeMetadata(null, null, null); }
获取到的DEMO中的所有CUBE如下 参数分别是: {connectionName} {catalogName} {schemaName} {cubeName} (1)Earthquakes /earthquakes /Global%20Earthquakes /Global%20Earthquakes /Earthquakes http://localhost:8080/saiku/rest/saiku/a1/discover/earthquakes/Global%20Earthquakes/Global%20Earthquakes/Earthquakes/metadata?key=earthquakes%2FGlobal+Earthquakes%2FGlobal+Earthquakes%2FEarthquakes (2)HR /foodmart /FoodMart /FoodMart /HR http://localhost:8080/saiku/rest/saiku/a1/discover/foodmart/FoodMart/FoodMart/HR/metadata?key=foodmart%2FFoodMart%2FFoodMart%2FHR (3)Sales /foodmart /FoodMart /FoodMart /Sales http://localhost:8080/saiku/rest/saiku/a1/discover/foodmart/FoodMart/FoodMart/Sales/metadata?key=foodmart%2FFoodMart%2FFoodMart%2FSales (4)Sales%202 /foodmart /FoodMart /FoodMart /Sales%202 http://localhost:8080/saiku/rest/saiku/a1/discover/foodmart/FoodMart/FoodMart/Sales%202/metadata?key=foodmart%2FFoodMart%2FFoodMart%2FSales%25202 (5)Sales%202 /foodmart /FoodMart /FoodMart /Store http://localhost:8080/saiku/rest/saiku/a1/discover/foodmart/FoodMart/FoodMart/Store/metadata?key=foodmart%2FFoodMart%2FFoodMart%2FStore (6)Warehouse /foodmart /FoodMart /FoodMart /Warehouse http://localhost:8080/saiku/rest/saiku/a1/discover/foodmart/FoodMart/FoodMart/Warehouse/metadata?key=foodmart%2FFoodMart%2FFoodMart%2FWarehouse (7)Warehouse%20and%20Sales /foodmart /FoodMart /FoodMart /Warehouse%20and%20Sales http://localhost:8080/saiku/rest/saiku/a1/discover/foodmart/FoodMart/FoodMart/Warehouse%20and%20Sales/metadata?key=foodmart%2FFoodMart%2FFoodMart%2FWarehouse%2520and%2520Sales