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

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

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.

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 Apr 03, 2019 in Marketplace Apps

How to estimate projects more accurately?

Gaining insight into your team’s effectiveness and choosing the right estimation technique.   Estimating projects is hard. It is because people have the tendency to underestimate the time thin...

272 views 2 8
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you