-1

I have been exploring Jira plugin development for a while.

I have a scenario where I need to store user-specific data in the backend. Consider it a set of some Input fields(On right panel of view issue page), which asks some info from user and later displays it when user had saved it. I don't want to enclose input fields in tag. I want to handle things via calling APIs(REST modules) via AJS. Please suggest best way to do this.

Even after going through various docs and examples I could not find a solid approach to do this, and still there is a bit of confusion.

For storing data, I could find two ways. I can use PluginSettingsFactory or ActiveObjects. Apparently, these two services cannot be used in REST modules(Correct me if I am wrong. It will solve my problem.)

I want to go via ActiveObjects approach. But I not sure whether I can use it in JIRA plugin because it is made for Generic Confluence apps.

Let's say if it is possible to use ActiveObjects in JIRA plugin. I am not sure how to call POST of servlet using AJS. Please suggest a way if there is any?

If ActiveObjects can't be used in JIRA plugin, I will anyways have to go with PluginSettingsFactory inside servlets because apparenly I cannot use PluginSettingsFactory in REST Module. Again, I will have to go via Servlet approach and I am not sure how to call POST of servlet using AJS.

I know there are too many questions in this post.

Please suggest a way if there is any?

Imamudin Naseem
  • 1,604
  • 18
  • 21

1 Answers1

0

You can use PluginSettingsFactory, at least I use it

Create UserSettings class

@ExportAsService
@Component
public class UserSettings {


   private final PluginSettingsFactory pluginSettingsFactory;
   private String KEY="mykey"

   @Autowired
   public UserSettings(
        @ComponentImport PluginSettingsFactory pluginSettingsFactory,
   ) {

      this.pluginSettingsFactory = pluginSettingsFactory;

   }


   public void set(String namespace, string key, string value){
      PluginSettings pluginSettings = pluginSettingsFactory.createSettingsForKey(KEY + namespace);
      pluginSettings.put(key, value);
   }


   public String get(String namespace, name key){
      PluginSettings pluginSettings = pluginSettingsFactory.createSettingsForKey(KEY + namespace);
      pluginSettings.get(key);
   } 

}   

Now in your REST module you can use

Component
@Path("/path")
public class RestModule {

   private final UserSettings UserSettings;

   @Autowired
   public RestModule(
           UserSettings UserSettings
   ){
       this.userSettings = userSettings;
   }

   @POST
   @Path("{someParam}")
   @Produces({MediaType.APPLICATION_JSON})
   @Consumes({MediaType.APPLICATION_JSON})
   public Response getResponse(@PathParam("someParam") String someParam, RequestDataModel data)        
   {
      try {
            // Storing a value of data.someKey with key "someKey" in namespace someParam
            userSettings.set(someParam,"someKey", data.someKey);
      }
   }

}

Disclaimer: I didn't compile and run this code specifically, it is a simplified version of my code that uses such concept

Yuri G.
  • 4,323
  • 1
  • 17
  • 32