Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,366,858
Community Members
 
Community Events
168
Community Groups

Groovy script to move objects to another schema

Hi,

I am looking for a way to keep a history of the objects that are removed from the sources. I want to move them to a new scheme.
I want to do it with an automatic rule that calls a script.
I have tried the following code to move the objects to this new schema which is a clone of my main one. But dosen't work

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);

List<ObjectTypeBean> crcAllObjectTypes = objectTypeFacade.findObjectTypeBeansFlat(1)

ObjectTypeBean srcObjectType = crcAllObjectTypes.find
{ o -> o.id == object.objectTypeId}

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(407);

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(6);
mObject.setFromObjectTypeId(srcObjectType.id);
mObject.setToObjectTypeId(407);
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()); }

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events