Hi Community, we are trying to figure out how to automatically update attribute values whenever a user edits or updates an object in the Jira asset schema.
1. Set a score for two attributes ( Network Connectivity and Authentication Method)
2. Calculate score, Likelihood is the average of Network Connectivity and Authentication Method scores
3. Overwrite Likelihood to the results of the calculation (attributeRef3Option)
I have written the script and was able to set attributeRef3Option to the desire value, however I encounter the error as shown
Unexpected error: No signature of method: com.riadalabs.jira.plugins.insight.services.model.MutableObjectAttributeBean.setTextValue() is applicable for argument types: (java.lang.String) values: [High] groovy.lang.MissingMethodException: No signature of method: com.riadalabs.jira.plugins.insight.services.model.MutableObjectAttributeBean.setTextValue() is applicable for argument types: (java.lang.String) values: [High]
Here is my script, I would like to know what was wrong and how to set value of attributeRef3Option back to objectTypeAttributeBean(Likelihood)? Likelihood is a select list and I am overwriting to one of the options.
import com.atlassian.jira.component.ComponentAccessor;
import com.riadalabs.jira.plugins.insight.services.model.MutableObjectAttributeValueBean;
import com.riadalabs.jira.plugins.insight.services.model.MutableObjectAttributeBean;
//import com.riadalabs.jira.plugins.insight.services.model.ObjectAttribute;
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade"));
def objectTypeAttributeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeAttributeFacade"));
def objectAttributeBeanFactory = ComponentAccessor.getOSGiComponentInstanceOfType(ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.services.model.factory.ObjectAttributeBeanFactory"));
def objectTypeAttributeBean = objectTypeAttributeFacade.loadObjectTypeAttributeBean(464).createMutable();//Likelihood ID
//def newObjectAttributeBean;
// Lists of single choose options for attributes
// Network Connectivity
def attributeRef1Options = [
"AWS VPC": 1,
"DMZ": 2,
"IP Whitelisted": 2,
"No Network Restrictions": 4
]
// Authentication Method
def attributeRef2Options = [
"S2S": 1,
"AWS IAM": 1,
"TLS-Based (mTLS)": 1,
"OAuth2.0": 2,
"OpenID": 2,
"JWT": 2,
"API Key": 3,
"SSH": 3,
"Username & Password": 4,
"SFTP": 4,
"Basic Auth": 5
]
int attributeRef1 = 475 // Network Connectivity ID
int attributeRef2 = 457 // Authentication Method ID
def objectAttribute1 = objectFacade.loadObjectAttributeBean(object.getId(), attributeRef1)
def objectAttribute2 = objectFacade.loadObjectAttributeBean(object.getId(), attributeRef2)
if (objectAttribute1 && objectAttribute2) {
/* Create the new attribute bean based on the value */
// Get option values
def option1Value
def option2Value
if(objectAttribute1.getObjectAttributeValueBeans()[0].getValue() in attributeRef1Options.keySet()) {
option1Value = attributeRef1Options[objectAttribute1.getObjectAttributeValueBeans()[0].getValue()]
}
if(objectAttribute2.getObjectAttributeValueBeans()[0].getValue() in attributeRef2Options.keySet()) {
option2Value = attributeRef2Options[objectAttribute2.getObjectAttributeValueBeans()[0].getValue()]
}
// Calculate score, Likelihood is the average of Network Connectivity and Authentication Method scores
def z = (option1Value * option2Value)/2
// Set attributeRef3 based on score
def attributeRef3Option
if(z >= 4.5) {
attributeRef3Option ="High"
} else if(z > 3.5) {
attributeRef3Option ="Moderate-High"
} else if(z>=2.5) {
attributeRef3Option ="Moderate"
} else if(z>=1.5) {
attributeRef3Option ="Low-Moderate"
}else {
attributeRef3Option ="Low"
}
// Create value bean
// def attributeRef3Value = new MutableObjectAttributeValueBean()
// attributeRef3Value.setTextValue(attributeRef3Option)
// Create new attribute bean
def newObjectAttributeBean = objectAttributeBeanFactory.createObjectAttributeBeanForObject(
object,
objectTypeAttributeBean,
z.toString()
)
// Set attribute value
//def attributeRef3 = new ObjectAttribute()
//attributeRef3.setValue(attributeRef3Value)
//attributeRef3Bean.setAttributeRef3(attributeRef3)
def attributeRef3Bean = new MutableObjectAttributeBean()
attributeRef3Bean.setTextValue(attributeRef3Option)
// attributeRef3Bean.setObjectAttributeValueBeans(attributeRef3Option)
newObjectAttributeBean.setAttributeRef3(attributeRef3Bean)
log.warn("Attribute value: $attributeRef3Option");
log.warn("Attribute value for new MutableObjectAttributeValueBean() : attributeRef3Bean");
// Set attributeRef3
// def attributeRef3Option = getAttributeRef3Option(z)
// Create new attribute bean
//def newObjectAttributeBean = createAttributeBean(z)
// Store attribute
storeAttribute(newObjectAttributeBean);
/* Load the attribute bean */
// def objectAttributeBean = objectFacade.loadObjectAttributeBean(object.getId(), objectTypeAttributeBean.getId());
if (objectAttributeBean != null) {
/* If attribute exist reuse the old id for the new attribute */
newObjectAttributeBean.setId(objectAttributeBean.getId());
}
/* Store the object attribute into Insight. */
try {
objectTypeAttributeBean = objectFacade.storeObjectAttributeBean(newObjectAttributeBean);
} catch (Exception vie) {
log.warn("Could not update object attribute due to validation exception:" + vie.getMessage());
}
}
Thank you for any advice!