How to programmatically update Process Configuration Source
After found this post (https://jazz.net/forum/questions/6862/where-is-the-xml-file-saved-for-process-configuration-source/6865) from the Jazz Process Team:
We tried to write a Plain Java Client to programmatically update all existing project areas in our repository.We don't have any support for importing into an existing project area,though. If you want to change the process configuration source ofmultiple project areas to be the same, you'll currently have tocopy/paste in the project area editor.
First we retrieved the Process Configuration Source from a process template:
ITeamRepository repo = ...IProcessDefinition processTemplate = ...Map<String, IContent> processTemplateData = processTemplate.getProcessData();final String PROCESS_CONFIGURATION_SOURCE_KEY = "com.ibm.team.internal.process.compiled.xml";
IContent content = processTemplateData.get(PROCESS_CONFIGURATION_SOURCE_KEY);OutputStream outStream = new ByteArrayOutputStream();repo.contentManager().retrieveContent(content, outStream, null);
Then, we tried to update the Process Configuration Source of the project area:
IProjectArea prjArea = ...IProcessDefinitionHandle prjAreaProcessH = (IProcessDefinitionHandle) prjArea.getProcessDefinition();IProcessDefinition prjAreaProcess = (IProcessDefinition) repo.itemManager().fetchCompleteItem(prjAreaProcessH, ItemManager.DEFAULT, null);
prjAreaProcess = (IProcessDefinition) prjAreaProcess.getWorkingCopy();Map<String, IContent> prjAreaProcessData = prjAreaProcess.getProcessData();prjAreaProcessData.put(PROCESS_CONFIGURATION_SOURCE_KEY, content);processClient.save(prjAreaProcess, null);
Although we fetched a working copy of the process, we get a "com.ibm.team.repository.common.internal.ImmutablePropertyException" exception. Any advice?
Thanks in advance.
One answer
Ok, we found this post https://jazz.net/forum/questions/49535/how-to-get-process-template-source, and now with the code below it works:
final String xml = outStream.toString();IWorkingCopyManager workingCopyManager = processClient.getWorkingCopyManager();IProjectAreaWorkingCopy prjAreaFreshCopy = (IProjectAreaWorkingCopy) workingCopyManager.createPrivateWorkingCopy(prjArea);IDocument document = prjAreaFreshCopy.getProcessSpecification();document.set(xml);prjAreaFreshCopy.save(null);