MicroStrategy ONE
Reading User Properties
All user objects have a set of basic properties. However, users can be given additional extended properties.
The sample code below illustrates how to read all of the extended properties for a user.
/**
* MicroStrategy SDK Sample
*
* Copyright © 2006 MicroStrategy Incorporated. All Rights Reserved.
*
* MICROSTRATEGY MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE
* SUITABILITY OF THIS SAMPLE CODE, EITHER EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. MICROSTRATEGY SHALL NOT
* BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
* MODIFYING OR DISTRIBUTING THIS SAMPLE CODE OR ITS DERIVATIVES.
*
*
*/
package com.microstrategy.sdk.samples.usermanagement;
import com.microstrategy.web.objects.WebFolder;
import com.microstrategy.web.objects.WebIServerSession;
import com.microstrategy.web.objects.WebObjectSource;
import com.microstrategy.web.objects.WebObjectsException;
import com.microstrategy.web.objects.WebObjectsFactory;
import com.microstrategy.web.objects.WebProperty;
import com.microstrategy.web.objects.WebPropertyGroup;
import com.microstrategy.web.objects.WebPropertySet;
import com.microstrategy.web.objects.WebSearch;
import com.microstrategy.web.objects.admin.users.WebUser;
import com.microstrategy.webapi.EnumDSSXMLApplicationType;
import com.microstrategy.webapi.EnumDSSXMLObjectSubTypes;
import com.microstrategy.webapi.EnumDSSXMLSearchDomain;
public class ReadUserPropertySets {
public static WebIServerSession sessionInfo;
public static final String userName = "New User";
/* The following information is required to login and manipulate the User management API */
/* iServerName is the IServer we are connecting to */
public static final String iServerName = "localhost";
/* projectName is the project name we are connecting to */
public static final String projectName = "";
/* loginName is the user name we use to login the project */
public static final String adminLoginName = "administrator";
/* loginPasswd is the password we use to login the project */
public static final String adminLoginPasswd = "";
public static void main(String[] args) {
sessionInfo = getServerSession(iServerName, projectName, adminLoginName, adminLoginPasswd);
WebObjectSource source =sessionInfo.getFactory().getObjectSource();
WebSearch userSearch = source.getNewSearchObject();
userSearch.setNamePattern(userName);
userSearch.setAsync(false);
userSearch.types().add(EnumDSSXMLObjectSubTypes.DssXmlSubTypeUser);
userSearch.setDomain(EnumDSSXMLSearchDomain.DssXmlSearchDomainRepository);
WebUser user = (WebUser) performSearch(userSearch);
if(user!=null){
try {
WebPropertyGroup wpg = user.getPropertySets();
for(int i=0; i< wpg.size(); i++){
WebPropertySet wps = wpg.get(i);
System.out.println(wps.getName());
for(int j=0; j<wps.size(); j++){
WebProperty wp = wps.get(j);
System.out.println("\t"+wp.getName()+": " +wp.getValue());
}
}
} catch (WebObjectsException e) {
e.printStackTrace();
}
}
}
public static WebIServerSession getServerSession(String serverName, String Project, String loginName, String password) {
WebIServerSession sessionInfo = null;
try {
WebObjectsFactory woFact = WebObjectsFactory.getInstance();
sessionInfo = woFact.getIServerSession();
sessionInfo.setServerName(serverName);
sessionInfo.setProjectName(Project);
sessionInfo.setLogin(loginName);
sessionInfo.setPassword(password);
sessionInfo.setApplicationType(EnumDSSXMLApplicationType.DssXmlApplicationCustomApp);
//Create a new session
sessionInfo.getSessionID();
} catch (WebObjectsException ex) {
System.out.println("Error creating a session");
}
return sessionInfo;
}
public static Object performSearch(WebSearch search){
try {
search.submit();
WebFolder folder = search.getResults();
if(folder.size()>0){
if(folder.size()==1){
return folder.get(0);
} else {
System.out.println("Search returns more than 1 object, returning first object");
return folder.get(0);
}
}
} catch (WebObjectsException ex) {
System.out.println("Error performing search: "+ex.getMessage());
}
return null;
}
}