Asset update owner by using RAM API
We want to implement the following goal:
One asset owner is A, it must be changed to owner B. But after we run the following RAM API codes, it not like we expect: UserInformation[] owners = asset.getOwners(); List<UserInformation> ownerList = new ArrayList<UserInformation>(); for(UserInformation userInfo: owners) { ownerList.add(userInfo); } Iterator<UserInformation> iterator = ownerList.iterator(); while (iterator.hasNext()) { UserInformation owner = iterator.next(); if (owner.getEmail().equals(asset.getOwner())) { iterator.remove(); } } After the above codes running, in the Asset page "Owners" tab the owner B is set as the default owner, but the owner A is not removed from the owner list, his name just followed B. Is my API codes has any problem? Thanks. |
4 answers
On 6/17/2011 4:08 AM, pantian wrote:
We want to implement the following goal: What version of RAMClient are you using? By the way: There is no concept of a default owner, you are either an owner or not an owner. And an asset has a list of owner(s). That is where I'm getting confused because none of the API have an asset.getOwner() (singular) method. They only have an asset.getOwners() (plural) method. With the RAMClient you need to set the new set of owners back into the RAMAsset and then do a putAsset to submit the updates to the host. Just removing it from your ownerList does nothing because that is just a copy you had made. -- Rich Kulp Rational Asset Manager developer |
Hi Rich,
We are using RAM version is 7.2.0.2, fix pack 6. Sorry, I should not use asset.getOwner() because actually in our codes this owner is just sent in as a parameter "assetOwner". We also have submitted the updates by setting the owner list, sorry I just lost the rest of codes: The completely codes like this: UserInformation[] owners = asset.getOwners(); List<UserInformation> ownerList = new ArrayList<UserInformation>(); for(UserInformation userInfo: owners) { ownerList.add(userInfo); } Iterator<UserInformation> iterator = ownerList.iterator(); while (iterator.hasNext()) { UserInformation owner = iterator.next(); if (owner.getEmail().equals(assetOwner)) { iterator.remove(); } } RAMUser user = session.getUser(account.getEmail()); ownerList.add(user); asset.setOwners(ownerList.toArray(new UserInformation)); session.put(asset, new RAMStatusMonitor()); Sorry for the mistake. |
Hi Pantian,
Go in through debug mode and take a look at the array created by "ownerList.toArray(new UserInformation)" and verify that the owner is actually removed from the list. It may be that owner.getEMail().equals(assetOwner) never actually matches anyone. The fact that it actually added your new user would indicate the update had worked. -- Rich Kulp Rational Asset Manager developer |
|
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.