Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

read all metadata keys of a project in groovy

Martina Riedel
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.
June 8, 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
Andreas Spall _evolu_software_
Atlassian Partner
June 21, 2018

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
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.
June 21, 2018

Yay, thanks, exactly what I was looking for.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events