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

Insight groovy scripts: how to create new object type?

Elina Pavlova May 19, 2022

Good afternoon,
I am stuck with groovy automation script, which will create new object type with given name string in object schema.
I tested a lot with insight classes. ObjectTypeFacade class has a method createObjectTypeBean(com.riadalabs.jira.plugins.insight.services.model.MutableObjectTypeBean objectTypeBean), but it is used as i understood to convert MutableObjectTypeBean to ObjectTypeBean.

I have no clue whether it is possible to create new object type with groovy script at all.

I also tried with ImmutableFactory https://insight-javadoc.riada.io/insight-javadoc-5.4.2/index.html?com/riadalabs/jira/plugins/insight/services/model/ImmutableFactory.html

def immutableFactory = ComponentAccessor.getOSGiComponentInstanceOfType(ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.services.model.ImmutableFactory"));

def newObjectType = immutableFactory.createObjectType(name=someString);

but it gives me an error: 
MissingMethodException: No signature of method: com.riadalabs.jira.plugins.insight.channel.external.api.facade.impl.ObjectFacadeImpl.createObjectType() is applicable for argument types: (java.lang.String)

Does anyone has a solution to create this MutableObjectTypeBean which is used to set the data? The following doesn't work either.

def mutableObjectTypeBean = ComponentAccessor.getOSGiComponentInstanceOfType(ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.services.model.MutableObjectTypeBean"));

MutableObjectTypeBean newObjectType = new MutableObjectTypeBean();

And is it possible just to parse Name and ParentObjectTypeId properties, because if i give it a random Id also, this might make a conflict as the id could be already in use.

2 answers

2 accepted

4 votes
Answer accepted
Mo Ziauddin July 28, 2022

The code in the above answer no longer works. The below function causes compilation error.

import com.riadalabs.jira.plugins.insight.services.model.MutableObjectTypeBean;
MutableObjectTypeBean newObjectType = new MutableObjectTypeBean();

I believe the right way to use insight objects in groovy console is as below.

import com.onresolve.scriptrunner.runner.customisers.WithPlugin
@WithPlugin("com.riadalabs.jira.plugins.insight")

import com.riadalabs.jira.plugins.insight.services.model.MutableObjectTypeBean;
def newObjectType = new MutableObjectTypeBean();

Enjoy coding...

0 votes
Answer accepted
Elina Pavlova May 27, 2022

Found the solution. Had to import the class through import (not through

ComponentAccessor like i tried) to create new object :
import com.riadalabs.jira.plugins.insight.services.model.MutableObjectTypeBean;
Then you can create new object type like this using MutableObjectTypeBean constructor:
MutableObjectTypeBean newObjectType = new MutableObjectTypeBean();

setObjectSchemaId, setIconBean, setName are mandatory to use after that or else it will throw an error if you will try to store it in schema as those are main parameters for an object type to have on creation.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events