Hi!
I am getting NullPointerException when I try to create a an entry using ActiveObjects. The exact function where I am getting this exception is executeInTransaction. I call the ActiveObject functions inside my rest resource and get error when I hit:
http://localhost:2990/jira/rest/kitchenduty/1.0/planning/persistTest
Any help in getting me rid of this exception is greatly appreciated!
AO Interface:
package io.codeclou.kitchen.duty.ao;
import net.java.ao.Entity;
import net.java.ao.Preload;
@Preload
public interface Week extends Entity {
Integer getWeek();
void setWeek(Integer week);
}
Its registry in atlassian-plugin.xml file:
<rest name="Kitchen Duty Resources" i18n-name-key="kitchen-duty-plugin.rest.resources.name" key="kitchen-duty-resources" path="/kitchenduty" version="1.0">
<description key="kitchen-duty-plugin.rest.resources.description">All Kitchen Duty REST Resources</description>
<package>io.codeclou.kitchen.duty.rest</package>
</rest>
<ao key="ao-module">
<description>The module configuring the Active Objects service used by this plugin</description>
<entity>io.codeclou.kitchen.duty.ao.Week</entity>
</ao>
Configuration Class:
package io.codeclou.kitchen.duty.config;
...
import com.atlassian.activeobjects.external.ActiveObjects;
@Configuration
@Import({
ModuleFactoryBean.class,
PluginAccessorBean.class
})
public class MyPluginJavaConfig {
...
@Bean
public ActiveObjects activeObjects() {
return ComponentAccessor.getComponent(ActiveObjects.class);
}
}
resources\META-INF\spring\component-scan.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
Package with Spring configuration
<context:component-scan base-package="io.codeclou.kitchen.duty.config" />
</beans>
Rest Resource:
package io.codeclou.kitchen.duty.rest;
import com.atlassian.plugins.rest.common.security.AnonymousAllowed;
import com.atlassian.sal.api.transaction.TransactionCallback;
import com.atlassian.activeobjects.external.ActiveObjects;
import io.codeclou.kitchen.duty.ao.Week;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@Component
@Path("/planning")
public class KitchenDutyPlanningResource {
public ActiveObjects activeObjects;
@Autowired
public KitchenDutyPlanningResource(ActiveObjects activeObjects) {
this.activeObjects = activeObjects;
}
public KitchenDutyPlanningResource() {
}
@GET
@Path("/persistTest")
@Produces({MediaType.APPLICATION_JSON})
@AnonymousAllowed
public Response persistTest() {
activeObjects.executeInTransaction(new TransactionCallback<Week>() {
@Override
public Week doInTransaction() {
Week testWeek = (Week) activeObjects.create(Week.class);
testWeek.setWeek(42);
testWeek.save();
return testWeek;
}
});
return Response.ok("ok").build();
}
}
POM Dependency:
<dependency>
<groupId>com.atlassian.activeobjects</groupId>
<artifactId>activeobjects-plugin</artifactId>
<version>1.1.5</version>
<scope>provided</scope>
</dependency>
<properties>
<jira.version>7.13.0</jira.version>
<amps.version>8.1.2</amps.version>
<plugin.testrunner.version>2.0.2</plugin.testrunner.version>
<osgi.javaconfig.version>0.2.0</osgi.javaconfig.version>
<spring.version>4.2.5.RELEASE</spring.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>