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

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,463,739
Community Members
 
Community Events
176
Community Groups

Moving Insight objects via Groovy fails

Hi,
as we have to move objects in various steps we want to automate this with groovy. I've seen similar requests in the forum but no valid answers.

The move with the following script works but the details / attributes are lost.
The objectTypes have the same parent and the source has one additional attribute that will be discarded.

Anybody with an idea?


import com.riadalabs.jira.plugins.insight.services.model.move.MoveObjectMapping
import com.riadalabs.jira.plugins.insight.services.model.move.MoveAttributeMapping
import com.riadalabs.jira.plugins.insight.services.model.move.MoveObjectBean
import helper.InsightManager

def im = new InsightManager()

def asset = im.getObjectBean("PROD-208936")

def moveMap = new MoveObjectMapping().create()
def fromAtts = im.objectTypeAttributeFacade.findObjectTypeAttributeBeans(asset.objectTypeId)
def toAtts = im.objectTypeAttributeFacade.findObjectTypeAttributeBeans(20)

moveMap.map(59,MoveAttributeMapping.create(fromAtts.find{id=59},toAtts.find{id=59})) // Key
moveMap.map(259,MoveAttributeMapping.create(fromAtts.find{id=259},toAtts.find{id=259})) // Artikelnummer
moveMap.map(60,MoveAttributeMapping.create(fromAtts.find{id=60},toAtts.find{id=60})) // Artikelname
moveMap.map(61,MoveAttributeMapping.create(fromAtts.find{id=61},toAtts.find{id=61})) // Created
moveMap.map(4522,MoveAttributeMapping.create(fromAtts.find{id=4522},toAtts.find{id=4522})) // Hersteller
moveMap.map(62,MoveAttributeMapping.create(fromAtts.find{id=62},toAtts.find{id=62})) // Updated
moveMap.map(4839,MoveAttributeMapping.create(fromAtts.find{id=4839},toAtts.find{id=4839})) // Gewicht
moveMap.map(403,MoveAttributeMapping.create(fromAtts.find{id=403})) // Kategorie

def mObject = new MoveObjectBean()

mObject.setFromObjectTypeId(asset.objectTypeId)
mObject.setObjectSchemaId(3)
mObject.setToObjectTypeId(20)
mObject.setMapping(moveMap)
mObject.setReferences(mObject.references.valueOf("KEEP_REFERENCES_TO_OBJECT"))
mObject.setIql("Key = " + asset.objectKey)

im.objectFacade.moveObjects(mObject)
im.objectFacade.storeObjectBean(asset.createMutable())

3 answers

1 accepted

Sorry, the stupiest mistake. In the find closure there were assigments (id=59) instead of comparison (it.id==59).

@Christof Hurstdid you find solution for this? In my case move is working, but also attributes are gone after moving an object form one typeId to another (in the same schema).

Solution is in the accepted answer. If attributes are missing I would presume that they are not in the list to be copied or not with the correct data or data format.

I am using .each function and not mapping them manually with IDs, but I get the same result with your example and mapping them manually.

toAtts?.each { item ->
MoveAttributeMapping temp = MoveAttributeMapping.create(item, fromAtts[index]);
moveMap.map(fromAtts[index].id, temp);
index++;
}

 

After I've done the mapping my MoveAttributeMap object shows like this:

moveObject: MoveObjectBean{fromObjectTypeId=69,
toObjectTypeId=100,
mapping=MoveObjectMapping{attributeMappingMap={789=com.riadalabs.jira.plugins.insight.services.model.move.MoveAttributeMapping@2a38a0a1,
791=com.riadalabs.jira.plugins.insight.services.model.move.MoveAttributeMapping@39fd8d10,
792=com.riadalabs.jira.plugins.insight.services.model.move.MoveAttributeMapping@221dac8a,
841=com.riadalabs.jira.plugins.insight.services.model.move.MoveAttributeMapping@1061a041,
842=com.riadalabs.jira.plugins.insight.services.model.move.MoveAttributeMapping@7f333744,
843=com.riadalabs.jira.plugins.insight.services.model.move.MoveAttributeMapping@2a73a0bf,
844=com.riadalabs.jira.plugins.insight.services.model.move.MoveAttributeMapping@65c53087,
845=com.riadalabs.jira.plugins.insight.services.model.move.MoveAttributeMapping@78bbf7d6,
846=com.riadalabs.jira.plugins.insight.services.model.move.MoveAttributeMapping@1ed46692,
847=com.riadalabs.jira.plugins.insight.services.model.move.MoveAttributeMapping@29955baf}},
iql=Key = KAS-132313,
objectSchemaId=3,
references=KEEP_REFERENCES_TO_OBJECT}

 Which looks like the mapping is done correctly, no?

The index variable is undefined. Can't work.

def index = 0; is set before this each loop.

Sorry I don't know. I know that my method is working. I would never trust this automatic way. I always define the set of attributes explicitely by myself.

0 votes

I have implemented a similar move (between two child object types with the same parent) and didn't need to use the "storeObjectBean" method.

So I wonder if that's what tripping your script. 

The moveObjects method kicks off an asynchronous process so in your case, perhaps the storeObjectBean method is attempting to save the old version of the object while the move is still being processed.

I had a similar problem when I was trying to populate a new attribute (date/time of the move on the target object after the move) before the move was complete.

I solved it by waiting for the move to complete before resuming any other part of my script.

Something like this:

def moveProgress = objectFacade.moveObjects(mObject)
Integer curWait = 0
Integer maxWaitMillis = 10000

log.debug "Waiting for move to finish: $curWait ($moveProgress.status)"
while (moveProgress.isFinished() == false && curWait < maxWaitMillis) {
Thread.sleep(100)
curWait = curWait + 100
log.debug "Waiting for move to finish: $curWait ($moveProgress.status)"
}
if (moveProgress.isFinished()) {
log.info "Move complete"
} else if (moveProgress.isError()) {
log.error "error during move"
return
} else {
log.warn "maxWaitMillis reach while waiting for move to finish."
return
}
//resume post move actions here, probably safects to re-laod your object bean after the move rather than keep the old asset object

Thanks for this answer but it didn't solve the problem.

The move now takes some millis to finish but the result is the same. All details are gone. Even the label. Line with storeObject was deleted. A clean reindex also didn't helped.

Actually the script is complete as shown above. There are no further actions. As the script is pretty simple and straight forward I have no glue.

@Christof Hurstdid you find solution for this?

My attributes are gone too after a successful object movement from one typeId to another.

Then I think finding the correct value in the old object is not working. For me it was = instead of ==

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS

Atlassian Community Events