Intellicus Enterprise Reporting and Business Insights 18.1

OLAP

0 views August 26, 2019 0

Import

//OLAP related imports

import com.impetus.intera.layout.datasource.qo.QODataSource;

import com.impetus.intera.layout.upx.FetchDataSource;

import com.impetus.intera.reportobjects.CubeObject;

import com.impetus.intera.reportobjects.QueryObjectColumn;

import com.impetus.intera.reportobjects.QueryObjectFacade;

import com.impetus.intera.reportobjects.ReportObjectException;

import com.impetus.intera.reportobjects.ReportObjectManager;

import com.intellica.client.common.EntityProperties;

import com.intellica.client.common.EntityProperty;

import com.intellica.client.common.Enums;

import com.intellica.client.layout.LayoutManager;

import com.intellica.client.olap.CubeDataSource;

import com.intellica.client.olap.DimMapping;

import com.intellica.client.olap.Dimension;

import com.intellica.client.olap.Hierarchy;

import com.intellica.client.olap.Level;

import com.intellica.client.olap.Measure;

import com.intellica.client.olap.MeasureGroups;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.Iterator;

import java.util.Map;

Cube Object
AddCube

This Java API is used to create a new Cube Object in the Intellicus Repository.

Refer to <Intellicus_Install_Path>/SampleCodes/Java APIs/OLAP/ AddCube.java for sample code of this use case.

Steps :

  1. Initialize Report Client.
  2. Initialize Requestor UserInfo.
  3. addReportObject() method of ReportObjectManager class
     
    Method: addReportObject

    This is the method of ReportObjectManager class i.e. used to add Cube Object in Repository

    public void addReportObject(ReportObject reportObject, UserInfo userInfo).

    Parameters:

    • ReportObject: Java object of Cube object to be added.
    • UserInfo: Object of UserInfo class.

Code Snippet of the sample code-

Set the Query Id for which Cube Object is to be created.

String queryId = “SampleCubeQuery”;

//Set other details.

String categoryId = “CT”; //Category in which cube object is to be added

String measureName = “Count”;

String measureDataField = “ResourceId”;

String measureSummaryFunction = “2”; //1 for sum, 2 for count

//Set cube object properties

CubeObject cubeObj = new CubeObject();

cubeObj.setCategoryId(categoryId); //category Id where Cube Object is to be saved.

cubeObj.setName(“Cube_”+queryId);

cubeObj.setId(“Cube_”+queryId);

cubeObj.setCoType(“INTERNAL”);

cubeObj.setCubeUniqueName(“Cube_”+queryId);

FetchDataSource fetchDataSource = new FetchDataSource();

QODataSource qoDataSrc = new QODataSource();

qoDataSrc.setId(queryId);   //Query Object Id

fetchDataSource.setSource(“QO”);

fetchDataSource.setSourceObj(qoDataSrc);

HashMap<String, FetchDataSource> cubeQueries = new HashMap<String, FetchDataSource>();

cubeQueries.put(“CUBE_QUERY_”+queryId, fetchDataSource);

cubeObj.setCubeQueries(cubeQueries);

Adding Dimensions

For adding dimensions, first iterate over the list of columns/fields of Query object, then add them.

ArrayList<Dimension> dimensionList = new ArrayList<Dimension>();
//Getting columns/fields in QO so as to iterate to create Dimensions
QueryObjectFacade queryObjFacade = (QueryObjectFacade)rom.getReportObjectFacadeById(Enums.IRO.TYPE.QUERY, queryId, requestorUserInfo);
ArrayList<QueryObjectColumn> qoColumnsList = queryObjFacade.getColumnList();
Iterator itr = qoColumnsList.iterator();

