It's all about the answers!

Ask a question

Process Configuration Source xml file posted back to the project Automation


KB 20 (123) | asked Apr 01 '14, 2:52 p.m.
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



permanent link
sam detweiler (12.5k6195201) | answered Apr 01 '14, 3:10 p.m.
 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();
}
}

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


sam detweiler commented Apr 24 '14, 11:41 a.m.

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
Qiong Feng Huang (76911610) | answered Apr 29 '14, 3:09 a.m.
JAZZ DEVELOPER
 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.
  • 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
KB 20 (123) | answered Jun 12 '14, 4:43 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


Register or to post your answer.