Post

3 followers Follow
0
Avatar

JSON representation of a ConfigurationItem from an EventListener

What is the Java class/method I would need to use to get the JSON representation of a ConfigurationItem from an EventListener java class? I know I can get it through the RestAPI, but those both require a separate HTTP call. I would like to do a direct method call from my existing Java class to get that info

Chris Evans

Please sign in to leave a comment.

7 comments

0
Avatar

To be on the safe side, use the REST call because it will be guaranteed to work across versions. Having said that, at what frequency do you need to produce JSON, in other words what are the event types you are listening for?

Kind regards,

Hes Siemelink 0 votes
0
Avatar

I am making frequent calls - whenever a CI item ( Folder, Release, Phase, and Task) is created, updated, or deleted.  This is part of my homegrown version control solution.  I would like to call the REST methods directly, without having to make the actually HTTP call for two reasons.  First, I'm already in the Java process, no sense in opening another thread; and secondly, I don't want to deal with the security aspect.

I know that when the rest call is made, some internal method is called that provides the JSON object to the REST client, I just don't have insight into what class and method might be.

Chris Evans 0 votes
0
Avatar

You can create ObjectMapper instance and use it to serialize POJO to JSON. Unfortunately, you cannot serialize ConfigurationItem directly because we do not provide any JSON writer as a public API, but you can easily create your own POJO class and serialize it with ObjectMapper.

Grigorii Tkachuk 0 votes
0
Avatar

I'm not sure that would work in my case - once I get the JSON from my event listener, I need the ability to POST it to the REST API at a future date, so it needs to be in the correct format.

Chris Evans 0 votes
0
Avatar

While we figure out if there is some JSON / CI wrapper available... what about the following

You say you do the POST -- to an external system? -- in the future. Is this because you are saving up the changes? 

In that case what you can do is save the release ID and do the retrieval of the REST representation of the template at the moment you want to POST it to the external system.

Kind regards,

Hes Siemelink 0 votes
0
Avatar

This is part of a version control system I am working on.  When I detect changes in a Template through the Event Listener, I grab the JSON representation of the ConfigurationItem and store it in Git.  If we need to rollback a change, say someone deleted a phase accidentally, or wanted to revert to a previous version of a template, I would be able to use the REST API to POST the JSON back  into XLR.  IN order to do that, I need to make sure the JSON I get in the EventListener is same format, etc that the REST API accepts.

 

Chris Evans 0 votes