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
![]() 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;}
|
![]()
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 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? 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. 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);
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);
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();
}
}
Not quite sure what you are asking..
showing 5 of 6
show 1 more comments
|