It's all about the answers!

Ask a question

how to call 'Synchronize Attributes' via client code


Stefania Axo (12621513) | asked Mar 16 '11, 7:42 p.m.
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

9 answers



permanent link
Stefania Axo (12621513) | answered Mar 18 '11, 1:24 p.m.
i think this is the code
com.ibm.team.workitem.common.model.ItemProfile.SynchronizeAttributesAction


i will try to use a similar logic

stefy

permanent link
Stefania Axo (12621513) | answered Mar 23 '11, 4:26 p.m.
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.

permanent link
SEC Servizi (97122652) | answered Oct 11 '12, 11:05 a.m.
edited Oct 11 '12, 11:10 a.m.
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.

permanent link
Stefania Axo (12621513) | answered Oct 11 '12, 2:07 p.m.
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 );

      }

   }





permanent link
SEC Servizi (97122652) | answered Oct 12 '12, 10:11 a.m.
edited Oct 12 '12, 10:14 a.m.
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...!

permanent link
Stefania Axo (12621513) | answered Oct 12 '12, 11:01 a.m.

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



permanent link
SEC Servizi (97122652) | answered Oct 12 '12, 11:20 a.m.

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!


permanent link
Canberk Akduygu (99237271) | answered Nov 27 '12, 5:12 a.m.
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?


Comments
Ralph Schoon commented Nov 27 '12, 6:15 a.m. | edited Nov 27 '12, 6:16 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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.


Ralph Schoon commented Nov 27 '12, 6:29 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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.


Canberk Akduygu commented Nov 27 '12, 10:54 a.m.

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 :(


Ralph Schoon commented Nov 27 '12, 10:59 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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
Ralph Schoon (60.5k33643) | answered Nov 27 '12, 6:10 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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/

Comments
Ralph Schoon commented Nov 27 '12, 6:11 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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 to post your answer.