Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

How to create Insight Object using groovy?

I am trying to create insight object and I know only the ObjectTypeId. Is it possible to do it? I tried using MutableObjectBean but it didn't work like below

 

def newobj = new MutableObjectBean()
newobj.setObjectTypeId(5)
newobj.setLabel("Test Object")

1 answer

1 accepted

1 vote
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Aug 31, 2022

Creating an object is a lot more complicated than that.

And you'll need to know the name of the attribute to set the label to (typically Name).

Here is the simplest code I can figure out to create an object with a single required field. 

import com.atlassian.jira.component.ComponentAccessor
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeAttributeFacade
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeFacade
import com.riadalabs.jira.plugins.insight.services.model.MutableObjectBean

ObjectFacade objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ObjectFacade)
ObjectTypeFacade objectTypeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ObjectTypeFacade)
ObjectTypeAttributeFacade objectTypeAttributeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ObjectTypeAttributeFacade)

def objectTypeId = 5
def labelValue = 'Test Object'
def attributeNameForLabel = 'Name'

def objectType = objectTypeFacade.loadObjectType(objectTypeId)
def object = objectType.createMutableObjectBean()
def objectTypeAttributes = objectTypeAttributeFacade.findObjectTypeAttributeBeans(objectType.id)

def
nameAttr = objectTypeAttributes.find { it.name == attributeNameForLabel }
def nameAttributeValuesHolder = object.createObjectAttributeBean(nameAttr)
def attributeValue = nameAttributeValuesHolder.createObjectAttributeValueBean()
attributeValue.setTextValue(labelValue)
nameAttributeValuesHolder.setObjectAttributeValueBeans([attributeValue])
object.objectAttributeBeans = [nameAttributeValuesHolder]
objectFacade.storeObjectBean(object)

 As you can see that are several layers.

The object contains a list of attributes. Each attribute contains a list a attributeValue objects. Each attributeValue object contains the actual text value (or number or object reference etc depending on the type). 

You must create all of those layers.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events