Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,360,972
Community Members
 
Community Events
168
Community Groups

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 9.0 is now available

Hey there, Data Center community! I'm Martyna Wojtas and I am the Product Manager for Bamboo Data Center. I’m excited to share that Bamboo 9.0 is now available. We purpose-built this platform to help...

310 views 0 7
Read article

Atlassian Community Events