Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

how to call 'Synchronize Attributes' via client code

hi
I want to be able to call the 'Synchronize Attributes' via code or doing the same thing via code.
how can i do so?
After the process specification changes, the 'Synchronize Attributes' of the work item query result in the RTC Eclipse IDE will get the changes .

thanks in advantage
Stefania

0 votes



9 answers

Permanent link
i think this is the code
com.ibm.team.workitem.common.model.ItemProfile.SynchronizeAttributesAction


i will try to use a similar logic

stefy

0 votes


Permanent link
seems to work fine with the
1. WorkItemOperation extension
2. workItemClient.updateWorkItemType(workItem, type, type, null); where old type and new type are the same.

0 votes


Permanent link
We are trying to use the code below to synchronize attributes on a work-item:
ITeamRepository repo = …
IWorkItem wi = …
IWorkItemClient workItemClient = (IWorkItemClient) repo.getClientLibrary(IWorkItemClient.class);
IWorkItemType wiType = workItemClient.findWorkItemType(wi.getProjectArea(), wi.getWorkItemType(), null);
IWorkItemWorkingCopyManager workingCopyManager = workItemClient.getWorkItemWorkingCopyManager();
workingCopyManager.connect(wi, IWorkItem.FULL_PROFILE, null);
WorkItemWorkingCopy workingCopy = workingCopyManager.getWorkingCopy(wi);
boolean changed = workItemClient.updateWorkItemType(workingCopy.getWorkItem(), wiType, wiType, null);
workingCopy.save(null);
But then no attributes have been synched... Any advice?
By the way, the same snippet code was suggested by a Jazz developer: https://jazz.net/forum/questions/75734/attributes-synchronization-with-java-possible/75738
Thanks in advance.

0 votes


Permanent link
to change the single work item
I created a query and synchronize each work item result of the query.

      while (result.hasNext( null ))
      {
         IResolvedResult<IWorkItem> resolved = result.next( null );

         IWorkItem workItem = resolved.getItem();

         WorkItemSynchronizeAttributes synchronizeOperation = new WorkItemSynchronizeAttributes();
         synchronizeOperation.run( workItem, null );
      }

WorkItemSynchronizeAttributes  extendis WorkItemOperation
its method execute will do the rest.
   protected void execute( WorkItemWorkingCopy workingCopy,
         IProgressMonitor monitor )
         throws TeamRepositoryException
   {
      IWorkItem workItem = workingCopy.getWorkItem();
      ITeamRepository teamRepository = workingCopy.getTeamRepository();
      IWorkItemClient workItemClient = (IWorkItemClient)teamRepository
            .getClientLibrary( IWorkItemClient.class );

      IWorkItemType type = workItemClient.findWorkItemType( workItem
            .getProjectArea(), workItem.getWorkItemType(), null );
      if (type != null)
      {
         workItemClient.updateWorkItemType( workItem, type, type, null );

      }

   }




0 votes


Permanent link
Ok, even our code seems to work like a charm.
We got problems when we try to update the project area's process with the new attributes using the code below:
IProcessDefinition processTemplate = ...
IProcessItemService processClient = (IProcessItemService) repo.getClientLibrary(IProcessItemService.class);
IWorkingCopyManager workingCopyManager = processClient.getWorkingCopyManager();
IProcessDefinitionWorkingCopy processTemplateFreshCopy = (IProcessDefinitionWorkingCopy) workingCopyManager.createPrivateWorkingCopy(processTemplate);
final String xml = processTemplateFreshCopy.getProcessSpecification().get();
IProjectAreaWorkingCopy prjAreaFreshCopy = (IProjectAreaWorkingCopy) workingCopyManager.createPrivateWorkingCopy(prjArea);
IDocument document = prjAreaFreshCopy.getProcessSpecification();
document.set(xml);
prjAreaFreshCopy.save(null);
This is a very strange behaviour because the process configuration source in the project area it really contains all the attributes...!

0 votes


Permanent link

are you trying to change the process configuration based on a new updated template?

