I would like add a property called "owner" to some groups. Is it possible?
I think there are 3 choices.
I'm most familiar with OfBizPropertyUtils: that stores values in propertyentry and propertytext tables (at least for jira):
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.core.ofbiz.util.OFBizPropertyUtilsimport groovy.json.JsonBuilderimport groovy.json.JsonSlurperdef GROUP_EDITOR_PROPERTY = 'com.acme.jira.group-editor'def properties = OFBizPropertyUtils.getCachingPropertySet(GROUP_EDITOR_PROPERTY, 1)def group = ComponentAccessor.groupManager.getGroup('bamboo-users')if (properties.exists(group.name)) {def editorsJson = properties.getText(group.name)def editorUserNames = new JsonSlurper().parseText(editorsJson)return editorUserNames.collect { ComponentAccessor.userManager.getUserByName(it as String) }} else {def editor = ComponentAccessor.userManager.getUserByName('editorName')def editorJson = new JsonBuilder([editor]).toString() properties.setText(group.name, editorJson)}
But I think the JsonEntityPropertyManager may also do the trick but I haven't tried to use it with custom entities or properties. This would store data in entiry_property
And finally, there is the CrowdService that stores data in cwd_group_attributes
import com.atlassian.jira.component.ComponentAccessordef GROUP_EDITOR_PROPERTY = 'com.acme.jira.group-editor'def cs = ComponentAccessor.crowdServicedef group = cs.getGroupWithAttributes('bamboo-users')cs.setGroupAttribute(group, GROUP_EDITOR_PROPERTY, 'editorName')//reload the groupgroup = cs.getGroupWithAttributes(group.name)group.getValue(GROUP_EDITOR_PROPERTY)
greaat! I can set a property with 2nd way!!!
but now how can I know all properties that I can define and how get all this properties?
I forgot to include the link to the GroupWithAttributes Javadoc.
In all cases I shared, you define the properties/attributes you want to store yourself.
These are completely custom. I find the best way to explore what properties have already been defined by the system or by other plugins is to use the database.
In the case of GroupWithAttributes, in my environment, there was nothing until I added my own property. There is a similar UserWithAttribute that typically holds several attributes stored by Jira (like last failed login etc).
Here is a groovy example for listing all the attributes for a given group:
import com.atlassian.jira.component.ComponentAccessordef cs = ComponentAccessor.crowdServicedef group = cs.getGroupWithAttributes(group.name)group.getKeys()
In my example above, the key for the new Attribute is 'com.acme.jira.group-editor' .
You can call it whatever you want. I use com.mycompany as a prefix to ensure I don't accidentally overwrite a system or plugin attribute.
It looks like you're new here. Sign in or register to get started.