The following code shows how to create a new user with the Strategy Web SDK 10.x. The code also shows how to retrieve an existent user to later set additional information on the object.
package com.Strategy.custom.standalone;
import com.Strategy.web.beans.UserBean;
import com.Strategy.web.beans.UserEntityBean;
import com.Strategy.web.beans.WebBeanException;
import com.Strategy.web.beans.WebBeanFactory;
import com.Strategy.web.objects.WebIServerSession;
import com.Strategy.web.objects.WebObjectSource;
import com.Strategy.web.objects.WebObjectsException;
import com.Strategy.web.objects.WebObjectsFactory;
import com.Strategy.web.objects.admin.users.WebUser;
import com.Strategy.webapi.EnumDSSXMLAuthModes;
public class newUser {
public static void main(String[] args) {
WebIServerSession isess =
WebObjectsFactory.getInstance().getIServerSession();
isess.setServerName("localhost");
isess.setLogin("administrator");
isess.setProjectName("Strategy Tutorial");
isess.setPassword("");
isess.setServerPort(0);
isess.setAuthMode(EnumDSSXMLAuthModes.DssXmlAuthStandard);
try {
isess.getSessionID();
WebObjectSource wos = isess.getFactory().getObjectSource();
UserEntityBean user = null;
user = WebBeanFactory.getInstance().newUserBean();
user.setSessionInfo(isess);
user.InitAsNew();
//Fetch properties for the user
WebUser ua = (WebUser) user.getUserEntityObject();
//Set basic user information
ua.setLoginName("ZZZ_TestUser");
ua.setFullName("Sample User");
user.getObjectInfo().setDescription("This user was created using SDK");
//Save new User
user.save();
//Gather user ID for later retrieval
String userID = user.getObjectID();
//Destroy User Object
user = null;
//Create a new User object
user = WebBeanFactory.getInstance().newUserBean();
user.setSessionInfo(isess);
user.InitAsNew();
//Attach the above created user
user.setObjectID(userID);
//Set description
user.getObjectInfo().setDescription("New Description");
//Save user changes
user.save();
System.out.println("Done");
} catch (WebBeanException ex) {
System.out.println("Error creating a session: " + ex.getMessage());
} catch (WebObjectsException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
WARNING MESSAGE:
Customization Code 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 may not be able to provide additional code on this matter even though this customization is provided at this time for this specific build.