//iterating through the Column List
while(itr.hasNext()){
	QueryObjectColumn qoColumn  = (QueryObjectColumn)itr.next();
	System.out.println("Column Name = "+qoColumn.getColumnName());
	columnName = qoColumn.getColumnName();
	
	dimMappingObj = new DimMapping();
	dimMappingObj.setDimensionId("DIMENSION_"+columnName);
	dimMappingMap.put("DIMENSION_"+columnName,dimMappingObj);
	
	Dimension dimensionObj = new Dimension();
	dimensionObj.setDimID("DIMENSION_"+columnName);
	dimensionObj.setIsValuesRestricted(false);
	dimensionObj.setGISEnabled(false);
	dimensionObj.setUniqueName("DIMENSION_"+columnName);
	dimensionObj.setName(columnName);
	dimensionObj.setType("REGULAR");
	HashMap<String, CubeDataSource> dataSourceObj = new HashMap<String, CubeDataSource>();
	CubeDataSource cubeDataSourceObj = new CubeDataSource();
	cubeDataSourceObj.setId("CUBE_QUERY_"+queryId);
	cubeDataSourceObj.setType("REFERENCED");
	dataSourceObj.put("CUBE_QUERY_"+queryId,cubeDataSourceObj );
	dimensionObj.setFetchSourcesForDimension(dataSourceObj);
	
	ArrayList<Hierarchy> hierarchyList = new ArrayList<Hierarchy>();
	Hierarchy hierachy = new Hierarchy();
	hierachy.setName("HIERARCHY");
	hierachy.setUniqueName("DIMENSION_HIERARCHY_"+columnName);
	ArrayList<Level> levelList = new ArrayList<Level>();
	Level level = new Level();
	//to allow All as member value of a dimension
	if(allowAll){
		level.setAll(true);
		level.setUniqueName("DIEMENSION_LEVEL_0");
		level.setName("Hierarchy.ALL");
		levelList.add(level);
	}
	level = new Level();
	level.setAll(false);
	level.setUniqueName("DIEMENSION_LEVEL_1");
	level.setName(columnName);
	level.setDataField(columnName);
	level.setAssociatedDimQueryId("CUBE_QUERY_"+queryId);
	levelList.add(level);
	
	hierachy.setLevels(levelList);
	hierarchyList.add(hierachy);
	dimensionObj.setHierarchies(hierarchyList);
	dimensionList.add(dimensionObj);
}

cubeObj.setDimMappings(dimMappingMap);

 
Adding the measure Dimension

//Adding Measure dimension

Dimension dimensionObj = new Dimension();

dimensionObj.setDimID(“Dim_Measures”);

dimensionObj.setIsValuesRestricted(false);

dimensionObj.setGISEnabled(false);

dimensionObj.setUniqueName(“Measures”);

dimensionObj.setName(“Measures”);

dimensionObj.setType(“MEASURE”);

 

ArrayList<Hierarchy> hierarchyList = new ArrayList<Hierarchy>();

Hierarchy hierachy = new Hierarchy();

hierachy.setUniqueName(“Measures”);

ArrayList<Level> levelList = new ArrayList<Level>();

Level level = new Level();

 

level.setAll(false);

level.setDataType(“Regular”);

level.setUniqueName(“MeasuresLevel”);

levelList.add(level);

 

hierachy.setLevels(levelList);

hierarchyList.add(hierachy);

dimensionObj.setHierarchies(hierarchyList);

dimensionList.add(dimensionObj);

 

cubeObj.setDimensions(dimensionList);

 

String measureId = “MEASURE_1”;

MeasureGroups measureGrpsObj = new MeasureGroups();

Map<String, ArrayList<String>> measureMap = new HashMap<String, ArrayList<String>>();

ArrayList<String> measureIdList = new ArrayList<String>();

measureIdList.add(measureId);

measureMap.put(“MeasureGroup”, measureIdList);

measureGrpsObj.setMeasureGroups(measureMap);

measureGrpsObj.setMeasureGroups(measureMap);

 

Map<String, CubeDataSource> dataSourceMap = new HashMap<String, CubeDataSource>();

ArrayList<String> DataSourceId = new ArrayList<String>();

CubeDataSource cubeDataSrcObj = new CubeDataSource();

cubeDataSrcObj.setId(“CUBE_QUERY_”+queryId);

cubeDataSrcObj.setType(“REFERENCED”);

dataSourceMap.put(“CUBE_QUERY_”+queryId, cubeDataSrcObj);

measureGrpsObj.setFetchSources(dataSourceMap);

 

cubeObj.setMeasureGroups(measureGrpsObj);

 

//Adding Measures

HashMap<String,Measure> measureList = new HashMap<String,Measure>();

Measure measureObj = new Measure();

 

