How to modify process XML in a process configuration aspect editor
We're implementing a process configuration aspect editor and need to change process configuration XML outside of the configuration element associated with the aspect. We can call getAspect().getConfigurationRoot() to get the root of the process configuration XML and then search the process configuration XML to find the XML element(s) that we need to modify. The problem is that getAspect().getConfigurationRoot() returns a ModelElement, which doesn't have any modification methods. So, how do we modify and save the process configuration XML once we've found the ModelElement(s) we want to modify?
3 answers
As you mentioned the Model returned from getAspect().getConfigurationRoot() returns a model that is not writable. Configuration data editors update the process specification by calling getAspect().update(), passing in the source of the XML for the model. The typical aspect editor for configuration data will call getAspect().getConfigurationRoot() to get the configuration data and convert that data into a data structure which is easier for the editor to work. When it comes time to save the modified data the data is written out in XML format and passed to getAspect().update().
One consequence of this design is that it is not easy for a configuration data editor to make modifications outside of the configuration data associated with the aspect. It is possible for aspect editors to cooperate with one another, for example the aspect editors used in work items share the same underlying data so that when you add an entry in types and attributes that type becomes available in the Editor Presentations tab. We don't however encourage a configuration data editor to make changes to other sections of the process specification such as permissions or roles.
Comments
showing 5 of 6
show 1 more comments
https://jazz.net/library/article/1000 explains how aspect editors work.
Comments
I did some more investigation and found that adding the following code to the aspect editor's saveState method allows changes to be made to the entire process configuration XML:
Log log = LogFactory.getLog( this.getClass() );
IProcessContainerWorkingCopy processContainerWorkingCopy = getAspect()
.getProcessContainerWorkingCopy();
IDocument spec = processContainerWorkingCopy.getProcessSpecification();
String s = spec.get();
String s1 = s.replace( "<project-configuration>",
"<project-configuration Geoff=\"it works\">" );
log.warn( "specification:\n" + s1 );
spec.set( s1 );
try
{
processContainerWorkingCopy.save( null );
}
catch (TeamRepositoryException e)
{
log.error( "TeamRepostioryException encountered saving "
+ "process specification changes", e );
}
I'm not sure that this is entirely kosher, but it does seem to do what we need.
Log log = LogFactory.getLog( this.getClass() );
IProcessContainerWorkingCopy processContainerWorkingCopy = getAspect()
.getProcessContainerWorkingCopy();
IDocument spec = processContainerWorkingCopy.getProcessSpecification();
String s = spec.get();
String s1 = s.replace( "<project-configuration>",
"<project-configuration Geoff=\"it works\">" );
log.warn( "specification:\n" + s1 );
spec.set( s1 );
try
{
processContainerWorkingCopy.save( null );
}
catch (TeamRepositoryException e)
{
log.error( "TeamRepostioryException encountered saving "
+ "process specification changes", e );
}
I'm not sure that this is entirely kosher, but it does seem to do what we need.
Comments
1 vote