JIRA | How do I make custom field type I wrote Searchable (updated question)

Moshe Hajaj March 28, 2013


Hi,

I wrote a calculated custom field that displays list of Versions. It is calculated (extends CalculatedCFType) and read-only (view screen only, no edit).

It works as expected, except for the searcher functionality.

I added the "customfield-searcher" and "component-import" to atlassian-plugin.xml

Still when I try to enable the plugin it fails:

ERROR admin /rest/plugin/1.0/<my-plugin-class>-key [plugin.osgi.factory.OsgiPlugin] Never resolved service '&versionSearcher' for plugin '<my-plugin-class>' with filter (objectClass=com.atlassian.jira.issue.customfields.searchers.VersionSearcher)

What is the proper way to make my custom field type searchable?

UPDATE:

I tried to override the searcher with a dummy custom searcher. here is the code:

public class PenVersionSearcher extends VersionSearcher
{
    public PenVersionSearcher(VersionManager versionManager, FieldVisibilityManager fieldVisibilityManager, VersionResolver versionResolver, JqlOperandResolver operandResolver, FieldFlagOperandRegistry fieldFlagOperandRegistry, VersionClauseContextFactory versionClauseContextFactory, PermissionManager permissionManager, ContextSetUtil contextSetUtil, FieldConfigSchemeClauseContextUtil clauseContextUtil, MultiClauseDecoratorContextFactory.Factory multiFactory, CustomFieldInputHelper customFieldInputHelper) {
        super(versionManager, fieldVisibilityManager, versionResolver, operandResolver, fieldFlagOperandRegistry, versionClauseContextFactory, permissionManager, contextSetUtil, clauseContextUtil, multiFactory, customFieldInputHelper);
    }
}

And referrenced it in my atlassain-plugin.xml:

&lt;customfield-searcher key="pen-versions-searcher" name="Versions Searcher"
                          class="com.mydomain.plugins.fields.searchers.PenVersionSearcher"&gt;
        &lt;description key="admin.customfield.searcher.versionsearcher.desc"&gt;Allow to search for calculated fields' versions using a dropdown list.&lt;/description&gt;

        &lt;resource type="velocity" name="search" location="templates/customfields/view-searcher/edit-version.vm"/&gt;
        &lt;resource type="velocity" name="view" location="templates/customfields/view-searcher/view-searcher-version.vm"/&gt;
        &lt;resource type="velocity" name="label" location="templates/customfields/view-searcher/label-searcher-version.vm"/&gt;

        &lt;valid-customfield-type package="com.mydomain.plugins.fields" key="pen-fix"/&gt;
    &lt;/customfield-searcher&gt;

This doesn't work!

Anyone has a clue what is the problem?

I can go on and add my custom-fileds to the system-customfield-types.xml file, but I don't like it, if I can make the custom searcher to work it will be best solution.

Thanks.

5 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
Moshe Hajaj April 8, 2013

This was solved eventually only by adding my custom field to the system-customfieldtypes-plugin.xml, like this:

&lt;customfield-searcher key="versionsearcher" name="Version Dropdown Searcher"
&lt;!--the rest of the data goes here--&gt;   &lt;valid-customfield-type package="com.mydomain.plugins.fields" key="pen-fix"/&gt;
&lt;/customfield-searcher&gt;

Not the most elegant solution, though.

0 votes
Jan Prokeš
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.
November 2, 2013

Hi there,

I'm triing to use number range searcher within my numeric field. I'm a little bit lost. Here what I have:

1) I have fully functional numeric field, I can set values to it, here is what I have in plugin descriptor

&lt;customfield-type name="Story Health Custom Field" i18n-name-key="story-health-custom-field.name" key="story-health-custom-field" class="com.komtesa.jira.customfields.StoryHealthCustomField"&gt;
        &lt;description key="story-health-custom-field.description"&gt;The Story Health Custom Field Plugin&lt;/description&gt;
        &lt;resource type="velocity" name="view" location="templates/view-storypointshealthfield.vm"/&gt;
        &lt;resource type="velocity" name="edit" location="templates/edit-storypointshealthfield.vm"/&gt;
        &lt;resource type="velocity" name="xml" location="templates/plugins/fields/xml/xml-basictext.vm"/&gt;
    &lt;/customfield-type&gt;

