cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to get detailed information of Universe, class, objects with BO 4.2 SP2 RestAPI?

Former Member
0 Kudos

Dear All,

I'm working on some script that would retrieve data from universes. I'm using RESTful on BO 4.2 SP2 platform and I was able to retrieve most information I need except object definition. I mean I would like to retrieve object properties (those we can see on Object Properties window in Universe Designer) like Select, Where, and so one. Normally if you are retrieving universe details via REST you can see outline with items and folders but there are only basic information like ID, Name, Type and Data type.

Please let me know if this is possible to get above info through Restful API.

Regards,

Deepak Kumar

Accepted Solutions (0)

Answers (3)

Answers (3)

DellSC
Active Contributor
0 Kudos

Aditya, I do the following:

1. Use the Platform Java SDK to load a universe into an IInfoObject. The base CMS query for this is Select * from CI_APPOBJECTS where SI_KIND = 'DSL.MetaDataFile'

2. Use the following code to get the connection information for the universe:

private void loadUNXConnects(IInfoObject o, QueryHelper qh) throws SDKException {
	IProperties conns = o.properties().getProperties("SI_SL_UNIVERSE_TO_CONNECTIONS");
	if (conns != null){
		int size = PropertyHelper.getIntProp(conns, "SI_TOTAL", _log);
		for (Integer i = 1; i <= size; i++){
			Integer conn = (Integer) conns.getInt(i);
			IInfoObject iobj = qh.getObjectByID(conn);
			if (iobj != null){
				_connects.add(new ConnectionInfo(iobj, qh, _log));
			}
		}
	}
}

3. I also use the platform SDK to get various other general information about the universe.

4. Initiate the Semantic Layer:

SlContext _context = SlContext.create();
_context.getService(CmsSessionService.class).setSession(<the IEnterpriseSession you logged in with>);
BusinessLayerFactory _blf = _context.getService(BusinessLayerFactory.class);
DataFoundationFactory _dff = _context.getService(DataFoundationFactory.class);
CmsResourceService _crs = _context.getService(CmsResourceService.class);
LocalResourceService _lrs = _context.getService(LocalResourceService.class);
String _unxPath = <path to download the unx to>

5. Get the root folder of the universe so we can recursively walk down the folders and get the data for each object:

public void loadUnxObjects(SLWrapper sl){
    String unvPath = "/"+(folder + title).replace('\\', '/');
    BlContainer blxRoot = sl.loadUniverse(unvPath);
    if (blxRoot != null && sl.getErrMsg().isEmpty()){
       _isOlap = sl.isOlap();
       _rootFolder = new UnxObjInfo((Folder) blxRoot, _isOlap);  //this will recursively get the child classes and objects
    } else {
        _errMsg = sl.getErrMsg();
    }
}

