...
Code Block | ||
---|---|---|
| ||
* This method is used to add single data security rule to semantic model * * @param cubeIdsmodelId: is of semantic cubemodel * @throws ISecurityException, UnsupportedEncodingException * @throws ReportObjectException * @throws InterfaceInitException */ public static ResponseStatus addDataSecurityRule(String cubeIdsmodelId) throws ISecurityException, UnsupportedEncodingException, ReportObjectException, InterfaceInitException { // userInfo => get user info SecurityManager secMgr = SecurityManager.getInstance(); RepositoryManager rm = new RepositoryManager(); // get semantic cubemodel object in which rule is to be added. ReportObjectManager rom = new ReportObjectManager(); CubeObject co = (CubeObject) rom.getReportObject(Enums.IRO.TYPE.ANALYTICAL, cubeIdsmodelId, true, userInfo, Enums.IRO.SUBTYPE.CUBE); List<ColumnLevelSecurityField> columnFieldList = new ArrayList<>(); // will contain column level rule objects List<com.kyvos.commons.entity.olap.viewer.Filter> rowFilterList = new ArrayList<>(); // will contain row level // filter objects // create row level filters String rowFilterDimensionName = "Account-CR"; String rowFilterFieldName = "Account"; String rowFilterOperator = "IN_LIST"; String rowFilterValue = "Assets"; // create filter object. // For IN_LIST operator : public com.kyvos.commons.entity.olap.viewer.Filter // createRowLevelDimensionFilterByList(CubeObject cubeObject, String // dimensionName, String levelName, String operator, List<String> valuesList) // For BETWEEN operator : public com.kyvos.commons.entity.olap.viewer.Filter // createFilter(CubeObject cubeObject, String dimensionName, String levelName, // String operator, String firstValue, String secondValue) // For other operators: public com.kyvos.commons.entity.olap.viewer.Filter // createRowLevelDimensionFilter(CubeObject cubeObject, String dimensionName, // String levelName, String operator, String value) com.kyvos.commons.entity.olap.viewer.Filter rowFilter = secMgr.createRowLevelDimensionFilter(co, rowFilterDimensionName, rowFilterFieldName, rowFilterOperator.toUpperCase(), rowFilterValue); rowFilter.setRelation(Enums.FilterRelation.and); rowFilterList.add(rowFilter); // create column level field String columnDimensionName = ""; String columnFieldType = ""; String columnFieldName = ""; String columnRestriction = Enums.ColumnLevelSecurityRestriction.CONDITIONAL_MASK_DATA.name(); // create masking info object if restriction type is masking. Add filters if // conditional masking is used. List<com.kyvos.commons.entity.olap.viewer.Filter> columnFilterList = new ArrayList<>(); String filterDimensionName = ""; String filterFieldName = ""; String filterOperator = ""; String filterValue = ""; // create filter object in same way as for row level rules com.kyvos.commons.entity.olap.viewer.Filter colFilter = secMgr.createRowLevelDimensionFilter(co, filterDimensionName, filterFieldName, filterOperator.toUpperCase(), filterValue); colFilter.setRelation(Enums.FilterRelation.and); // for column level filters enclosures are supported colFilter.setStartEnclosure("("); colFilter.setEndEnclosure(")"); columnFilterList.add(colFilter); ColumnLevelSecurityMaskingInfo columnMaskingInfo = new ColumnLevelSecurityMaskingInfo( Enums.ColumnLevelSecurityMaskType.FIX, "*", "", columnFilterList); // get ColumnLevelSecurityField object // createColumnLevelField(CubeObject cubeObject, String dimensionName, String // fieldType, String fieldName, String restriction, // ColumnLevelSecurityMaskingInfo maskingInfo) throws ISecurityException { ColumnLevelSecurityField columnField = secMgr.createColumnLevelField(co, columnDimensionName, columnFieldType, columnFieldName, columnRestriction, columnMaskingInfo); columnFieldList.add(columnField); String ruleName = "testRule"; String ruleDescription = "desc"; // Add rule using Java API return secMgr.addDataSecurityRule(co, ruleName, ruleDescription, rowFilterList, columnFieldList, userInfo); } |
...
Code Block | ||
---|---|---|
| ||
** * This method is used to update single data security rule * * @param cubeIdsmodelId: is of cube * @param ruleName: name of rule to be updated * @throws ISecurityException, UnsupportedEncodingException * @throws ReportObjectException */ public static ResponseStatus updateDataSecurityRule(String cubeIdsmodelId, String ruleName) throws ISecurityException, UnsupportedEncodingException, ReportObjectException { // userInfo => get user info SecurityManager secMgr = SecurityManager.getInstance(); RepositoryManager rm = new RepositoryManager(); // get cubesemantic model object in which rule is to be added. ReportObjectManager rom = new ReportObjectManager(); CubeObject co = (CubeObject) rom.getReportObject(Enums.IRO.TYPE.ANALYTICAL, cubeIdsmodelId, true, userInfo, Enums.IRO.SUBTYPE.CUBE); DataSecurityRule rule = DataSecurityJavaAPI.getDataSecurityRule(cubeIdsmodelId, ruleName); if (rule == null) { return null; } List<ColumnLevelSecurityField> columnFieldList = new ArrayList<>(); // will contain column level rule objects List<com.kyvos.commons.entity.olap.viewer.Filter> rowFilterList = new ArrayList<>(); // will contain row level // filter objects // create row level filters String rowFilterDimensionName = ""; String rowFilterFieldName = ""; String rowFilterOperator = ""; String rowFilterValue = ""; // create filter object. // For IN_LIST operator : public com.kyvos.commons.entity.olap.viewer.Filter // createRowLevelDimensionFilterByList(CubeObject cubeObject, String // dimensionName, String levelName, String operator, List<String> valuesList) // For BETWEEN operator : public com.kyvos.commons.entity.olap.viewer.Filter // createFilter(CubeObject cubeObject, String dimensionName, String levelName, // String operator, String firstValue, String secondValue) // For other operators: public com.kyvos.commons.entity.olap.viewer.Filter // createRowLevelDimensionFilter(CubeObject cubeObject, String dimensionName, // String levelName, String operator, String value) com.kyvos.commons.entity.olap.viewer.Filter rowFilter = secMgr.createRowLevelDimensionFilter(co, rowFilterDimensionName, rowFilterFieldName, rowFilterOperator.toUpperCase(), rowFilterValue); rowFilter.setRelation(Enums.FilterRelation.and); rowFilterList.add(rowFilter); // create column level field String columnDimensionName = ""; String columnFieldType = ""; String columnFieldName = ""; String columnRestriction = Enums.ColumnLevelSecurityRestriction.CONDITIONAL_MASK_DATA.name(); // create masking info object if restriction type is masking. Add filters if // conditional masking is used. List<com.kyvos.commons.entity.olap.viewer.Filter> columnFilterList = new ArrayList<>(); String filterDimensionName = ""; String filterFieldName = ""; String filterOperator = ""; String filterValue = ""; // create filter object in same way as for row level rules com.kyvos.commons.entity.olap.viewer.Filter colFilter = secMgr.createRowLevelDimensionFilter(co, filterDimensionName, filterFieldName, filterOperator.toUpperCase(), filterValue); colFilter.setRelation(Enums.FilterRelation.and); // for column level filters enclosures are supported colFilter.setStartEnclosure("("); colFilter.setEndEnclosure(")"); columnFilterList.add(colFilter); ColumnLevelSecurityMaskingInfo columnMaskingInfo = new ColumnLevelSecurityMaskingInfo( Enums.ColumnLevelSecurityMaskType.FIX, "*", "", columnFilterList); ColumnLevelSecurityField columnField = secMgr.createColumnLevelField(co, columnDimensionName, columnFieldType, columnFieldName, columnRestriction, columnMaskingInfo); columnFieldList.add(columnField); String ruleDescription = "desc"; // update rule information rule.setColumnLevelFieldsList(columnFieldList); rule.setRowLevelFiltersList(rowFilterList); rule.setDescription(ruleDescription); return secMgr.updateDataSecurityRule(co, rule, userInfo); } |
...
Code Block | ||
---|---|---|
| ||
/** * method to get data security rule * * @param cubeIdsmodelId: idID of cubeSemantic Model * @param ruleName: name of rule to be deleted * @return object of type DataSecurityRule. * @throws ReportObjectException * @throws ISecurityException. */ public static DataSecurityRule getDataSecurityRule(String cubeIdsmodelId, String ruleName) throws ISecurityException, UnsupportedEncodingException, ReportObjectException { // userInfo => get user info SecurityManager secMgr = SecurityManager.getInstance(); // get semantic cubemodel object in which rule is applied. ReportObjectManager rom = new ReportObjectManager(); CubeObject cubeObject = (CubeObject) rom.getReportObject(Enums.IRO.TYPE.ANALYTICAL, cubeIdsmodelId, true, userInfo, Enums.IRO.SUBTYPE.CUBE); // java api to get data security rule return secMgr.getDataSecurityRule(cubeObject, ruleName, userInfo); } |
...
Code Block | ||
---|---|---|
| ||
/** * method to delete data security rule from semantic model of given semanitc model ID * * @param cubeIdsmodelId: ID idof ofsemantic cubemodel * @param ruleName: name of rule to be deleted * @return object of type ResponseStatus. * @throws ReportObjectException * @throws ISecurityException. */ public static ResponseStatus deleteDataSecurityRule(String cubeIdsmodelId, String ruleName) throws ISecurityException, UnsupportedEncodingException, ReportObjectException { // userInfo // get semantic cubemodel object in which rule is applied. ReportObjectManager rom = new ReportObjectManager(); CubeObject cubeObject = (CubeObject) rom.getReportObject(Enums.IRO.TYPE.ANALYTICAL, cubeIdsmodelId, true, userInfo, Enums.IRO.SUBTYPE.CUBE); SecurityManager secMgr = SecurityManager.getInstance(); // java api to delete single data security rule return secMgr.deleteDataSecurityRule(cubeObject, ruleName, userInfo); } |
...
Code Block | ||
---|---|---|
| ||
/** * method to add data security rules mapping for a user. * * @param cubeIdsmodelId: idID of semantic cubemodel * @return object of type ResponseStatus. * @throws ReportObjectException * @throws ISecurityException. */ public static ResponseStatus assignDataSecurityRulesToUser(String cubeIdsmodelId) throws ISecurityException, UnsupportedEncodingException, ReportObjectException { // userInfo // get cubesemantic model object in which rule is applied. ReportObjectManager rom = new ReportObjectManager(); CubeObject cubeObject = (CubeObject) rom.getReportObject(Enums.IRO.TYPE.ANALYTICAL, cubeIdsmodelId, true, userInfo, Enums.IRO.SUBTYPE.CUBE); SecurityManager secMgr = SecurityManager.getInstance(); // user to which rules are to be assigned String userName = "userName"; // set rules which are to be assigned to user List<String> ruleNames = new ArrayList<>(); ruleNames.add("testRule"); // java api to assign rules to user return secMgr.addDataSecurityRulesMappingForUser(cubeObject, userName, ruleNames, userInfo); } |
...
Code Block | ||
---|---|---|
| ||
/** * method to add data security rules mapping for a group. * * @param cubeObject: Object of type CubeObject. * @return object of type ResponseStatus. * @throws ReportObjectException * @throws ISecurityException. */ public static ResponseStatus assignDataSecurityRulesToGroup(String cubeIdsmodelId) throws ISecurityException, UnsupportedEncodingException, ReportObjectException { // userInfo // get semantic cubemodel object in which rule is applied. ReportObjectManager rom = new ReportObjectManager(); CubeObject cubeObject = (CubeObject) rom.getReportObject(Enums.IRO.TYPE.ANALYTICAL, cubeIdsmodelId, true, userInfo, Enums.IRO.SUBTYPE.CUBE); SecurityManager secMgr = SecurityManager.getInstance(); // group name to which rules are to be assigned String groupName = "TestGroup"; // rules names which are to be assigned to group List<String> ruleNames = new ArrayList<>(); ruleNames.add("testRule"); return secMgr.addDataSecurityRulesMappingForGroup(cubeObject, groupName, ruleNames, userInfo); } } |
...
Code Block | ||
---|---|---|
| ||
public class CubeAPI { String drdXML = ""; DRDObject sourceDRD = new DRDObject(drdXML); public static void createCubeWithDRD(DRDObject drdObj) throws UnsupportedEncodingException { CubeObject cubeObject = new CubeObject(drdObj, "API_CUBE_1_ID", "API_CUBE_1"); cubeObject.setFolderId(""); cubeObject.setFolderName(""); Dimension dim = cubeObject.addDimension("Transactions"); DimAttribute attr = dim.addDimAttribute("lineorder", "COLUMN13"); attr.setName("QUANTITY"); attr.setDataType("NUMBER"); attr = dim.addDimAttribute("lineorder", "COLUMN12"); attr.setName("DISCOUNT"); attr.setDataType("NUMBER"); dim = cubeObject.addDimension("Dates"); Hierarchy hierarchy = dim.addTimeHierarchy("H_Dates", "Y-M-D", "dates", "D_DATEKEY"); Level level = hierarchy.addLevel(hierarchy.getAssociatedQueryName(), hierarchy.getDataField()); level.setName("Year"); level.setDataType("DATE"); level.setDateDataType("Year"); level.setFormatType("4"); level = hierarchy.addLevel(hierarchy.getAssociatedQueryName(), hierarchy.getDataField()); level.setName("Month"); level.setDataType("DATE"); level.setDateDataType("Month"); level = hierarchy.addLevel(hierarchy.getAssociatedQueryName(), hierarchy.getDataField()); level.setName("Day"); level.setDataType("DATE"); level.setDateDataType("Day"); attr = dim.addDimAttribute("dates", "D_YEARMONTHNUM"); attr.setName("YEARMONTHNUM"); attr.setDataType("NUMBER"); attr = dim.addDimAttribute("dates", "D_WEEKNUMINYEAR"); attr.setName("D_WEEKNUMINYEAR"); attr.setDataType("NUMBER"); attr = dim.addDimAttribute("dates", "D_YEARMONTH"); attr.setName("D_YEARMONTH"); dim = cubeObject.addDimension("Parts"); hierarchy = dim.addHierarchy("H_Parts"); level = hierarchy.addLevel("part", "COLUMN3"); level.setName("MFGR"); level = hierarchy.addLevel("part", "COLUMN4"); level.setName("CATEGORY"); level = hierarchy.addLevel("part", "COLUMN5"); level.setName("BRAND1"); CalculatedMember member = new CalculatedMember(); member.setId("CalculatedMember1_ID"); member.setMemberName("CalculatedMember1"); member.setExpression("[Measures].[Profit]-20"); member.setParentMemberUname(hierarchy.getUniqueName()); member.setParentHierachy(hierarchy.getName()); member.setParentLevelMemb("ALLMEMBER"); member.setDescription("test description"); ArrayList<CalculatedMember> calculatedMembers = dim.getCalculatedMembers(); calculatedMembers.add(member); dim = cubeObject.addDimension("Supplier"); // Set materialize dim.setMaterialize("NO"); // Set SCD dim.setScd(null); // Set SCD TYPE dim.setSCDType(1); hierarchy = dim.addHierarchy("H_Supplier"); // Set materialize hierarchy.setMaterialize("NO"); level = hierarchy.addLevel("supplier", "COLUMN6"); level.setName("REGION"); level = hierarchy.addLevel("supplier", "COLUMN5"); level.setName("NATION"); level = hierarchy.addLevel("supplier", "COLUMN4"); level.setName("CITY"); dim = cubeObject.addDimension("Customer"); hierarchy = dim.addHierarchy("H_Customer"); level = hierarchy.addLevel("Customer", "COLUMN6"); level.setName("REGION"); level = hierarchy.addLevel("Customer", "COLUMN5"); level.setName("NATION"); level = hierarchy.addLevel("Customer", "COLUMN5"); level.setName("CITY"); // Set custom rollup level.setCustomrollup(null); cubeObject.addMeasureGroups("MeasureGroup"); Measure measure = cubeObject.addMeasureInMeasureGroup("lineorder", "Revenue", "MeasureGroup"); measure.setIsDefault(true); measure.setFormat("#,##0"); measure = cubeObject.addMeasureInMeasureGroup("lineorder", "COLUMN13", "MeasureGroup"); measure.setName("Lo_Revenue"); measure = cubeObject.addMeasureInMeasureGroup("lineorder", "Profit", "MeasureGroup"); measure = new Measure(); measure.setName("PROFIT-10"); measure.setType(Enums.CubeObject.Measure.Type.CALCULATED); measure.setSolveOrder(0); measure.setExpression("[Measures].[Profit]-10"); measure.setNonEmptyBehavior(Enums.CubeObject.Measure.NonEmptyBehavior.BY_EXPRESSION); cubeObject.addMeasureInMeasureGroup(measure, "MeasureGroup"); // Sliding Window SlidingWindow slidingWindow = new SlidingWindow(); slidingWindow.setSlidingWindowID("ID"); slidingWindow.setDimensionIdForPartition("DIM_ID"); slidingWindow.setHierarchyIdForPartition("HIERARCHY_ID"); slidingWindow.setLevelIdForPartition("LEVEL_ID"); slidingWindow.setPartitionField("LEVEL_NAME"); slidingWindow.setPartitionLength(1); slidingWindow.setTotalPartitions(2); slidingWindow.setTotalLength(3); slidingWindow.setAutoCalculatePartition(true); slidingWindow.setUnit("UNIT"); slidingWindow.setSlidingWindowEnabled(true); // subPartition ArrayList<SubPartition> subPartitions = new ArrayList<SubPartition>(); SubPartition subPartition = new SubPartition(); subPartition.setDimensionId("MyDimID"); subPartition.setLevelId("LEVEL_ID"); subPartition.setField("LEVEL_NAME"); subPartition.setHierarchyId("HIERARCHY_ID"); subPartitions.add(subPartition); slidingWindow.getOrderedSubpartitionDims().add(subPartition.getDimensionId()); slidingWindow.setSubPartitions(subPartitions); ArrayList<SlidingWindow> slidingWindowList = new ArrayList<SlidingWindow>(); slidingWindowList.add(slidingWindow); cubeObject.setSlidingWindows(slidingWindowList); // Aggregation Strategy // Add CONFIGURATION_DRIVEN Aggregation Strategy. ConfigurationBasedAggregatesStrategy configAggregatesStrategy = new ConfigurationBasedAggregatesStrategy(cubeObject.getId()); EntityProperty.EntityAdvanceProperty property = new EntityProperty.EntityAdvanceProperty(); property.setName("nameNode"); property.setValue("valueNode"); property.setRecommendedValue("recValueNode"); property.setSystemDefaultValue("sysDefaultValueNode"); property.setInheritedValue("inheritedValueNode"); property.setMode("MANUAL"); property.setRemarks("remarks"); Map<String, EntityProperty.EntityAdvanceProperty> configurationBasedPropMap = new HashMap<>(); configurationBasedPropMap.put(property.getName(), property); configAggregatesStrategy.setPropertiesMap(configurationBasedPropMap); cubeObject.setAggregatesStrategy(configAggregatesStrategy); // Add QUERY_DRIVEN Aggregation Strategy. QueryBasedAggregatesStrategy queryAggregatesStrategy = new QueryBasedAggregatesStrategy(cubeObject.getId()); queryAggregatesStrategy.setAggregatesID("aggregateIdNode"); queryAggregatesStrategy.setOrientationInfo("orientationInfoNode"); queryAggregatesStrategy.setAggregateCount("aggregatesCountNode"); queryAggregatesStrategy.setLastAcceptedTime("lastAcceptedTimeNode"); queryAggregatesStrategy.setLastQueryCount("lastQueryCount"); queryAggregatesStrategy.setLastQueryConsiderationTime("lastQueryConsiderationTimeNode"); cubeObject.setAggregatesStrategy(queryAggregatesStrategy); // SET Raw data querying cubeObject.setAllowRawDataQuery(Enums.SQLRawDataQueryingModes.ENABALED); String params = "cubeXMLsmodelXML="+URLEncoder.encode(cubeObject.getXML(), java.nio.charset.StandardCharsets.UTF_8.toString()); System.out.println(RESTClient.sendRequest("cubessmodels", params, "POST")); } public static void createCubeWithoutDRD() throws UnsupportedEncodingException { CubeObject cubeObject = new CubeObject(); cubeObject.setId("CUBE_OBJECT_16618824042"); cubeObject.setName("test_cube_1_2222"); cubeObject.setFolderId("folder_16520830348231127029020129312845"); cubeObject.setFolderName(""); cubeObject.setDRDBasedCube(true); cubeObject.setDrdID("DRD_14641110707932127044085187784961"); cubeObject.setDrdName("Dell_Sample"); Dimension dim = new Dimension(); dim.setName("Product"); dim.setUniqueName("DIM_632407_1"); dim.setDimID("DIM_632407_1"); dim.setType("Regular"); Hierarchy hierarchy = new Hierarchy(); hierarchy.setUniqueName("H_514877_1"); hierarchy.setName("H_Product"); Level level = new Level(); level.setDataField("Product_Category"); level.setName("Product_Category"); level.setDataType("CHAR"); level.setAssociatedDimQueryName("SampleDell"); level.setAssociatedDimQueryId("14641108622483127092051153919832_0"); level.setUniqueName("DIMENSION_ATTRIBUTE_410611_1"); hierarchy.addLevel(level); dim.addHierarchy(hierarchy); dim.addDimAttribute(null, null); cubeObject.addMeasureGroups("MeasureGroup"); Measure measure = new Measure(); measure.setName("Sale_Amount"); measure.setDataField("Sale_Amount"); measure.setQueryName("SampleDell"); measure.setQueryID("14641108622483127092051153919832_0"); measure.setDataType("NUMBER"); measure.setSummaryFunction("0"); measure.setFormat("#,##0.00"); measure.setFormatType("2"); measure.setIsDefault(true); cubeObject.addMeasureInMeasureGroup(measure, "MeasureGroup"); cubeObject.addDimension(dim); String params = "cubeXMLsmodelXML="+URLEncoder.encode(cubeObject.getXML(), java.nio.charset.StandardCharsets.UTF_8.toString()); System.out.println(RESTClient.sendRequest("cubessmodels", params, "POST")); } |
Updating a semantic model
Code Block | ||
---|---|---|
| ||
public static void updateCube(String cubeIdsmodelId) throws UnsupportedEncodingException { CubeObject co = new CubeObject(getCubeObject(cubeIdsmodelId, null, null)); // get dimension list, iterate and get all dimensions. // dimensions cab be modified now. // dimensions cab also be removed from list. ArrayList<Dimension> dimensions = co.getDimensions(); Dimension dim1 = dimensions.get(0); // get hierarchy and it can be modified. Hierarchy hierarchy = dim1.getHierarchy(); // get level list, iterate and get all levels. // levels cab be modified now. // levels cab also be removed from list. ArrayList<Level> levels = hierarchy.getLevels(); // get attribute list, iterate and get all attributes. // attributes cab be modified now. // attributes cab also be removed from list. ArrayList<DimAttribute> attributes = dim1.getDimAttributes(); // get calculated member list, iterate and get all calculated members. // calculated members cab be modified now. // calculated members cab also be removed from list. ArrayList<CalculatedMember> calcMembers = dim1.getCalculatedMembers(); // below methods can be used to update measures. co.getMeasureById("measureid"); co.getMeasureByName("measureName"); co.removeMeasureByUniqName("measureId"); Map<String , Measure> measures = co.getMeasures(); for(String measureName: measures.keySet()) { System.out.println(measureName); Measure measure = measures.get(measureName); System.out.println(measure.getXML()); } // Working with sliding windows. ArrayList<SlidingWindow> slidingWindows = co.getSlidingWindows(); IAggregatesStrategy aggregatesStrategy = co.getAggregatesStrategy(); // check aggregation strategy class. if (aggregatesStrategy instanceof QueryBasedAggregatesStrategy) { QueryBasedAggregatesStrategy queryBasedAggregatesStrategy = (QueryBasedAggregatesStrategy) aggregatesStrategy; } else if (aggregatesStrategy instanceof ConfigurationBasedAggregatesStrategy) { ConfigurationBasedAggregatesStrategy configurationBasedAggregatesStrategy = (ConfigurationBasedAggregatesStrategy) aggregatesStrategy; } // finally update the cubesemantic model object. String params = "cubeXMLsmodelXML="+URLEncoder.encode(co.getXML(), java.nio.charset.StandardCharsets.UTF_8.toString()); RESTClient.sendRequest("cubessmodels/"+co.getId(), params, "PUT"); } |
...