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;
}
}
}

0 answers

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Monday in Confluence

Organizing your space just got easier - Page Tree Drag & Drop is here

Hi Community! I’m Elaine, Confluence Product Manager. You may have read my earlier post about page tree in space navigation sidebar. I'm excited to share another improvement that helps you organize ...

58 views 3 2
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you