Missed Team ’24? Catch up on announcements here.

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

Active object config on stash

AhmedO May 5, 2014

Hello

I've succed to build a plugin which listens to the reposotory event's and build RSS Feed.

Now I use Files to store events and feed and I'd like to store them into a DB. I started by following this tutorial Active Object with RefApp. Then I found how could we configure Active Objects with Jira, Conflence Bamboo etc.

Now I wonder if AO require the same config with Stash and in this case why we don't find a link which demonstrates how can we configure AO within Stash ?

Thank you.

Cheers,
Ahmed.

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Andy Brook [Plugin People]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 14, 2014

It ought to be listed through atlas-create-stash-plugin-module but isn't.

pom.xml

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

atlassian-plugin.xml

<component key="stashblah-ao-service" name="Stash Blah AO Service" class="com.blah.ao.StashBlahAOImpl">
    <interface>com.blah.ao.IAoStashBlahService</interface>
    <description>Provides Stash Blah ActiveObject Services</description>
  </component>
<component-import key="ao" name="Active Objects service" interface="com.atlassian.activeobjects.external.ActiveObjects"/>
  <component key="tx-processor" name="Transactional Annotation Processor" class="com.atlassian.activeobjects.external.TransactionalAnnotationProcessor">
    <description>Processes @Transactional annotations.</description>
  </component>
  <ao key="stashblah-ao-module">
        <entity>com.blah.ao.Thing</entity>
  </ao>

IAoStashBlahService.java

@Transactional
public interface IAoStashBlahService
{
...   
}

AhmedO May 22, 2014

Hello Andry,

Thank you for your response, it was very helpfull.

Cheers,
Ahmed.

Hannes Niederhausen June 27, 2016

Hi,

I have the same problem, but can't use the solution, because component definitions aren't allowed anymore. Any other solution?

thanks in advance

Hannes

Josh Wheeler
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 28, 2016

@Hannes Niederhausen, you can still use the old style - all you have to do is comment out the <Atlassian-Plugin-Key> in the <instructions> section of the pom.xml file.

0 votes
Lothar Schulz January 16, 2015

A fix for my issue is to separate the entity definition from the activeObjects component-import like this:

...
&lt;ao key="stash-ao-module"&gt;
   &lt;entity&gt;stash.entity.DatabaseCheck&lt;/entity&gt;
&lt;/ao&gt;
...
&lt;component-import key="activeObjects" interface="com.atlassian.activeobjects.external.ActiveObjects"/&gt;
....
0 votes
Lothar Schulz January 15, 2015

I also want to add persistence to my existing plugin. When saving something my code produces a Runtime Exception:

...
... java.lang.RuntimeException: plugin [{stash.stash-db-consistency-bridge}]
 invoking ActiveObjects before &lt;ao&gt; configuration module is enabled or plugin
 is missing an &lt;ao&gt; configuration module. Note that scanning of entities from
 the ao.model package is no longer supported.
....

What could cause that?

 

Here some details of my persistence setup:

...
&lt;dependency&gt;
  &lt;groupId&gt;com.atlassian.activeobjects&lt;/groupId&gt;
  &lt;artifactId&gt;activeobjects-plugin&lt;/artifactId&gt;
  &lt;version&gt;${ao.version}&lt;/version&gt;
  &lt;scope&gt;provided&lt;/scope&gt;
&lt;/dependency&gt;
...
&lt;ao.version&gt;0.21.2&lt;/ao.version&gt;
...
&lt;component-import key="activeObjects" interface="com.atlassian.activeobjects.external.ActiveObjects"&gt;
        &lt;component key="tx-processor" name="Transactional Annotation Processor" class="com.atlassian.activeobjects.external.TransactionalAnnotationProcessor"&gt;
            &lt;description&gt;Processes @Transactional annotations.&lt;/description&gt;
        &lt;/component&gt;
        &lt;ao key="stash-ao-module"&gt;
            &lt;entity&gt;stash.entity.DatabaseCheck&lt;/entity&gt;
        &lt;/ao&gt;
    &lt;/component-import&gt;
