How to get metadata in groovy postfunction?

Mayorov Alexander February 14, 2016

Hello!

Could please someone explain the method of obtaining metadata values of Project (by its ID, for example).

Need groovy exaple.

Thank you!

3 answers

1 accepted

1 vote
Answer accepted
Mayorov Alexander February 24, 2016

Based on JM-48 got working mehod:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager

import org.apache.log4j.Category
def Category log = Category.getInstance("get.metadata.values.from.project")
log.setLevel(org.apache.log4j.Level.DEBUG)

//processing projectpicker
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cfClient = customFieldManager.getCustomFieldObject("customfield_12700")
def cfClientValue = issue.getCustomFieldValue(cfClient)

def projectManager = ComponentAccessor.getProjectManager()
def projectObject = projectManager.getProjectObjByName(cfClientValue.name)
Issue myIssue = issue
log.debug("HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH")
log.debug("HHH Metadata Value: " + ComponentAccessor.getComponentOfType(myIssue.getClass().getClassLoader().findLoadedClass("com.atlassian.jira.plugin.JiraOsgiContainerManager")).getServiceTracker("com.osoboo.jira.metadata.MetadataService").getService().getMetadataValue(projectObject, "Key"))
log.debug("HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH")
0 votes
JamieA
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.
February 22, 2016

You would have to see how that plugin stores additional data. Most likely OSProperty, in which case:

import com.atlassian.core.ofbiz.util.OFBizPropertyUtils

OFBizPropertyUtils.getPropertySet(project.genericValue)
0 votes
Tsol
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.
February 14, 2016

Hi,

if you want the ID you can use the following

import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.project.Project;


//Create the project object
Project project = issue.getProjectObject();
//Create project id
Long pr_id = project.getId();
Mayorov Alexander February 14, 2016

Hi, Kostas,

thank you for answer. No problems with project ID.

But need to get project's metadata values.

Tsol
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.
February 14, 2016

Hi again,

what exactly do you mean by metadata?

The following might be helpful

https://developer.atlassian.com/static/javadoc/jira/latest/reference/com/atlassian/jira/project/Project.html

Mayorov Alexander February 14, 2016

There is add-on "Metadata for JIRA", created by @Andreas Spall. This add-on adds some fields to project.

Tsol
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.
February 14, 2016

hmm, i see. No idea about about how you could do that.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events