Process Configuration Source xml file posted back to the project Automation
This is for an automation we are trying to do. I have been able to download the Process Config Source xml for project(s) to my local machine, now that I am done editing it, I need to be able to post (paste) it back again to the project using plain java client libraries. Does anyone know how to do this?
|
3 answers
well, there is no official way to do this,
my code to extract it is here , see post Mar 21, 6:08 p.m.
https://jazz.net/forum/questions/142728/auto-backup-of-process-configuration-xml-source
you will have to reverse the process of extracting it to put it back.
Comments
KB 20
commented Apr 03 '14, 11:39 a.m.
Thanks! In the link you gave above, does 'keyname' hold the entire data of xml for the project? If not, then what object is storing the xml data until it is written out to a file?
sam detweiler
commented Apr 03 '14, 11:41 a.m.
for extract it appears to hold the whole XML. I never wrote it back, so I am not sure if there any details to be aware of.
KB 20
commented Apr 24 '14, 11:30 a.m.
So, I am able to store the document and all I need is a way to set the stored content and then save it. Here is what I have so far:
if (processSource != null)
{
File xmlFile = new File(filename);
System.out.println("Extracting: " + xmlFile);
inStream = new FileInputStream(xmlFile);
try
{
ByteArrayOutputStream contents = copyFileData(inStream);
KB 20
commented Apr 24 '14, 11:31 a.m.
So, I am able to store the document and all I need is a way to set the stored content and then save it. Here is what I have so far:
if (processSource != null)
{
File xmlFile = new File(filename);
System.out.println("Extracting: " + xmlFile);
inStream = new FileInputStream(xmlFile);
try
{
ByteArrayOutputStream contents = copyFileData(inStream);
KB 20
commented Apr 24 '14, 11:33 a.m.
Couldn't post the entire thing in one code; here is the rest.
try
{
IContentManager icm = fTeamRepository.contentManager();@SuppressWarnings("deprecation")
IContent content = icm.storeContent(newByteArrayInputStream(contents.toByteArray()), fMonitor);
}finally
{
contents.close();
}
}finally
{
inStream.close();
}
}
sam detweiler
commented Apr 24 '14, 11:41 a.m.
Not quite sure what you are asking..
showing 5 of 6
show 1 more comments
|
It's NOT recommended to change the process configuration source programatically. It would cause unexpected behavior. But if you still insist on doing that and willing take the risks, you can try the following methods:
// store your customized process configuration source
IContentService contentService = getService(IContentService .class);
IContent newSpecContent = IContentService.storeContent3(...)
// put it back to the project area
IProjectArea projectAreaWorkingCopy = (IProjectArea) projectArea.getWorkingCopy();
projectAreaWorkingCopy.getProcessData().put(ProcessContentKeys.PROCESS_SPECIFICATION_KEY, newSpecContent);
// save the project area
IProcessServerService processService = getService(IProcessServerService.class);
processService.saveProcessItem(projectAreaWorkingCopy);
Comments
KB 20
commented Apr 29 '14, 2:46 p.m.
|
I got the solution, so here it is: if(login(repoUrl, userID, password, fMonitor) != null){ fTeamRepository = getRepository(repoUrl); List<IProjectArea> projectList = getProjectArea(fTeamRepository, fMonitor, project_name);System.out.println("There is/are " + projectList.size() + " project(s) with this name"); for(int i = 0; i < projectList.size(); i++){ IProjectArea ip = projectList.get(i);System.out.println("\nProject name = " + ip.getName());
try{ File xmlFile =new File(filename);InputStream inStream = new FileInputStream(xmlFile); ByteArrayOutputStream contents = copyFileData(inStream); String xml = contents.toString(); IItemManager itemManager =feamRepository.itemManager();IProjectArea projectArea = (IProjectArea)itemManager.fetchCompleteItem( ip.getItemHandle(), IItemManager.REFRESH, fMonitor );fTeamRepository = (ITeamRepository) projectArea.getOrigin(); IProcessItemService processClient = (IProcessItemService) fTeamRepository.getClientLibrary(IProcessItemService.class); IWorkingCopyManager workingCopyManager = processClient.getWorkingCopyManager(); workingCopyManager.connect( projectArea ); IProjectAreaWorkingCopy projectAreaFreshCopy = (IProjectAreaWorkingCopy) workingCopyManager.createPrivateWorkingCopy(projectArea); IDocument spec = projectAreaFreshCopy.getProcessSpecification(); spec.set(xml); projectAreaFreshCopy.save(fMonitor);workingCopyManager.disconnect( projectArea );}catch (Exception ex){ System.out.println("Exception = " + ex.toString())}}}}catch (Exception ex){ System.out.println("Exception = " + ex.toString());private static ByteArrayOutputStream copyFileData(InputStream inStream) throws IOException{ ByteArrayOutputStream contents = new ByteArrayOutputStream();
byte[] buf = new byte[3072]; int read; while((read = inStream.read(buf)) != -1){ contents.write(buf, 0, read);} contents.flush();return contents;}
|
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.