The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hello,
I'm trying to move an Insight object from one object type to another. Of course, if you are using the interface, this is no problem. But we want to move an object in a post function. The background of this is that we have a JIRA process that handles Hardware exchanges. At a certain status the user is asked, if the "old" Hardware should be scraped or put back in the pool for further usage.
If the user chooses "Scrape" the Hardware will be moved to the object type "Deprecated Hardware". With this, we can still access the old hardware in the Insight Backend, but remove the object from being chosen by a user during a "New User" Workflow.
I'm using the code below, and it does actually move the object (I'm using JMWE Groovy Script), but unfortunately without any values, but I can't figure out, where the problem in my code is. Help is much appreciated.
Thanks a lot, Michael
import com.atlassian.jira.component.ComponentAccessor;
import com.riadalabs.jira.plugins.insight.services.model.move.MoveObjectMapping;
import com.riadalabs.jira.plugins.insight.services.model.move.MoveObjectBean;
import com.riadalabs.jira.plugins.insight.services.model.move.MoveAttributeMapping;
/* Get Insight Object Facade from plugin accessor */
Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade");
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass);
Class objectTypeAttFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeAttributeFacade");
def objectTypeAttFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectTypeAttFacadeClass);
def moveMap = new MoveObjectMapping();
def fromAtts = objectTypeAttFacade.findObjectTypeAttributeBeans(826);
def toAtts = objectTypeAttFacade.findObjectTypeAttributeBeans(832);
def index = 0;
toAtts?.each { item ->
MoveAttributeMapping temp = MoveAttributeMapping.create(item,fromAtts[index]);
moveMap.map(fromAtts[index].id,temp);
index++;
}
def mObject = new MoveObjectBean();
mObject.setFromObjectTypeId(826);
mObject.setObjectSchemaId(47);
mObject.setToObjectTypeId(832);
mObject.setMapping(moveMap);
mObject.setReferences(mObject.getReferences().valueOf("KEEP_REFERENCES_TO_OBJECT"));
def insightObjects = issue.get("Old asset");
if (insightObjects != null) {
insightObjects.each{insightObject ->
/* Move object/s */
try {
mObject.setIql("Key = " + insightObject.objectKey);
objectFacade.moveObjects(mObject);
} catch (Exception vie) {
log.warn("Could not update object attribute due to validation exception:" + vie.getMessage());
}
}
}
return true
Hi Guys,
I tried this script with automation, but it do not work. Do you have any idea what may wrong with it?
BR,
Attila
import com.atlassian.jira.component.ComponentAccessor;
import com.riadalabs.jira.plugins.insight.services.model.move.MoveObjectMapping;
import com.riadalabs.jira.plugins.insight.services.model.move.MoveObjectBean;
import com.riadalabs.jira.plugins.insight.services.model.move.MoveAttributeMapping;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Logger log = LoggerFactory.getLogger("1. log");
/* Get Insight Object Facade from plugin accessor */
Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade");
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass);
Class objectTypeAttFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeAttributeFacade");
def objectTypeAttFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectTypeAttFacadeClass);
def moveMap = new MoveObjectMapping();
def fromAtts = objectTypeAttFacade.findObjectTypeAttributeBeans(object.getObjectTypeId());
def toAtts = objectTypeAttFacade.findObjectTypeAttributeBeans(144);
def index = 0;
toAtts?.each { item ->
MoveAttributeMapping temp = MoveAttributeMapping.create(item,fromAtts[index]);
moveMap.map(fromAtts[index].id,temp);
index++;
}
def mObject = new MoveObjectBean();
mObject.setFromObjectTypeId(object.getObjectTypeId());
mObject.setObjectSchemaId(1);
mObject.setToObjectTypeId(144);
mObject.setMapping(moveMap);
mObject.setReferences(mObject.getReferences().valueOf("KEEP_REFERENCES_TO_OBJECT"));
def insightObjects = object;
if (insightObjects != null)
{
/* Move object */
try
{
mObject.setIql("Key = " + insightObjects.objectKey);
objectFacade.moveObjects(mObject);
objectFacade.storeObjectBean(insightObjects);
} catch (Exception vie)
{
log.warn("Could not update object attribute due to validation exception:" + vie.getMessage());
}
}
Hi Michael.
You have to map every attribute from the source to the destination - and the type must match between source and target attributes...
The best way to understand the Move Object is to follow the Bulk-Move UI - the same should be done in your script.
Missing attributes won't be moved if not specified.
Kind regards,
Yinon
Team Riada
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Yinon Negev ,
I faced pretty the same challenge @Michael Aydemir was dealing with. Unfortunately, I'm not sure I did follow your hint exactly the way you were describing. Let me describe the issue, what is it current status and ask you for piece of code if possible :)
We are storing important kind of data in CRC object schema.
Because of the importance, we don't want anyone to operate manually.
Operations like new object creation or update are fully automated. Unfortunately, objects "removal" has to be done manually. We'd like to automate it.
There are 3 main object types:
Here is one of my try, mainly based on this post.
Object is moved but without any attribute. It's searchable by it's label, but none attribute displayed and none attribute is saved when object edited manually.
Wondering if anything should be done with Progress object returned by moveObjects method (https://insight-javadoc.riada.io/insight-javadoc-5.4.2/com/riadalabs/jira/plugins/insight/channel/external/api/facade/ObjectFacade.html#moveObjects-com.riadalabs.jira.plugins.insight.services.model.move.MoveObjectBean-) but was not able any clue for that :/
/*
skipping imports and issue load
*/
def object = (issue.getCustomFieldValue(cfObject)[0]).createMutable()
Class objectSchemaFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectSchemaFacade");
ObjectSchemaFacade objectSchemaFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectSchemaFacadeClass);
Class objectTypeFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeFacade");
ObjectTypeFacade objectTypeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectTypeFacadeClass);
ObjectSchemaBean crc = objectSchemaFacade.findObjectSchemaBeans().find
{ o -> o.objectSchemaKey == 'CRC'}
List<ObjectTypeBean> crcAllObjectTypes = objectTypeFacade.findObjectTypeBeansFlat(crc.id)
ObjectTypeBean srcObjectType = crcAllObjectTypes.find
{ o -> o.id == object.objectTypeId}
ObjectTypeBean tgtObjectType = crcAllObjectTypes.find
{ o -> o.name == ('Removed ' + srcObjectType.name)}
Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade");
ObjectFacade objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass);
Class objectTypeAttFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeAttributeFacade");
ObjectTypeAttributeFacade objectTypeAttFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectTypeAttFacadeClass);
MoveObjectMapping moveMap = new MoveObjectMapping();
List<ObjectTypeAttributeBean> fromAtts = objectTypeAttFacade.findObjectTypeAttributeBeans(srcObjectType.id);
List<ObjectTypeAttributeBean> toAtts = objectTypeAttFacade.findObjectTypeAttributeBeans(tgtObjectType.id);
def index = 0;
toAtts?.each
{ item -> MoveAttributeMapping temp = MoveAttributeMapping.create(item,fromAtts[index]); moveMap.map(fromAtts[index].id,temp); index++; }
MoveObjectBean mObject = new MoveObjectBean();
mObject.setObjectSchemaId(crc.id);
mObject.setFromObjectTypeId(srcObjectType.id);
mObject.setToObjectTypeId(tgtObjectType.id);
mObject.setMapping(moveMap);
// mObject.setReferences(mObject.getReferences().valueOf("REMOVE_REFERENCES_TO_OBJECT"));
try
{ mObject.setIql("Key = " + object.objectKey); objectFacade.moveObjects(mObject); // objectFacade.storeObjectBean(object) }
catch (Exception vie)
{ log.warn("Could not update object attribute due to validation exception:" + vie.getMessage()); }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This month the spotlight is on AppLiger. We caught up with Pavel Pavlovsky, CEO and Product Manager, to learn how the company started and what fuels the team's creativity. Atlassian:...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.