It's all about the answers!

Ask a question

Asset update owner by using RAM API


pan tianming (4765644) | asked Jun 17 '11, 3:54 a.m.
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



permanent link
Rich Kulp (3.6k38) | answered Jun 17 '11, 10:52 a.m.
FORUM MODERATOR / JAZZ DEVELOPER
On 6/17/2011 4:08 AM, pantian wrote:
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.


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

permanent link
pan tianming (4765644) | answered Jun 20 '11, 4:59 a.m.
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.

permanent link
Rich Kulp (3.6k38) | answered Jun 20 '11, 9:27 a.m.
FORUM MODERATOR / JAZZ DEVELOPER
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

permanent link
pan tianming (4765644) | answered Jun 20 '11, 11:14 p.m.
Hi Rich,

Sure, thank you, I will try it.

Your answer


Register or to post 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.