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

How to Access Admin Configuration form data in Task plugin?

sourabh sharma April 18, 2017

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
Gonchik Tsymzhitov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 9, 2019

Hi! 

What is was the use case? 

Cheers,

Gonchik Tsymzhitov

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events