Process Configuration Source xml file posted back to the project Automation
3 answers
Comments
Comments
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;}