JIRA SOAP - Create a new Role

AbrahamA
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.
December 24, 2012

Hi

I am trying to create roles programatically.

I have the authtoken and jirasoapservice:

Just stuck here. Any pointers or code snippets are appreciated.

Thanks

Abe

I was able to create Project, User ( now trying to create roles, but going no where)

// What I have been trying

public static void CreateRoles(String token, JiraSoapServicejiraSoapService, String myRole){

//RemoteProjectRole rmpRole = new RemoteProjectRole(token, myRole," Description");

//jiraSoapService.createProjectRole(token, new RemoteProjectRole(token,myRole));

}

2 answers

1 accepted

0 votes
Answer accepted
Faisal
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.
December 24, 2012

Hi Abraham,

Looking at the provided code, I believe that the rmpRole object needs to be initialized first. I did a bit testing on my end, and I am able to create a project role via SOAP using the following piece of code:

static final String rolename="Role Name";

......


private static void testCreateRole(JiraSoapService jiraSoapService, String token)
			throws RemoteException
	{
		Timing timing = Timing.startTiming("createprojectrole by setName");
		
		try
		{
			System.out.println("Testing Create Project Role");
			RemoteProjectRole create = new RemoteProjectRole(); 
			create.setName(rolename);
			create.setDescription("This is a Role created by SOAP");
			jiraSoapService.createProjectRole(token, create);
		}
		finally
		{
			timing.printTiming();
		}
	}

I hope that this will help!

AbrahamA
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.
December 24, 2012

Thanks Ahmad.

I got it to work with your code.

What is this Timing class, which package does it come from?

Thanks

Abe

Faisal
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.
December 25, 2012

Thanks Abe, I'm glad to know that the example provided above helps.

Anyway as for the timing method, actually it's meant to capture the time information of how long does it take for a method to run when we execute the code. The information will be displayed in the console. Here's a snippet of the full method:

private static class Timing
    {
        private String operationDesc;
        private long then;

        private Timing(final String operationDesc)
        {
            this.operationDesc = operationDesc;
            this.then = System.currentTimeMillis();
        }

        private static Timing startTiming(String operationDesc)
        {
            System.out.println("\nRunning : " + operationDesc);
            return new Timing(operationDesc);
        }

        private void printTiming()
        {
            final long howLong = System.currentTimeMillis() - this.then;
            System.out.println("________________________________________________________________");
            DecimalFormat decFormat = new DecimalFormat("###,##0");
            System.out.println("\t" + this.operationDesc + " took " + decFormat.format(howLong) + " ms to run");
        }
    }

And when running the SOAP client, the output should look like below in the console:

Running : createprojectrole by setName
Testing Create Project Role
________________________________________________________________
        createprojectrole by setName took 70 ms to run

Thanks!

0 votes
Renjith Pillai
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.
December 24, 2012

What is the exception that you are getting?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events