measureObj.setId(measureId);

measureObj.setUniqueName(measureId);

measureObj.setName(measureName);

measureObj.setIsDefault(true);

//measureObj.setFormatType(“2”);

measureObj.setFormat(“0”);

measureObj.setQueryID(“CUBE_QUERY_”+queryId);

measureObj.setDataField(measureDataField);

measureObj.setSummaryFunction(measureSummaryFunction);

measureList.put(measureId, measureObj);

cubeObj.setMeasures(measureList);

Calling addReportObject() method

//Method used to add Cube Object in Repository

rom.addReportObject(cubeObj, requestorUserInfo);

Get Dimensions List

This Java API is used to get the list of dimensions for provided Cube Object Id.

Refer to <Intellicus_Install_Path>/SampleCodes/Java APIs/OLAP/GetDimensionList.java for sample code of this use case.

Steps:

  1. Initialize Report Client.
  2. Initialize Requestor UserInfo.
  3. addReportObject() method of ReportObjectManager class

Method: getDimensions

This is the method of CubeObject class i.e. used to get the dimensions of requested Cube object

public ArrayList<Dimension> getDimensions()

Code Snippet of the sample code-

Set the Cube Object Id whose dimensions are to be fetched.

String cubeName = “SampleCubeQuery”;

Getting Cube Object Detail to get its dimensions.

OLAPManager olapMgr = new OLAPManager();
CubeObject cubeObj = (CubeObject)olapMgr.getCubeObjectDetail(cubeName, cubeName, requestorUserInfo);
ArrayList<Dimension> dimList = cubeObj.getDimensions();
Dimension dim = null;
//iterating through the list of dimensions
for(int i=0;i<dimList.size();i++){
	dim = (Dimension)dimList.get(i);
	System.out.println("Dimension Id = "+dim.getUniqueName()+", Name = "+dim.getName());
}

 

Delete Cube Object

This Java API is used to delete the cube object from the Intellicus Repository for given Cube Object Id.

Refer to <Intellicus_Install_Path>/SampleCodes/Java APIs/OLAP/DeleteCubeObject.java for sample code of this use case.

Steps:

  1. Initialize Report Client.
  2. Initialize Requestor UserInfo.
  3. Delete the Report Object
     
    Method: deleteReportObject

    For deleting the Report Object, call deleteReportObject method of ReportObjectManager

    com.impetus.intera.reportobjects.ReportObjectManager

                  public void deleteReportObject(ReportObject reportObject,

    UserInfo userInfo)

    Parameters:

    • ReportObject: Java object of Cube object to be deleted.
    • UserInfo: Object of UserInfo class.

    //This will be used to delete the Cube Object.

    reportObjectManager.deleteReportObject(qoObj,userInfo);

    Part of Sample Code implementing “Delete Cube Object”

    Set the Cube Object Id that is to be deleted.

    //Cube object Id that is to be deleted

    String cubeObjId = “Cube_QOForCube_1”;

    Getting the object of Cube and deleting it from Repository

    //getting ReportObject corresponding to provided Cube Object Id

    ReportObject rObj = (ReportObject)rom.getReportObject (Enums.IRO.TYPE.CUBEOBJECT, cubeObjId, cubeObjId, true ,requestorUserInfo);

    //Method to delete Cube

    rom.deleteReportObject(rObj, requestorUserInfo);

Build Cube Object

This Java API is used to build the cube for provided Cube Object.

Refer to <Intellicus_Install_Path>/SampleCodes/Java APIs/OLAP/BuildCubeObject.java for sample code of this use case.