2) have created custom searcher with dummy class, here is the code:

&lt;customfield-searcher name="Number Range Searcher" i18n-name-key="number-range-searcher.name" key="number-range-searcher" class="com.komtesa.jira.customfields.StoryHealthSearcher"&gt;
        &lt;description key="number-range-searcher.description"&gt;The Number Range Searcher Plugin&lt;/description&gt;
        &lt;resource type="velocity" name="search" location="templates/plugins/fields/edit-searcher/search-basictext.vm"/&gt;
        &lt;resource type="velocity" name="view" location="templates/plugins/fields/view-searcher/view-searcher-basictext.vm"/&gt;
        &lt;valid-customfield-type package="com.komtesa.jira.customfields" key="story-health-custom-field"/&gt;
    &lt;/customfield-searcher&gt;

and the class itself

public class StoryHealthSearcher extends NumberRangeSearcher {

    public StoryHealthSearcher(
            JqlOperandResolver jqlOperandResolver, 
            DoubleConverter doubleConverter, 
            CustomFieldInputHelper customFieldInputHelper, 
            I18nHelper.BeanFactory beanFactory, 
            FieldVisibilityManager fieldVisibilityManager) {
        
        super(jqlOperandResolver, doubleConverter, customFieldInputHelper, beanFactory, fieldVisibilityManager);
    }

}

But I still get message Field 'Story Health' is not searchable, it is only sortable.

Thank you very much for help.

Jan Prokeš
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.
November 2, 2013

Omg, I have wasted some time :-)

For others: Don't forget to configure field to use searcher in field edit screen if you add searcher to plugin after you create the field itself.

0 votes
vijaya reddy June 30, 2013

In jira 5.0.7 .

Below code will work.

public class CustomVersionSearcher extends VersionSearcher {

public CustomVersionSearcher(VersionManager versionManager,
FieldVisibilityManager fieldVisibilityManager,
JqlOperandResolver operandResolver,
PermissionManager permissionManager, CustomFieldInputHelper customFieldInputHelper) {
super(versionManager, fieldVisibilityManager, new VersionResolver(versionManager), operandResolver,
new DefaultFieldFlagOperandRegistry() , new VersionClauseContextFactory(operandResolver, new VersionResolver(versionManager), permissionManager) ,
permissionManager, ContextSetUtil.getInstance(), ComponentAccessor.getComponent(FieldConfigSchemeClauseContextUtil.class) , new MultiClauseDecoratorContextFactory.Factory( new DefaultOperatorUsageValidator(operandResolver, ComponentAccessor.getI18nHelperFactory()) , operandResolver, ContextSetUtil.getInstance()),
customFieldInputHelper);

}

0 votes
Moshe Hajaj April 2, 2013

I created another calculated custom field, this time it's even simpler. The return value is collection of strings. So my search is using the MultiSelectSearcher.

When I come to edit the custom field (and add the search template), I get the following exception in the log file:

Unsatisfied dependency expressed through constructor argument with index 0 of type [com.atlassian.jira.util.ComponentLocator]: : No unique bean of type [com.atlassian.jira.util.ComponentLocator] is defined: Unsatisfied dependency of type [interface com.atlassian.jira.util.ComponentLocator]: expected at least 1 matching bean; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.atlassian.jira.util.ComponentLocator] is defined: Unsatisfied dependency of type [interface com.atlassian.jira.util.ComponentLocator]: expected at least 1 matching bean

This my custom searcher:

public class FamilySearcher extends MultiSelectSearcher {
    public FamilySearcher(ComponentLocator componentLocator, ComponentFactory componentFactory) {
        super(componentLocator, componentFactory);
    }
}

Any idea, anyone?

0 votes
Naren
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.
March 28, 2013

Refer this tutorial, as it gives the exact approach of writing the customfield searcher. Hope you find it useful.

http://www.j-tricks.com/1/post/2010/09/custom-field-searchers.html

Moshe Hajaj March 30, 2013

The thing is that I tried the way j-tricks suggests. Including creating a dummy custom Searcherclass. Maybe I shouldn't use VersionSaercher class?

Naren
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.
April 1, 2013

Can you try using the TextSearcher or ExactTextSearcher. Hope that should work!

Moshe Hajaj April 1, 2013

Yes. it works, but I can't use it because the custom-filed values are Version names, not text.

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