It's all about the answers!

Ask a question

Moving assets into approved state using Java API


Anuradha Bhamidipaty (1322) | asked Sep 23 '13, 6:56 a.m.
The requirement is to bulk upload assets and transition them into approved state.

Asset Lifecycle is set to Draft -> Review -> Approved
Review to Approved transition requires at least one approval from the asset reviewers user group.

I am the community admin and belong to asset reviewers user group. I am using the following code to transition the lifecycle of assets. The program executes fine but the assets are set to Review state instead of approved state.

Would be helpful if someone can point out the error?
public void setApproveState(RAMAsset anAsset) {
	//move the asset into review state
RAMAction[] actions = anAsset.getAvailableActions();
for (int i = 0; i < actions.length; i++) {
if (actions[i].getName().equals("Submit for Approval")) {
anAsset.setAction(actions[i]);
break;
}
}
session.put(anAsset, new NullProgressMonitor());

//provide one approval for the asset in review state
RAMStateHistory stateHistory = anAsset.getCurrentStateHistory();
RAMVote review = new RAMVote();
review.setVoteChoice(RAMVote.APPROVE);
review.setComment("comment");
stateHistory.castVote(review);
session.put(anAsset, new NullProgressMonitor());

// move the asset to approved state
actions = anAsset.getAvailableActions();
for (int i = 0; i < actions.length; i++) {
if (actions[i].getName().equals("Approve")) {
anAsset.setAction(actions[i]);
break;
}
}
session.put(anAsset, new NullProgressMonitor());
}

Comments
Gili Mendel commented Sep 23 '13, 9:20 a.m.
JAZZ DEVELOPER

Are you saying that the first transition, and the vote are recorded fine, but that the last action ("Approve") did not take place?  ... i.e., if you look at the asset on the web, you it is in the 2nd state, and the vote is recorded?


btw, there is no indication in your code if any action was found .... are you sure that the setAction was executed?


Anuradha Bhamidipaty commented Sep 23 '13, 9:50 a.m.

Gili, when I look the asset on the web, the first transition and vote are recorded fine but the last approve action didn't take place.
I removed logging statements here but the log confirms that setAction(...) was executed.

Is there something missing in the code to satisfy the policy constraint of having one approval by asset reviewer?

My transition condition from Review -> Approve is
- Manual action is Approve
- Number of approvals from Asset reviewers is 1


Millard Ellingsworth commented Sep 27 '13, 7:15 p.m.
FORUM ADMINISTRATOR / JAZZ DEVELOPER

Where does this code run? Perhaps the RAMVote needs to be associated with a user from the Asset reviewers group (while you say the vote is recorded, does it show as recorded by you)? Does logging also confirm that closing put() is called? A stretch, I know...

Be the first one to answer this question!


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.