Steps:

  1. Initialize Report Client.
  2. Initialize Requestor UserInfo.
  3. Build the Cube Object
     
    Method: buidCubeObject

    For building the cube, call method of ReportObjectManager

    com.impetus.intera.reportobjects.ReportObjectManager

    public void buildCubeObject(String cubeBuildXML, UserInfo userInfo) throws ReportObjectException{

    Parameters:

    • cubeBuildXML: XML of CubeObject Build.
    • UserInfo: Object of UserInfo class.

    Part of Sample Code implementing “Build Cube Object”

    Set the Cube Object Id that is to be build.

    //Cube object Id that is to be deleted

    String cubeObjId = “Cube_QOForCube_1”;

    Getting the object of Cube and deleting it from Repository

    String buildXML = “<CUBEOBJECT_BUILD ID=\””+cubeObjId+”\”>\n”;

    buildXML += “\t\t\t<BUILD_INFO>\n\t\t\t\t<PROPERTIES>\n”;

    buildXML += “\t\t\t\t<PARAM NAME=\”BUILD_ON_HADOOP\”>\n”;

    buildXML += “\t\t\t\t\t<VALUE><![CDATA[FALSE]]></VALUE>\n”;

    buildXML += “\t\t\t\t</PARAM>\n”;

    buildXML += “\t\t\t\t</PROPERTIES>\n”;

    buildXML += “\t\t\t</BUILD_INFO>\n”;

    buildXML += “<SCHEDULE_INFO JOBTYPE=\”NOW\”></SCHEDULE_INFO></CUBEOBJECT_BUILD>”;

    //method used to build the cube object.

    rom.buildCubeObject(buildXML, requestorUserInfo);

Get Build Status

This Java API is used to get the build status for the given Cube.

Possible values of build status –

“BUILDING”, “COMPLETED”, “PENDING”, “FAILED”, “BUILD_SUBMITTED”

Refer to <Intellicus_Install_Path>/SampleCodes/Java APIs/OLAP/GetBuildStatus.java for sample code of this use case.

Steps:

  1. Initialize Report Client.
  2. Initialize Requestor UserInfo.
  3. Get the build status for the Cube Object
     
    Method: getCubeObjectBuildStatus

    For getting the build status, call method of ReportObjectManager

    com.impetus.intera.reportobjects.ReportObjectManager

    public COBuildStatus getCubeObjectBuildStatus(Filters filters,UserInfo userInfo) throws ReportObjectException{

    Parameters:

    • filters : filters to get CubeObject Build Status
    • UserInfo: Object of UserInfo class.

    Part of Sample Code implementing “Get Build Status”

    Set the Cube Object Id that is to be build.

    //Cube object Id whose build status is to get

    String cubeObjId = “SalesCube”;

    Getting the object of Cube and deleting it from Repository

    Filters filters = new Filters();

    Filter filter = new Filter(“CUBEOBJECT_ID”, “”, cubeObjId);

    filters.add(filter);

    COBuildStatus coBuildStatus = rom.getCubeObjectBuildStatus(filters, requestorUserInfo);

    System.out.println(“Build Status = “+coBuildStatus.getStatus()

Cancel Build

This Java API is used cancel the build for which build cube request is sent to Report Engine

Refer to <Intellicus_Install_Path>/SampleCodes/Java APIs/OLAP/CancelBuild.java for sample code of this use case.

Steps:

  1. Initialize Report Client.
  2. Initialize Requestor UserInfo.
  3. Get the build status for the Cube Object
     
    Method: cancelCubeObjectBuild

    For cancelling the cube build process, call method of ReportObjectManager

    com.impetus.intera.reportobjects.ReportObjectManager

    public void cancelCubeObjectBuild(HashMap requestParams,UserInfo userInfo) throws ReportObjectException{

    Parameters:

    • requestParams : Request Params required to cancel Cube Object Build(REQUEST_ID)
    • UserInfo: Object of UserInfo class.

    Part of Sample Code implementing “Cancel Build”

    Set the Cube Object Id that is to be build.

    //Cube object Id whose build status is to get

    String cubeObjId = “SalesDataCube”;

    Getting the object of Cube and deleting it from Repository

    Filters filters = new Filters();
    Filter filter = new Filter("CUBEOBJECT_ID", "", cubeObjId);
    filters.add(filter);
    COBuildStatus coBuildStatus = rom.getCubeObjectBuildStatus(filters, requestorUserInfo);
    COBuildingStatus cbStatus = (COBuildingStatus)coBuildStatus.getCubeStatus();
    buildRequestId = cbStatus.getBuildRequestId();
    //if build is not yet completed, then only cancel build process
    if(!buildRequestId.isEmpty()){
    requestParams.put(InteraConstants.SysParams.REQUESTID_GUID, buildRequestId);
        //method to cancel build process
        rom.cancelCubeObjectBuild(requestParams, requestorUserInfo);
    }