Up-To-Date Tutorial of how to use Active Objects

Dear Community,

I am new in developing Add-Ons and at the moment, I am trying to use Active Objects but unfortunately, it doesn’t work. Can you please help me?

First of all: I am using Jira SDK with the following settings:

  • Jira version 7.12.0
  • amps version 6.3.21
  • Spring scanner: 1.2.13

What have I done so far?

I have my Add-On Skeleton which works fine so far. I have a webwork which I want to use to enter data. That works fine. A HTML formular appears and I am able to hit “save”. “Save” goes to my Java class which accept all the HTML formular fields. Furthermore I have an active objects class with the definition my of “table”:

package de.idsimaging.com.jira.activeobjects;
import net.java.ao.Entity;

public interface MyOwnTable extends Entity
{
String getName();
String setName(String name);

String getDescription();
String setDescription(String description);

}

No compiler errors so far and the “table” also appears in database and in “Plugin data storage” section in JIRA.

Now, it’s time to use it but that’s the point where i struggled with and where I ask for your help. I’ve read several tutorials but either i don’t understand or the tutorials are out of date. I’ve read the following points, unknown if they true or false:

I need to import the right package

import com.atlassian.activeobjects.external.ActiveObjects;

Result: Works. No errors.

I need to extend my constructor of my related Java class by adding:

public MyOwnTableAction(@ComponentImport final ActiveObjects ao)
{
obj_ProjectManager = getProjectManager();
//this.ao = ao;

}

Result: It doesn’t work. Error file says “org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name…” In that case, I’ve read, that I have to import an “component-import” to my plugin.xml ->

I need to add a component-import to my plugin.xml

<component-import key=“ao” name=“Active Objects service” interface=“com.atlassian.activeobjects.external.ActiveObjects”>
<description>Component to access Active Objects functionality from the plugin</description>
</component-import>

Result: It doesn’t work. Error appears: “atlassian-plugin.xml contains a definition of component-import. This is not allowed when Atlassian-Plugin-Key is set.” No idea of what to do.

I need to add an dependency to my pom.xml

<dependency>
<groupId>com.atlassian.activeobjects</groupId>
<artifactId>activeobjects-plugin</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>

Result: Done. No errors. But I also have read that I don’t have to do it when I use Atlassian Spring Scanner? Not sure what that means but I have some active spring scanner settings in my pom.xml.

Can you please help me to find the absolut minimalist of how to use a very simple Active Objects in an Add-On? Thank you very much in advance.

Kind regards!

One of your problems is that you are getting mixed up between two different ways that an app can do component imports.

The old way is to use component-import in atlassian-plugin.xml like you tried to by adding:

<component-import key=“ao” name=“Active Objects service” interface=“com.atlassian.activeobjects.external.ActiveObjects”>
<description>Component to access Active Objects functionality from the plugin</description>
</component-import>

The new way is to use something called Spring Scanner where you use annotations like @ComponentImport such as below, you read more about it here Bitbucket

public MyOwnTableAction(@ComponentImport final ActiveObjects ao)

Either you should import ActiveObjects using the atlassian-plugin.xml declaration or using the annotation via spring scanner, not both. Having the property <Atlassian-Plugin-Key> in your pom.xml tells Jira that your plugin is using spring scanner. Which is why it throws an error when you added the component-import to your atlassian-plugin.xml. You can safely leave the import out of the xml it’s not required since you have the annotation.

Sorry the above only answers part of your question, but that’s all the time I have for now :slight_smile:

2 Likes

Thank you very much for your help. It lead me to the right way and now it works. I had to do the following:

  1. Design my Entity

  2. Add my Entities to my Plugin Descriptor

<ao key=“de.mypackage.com.jira.activeobjects”>
<entity>de.mypackage.com.jira.activeobjects.MyClass</entity>
</ao>

  1. Adding a dependency to my pom.xml

<dependency>
<groupId>com.atlassian.activeobjects</groupId>
<artifactId>activeobjects-plugin</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>

  1. Add “@Scanned” to my Action Class

@Scanned
public class MyClassAction extends JiraWebActionSupport
{

  1. Use “@ComponentImport” inside of my Action Class

@ComponentImport
private ActiveObjects ao;

  1. Extend my Constructor inside of my Action Class by using “@Inject

@Inject
public MyClassAction(ActiveObjects ao)
{
this.ao = ao;
}

After that, I am able to use my entity and to save data. For example:

public String doSave() throws Exception {
MyClass myTest = ao.create(MyClass.class);
myTest.setName(this.getMyProperty());
myTest.save();
}

Perhaps somebody has the same problem, this steps might help.

Keep coding! :smiley:

5 Likes

Thank you for sharing this. I have been trying to figure this out for days.
I uploaded an updated Active Objects “tutorial” files that work in 2020, over here:

5 Likes

Thank you so much!!!

1 Like