The following sample code explains how to create a new subscription address for a user in the user editor using Strategy Web SDK version 9.3.1 - 9.4.x
Editing of a user needs an admin session as shown below
//Create IServer session
WebIServerSession isess = WebObjectsFactory.getInstance().getIServerSession();
isess.setServerName("IServer");
isess.setLogin("administrator");
isess.setPassword("");
isess.setServerPort(0);
isess.setAuthMode(EnumDSSXMLAuthModes.DssXmlAuthStandard);
WebObjectSource source = isess.getFactory().getObjectSource();
//Get the user for whom the address needs to be created
WebUser user= (WebUser) source.getObject("05873C524739B624373D648972366580", EnumDSSXMLObjectTypes.DssXmlTypeUser); //Replace the object with user's UID.
user.populate(); // need to call populate method before manipulating the object.
//Get the current user addresses
WebSubscriptionUserAddresses _addresses = user.getAddresses();
//Add new address to the addresses list for the required delivery mode
WebSubscriptionAddress subAddr = _addresses.addNewAddress(EnumDSSXMLSubscriptionDeliveryType.DssXmlDeliveryTypeEmail);
//Set the Address Name
subAddr.setName("MyTest");
//Set the Physical Address
subAddr.setValue("myaddr@abc.com");
//Set the device id to generic email
subAddr.setDevice("1D2E6D168A7711D4BE8100B0D04B6F0B");
//Save the address
subAddr.save();
_addresses.saveAddress(subAddr);
//Save the user
source.save(user);
for (int i = 0; i < _addresses.size(); i++) {
//Get a subscription address from the list of already created addresses
WebSubscriptionAddress addr = _addresses.get(i);
addr.populate();
//Get the device corresponding to the desired address
WebSubscriptionDevice device = addr.getDevice();
//Get the deviceID
String deviceID = device.getID();
}
NOTE
The size of the addresses for that user is not updated after saving the new address to the user. If an output for size() from the WebSubscriptionUserAddresses class is called before the address is added and after the address is added, the number does not appear to be changing. Using the sample above, the following lines would be added before and after adding an address (respectively):
//Output the number of addresses before adding a new address:
System.out.println("# of Addresses before is: " + _addresses.size());
//Output the number of addresses after adding a new address:
System.out.println("# of Addresses after is: " + _addresses.size());
user= (WebUser) source.getObject("54F3D26011D2896560009A8E67019608", EnumDSSXMLObjectTypes.DssXmlTypeUser);
user.populate();
_addresses = user.getAddresses();