....
    &lt;component key="databaseCheckPersistenceManagerImpl" class="de.zalando.stash.persistence.DatabaseCheckPersistenceManagerImpl"&gt;
        &lt;interface&gt;stash.persistence.DatabaseCheckPersistenceManager&lt;/interface&gt;
    &lt;/component&gt;
 
@Table("DBCheck")
@Preload
public interface DatabaseCheck extends Entity{
    @NotNull
    public Integer getCheckId();
    public void setCheckId(Integer id);
    @NotNull
    public String getStatus();
    public void setStatus(String status);

    public String getNotes();
    public void setNotes(String notes);
}
 
public class DatabaseCheckPersistenceManagerImpl implements DatabaseCheckPersistenceManager {
    private final ActiveObjects activeObjects;
 
    public DatabaseCheckPersistenceManagerImpl(ActiveObjects activeObjects) {
        this.activeObjects = activeObjects;
....
    }
    public DatabaseCheck createOrUpdateDatabaseCheck(int checkID, String notes, String status) throws SQLException
    { // put method paremeters to dBParams array
            DatabaseCheck newDatabaseCheck = activeObjects.create(
                    DatabaseCheck.class,
                    dBParams
            );
      ....
    }

the method createOrUpdateDatabaseCheck is called in class PullRequestEventListener:

public class PullRequestEventListener implements AsyncPostReceiveRepositoryHook {
private final DatabaseCheckPersistenceManagerImpl databaseCheckPersistenceManager;
....
public PullRequestEventListener(...,                                    DatabaseCheckPersistenceManager databaseCheckPersistenceManager,
                                ...) {
        this.databaseCheckPersistenceManager = databaseCheckPersistenceManager;
 ....
 }
 ....
 public boolean persistPostResponse(Map&lt;String, String&gt; response){
        .... // retrieve details from response
        try {
            DatabaseCheck dbcheck = this.databaseCheckPersistenceManager.createOrUpdateDatabaseCheck(checkID, notes, status);
            return true;
        } catch (SQLException sqlException) {
            log.error("sql exception: {}: ", sqlException);
        }
        ....
 }
...
}

that causes the RuntimeException above. I experience this runtime exception regardless of the type of class-member databaseCheckPersistenceManager: DatabaseCheckPersistenceManagerImpl or DatabaseCheckPersistenceManager.

 

I also wonder why the runtime excpetion does not appear in my test:

@RunWith(ActiveObjectsJUnitRunner.class)
@Jdbc(DynamicJdbcConfiguration.class)
@Data(InitialData.class)
public class PersistenceTest {
    private EntityManager entityManager;
    private ActiveObjects activeObjects;
    private DatabaseCheckPersistenceManager databaseCheckPersistenceManager;
...   
    @Before
    public void setUp() throws Exception {
        // ensure the runner set this already
        assertNotNull(entityManager);
        this.activeObjects = new TestActiveObjects(entityManager);
        this.databaseCheckPersistenceManager = new DatabaseCheckPersistenceManagerImpl(this.activeObjects);
    }
...
    @Test
    public void createDatabaseCheckTest() throws SQLException{
        DatabaseCheck databaseCheckNotExisting =         this.databaseCheckPersistenceManager.createOrUpdateDatabaseCheck(CHECKID_22, NOTES_4_CREATION, STATUS_SCHEDULED);
        DatabaseCheck databaseCheckCreated = this.databaseCheckPersistenceManager.getDatabaseCheck(CHECKID_22);
        assertTrue(CHECKID_22 == databaseCheckCreated.getCheckId());
...
     }
...
    public static class InitialData implements DatabaseUpdater {
        @Override
        public void update(EntityManager entityManager) throws Exception {
            entityManager.migrate(DatabaseCheck.class);
            DatabaseCheck databaseCheck1 = entityManager.create(
                    DatabaseCheck.class,
                    new DBParam(CHECKID, CHECKID_10),
                    new DBParam(STATUS, STATUS_CREATED),
                    new DBParam(NOTES, NOTES_SOME_COMMENTS)
            );
            ... // more test data
        }
    }
}
TAGS
AUG Leaders

Atlassian Community Events