this is what i do

-------------------------------------------------------------------------------------------

IProcessItemService processService = (IProcessItemService)repository.getClientLibrary( IProcessItemService.class );

IWorkingCopyManager workingCopyManager = processService.getWorkingCopyManager();

workingCopyManager.connect( projectArea );

IProcessItemWorkingCopy itemWorkingCopy = workingCopyManager.getWorkingCopy( projectArea );

......

document.set(xml);

itemWorkingCopy.save( null );


0 votes


Permanent link

Yep, given a template we update all the existing project area with that template.

So, instead of:

IProjectAreaWorkingCopy prjAreaFreshCopy = (IProjectAreaWorkingCopy) workingCopyManager.createPrivateWorkingCopy(prjArea);

as suggest here: https://jazz.net/forum/questions/49535/how-to-get-process-template-source/49536, we have to use:

workingCopyManager.connect(prjArea);
IProjectAreaWorkingCopy prjAreaFreshCopy = (IProjectAreaWorkingCopy) workingCopyManager.getWorkingCopy(prjArea);

P.S. Thanks a bunch for you answers, Stefania!

0 votes


Permanent link
Hello,

I try to synch my workitem to another workitem via server-side code. When I press Save Button, my plugin will synchronize Task WorkItem to Release Workitem. And there are some other controls which happens when a Release Workitem created.
IWorkItemType oldType = wiServer.findWorkItemType(operation.getProcessArea().getProjectArea(),"task", monitor);
IWorkItemType newType = wiServer.findWorkItemType(operation.getProcessArea().getProjectArea(),"com.avea.workItemType.release", monitor);
                        workItemCommon.updateWorkItemType(newWorkItem, newType, oldType, monitor);              

Synchronization worked for the attributes but workflow didnt get synchronized. It says "Uninitialized" And also link type with the other workitems is lost. I can see the my childworkitems but there's no releation information.

Do you have any idea how to solve this problem?

0 votes

Comments

I am pretty sure that synchronizing work items is not supposed to solve your scenario. Synchronize attributes is only supposed to add any missing attributes from the type to the work item. If you change the type there is a certain mapping that would need to be done. If the work item has a state literal that is not available in the new type's workflow, I would assume issues. Synchronize won't fix that. You might have to: Change the type, map some attributes such as the state (see http://rsjazz.wordpress.com/2012/11/26/manipulating-work-item-states/) and then sync to get new attributes added.

On a second thought, if you change the type of the work item and there is no matching state in the new type, the work item gets the new state.

You might want to think about:

  1. Running the query and export the data to CSV
  2. Change the type to the desired type
  3. Run a synchronize attributes
  4. Map the states in the CSV file to the new states and use a CSV import to change the state where needed.

As you said there's no matching state in both workitems but state turns into Uninitilized state or may be I understood your assumption.

We have to trigger that action in the editor when we catch the save event. We dont have the choice to export/import. It's a big burden for a "normal" user to know the state name,etc... Workitem should be turned into another workitem during its lifecycle in my case.

If RTC had a rule which might prevent workitem transformation unless user not press the SYNCH link on the editor, it would be great. If the user dont press SYNCH link, some data get lost. I'd like to automatize that action actually.

Mapping the state programmatically is another issue that I am having difficulties :(

You could create an Advisor that prevents from changing the type. For API hints look at http://rsjazz.wordpress.com/2012/11/26/manipulating-work-item-states/, the development Wiki and other posts and links.


Permanent link
Here is an APP that does it for you: http://rsjazz.wordpress.com/2012/11/19/using-an-expression-to-synchronize-attributes-for-work-items-of-a-specific-type/

0 votes

Comments

Instead of an expression you can also use a query as described in http://rsjazz.wordpress.com/2012/10/29/using-work-item-queris-for-automation/

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,953

Question asked: Mar 16 '11, 7:42 p.m.

Question was seen: 6,880 times

Last updated: Nov 27 '12, 10:59 a.m.

Confirmation Cancel Confirm