Process Configuration Source xml file posted back to the project Automation
3 answers
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:
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:
Couldn't post the entire thing in one code; here is the rest.
Not quite sure what you are asking..
you GET the existing IContent Object with IContent processSource = (IContent) pd.get(keyname);
then extract it to text
then edit it
then put it back into an IContent object (per your posts above)
then put it back in the project with pd.put(keyname,IContent_object);
I would guess u need to use the project area working copy and
then save the project area after updating the map.
Comments
- Thank you for your help Qiong. I do understand the concern about editing the process config file, but I think we will be able to handle it in case of any problems. :)
- I think the IContentService, getService, and IProcessServerService are custom methods, meaning they are not part of the Plain Java Library -- am I right, because I can't find anything to import them?
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;}