Jira 7.2.2
I need to generate some menu items dynamically. From what I've read, it seems that the way to do this is to add a web-section in my atlassian-plugin.xml:
<web-section
key="create-document-section"
i18n-name-key="create-document-section.name"
location="opsbar-operations"
weight="100">
<label key="create-document-section.label"/>
</web-section>
And then a web-item-provider stanza:
<web-item-provider key="create-document-menu-item-factory"
name="Create Document Menu Item Factory"
section="create-document-section"
i18n-name-key="create-document-item-factory.name"
class="com.blizzard.web.DynamicLinkFactory" />
And then implement WebItemProvider:
package com.blizzard.web;
import com.atlassian.plugin.web.api.WebItem;
import com.atlassian.plugin.web.api.model.WebFragmentBuilder;
import com.atlassian.plugin.web.api.provider.WebItemProvider;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class DynamicLinkFactory implements WebItemProvider {
@Override
public Iterable<WebItem> getItems(Map<String, Object> context) {
final List<WebItem> links = new ArrayList<WebItem>();
links.add(new WebFragmentBuilder(10).
id("create_document_item").
label("test").
title("temp").
webItem("create-document-section").
url("/browse/").
build());
return links;
}
}
This compiles and loads into Jira, but when a page is rendered, I get:
...DynamicLinkFactory cannot be cast to
com.atlassian.plugin.web.api.provider.WebItemProvider'.
Web-items provided by this provider will be ignored.
What am I doing wrong?
Update:
I have a theory that JIRA and my plugin are both loading DynamicLinkFactory, and the casting problem is a result of the ambiguity between the two. I have jira-api listed as a "provided" dependency:
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-api</artifactId>
<version>${jira.version}</version>
<scope>provided</scope>
</dependency>
And I have tried with and without atlassian-plugins-webfragment-api listed:
<dependency>
<groupId>com.atlassian.plugins</groupId>
<artifactId>atlassian-plugins-webfragment-api</artifactId>
<version>4.1.0</version>
<scope>provided</scope>
</dependency>
But there has been no effect.
Can anyone tell me if I'm on the right track? And if so, maybe how to resolve the issue?