How to redirect on version creation ?

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.
April 12, 2012

Hi All ,

I want to redirect the user to a version tab panel(created through a plugin) after the user creates a version. How can this be done ? In 4.3 there is a AddVersion action which can be extended and for 4.4 there is an Add Version Event .

Please can someone help me with this .

Thanx

7 answers

1 accepted

4 votes
Answer accepted
JamieA
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.
April 15, 2012

I wouldn't modify any of the files in jira.

Instead, add the following using a web resource context, or just put in announcement banner:

AJS.$(function () {
    AJS.$("#project-config-versions-add").submit(function() {
        window.location.href = "http://www.google.com";
    });
});

That's just an example - you should check the return code of the ajax call, and only if valid and the version is created should you redirect. I'm putting this code very much as a starting point only...

Jobin Kuruvilla [Adaptavist]
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.
April 15, 2012

like that!

(10 characters needed in comment? )

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.
April 15, 2012

Thanx Jamie :) , the script works fine for 4.4 but not for 4.3 . what changes should i make to make this script work in 4.3 ?

and by web resource context you meant web resource plugin module ?

In my url i need the project key and the created version id , will i be able to get that in the script ?

JamieA
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.
April 15, 2012

for 4.3 you need to do it the old way AFAIK.

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.
April 16, 2012

For 4.3 i am trying the below code to redirect in the class which extends the AddVersion action

Redirect redirect=(Redirect)ActionFactory.getAction(Action.SUCCESS);
		redirect.setUrl("http://www.google.com");
		return redirect.execute();

but i get an exception

java.lang.IllegalArgumentException: Action 'success' not found or could not be initialized a class with that name could not be found.

Is the correct way to redirect ?

i also tried by adding a new <view> in the plugin.xml and return to that view but i get an exception

java.lang.illegalstateexception cannot forward after response has been committed

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.
April 16, 2012

Hi Jamie,

with the old way i am not able to redirect to the version tab .

i used the following

return getRedirect("../../browse/"+pKey+"/fixforversion/"+vId+"");

Is this correct ? am i missing something ?

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.
April 16, 2012

Hi Jobin, When i use the above return statement i get a java.lang.IllegalStateException

and the URL is :http://localhost:2990/jira/secure/project/AddVersion.jspa?atl_token=BV8N-OK2J-IQUQ-YNNK|90ac7060aaed2a887488c89579c0438382ac78e8|lin&pid=10000

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.
April 16, 2012

I am sorry , i did not get , which token at the end ?

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.
April 16, 2012

For testing i had used this as a URL

return getRedirect("/browse/RM/fixforversion/10221");

a valid pkey and version id .

Jobin Kuruvilla [Adaptavist]
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.
April 16, 2012

cool. But it is still missing the token. Just a wild guess.

Jobin Kuruvilla [Adaptavist]
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.
April 16, 2012

Maybe it is because of the missing token in the end? Can you try adding that too in the URL and see if it helps?

Jobin Kuruvilla [Adaptavist]
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.
April 16, 2012
?atl_token=BV8N-OK2J-IQUQ-YNNK|90ac7060aaed2a887488c89579c0438382ac78e8|lin

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.
April 17, 2012

I tried with the token but its still not redirecting and giving the same exception(java.lang.IllegalStateException) when i add a version .

My tab is in the first position so its displayed by default when i redirect to browse/RM/fixforversion/10221

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.
September 19, 2012

Hi Jamie ,

How can i check the return code of the ajax call in the script provided by you.

AJS.$(function () {
    AJS.$("#project-config-versions-add").submit(function() {
        window.location.href = "http://www.google.com";
    });
});

Also the URL contains the version id which is created , can this be possible ?

Thank you

2 votes
tousifs
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.
April 18, 2012

Hi Mizan,

I have implemented AddVersion 4.3 in do execute method i have put this

{

String url="http://localhost:2990/jira/browse/MP/fixforversion/10001";

return getRedirect(url);

}

i am able to redirect properly.

problem:- i am not able to add new version from Manage Versions even it is not showing in versions list. but i am able to get in my code via super.getName();

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.
April 18, 2012

You are able to redirect and the version is not getting added because you have not called the super.doExecute()

super.getName() returns the name you have entered not the version name

I dont know why its not redirecting

@Override
	protected String doExecute() throws Exception {
		Long vid = null;
		String ret_val  = super.doExecute();
		if (!ret_val.equals(Action.ERROR)){
			
			String verName=getName();
			System.out.println("Version name from add version:"+verName);
			String in=getProjectObject().getKey();
			
			System.out.println("pid:"+in);
			Collection&lt;Version&gt; version1=getVersionManager().getVersionsByName(verName);
			Iterator i=version1.iterator();
			if(i.hasNext())
			{
				Version v=(Version) i.next();
				vid=v.getId();
				
			}
			
			
		return getRedirect("/browse/"+in+"/fixforversion/"+vid+"");
			
		}
		else{
			System.out.println("this is a error"+ret_val);
			return ret_val;
			
		}
		}

Above is my code

tousifs
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.
April 18, 2012

i have done with Redirection

i just have @overiden all methods AddVersion in my class.

addition to that i have called super(authenticationContext,versionService); constructor.

the basic change in code is doexucute method is : return getRedirect("/browse/MP/fixforversion/10002");

prior to this it was : returning as return getRedirect("ManageVersions.jspa?pid=" + getProjectObject().getId());

now its working fine.

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.
April 18, 2012

Thanks Tousif , From Jira source i noticed that doExecute() returns getRedirect("ManageVersions.jspa?pid=" + getProjectObject().getId());

I did as you said and replaced

getRedirect("ManageVersions.jspa?pid=" + getProjectObject().getId());

with

return getRedirect("/browse/"+pkey+"/fixforversion/"+vid);

2 votes
Jobin Kuruvilla [Adaptavist]
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.
April 16, 2012

Try

return getRedirect("/browse/"+pKey+"/fixforversion/"+vId);

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.
April 15, 2012

Thanx , so it is possible to redirect after listening the VersionCreateEvent ? for 4.3 i am trying to redirect using the getRedirect("url");

eg:

return getRedirect("../../browse/"+pKey+"/fixforversion/"+vId+"");

but this does not help i get a java.lang.IllegalStateException

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.
April 15, 2012

Which js files i will have to modify ?

0 votes
Jobin Kuruvilla [Adaptavist]
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.
April 15, 2012

Listeners run in a different thread. So redirecting in a listener is not possible. You should modify the Javascript files as Jamie mentioned!

0 votes
JamieA
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.
April 12, 2012

It's done through a rest call in 4.4, so I think you would need to write some javascript to plug in to that. It won't be as simple as the old way.

Suggest an answer

Log in or Sign up to answer