It's all about the answers!

Ask a question

data migration of new customAttributes programmatically


Stefania Axo (12621513) | asked Mar 11 '11, 2:47 p.m.
hi
i need to migrate workitem customattributes via code

Here is my scenario:
- my process changed
- i had before a customAttribute id 'text' type 'smallString'
- i introduced a new customattribute id 'text2' as 'string'
- the new process has been saved with success that contains the new customAttribute 'text2'
- i want via code:
1. 'text2' to be updated to my workitem type ...it does not show up
2. the value of 'text' to be copied on 'text2'

can somebody give me some code that i can look into to achieve what i want to do?


thank you
Stefania

4 answers



permanent link
Stefania Axo (12621513) | answered Mar 17 '11, 10:49 a.m.
After query the work item with a specific type.
I copied what was in the old attribute to the new attribute by extending WorkItemOperation and it works


&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
private static class WorkItemAttributeCopy
extends WorkItemOperation
{

private IAttribute fAttribute1;
private IAttribute fAttribute2;

public WorkItemAttributeCopy( IAttribute attribute1, IAttribute attribute2 )
{
super( "Initializing Work Item", IWorkItem.FULL_PROFILE );
fAttribute1 = attribute1;
fAttribute2 = attribute2;
}
protected void execute( WorkItemWorkingCopy workingCopy, IProgressMonitor monitor )
throws TeamRepositoryException
{
IWorkItem workItem = workingCopy.getWorkItem();
workItem.setValue( fAttribute2, workItem.getValue( fAttribute1 ) );
}

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

This is good for when i need to migrate data from an old attribute to a new attribute when i decided to change its type for whatever reason.

The simple attribute add a remove in my process specification that do not require data migration should be solved by calling the same code that does the client "Synchronize Attributes". I asked the link to the code in another forum.

http://jazz.net/forums/viewtopic.php?p=52809#52809.

thanks
Stefania

permanent link
Stefania Axo (12621513) | answered Mar 15 '11, 10:06 a.m.
first: it will be a client application to do the migration.

I got to work the query part of my application. By looking at the example https://jazz.net/wiki/bin/view/Main/QueryDevGuide#ExampleTwo

I can query project area /work item of a certain type and get the List of work items.

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
IQueryableAttribute projectAreaAttribute = findAttribute( projectArea, auditableClient, IWorkItem.PROJECT_AREA_PROPERTY, null );
IQueryableAttribute workItemTypeAttribute = findAttribute( projectArea, auditableClient, IWorkItem.TYPE_PROPERTY, null );
AttributeExpression projectAreaExpression = new AttributeExpression( projectAreaAttribute, AttributeOperation.EQUALS, projectArea );
AttributeExpression workItemTypeExpression = new AttributeExpression( workItemTypeAttribute, AttributeOperation.EQUALS,
"myworkitemtypeid" );

Term term = new Term( Operator.AND );
term.add( projectAreaExpression );
term.add( workItemTypeExpression );
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

Now i need to see how to use the IWorkItem.addCustomAttribute and IWorkItem.removeCustomAttribute for each of my found work item where the custom attributes have already been added or simply removed in my changed process specification.

thank you
Stefania

permanent link
Stefania Axo (12621513) | answered Mar 14 '11, 1:51 p.m.
IWorkItem.addCustomAttribute(IAttribute attribute);

seems to be what i need in order to add a new custom attribute.
I still have questions on how to make it work??
what is the class that i need to use in order to have my workitmetype updated?

After i get all the list of my IWorkItem (possible from a query).


thank you
Stefania

permanent link
Stefania Axo (12621513) | answered Mar 11 '11, 7:34 p.m.
hi
in particular,
- I want to have access to a List <IWorkItem> coming for a query for only 1 WorkItemType.
- refresh/synchronize the customAttributes of my IWorkItemType
- then be able to use a IAttribute findAttribute by attribute id to find the attribute that i want to retrieve the value (IWorkItem.getValue(IAttribute) for currentValue) to be able to do IWorkItem.setValue(newAttribute, currentValue)


please help
thanks
Stefania

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.