Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to Access Admin Configuration form data in Task plugin? Edited

I created a task plugin which includes a admin configuration form.I can save data in admin configuraion form but now I have to access that admin form data in task plugin while I build that task.Below is the rest resource class which is used to get and put admin form data. Data is name and time. Is there any way by which I can access this name and time data from another java class.

.

.

.
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.atlassian.plugin.spring.scanner.annotation.component.Scanned;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
import javax.inject.Inject;

import com.atlassian.sal.api.pluginsettings.PluginSettings;
import com.atlassian.sal.api.pluginsettings.PluginSettingsFactory;
import com.atlassian.sal.api.transaction.TransactionCallback;
import com.atlassian.sal.api.transaction.TransactionTemplate;
import com.atlassian.sal.api.user.UserManager;

@Path("/")
@Scanned
public class ConfigResource
{
@ComponentImport
private final UserManager userManager;
@ComponentImport
private final PluginSettingsFactory pluginSettingsFactory;
@ComponentImport
private final TransactionTemplate transactionTemplate;

@Inject
public ConfigResource(UserManager userManager, PluginSettingsFactory pluginSettingsFactory,
TransactionTemplate transactionTemplate)
{
this.userManager = userManager;
this.pluginSettingsFactory = pluginSettingsFactory;
this.transactionTemplate = transactionTemplate;
}

@GET
@Produces(MediaType.APPLICATION_JSON)
public Response get(@Context HttpServletRequest request)
{
String username = userManager.getRemoteUsername(request);
if (username == null || !userManager.isSystemAdmin(username))
{
return Response.status(Status.UNAUTHORIZED).build();
}

return Response.ok(transactionTemplate.execute(new TransactionCallback()
{
public Object doInTransaction()
{
PluginSettings settings = pluginSettingsFactory.createGlobalSettings();
Config config = new Config();
config.setName((String) settings.get(Config.class.getName() + ".name"));

String time = (String) settings.get(Config.class.getName() + ".time");
if (time != null)
{
config.setTime(Integer.parseInt(time));
}
return config;
}
})).build();
}

@PUT
@Consumes(MediaType.APPLICATION_JSON)
public Response put(final Config config, @Context HttpServletRequest request)
{
String username = userManager.getRemoteUsername(request);
if (username == null || !userManager.isSystemAdmin(username))
{
return Response.status(Status.UNAUTHORIZED).build();
}

transactionTemplate.execute(new TransactionCallback()
{
public Object doInTransaction()
{
PluginSettings pluginSettings = pluginSettingsFactory.createGlobalSettings();
pluginSettings.put(Config.class.getName() + ".name", config.getName());
pluginSettings.put(Config.class.getName() +".time", Integer.toString(config.getTime()));
return null;
}
});
return Response.noContent().build();
}

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public static final class Config
{
@XmlElement private String name;
@XmlElement private int time;

public String getName()
{
return name;
}

public void setName(String name)
{
this.name = name;
}

public int getTime()
{
return time;
}

public void setTime(int time)
{
this.time = time;
}
}
}

1 answer

0 votes

Hi! 

What is was the use case? 

Cheers,

Gonchik Tsymzhitov

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bamboo

Bamboo 101 Video

G’day Community! As we gear up to introduce Bamboo Data Center to the world, we wanted to make sure that we shared a bit more about Bamboo, the product. Our team has put together an overview video ...

223 views 4 6
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you