It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

read all metadata keys of a project in groovy

Martina Riedel Jun 08, 2018

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

1 answer

1 accepted

0 votes
Answer accepted

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()
}
Martina Riedel Jun 21, 2018

Yay, thanks, exactly what I was looking for.

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Marketplace Apps & Integrations

Webinar invitation: Generate custom Jira Cloud PDF reports and exports

Jira may be a staple part of your workday, but your colleagues, customers, business partners or an auditor might need information presented in a different format, that is easy to access and read. And...

58 views 0 1
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you