EducationSoftwareStrategy.com
StrategyCommunity

Knowledge Base

Product

Community

Knowledge Base

TopicsBrowse ArticlesDeveloper Zone

Product

Download SoftwareProduct DocumentationSecurity Hub

Education

Tutorial VideosSolution GalleryEducation courses

Community

GuidelinesGrandmastersEvents
x_social-icon_white.svglinkedin_social-icon_white.svg
Strategy logoCommunity

© Strategy Inc. All Rights Reserved.

LegalTerms of UsePrivacy Policy
  1. Home
  2. Topics

KB20483: How to Return a Filtered Set of Elements Using the MicroStrategy Java Web SDK


Community Admin

• Strategy


Using the MicroStrategy Java Web SDK, it is possible to perform filtered element browsing when requesting a list of elements from the Intelligence Server.

 
Using the Strategy Java Web SDK 9.4, it is possible to perform filtered element browsing when requesting a list of elements from the Intelligence Server. For example, there might be several quarter attribute elements, but it may be only necessary to get the quarters for a specific year. In the following code sample, a static filter on year was previously created and used to filter the elements. To see how this can be accomplished, see the code sample below:
 


package customclasses.misc;
import java.util.Enumeration;
import com.Strategy.web.objects.WebAttribute;
import com.Strategy.web.objects.WebAttributeForm;
import com.Strategy.web.objects.WebAttributeForms;
import com.Strategy.web.objects.WebElementSource;
import com.Strategy.web.objects.WebElements;
import com.Strategy.web.objects.WebFilter;
import com.Strategy.web.objects.WebIServerSession;
import com.Strategy.web.objects.WebObjectInfo;
import com.Strategy.web.objects.WebObjectSource;
import com.Strategy.web.objects.WebObjectsException;
import com.Strategy.web.objects.WebObjectsFactory;
import com.Strategy.webapi.EnumDSSXMLApplicationType;
import com.Strategy.webapi.EnumDSSXMLAuthModes;
import com.Strategy.webapi.EnumDSSXMLObjectTypes;
public class GetFilteredElements {

public static void main(String[] args) {

String uid = "administrator";
String pwd = "";
String SessionID = "";

// Create factory object.

WebObjectsFactory factory=WebObjectsFactory.getInstance();
WebIServerSession serverSession=factory.getIServerSession();

// Set properties on the session object

serverSession.setServerName("SERVERNAME");
serverSession.setServerPort(0);
serverSession.setProjectName("PROJECTNAME");
serverSession.setLogin(uid);
serverSession.setPassword(pwd);
serverSession.setAuthMode(EnumDSSXMLAuthModes.DssXmlAuthStandard);
serverSession.setApplicationType(EnumDSSXMLApplicationType.DssXmlApplicationDSSWeb);

try {

//Create a session on the I-server
SessionID = serverSession.getSessionID();
System.out.println("Welcome " + serverSession.getLogin());
System.out.println("SessionID: " + SessionID);

WebObjectInfo objInfo = null;
WebElementSource wes = null;
WebElements oElements = null;
WebObjectSource objectSource = null;
WebAttribute oAtt = null;

//filter Year 2009 ID: 2BD0AE1C4C43A8586E685884AB8F3FB8
//attribute Year ID: 8D679D5111D3E4981000E787EC6DE8A4
// attribute quarter id: 8D679D4A11D3E4981000E787EC6DE8A4

objectSource=serverSession.getFactory().getObjectSource();
wes = serverSession.getFactory().getElementSourceObject();
objInfo = objectSource.getObject("8D679D4A11D3E4981000E787EC6DE8A4",EnumDSSXMLObjectTypes.DssXmlTypeAttribute,true);
//get the forms in this attribute:

oAtt = (WebAttribute)objInfo;
WebAttributeForms oforms = oAtt.getTemplateForms();
WebAttributeForm form = null;
for (int x=0;x<oforms.size();x++){
form = oforms.get(x);
}


//set the object in the wes

wes.setObject(objInfo);

//set the filter on the wes object


WebObjectInfo filterInfo = objectSource.getObject("2BD0AE1C4C43A8586E685884AB8F3FB8",EnumDSSXMLObjectTypes.DssXmlTypeFilter,true);

WebFilter ofilter = (WebFilter)filterInfo;

wes.getFilter().getExpression().populate(ofilter.getExpression());

//then run wes.getElements(...)

oElements = wes.getElements();

Enumeration e = oElements.elements();

int i = 0;
while(e.hasMoreElements()){
i++;
e.nextElement();
}

}catch (WebObjectsException ex) {

ex.printStackTrace();
}
}
}
//It is also possible to build the expression on the fly; however, depending on the type of expressions required, extra overhead may be incurred. To programmatically build the expression instead, change the following line:


