Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

VersionDeleteEvent GetVersion information

Hans de Groot
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 11, 2013

I'm trying to do something usefull with the VersionDeleteEvent. The event is triggered but I only gat an Id. And from this event I cannot get any version information.

This is my code:

@EventListener

public void VersionDeleteEvent(VersionDeleteEvent versionDeleteEvent) {

Long id = versionDeleteEvent.getVersionId();

Version version = versionManager.getVersion( id );

Project project = version.getProjectObject();

}

The getVersion returns null, so I dont know what project or version is deleted. How can I retrieve this information?

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Hans de Groot
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 14, 2013

Define the cache

private HashMap<Long, Version> versions = new HashMap<Long, Version>();

Fill the cache, on afterPropertiesSet and version creation/deletion

private void CacheVersions() {
		Collection<Version> allVersions = versionManager.getAllVersions();
		versions.clear();
		for(Version v : allVersions)
		{
			versions.put(v.getId(), v);
		}
	}

Use the cache

if(versions.containsKey(versionDeleteEvent.getVersionId())){
			Version version = versions.get(versionDeleteEvent.getVersionId());
			// use the version. 
		}

0 votes
Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 11, 2013

The only way is to create your own cache in the lictener class and store the attributes you need, so when the version is removed you're able to lookup the value from the cache by id. As Mizan said there is no way to get the actual object as the code in JIRA is :

// delete the version from the system
versionManager.deleteVersion(version);
...
eventPublisher.publish(new VersionDeleteEvent(version.getId()));

Dipti Ranjan Behera
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 11, 2013

@Boris,

can you elaborate , how to create cache if the listener class is called only when the event has occured.

Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 11, 2013

I suppose your listener class implements InitializingBean, DisposableBean. In that case you can initialize the cache in the afterPropertiesSet before calling eventPublisher.register(this); and then clear the cache in the destroy method after the call to eventPublisher.unregister(this);

Hans de Groot
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 11, 2013

I was already afraid for this answer. But why is it implemented this way. And why isn't there a pre-VersionDeleteEvent I think it can be very usefull.

Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 11, 2013

You can always log a feature request to JIRA :). I've got no idea why thy've implemented it this way. Actually getting an id to a non-existing object is not very useful.

Hans de Groot
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 11, 2013

So I created a feature request: https://jira.atlassian.com/browse/JRA-33879

Lets see what happens with that.

Dipti Ranjan Behera
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 11, 2013

@Boris,

i will definitely your suggestion.

0 votes
Dipti Ranjan Behera
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 11, 2013

@Hans,

as the version is deleted from DB, therefore you wont get any version information (object) except the id of it .

workaround :

you can create a separate table with version id , name , project as input when somebody creates a version in any of the project (versioncreate event can take of this).

so when somebody deletes a version , you have the version id and you can get version info from your custom created table.

0 votes
Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 11, 2013
Since the version is deleted from JIRA it is returning null, You can only get the version id . Even I had faced this issue earlier .

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events