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.ComponentAccessor
import com.atlassian.core.ofbiz.util.OFBizPropertyUtils
import groovy.json.JsonBuilder
import groovy.json.JsonSlurper
def 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.ComponentAccessor
def GROUP_EDITOR_PROPERTY = 'com.acme.jira.group-editor'
def cs = ComponentAccessor.crowdService
def group = cs.getGroupWithAttributes('bamboo-users')
cs.setGroupAttribute(group, GROUP_EDITOR_PROPERTY, 'editorName')
//reload the group
group = 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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.ComponentAccessor
def cs = ComponentAccessor.crowdService
def 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.