Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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?

0 votes



3 answers

Permanent link
 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. 

0 votes

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();
}
}

Any directions on what method I could use to read the 'IContent content' object and then save it?  

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.

showing 5 of 6 show 1 more comments

Permanent link
 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);

0 votes

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?
     


Permanent link

 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;}

0 votes

Your answer

Register or log in to post 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details

Question asked: Apr 01 '14, 2:52 p.m.

Question was seen: 4,684 times

Last updated: Jun 12 '14, 4:43 p.m.

Confirmation Cancel Confirm