6. And here is the UnxObjInfo class. The recursion is done here so that you end up with a single object that contains all of the information about the universe objects. In order to output the info, you have to walk down the children of the root folder and also each child folder (to get the folder's objects) and dimension (will have children if there are any attributes for the dimension).

import java.util.ArrayList;
import java.util.List;
import com.sap.sl.sdk.authoring.businesslayer.BlContainer;
import com.sap.sl.sdk.authoring.businesslayer.BlItem;
import com.sap.sl.sdk.authoring.businesslayer.Dimension;
import com.sap.sl.sdk.authoring.businesslayer.Filter;
import com.sap.sl.sdk.authoring.businesslayer.Folder;
import com.sap.sl.sdk.authoring.businesslayer.Measure;
import com.sap.sl.sdk.authoring.businesslayer.NativeRelationalFilter;
import com.sap.sl.sdk.authoring.businesslayer.RelationalBinding;
import com.sap.sl.sdk.authoring.businesslayer.Attribute;
    public class UnxObjInfo extends baseInfo {
	protected String _objType = "";
	protected String _sql = "";
	protected String _sqlWhere = "";
	protected String _lovName = "";
	protected String _dataType = "";
	protected String _descrip = "";
	protected String _state = "";
	protected String _parentName = "";
	protected String _errMsg = "";
	protected String _accsLvl = "";
		
	protected boolean _isOlap = false;
	protected boolean _results = true;
	protected boolean _conditions = true;
	protected boolean _sort = true;
	protected boolean _mandatory_filter = false;
	protected boolean _filter_universe = false;
	protected boolean _filter_LOV = false;
	protected ArrayList<UnxObjInfo> children = null;
	
	public UnxObjInfo(){
		//we need this so that we can extend into UnvObjInfo
	}
	
	/**
	 * This constructor is for the root "folder" class of a unx
	 * @param fldr
	 * @param olap
	 */
	public UnxObjInfo(Folder fldr, boolean olap){
		_descrip = fldr.getDescription();
		title = fldr.getName();
		_objType = "Class";
		cuid = fldr.getIdentifier();
		_state = fldr.getState().toString();
		_isOlap = olap;
		_results = false;
		_conditions = false;
		_sort = false;
		children = new ArrayList<UnxObjInfo>();
		_errMsg = "";
		loadChildren(fldr);
	}
	
	/**
	 * This constructor is for any other folders/classes of a unx
	 * @param fldr
	 * @param parentId
	 */
	public UnxObjInfo(Folder fldr, String parentId, String parentName){
		_descrip = fldr.getDescription();
		title = fldr.getName();
		_objType = "Class";
		cuid = fldr.getIdentifier();
		_state = fldr.getState().toString();
		_results = false;
		_conditions = false;
		_sort = false;
		parentCuid = parentId;
		_parentName = parentName;
		children = new ArrayList<UnxObjInfo>();
		loadChildren(fldr);
	}
	
	/**
	 * This constructor is for dimensions
	 * @param dim
	 */
	public UnxObjInfo(Dimension dim, String parentId, String parentName){
		_descrip = dim.getDescription();
		title = dim.getName();
		_objType = "Dimension";
		cuid = dim.getIdentifier();
		_state = dim.getState().toString();
		_dataType = dim.getDataType().toString();
		try {
			if (dim.isAssociatedLovEnabled()){
				_lovName = dim.getAssociatedLov().getName();
			}
		} catch (Exception e){
			//do nothing - eat the Null error when there is no LOV.
		}
		RelationalBinding rb = (RelationalBinding) dim.getBinding();
		_sql = rb.getSelect();
		_sqlWhere = rb.getWhere();
		parentCuid = parentId;
		_parentName = parentName;
		_accsLvl = dim.getAccessLevel().toString();
		children = new ArrayList<UnxObjInfo>();
		loadChildren(dim);
	}
	
	/**
	 * This constructor is for measures
	 * @param measure
	 */
	public UnxObjInfo(Measure measure, String parentId, String parentName){
		_descrip = measure.getDescription();
		title = measure.getName();
		_objType = "Measure";
		cuid = measure.getIdentifier();
		_state = measure.getState().toString();
		_dataType = measure.getDataType().toString();
		parentCuid = parentId;
		_parentName = parentName;
		_accsLvl = measure.getAccessLevel().toString();
		RelationalBinding rb = (RelationalBinding) measure.getBinding();
		_sql = rb.getSelect();
		_sqlWhere = rb.getWhere();
	}
	
	/**
	 * This constructor is for attributes of dimensions
	 * @param attr
	 */
	public UnxObjInfo(Attribute attr, String parentId, String parentName){
		_descrip = attr.getDescription();
		title = attr.getName();
		_objType = "Measure";
		cuid = attr.getIdentifier();
		_state = attr.getState().toString();
		_dataType = attr.getDataType().toString();
		parentCuid = parentId;
		_parentName = parentName;
		_accsLvl = attr.getAccessLevel().toString();
		RelationalBinding rb = (RelationalBinding) attr.getBinding();
		_sql = rb.getSelect();
		_sqlWhere = rb.getWhere();
	}
	
	/**
	 * This constructor is for filters
	 * @param fltr
	 */
	public UnxObjInfo(NativeRelationalFilter fltr, String parentId, String parentName) {
		_descrip = fltr.getDescription();
		title = fltr.getName();
		_objType = "Filter";
		cuid = fltr.getIdentifier();
		_state = fltr.getState().toString();
		parentCuid = parentId;
		_parentName = parentName;
		_mandatory_filter = fltr.isMandatory();
		_filter_universe = fltr.isAppliedOnUniverse();
		_filter_LOV = fltr.isAppliedOnLOV();
		RelationalBinding rb = fltr.getBinding();
		_sqlWhere = rb.getWhere();
		_sql = rb.getSelect();
	}
	
	//Getters
	public ArrayList<UnxObjInfo> getChildren() { return children; }
	public String getObjType(){ return _objType; }
	public String getSql() { return _sql; }
	public String getSqlWhere() { return _sqlWhere; }
	public String getLovName() { return _lovName; }
	public boolean hasLOV() { return !_lovName.isEmpty(); }
	public String getDataType() { return _dataType; }
	public String getDescription() { return _descrip; }
	public String getState() { return _state; }
	public String getParentName() { return _parentName; }
	public String getErrMsg() { return _errMsg; }
	public String getAccessLevel() { return _accsLvl; }
	public boolean isOlap() { return _isOlap; }
	public boolean useInResults() { return _results; }
	public boolean useInConditions() { return _conditions; }
	public boolean useInSort() { return _sort; }
	public boolean isMandatory() { return _mandatory_filter; }
	public boolean isOnUniverse() { return _filter_universe; }
	public boolean isOnLOV() { return _filter_LOV; }


	//Private Methods
	
	/**
	 * loadChildren - Walk down the tree that contains a folder's children
	 * 
	 * @param fldr - The folder whose children we're loading
	 */
	private void loadChildren(BlContainer fldr){
		_errMsg = "";
		try{
			List<BlItem> kids = fldr.getChildren();
			for (BlItem child : kids){
				UnxObjInfo oInfo = null;
				if (child instanceof Folder){
					//This line makes this recursive - we'll end up with everything at the top level.
					oInfo = new UnxObjInfo((Folder) child, this.cuid, this.title);  
				} else if (child instanceof Dimension){
					oInfo = new UnxObjInfo((Dimension) child, this.cuid, this.title);
				} else if (child instanceof Measure){
					oInfo = new UnxObjInfo((Measure) child, this.cuid, this.title);
				} else if (child instanceof Attribute) {
					oInfo = new UnxObjInfo((Attribute) child, this.cuid, this.title);
				} else if (child instanceof Filter){
					oInfo = new UnxObjInfo((NativeRelationalFilter) child, this.cuid, this.title);
				}
				if (oInfo != null){
					this.children.add(oInfo);
					if (!oInfo.getErrMsg().isEmpty()){
						_errMsg += oInfo.getErrMsg() + "|";
					}
				}
				
			}
		} catch (Exception e) {
			_errMsg = "loadChildren: " + e.getMessage();
		}
	}
	
}

-Dell

former_member198519
Active Contributor
0 Kudos
DellSC
Active Contributor
0 Kudos

Unfortunately, in order to get that information you'll have to go outside of the RESTful SDK.

For IDT universes (.unx) you'll need to use the Semantic Layer Java SDK to get this information.

For Universe Designer universes (.unv), it's a little more complex. The Designer SDK is based on COM, which can be difficult to work with in Java, so I usually do this part in .NET. You have to install the Universe Designer from Client Tools and register its Type Library by running it with the "\RegServer" command line flag.

I may be able to get you sample code for both of these if you're interested.

-Dell

Former Member
0 Kudos

Hi Dell,

Can you help me with sample code for IDT Universes for retriving above mentioned information using SL Java SDK

thanks in advance

0 Kudos

Hi Dell,

Thanks for this piece of information. I am interested in doing this for Universe design tool and wasn’t able to find a guide on SAP site. Could you please share the sample code for universe design as well?


Also would be really grateful if you can share any link with SAP documentation please?

Thanks

DellSC
Active Contributor
0 Kudos

Hi Jon,

Unfortunately, it appears that the links I have to the documentation no longer work. However, if you'll ask this as a new question instead of tagging onto an old question that has already been answered, I'll see what I can do about posting some sample code.

-Dell