how to call 'Synchronize Attributes' via client code
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
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);
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 );
}
}
IProcessDefinition processTemplate = ...This is a very strange behaviour because the process configuration source in the project area it really contains all the attributes...!
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);
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 );
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!
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
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:
- Running the query and export the data to CSV
- Change the type to the desired type
- Run a synchronize attributes
-
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.
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/