It's all about the answers!

Ask a question

How to get buildDefinition from AdvisableOperation via RTC API


han huynh (1911) | asked Jul 22 '16, 3:35 a.m.
edited Jul 22 '16, 4:41 a.m. by Ralph Schoon (58.7k23642)
Dear RTC API team,

I'd like to have question on getting buildDefinition from AdvisableOperation via RTC API.
I'm trying to write a RTC extension with the event has operation id com.ibm.team.build.server.saveBuildDefinition for my case of update a build definition, I can debug in my class SaveBuildDefinition implements IOperationParticipant and see val$buildDefinition variable, but I can't find any API to get BuildDefinitionImpl object.

My point is when I update a build definition and do save, RTC server will trigger my class SaveBuildDefinition and then I can get the build definition info which I'm working on.

Can you please help me out.

Thank You!

Comments
han huynh commented Jul 22 '16, 3:50 a.m. | edited Jul 22 '16, 4:42 a.m.

Now I can find a way like:

Field field = operation.getClass().getDeclaredField("val$buildDefinition");
field.setAccessible(true);
BuildDefinitionImpl buildDefinition = (BuildDefinitionImpl)field.get(operation);

If someone has any better way, please help to provide.

Thanks.

One answer



permanent link
Ralph Schoon (58.7k23642) | answered Jul 22 '16, 4:47 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Jul 22 '16, 4:49 a.m.
I would suggest to look at one of the advisors here: https://rsjazz.wordpress.com/?s=advisor

All work with this pattern:
Object data = operation.getOperationData();
	if (data instanceof ISaveParameter) {
		IAuditable auditable = ((ISaveParameter) data).getNewState();
		if (auditable instanceof IWorkItem) {
			IWorkItem workItem = (IWorkItem) auditable;


You test if the object is what you expect it to be - depends on the operation ID - and cast it.
Note in your case the interface is likely IBuildDefinition or something. Without good reason you never cast to the implementation class. You always use the interface.





Comments
han huynh commented Jul 22 '16, 5:30 a.m.

Thanks Ralph for the quick response. In my case currently operation.getOperationData() returns null.


Ralph Schoon commented Jul 22 '16, 6:17 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

You don't provide any information about the operation etc. So what you see above is what works in general. See How should I ask a question in the Forum if I want to receive useful answers?


han huynh commented Jul 22 '16, 6:36 a.m.

Ok. I will try to explain my issue. Thanks for your time.

Your answer


Register or to post your answer.