https://community.atlassian.com/t5/Marketplace-Apps-discussions/Sample-code-for-retrieving-a-project-metadata/td-p/461651 shows how to get the value of a known meta-data key in groovy.
getAllMetadata(projectObject) will get a map of elements like
AO_xxxxxx_JIRA_METADATA {ID = 5}
There is a rest api call
e.g. get all metadata for project JM (as project-admin): https://jira.atlassian.internal/rest/metadata/1.0/project/JM?includeHidden=true
that returns what I want.
I've looked, but I haven't found anything that will do a getMetadataKeyValue or so.
Since the rest api can do it, I'm hoping groovy can also do it.
Thanks
Hi Martina,
the Method getAllMetadata(projectObject) will return you a full list of all metadata for the given project as a collection ob JiraMetadata-Objects.
I hope the following source code is helpful for you.
import com.atlassian.jira.ComponentManager
import com.atlassian.plugin.osgi.container.OsgiContainerManager
import com.atlassian.jira.project.Project
import com.atlassian.jira.component.ComponentAccessor
import com.osoboo.jira.metadata.MetadataService
import com.osoboo.jira.metadata.JiraMetadata
Project project = ComponentAccessor.getProjectManager().getProjectObjByKey("RISK");
OsgiContainerManager osgiManager = ComponentManager.getInstance().getComponentInstanceOfType(OsgiContainerManager.class)
MetadataService metadataService = (MetadataService) osgiManager.getServiceTracker("com.osoboo.jira.metadata.MetadataService").getService()
// the
String x = metadataService.getMetadataValue(project, "mykey")
// includes all non-hidden metadata objects for the given project
Collection<JiraMetadata> allNonHiddenMetadataObjects = metadataService.getMetadata(project)
for(jiraMetadata in allNonHiddenMetadataObjects){
String key = jiraMetadata.getUserKey()
String value = jiraMetadata.getUserValue()
String group = jiraMetadata.getUserGrouping()
boolean hidden = jiraMetadata.isHidden()
}
// includes all metadata objects for the given project
Collection<JiraMetadata> allMetadataObjects = metadataService.getAllMetadata(project)
for(jiraMetadata in allMetadataObjects){
String key = jiraMetadata.getUserKey()
String value = jiraMetadata.getUserValue()
String group = jiraMetadata.getUserGrouping()
boolean hidden = jiraMetadata.isHidden()
}
Yay, thanks, exactly what I was looking for.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.