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

Getting a handle on the FieldNameConverter

Charles Duffy
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 13, 2012

Under most circumstances, an ActiveObjects user has a handle on an EntityManager, and can thereby get access to the FieldNameConverter used to map between object fields and row names.

Using JIRA, by contrast, the user has access not to an EntityManager, but to an implementation of com.atlassian.activeobjects.external.ActiveObjects. While this provides access to many of the same methods included in the EntityManager interface, it does not implement getFieldNameConverter or getTableNameConverter -- both of which are very useful if trying to add a higher-level API on top of the (very thin) ActiveObjects interface.

If one already has an entity instance, one can use RawEntity.getEntityManager() to get a handle on an EntityManager from which the table and field name converters can be queried -- but this is of little use if one wishes to implement an interface to use in querying for such instances in the first place.

Can this be accomplished? How?

3 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Andrey Levchenko September 22, 2014

after spending some time I figured out solution below:

public static String getTableName(String pluginKey, Class clazz){
        PluginAccessor pluginAccessor = ComponentAccessor.getPluginAccessor();
        OsgiPlugin osgiPlugin = ((OsgiPlugin) pluginAccessor.getPlugin(pluginKey));
        BundleContext bundleContext = osgiPlugin.getBundle().getBundleContext();
        
        String filter = String.format("(com.atlassian.plugin.key=%s)", osgiPlugin.getBundle().getSymbolicName());
        
        ServiceReference[] serviceReferences = null;
        
        try {
            serviceReferences = bundleContext.getServiceReferences("com.atlassian.activeobjects.config.ActiveObjectsConfiguration", filter);
        } catch (InvalidSyntaxException ex) {
            //log error here
        }
        if (serviceReferences.length > 0){
            ActiveObjectsConfiguration activeObjectsConfiguration = (ActiveObjectsConfiguration)bundleContext.getService(serviceReferences[0]);
        
            return activeObjectsConfiguration.getNameConverters().getTableNameConverter().getName(clazz);
        } else {
            return null;
        }
    }
Frédéric Esnault February 23, 2015

Hi Andrey, I'm wondering how you did that. It requires to import package com.atlassian.activeobjects.configuration, which is private to the AO OSGi plugin. I can't get this to work. Do you have an explanation about this ?

Andrey Levchenko February 26, 2015

Hi Looks like mentioned package is exported through OSGI (According to jira source I have). Which version of jira do you use?

Frédéric Esnault March 5, 2015

Actually it is confluence. But i confirm the package is private (ao version 0.19.7). Here is a copy of the OSGi console for ao plugin : 29 - ActiveObjects Plugin - OSGi Bundle Archiver-Version Plexus Archiver Atlassian-Plugin-Key com.atlassian.activeobjects.activeobjects-plugin [...] Bundle-ManifestVersion 2 Bundle-Name ActiveObjects Plugin - OSGi Bundle Bundle-SymbolicName com.atlassian.activeobjects.activeobjects-plugin Bundle-Vendor Atlassian Bundle-Version 0.19.7 Created-By 1.6.0_29 (Apple Inc.) Manifest-Version 1.0 Spring-Context *;timeout:=60 Tool Bnd-0.0.311 Export-Package - 6 entries Ignore-Package - 9 entries Import-Package - 98 entries Private-Package - 101 entries com.ctc.wstx.exc version: 0.19.7 org.springframework.web.servlet.view.jasperreports version: 0.19.7 org.springframework.web.servlet.tags version: 0.19.7 com.atlassian.activeobjects.internal.config version: 0.19.7 org.codehaus.stax2.ri.dom version: 0.19.7 [...] com.atlassian.dbexporter version: 0.19.7 com.atlassian.activeobjects.backup version: 0.19.7 org.springframework.web.servlet.view.velocity version: 0.19.7 com.ctc.wstx.dtd version: 0.19.7 ** com.atlassian.activeobjects.config version: 0.19.7 **

0 votes
Sebastian Braun July 15, 2012

I have the same Problem here.

0 votes
Charles Duffy
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, 2012

This is additionally complicated by being unable to import either net.java.ao.atlassian or com.atlassian.activeobjects.ao -- putting either of them in bundle-instructions/Import-Package results in a BundleException on startup, presumably because these bundles aren't exported, so I can't just create my own instances of these classes.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events