Objective
Craft a service to refresh a certain set of project-level data in JIRA. (Version dates to be specific.) Fun facts about this service:
And it's this plugin that's currently the crux of my question. I found this code snippet that explains the proper API call for the plugin, but it assumes you're calling it from a listener or post-function and not a service:
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.comments.CommentManager import com.opensymphony.workflow.WorkflowContext import com.atlassian.plugin.osgi.container.OsgiContainerManager import org.apache.log4j.Category OsgiContainerManager osgiManager = ComponentManager.getInstance().getComponentInstanceOfType(OsgiContainerManager.class) issue.setDescription(osgiManager.getServiceTracker("com.osoboo.jira.metadata.MetadataService").getService().getMetadataValue(issue.getProjectObject(), "accounting.code"))
What I'm really looking for is some API call with this plugin that returns an object of type Project when given a custom field name and custom field value.
Questions
Hi,
1. your script-snipplet should work with Groovy Runner.
2. you should ask the ProjectManager to get the Project (Project Object)
e.g. ComponentManager.getInstance().
getProjectManager().getProjectObjByKey("ProjectKey") (see: http://docs.atlassian.com/jira/latest/com/atlassian/jira/project/ProjectManager.html and http://docs.atlassian.com/jira/latest/com/atlassian/jira/ComponentManager.html)
3. you can change the medatadata value (custom project field) via api call
e.g.
osgiManager.getServiceTracker(
"com.osoboo.jira.metadata.MetadataService"
).getService().
save(issue.getProjectObject(), "accounting.code", "the new value"); (see: https://studio.plugins.atlassian.com/source/browse/JMETA/trunk/jira.metadata.plugin/src/main/java/com/osoboo/jira/metadata/MetadataService.java?hb=true)
</span<>>
hope this will help you out
Andreas
Thanks, Andreas. We're getting there, but it's not quite what I'm looking for. My source data contains a whole list of projects. This data is tied to the data in JIRA by a metadata field called "Theme Key." Ideally, I would make an API call via JIRA Metadata to a method looking something like this:
Project getProject (String customFieldName, String customFieldValue)
My code would never need to modify the metadata only use it to find which project to update. In short, this is what I want my code to do:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Also, Andreas, by the looks of it, this guy might do the trick:
Collection<JiraMetadata> getMetadata(ObjectenrichedObject);
But that's only if:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The enriched object must be a project or version object. The collection will be all metadata values for this project/version object
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can iterate over all projects.something like:
for (Project p : ProjectManager.getProjectObjects()) {
if ("the value ".equals(metadataService.getMetadataValue(p, "theme"))) {
gogo
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In that case, getMetadata won't do the trick. Is there anything in JIRA Metadata that will, Andreas?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
brilliant. i hadn't thought to tackle the problem from the other direction. That should do nicely. Thank you!! :)
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.