Applies to: Kyvos Enterprise Kyvos Cloud (SaaS on AWS) Kyvos AWS Marketplace
Kyvos Azure Marketplace Kyvos GCP Marketplace Kyvos Single Node Installation (Kyvos SNI)
Here are some sample codes to help you use REST and Java APIs for working with Kyvos entities.
Adding new user group in Kyvos
/**Method to add new group in Kyvos*/ public static void addGroup(String groupName) throws UnsupportedEncodingException { UserGroup group = new UserGroup(); group.setGroupName(groupName); group.setUserGroupId(groupName); group.setDescription("test Group"); group.setRole("0"); group.setGroupType(UserAuthType.NATIVE); group.setUserIds(new String[]{""}); System.out.println(group.getXML()); String params = "groupXML="+URLEncoder.encode(group.getXML(), java.nio.charset.StandardCharsets.UTF_8.toString()); RESTClient.sendRequest("group", params, "POST");
Updating user group in Kyvos
/**Method to update a group in Kyvos*/ public static void updateGroup(String groupName) throws UnsupportedEncodingException { String groupXML = RESTClient.sendRequest("group/"+groupName+"?addResponseTag=false", null, "GET"); System.out.println(groupXML); UserGroup group = new UserGroup(groupXML); System.out.println(group.getXML()); group.setUserIds(new String[]{"", ""}); String params = "groupXML="+URLEncoder.encode(group.getXML(), java.nio.charset.StandardCharsets.UTF_8.toString()); RESTClient.sendRequest("group/"+group.getGroupName(), params, "PUT");
Creating new relationship design
/**Method to create a fresh DRD*/ public static void createDRD() throws Exception { String RF_1_ID = ""; String RF_2_ID = ""; DRDObject drdObject = new DRDObject(); drdObject.setViewType(Enums.DRDViewType.TABULAR); drdObject.setName(""); drdObject.setId(Utility.getGUID()); drdObject.setFolderName(""); drdObject.setFolderId(""); // Creating DRD Node using registered file id DRDObject.DRDDatasetDetails node1 = new DRDObject.DRDDatasetDetails(); node1.setId(RF_1_ID); node1.setAliasName("NODE_NAME_1"); drdObject.addNode("NODE_ID_1", node1); DRDObject.DRDDatasetDetails node2 = new DRDObject.DRDDatasetDetails(); node2.setId(RF_2_ID); node2.setAliasName("NODE_NAME_2"); drdObject.addNode("NODE_ID_2", node2); DRDRelation drdRelation = new DRDRelation(); drdRelation.setSourceID("NODE_ID_1"); drdRelation.setFirstDSID("NODE_ID_1"); drdRelation.setSecondDSID("NODE_ID_2"); drdRelation.setRelationType("ONE_TO_MANY"); drdRelation.addJoin("ID", "Product_ID"); drdRelation.setRelationName("test"); ArrayList<DRDRelation> drdRelationList = new ArrayList<>(); drdRelationList.add(drdRelation); drdObject.getDrdRelationsMap().put(Utility.getClientGuid(""), drdRelationList); System.out.println(drdObject.getXML()); String params = "drdXML="+URLEncoder.encode(drdObject.getXML(), java.nio.charset.StandardCharsets.UTF_8.toString()); System.out.println(RESTClient.sendRequest("datasetrelationship", params, "POST")); }
Updating relationship design
/**Method to update existing DRD*/ public static void updateDRD(String drdName) { String drdXML = ""; DRDObject drdObj = new DRDObject(drdXML); // user can add, remove or modify drd nodes from map. HashMap<String, DRDDatasetDetails> drdNodeMap = drdObj.getDrdDataSetDetailsMap(); // user can add, remove or modify node relations. HashMap<String, ArrayList<DRDRelation>> relationMap = drdObj.getDrdRelationsMap(); for (String relationKEy : relationMap.keySet()) { for (DRDRelation drdRelation : relationMap.get(relationKEy)) { if ("NODE_ID_1".equals(drdRelation.getSourceID())) { List<DRDJoinBy> joinByList = drdRelation.getDRDJoinByList(); for (DRDJoinBy joinBy : joinByList) { if (joinBy.getFirstDSCol().equalsIgnoreCase("saledate")) { joinBy.setFirstDSCol("saledate2"); } } } } } System.out.println(drdObj.getXML()); } }
Adding single data security rule to cube
* This method is used to add single data security rule to cube * * @param cubeId: is of cube * @throws ISecurityException, UnsupportedEncodingException * @throws ReportObjectException * @throws InterfaceInitException */ public static ResponseStatus addDataSecurityRule(String cubeId) throws ISecurityException, UnsupportedEncodingException, ReportObjectException, InterfaceInitException { // userInfo => get user info SecurityManager secMgr = SecurityManager.getInstance(); RepositoryManager rm = new RepositoryManager(); // get cube object in which rule is to be added. ReportObjectManager rom = new ReportObjectManager(); CubeObject co = (CubeObject) rom.getReportObject(Enums.IRO.TYPE.ANALYTICAL, cubeId, 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); }
Updating single data security rule
** * This method is used to update single data security rule * * @param cubeId: is of cube * @param ruleName: name of rule to be updated * @throws ISecurityException, UnsupportedEncodingException * @throws ReportObjectException */ public static ResponseStatus updateDataSecurityRule(String cubeId, String ruleName) throws ISecurityException, UnsupportedEncodingException, ReportObjectException { // userInfo => get user info SecurityManager secMgr = SecurityManager.getInstance(); RepositoryManager rm = new RepositoryManager(); // get cube object in which rule is to be added. ReportObjectManager rom = new ReportObjectManager(); CubeObject co = (CubeObject) rom.getReportObject(Enums.IRO.TYPE.ANALYTICAL, cubeId, true, userInfo, Enums.IRO.SUBTYPE.CUBE); DataSecurityRule rule = DataSecurityJavaAPI.getDataSecurityRule(cubeId, 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); }
Getting data security rule
/** * method to get data security rule * * @param cubeId: id of cube * @param ruleName: name of rule to be deleted * @return object of type DataSecurityRule. * @throws ReportObjectException * @throws ISecurityException. */ public static DataSecurityRule getDataSecurityRule(String cubeId, String ruleName) throws ISecurityException, UnsupportedEncodingException, ReportObjectException { // userInfo => get user info SecurityManager secMgr = SecurityManager.getInstance(); // get cube object in which rule is applied. ReportObjectManager rom = new ReportObjectManager(); CubeObject cubeObject = (CubeObject) rom.getReportObject(Enums.IRO.TYPE.ANALYTICAL, cubeId, true, userInfo, Enums.IRO.SUBTYPE.CUBE); // java api to get data security rule return secMgr.getDataSecurityRule(cubeObject, ruleName, userInfo); }
Deleting data security rule from cube of given cubeId
/** * method to delete data security rule from cube of given cubeId * * @param cubeId: id of cube * @param ruleName: name of rule to be deleted * @return object of type ResponseStatus. * @throws ReportObjectException * @throws ISecurityException. */ public static ResponseStatus deleteDataSecurityRule(String cubeId, String ruleName) throws ISecurityException, UnsupportedEncodingException, ReportObjectException { // userInfo // get cube object in which rule is applied. ReportObjectManager rom = new ReportObjectManager(); CubeObject cubeObject = (CubeObject) rom.getReportObject(Enums.IRO.TYPE.ANALYTICAL, cubeId, true, userInfo, Enums.IRO.SUBTYPE.CUBE); SecurityManager secMgr = SecurityManager.getInstance(); // java api to delete single data security rule return secMgr.deleteDataSecurityRule(cubeObject, ruleName, userInfo); }
Adding data security rules mapping for user
/** * method to add data security rules mapping for a user. * * @param cubeId: id of cube * @return object of type ResponseStatus. * @throws ReportObjectException * @throws ISecurityException. */ public static ResponseStatus assignDataSecurityRulesToUser(String cubeId) throws ISecurityException, UnsupportedEncodingException, ReportObjectException { // userInfo // get cube object in which rule is applied. ReportObjectManager rom = new ReportObjectManager(); CubeObject cubeObject = (CubeObject) rom.getReportObject(Enums.IRO.TYPE.ANALYTICAL, cubeId, 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); }
Adding data security rules mapping for a group
/** * 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 cubeId) throws ISecurityException, UnsupportedEncodingException, ReportObjectException { // userInfo // get cube object in which rule is applied. ReportObjectManager rom = new ReportObjectManager(); CubeObject cubeObject = (CubeObject) rom.getReportObject(Enums.IRO.TYPE.ANALYTICAL, cubeId, 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); } }
Creating a Registered file
/**Method to create RF*/ addRegisteredFile(""); } public static void addRegisteredFile(String fileName) throws Exception { ReportClient.init("." + java.io.File.separator + "conf" + java.io.File.separator + "kyvosclient.properties", "." + java.io.File.separator + "conf" + java.io.File.separator + "globals.properties", true); RepositoryManager rm = new RepositoryManager(); UserInfo userInfo = new UserInfo("Username","Password"); RegisteredFile rf = new RegisteredFile(); rf.setId(rm.getGuid()); rf.setName(fileName); rf.setFolderId("folder_16648879882851127070040120298929"); rf.setFolderName("RESTAPI"); rf.setConnectionName("DefaultHadoopCluster01"); // To Create TABLE based Register file. rf.setInputType(Enums.RFInputTypes.TABLE); HCatalogSource hCatalogSource = (HCatalogSource)rf.getDataSource(); hCatalogSource.setDbName("automationtables"); hCatalogSource.setTableName("account"); // Get column details for current Register file using REST API. ArrayList<FetchColumn> columnDetails = getColumnDetailsFromServer(rf); System.out.println("Colum Details "+ columnDetails.size()); // TO add or update user parameters. rf.addOrUpdateQOPrameter("dbName", "automationtables", "My Description "); // Setting column details. rf.setColumnDetails(columnDetails); // Invoking REST API to save file. String urlParameters = "registerFileXML="+ URLEncoder.encode(rf.getXML(), java.nio.charset.StandardCharsets.UTF_8.toString()); RESTClient.sendRequest("registerfiles", urlParameters, "POST"); RegisteredFile registeredFile = rm.getRegisteredFileByName("SQLRF","RESTAPI",userInfo); ArrayList columnsDetails = registeredFile.getFetchStep().getColumnDetails(); System.out.println("columnDetails size = " + columnsDetails.size()); } public static ArrayList getColumnDetailsFromServer(RegisteredFile rf) throws IOException { String urlParameters = "registerFileXML="+URLEncoder.encode(rf.getXML(), java.nio.charset.StandardCharsets.UTF_8.toString()); /**Rest API Method to send request to create RF*/ String responseString = RESTClient.sendRequest("registerfiles/createFetchStep", urlParameters, "POST"); FetchStep fetchStep = new FetchStep(responseString); return fetchStep.getColumnDetails(); } }
Creating Cube
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 = "cubeXML="+URLEncoder.encode(cubeObject.getXML(), java.nio.charset.StandardCharsets.UTF_8.toString()); System.out.println(RESTClient.sendRequest("cubes", 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 = "cubeXML="+URLEncoder.encode(cubeObject.getXML(), java.nio.charset.StandardCharsets.UTF_8.toString()); System.out.println(RESTClient.sendRequest("cubes", params, "POST")); }
Updating a cube
public static void updateCube(String cubeId) throws UnsupportedEncodingException { CubeObject co = new CubeObject(getCubeObject(cubeId, 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 cube object. String params = "cubeXML="+URLEncoder.encode(co.getXML(), java.nio.charset.StandardCharsets.UTF_8.toString()); RESTClient.sendRequest("cubes/"+co.getId(), params, "PUT"); }
Adding a connection
public static void addConnection(String connectionName) throws UnsupportedEncodingException { DBConnection connection = new DBConnection(); connection.setConnectionName(connectionName); connection.setProperty("kyvos.connection.role", "SYSADMIN"); connection.setProperty("kyvos.connection.server", ""); connection.setProperty("kyvos.connection.isEncryptedConnection", "true"); connection.setProperty("kyvos.connection.provider", "SNOWFLAKE"); connection.setProperty("kyvos.connection.properties.version", ""); connection.setProperty("kyvos.connection.url", ""); connection.setProperty("kyvos.connection.lastUpdateTimestamp", ""); connection.setProperty("kyvos.connection.userImpersonation", "false"); connection.setProperty("kyvos.connection.warehouse", ""); connection.setProperty("kyvos.connection.user", ""); connection.setProperty("kyvos.connection.isRead", "true"); connection.setProperty("kyvos.connection.password", "", "true", null); connection.setProperty("kyvos.connection.database", ""); connection.setProperty("kyvos.connection.account", ""); connection.setProperty("kyvos.connection.defaultsqlengine", "true"); connection.setProperty("kyvos.connection.name", connectionName); connection.setProperty("kyvos.connection.authenticationtype", "SNOWFLAKE"); connection.setProperty("kyvos.databricks.cluster.id", ""); System.out.println(connection.getXML()); String params = "connectionXML="+URLEncoder.encode(connection.getXML(), java.nio.charset.StandardCharsets.UTF_8.toString()); /**Rest API Method to create connection*/ RESTClient.sendRequest("connection", params, "POST"); }
Updating a connection
public static void updateConnection(String connectionName) throws UnsupportedEncodingException { /**Rest API Method to get connection details*/ String connectionXML = RESTClient.sendRequest("connection/"+connectionName+"?addResponseTag=false", null, "GET"); /**Updating Connection XML*/ DBConnection connection = new DBConnection(connectionXML); connection.setProperty("kyvos.connection.user", ""); String params = "connectionXML="+URLEncoder.encode(connection.getXML(), java.nio.charset.StandardCharsets.UTF_8.toString()); /**Rest API Method to update connection*/ System.out.println(RESTClient.sendRequest("connection", params, "PUT")); } }