Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
/**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

...

semantic model

Code Block
languagejava
* This method is used to add single data security rule to semantic cubemodel
	 * 
	 * @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);

	}

...

Code Block
languagejava
/**
	 * 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

...

semantic model of given

...

semantic model ID

Code Block
languagejava
/**
	 * method to delete data security rule from semantic cubemodel of given semanitc model cubeIdID
	 * 
	 * @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);

	}

...

Code Block
languagejava
/**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

...

semantic model

Code Block
languagejava
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

...

semantic model

Code Block
languagejava
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");
	}

...