wes.getFilter().getExpression().populate(ofilter.getExpression());

//to this instead:


WebExpression exp = wes.getFilter().getExpression();
WebOperatorNode root = (WebOperatorNode) exp.getRootNode();
root.setExpressionType(EnumDSSXMLExpressionType.DssXmlFilterSingleBaseFormQual);
root.setFunction(EnumDSSXMLFunction.DssXmlFunctionEquals);

WebObjectInfo objYear = objectSource.getObject("8D679D5111D3E4981000E787EC6DE8A4",EnumDSSXMLObjectTypes.DssXmlTypeAttribute,true);
WebAttribute attYear = (WebAttribute)objYear;
WebAttributeForms attYearForms = attYear.getBrowseForms();
WebAttributeForm attYearForm = null;
for(int i=0;i<attYearForms.size();i++){
WebAttributeForm currentForm = attYearForms.get(i);
if(currentForm.getUseName().equalsIgnoreCase("ID")){
attYearForm = currentForm;
}
}


exp.createFormShortcutNode(attYear, attYearForm );


//second child is exp type


exp.createConstantNode("2009",EnumDSSXMLDataType.DssXmlDataTypeReal);

 

 
For more information on creating expressions click the following link:
 
https://resource.microstrategy.com/Support/Authoring/DisplayTN.aspx?tnkey=18289&formatted=1
 
Note: Creating the expression on the fly can diminish performance. For example, running this code (in a very simple single-user test run on a client machine) without setting the filter takes approximately 1500ms to run. Populating the filter expression with an existing filter object takes about 1125ms - an improvement of almost 400ms. Building the same expression on the fly takes about 1281ms to complete making the overall improvement less (about 219ms) than when the filter object is used.
 
Note: Starting in Strategy Java Web SDK 9.x the following line can also be used to create an expression on the fly:
 
wes.getFilter().getExpression().populate("Year@ID in (\"2009\")");
 
or
 
wes.getFilter().getExpression().populate("Category@Desc in (\"Electronics\")");
 
For more information on using this method, click the following link:
https://resource.microstrategy.com/support/Authoring/DisplayTN.aspx?tnkey=33835&formatted=1
 
The example provided in this document is provided “as-is” and user has read the following customization warning:
ADDITIONAL INFORMATION:
The Strategy SDK allows you to customize several Strategy products and extend and integrate the Strategy business intelligence functionality into other applications. However, before changing the way Strategy products look or behave, it is helpful to understand how the application is built. For more information regarding the Strategy products or the process of customizing Strategy products, please refer to Strategy Developer Zone (https://developer.microstrategy.com).
To access the Strategy Developer Zone, you must have access to the Strategy Knowledge Base, you must have purchased the Strategy SDK, and you must be current on your Strategy maintenance agreement. If you are a US-based business and believe that you satisfy all three of these conditions but you do not have access to the Strategy Developer Zone, please contact Strategy Technical Support at support@microstrategy.com or at (703) 848-8700. If you are an international business, please contact Strategy Technical Support at the appropriate email address or phone number found at https://www.microstrategy.com/us/services/support/contact.
CUSTOMIZATION WARNING:
This customization is provided as a convenience to Strategy users and is only directly applicable to the version stated. While this code may apply to other releases directly, Strategy Technical Support makes no guarantees that the code provided will apply to any future or previous builds. In the event of a code change in future builds, Strategy Technical Support makes no guarantee that an updated version of this particular customization will be provided. In the event of a code change in future builds, Strategy may not be able to provide additional code on this matter even though this customization is provided at this time for this specific build. For enhancements to this customization or to incorporate similar functionality into other versions, contact your Account Executive to inquire about Strategy Consulting assistance.
 


Comment

0 comments

Details

Knowledge Article

Published:

June 21, 2017

Last Updated:

June 21, 2017