Create new enumeration values from the Wiki?

Description
gcueppers
Posts: 16
Joined: Tue Feb 26, 2008 2:24 pm
Location: Aachen, Germany
Contact:

Create new enumeration values from the Wiki?

Postby gcueppers » Thu Jan 13, 2011 2:08 pm

Hallo all,

how is it possible to create new enumeration values from the Wiki?

We have developed an formular to entry an enumeartaion value "system" and press a "create" Button.
After this, the formular value should be configured automatically as an additional value within the system-enum.xml for the actual project. Unfortunately we did not find a way to do this by searching the javadoc help files.
A code example would be great!

Thanks in advance and kind regards..
kind regards,
Guido

Sandro_F
Posts: 19
Joined: Wed Jan 19, 2011 8:40 am

Re: Create new enumeration values from the Wiki?

Postby Sandro_F » Wed Jan 19, 2011 8:57 am

Hello,

well, you can create a Servlet:
- get the xml file
- parse it
- add some values
- commit the xml file

You can use SvnKit and JDOM librarys for this. You can also use the Interface "IRepositoryService" from Polarion, but I use SvnKit in this example:

Code: Select all


// Setup connection to Repository
DAVRepositoryFactory.setup();
SVNRepository repos = SVNRepositoryFactory.create(SVNURL.parseURIDecoded("https://polarion.server.company/repo/"));
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(name, password);   
repos.setAuthenticationManager(authManager);

// Get xml file
String currentUrl = "path/to/enumfile";
SVNProperties fileProperties = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream( );
repos.getFile( currentUrl , -1 , fileProperties , baos );
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());

// add value
SAXBuilder saxBuilder = new SAXBuilder();
Document document = saxBuilder.build(bais);
Element rootElement = document.getRootElement();
List  listParentElements = rootElement.getChildren("option");
Element elNew = new Element("option");
elNew.setAttribute("id", optionValue);
elNew.setAttribute("name", optionValue);
listParentElements.add(0, elNew );

// commit file
XMLOutputter outp = new XMLOutputter();
outp.setFormat(Format.getPrettyFormat());
// Save to file
file = new File("/path/to/a/tmp/file");
FileOutputStream fileOutput = new FileOutputStream(file);
outp.output(document, fileOutput);
fileOutput.close();
InputStream fileReader = new FileInputStream(file);
ISVNEditor editor = repos.getCommitEditor("", new WorkspaceMediator());
SVNCommitInfo commitInfo = SVNUtils.modifyFile(editor, dirPath, currentUrl, fileReader, size);


Well, this code is not running out of the box. You have to adjust some objects and variables. Anyway, you need some Java-Experience for this.

Maybe I will publish a Extension for adding enum values over a Wiki page.


Regards,
Sandro Frenzel

gbonney
Posts: 1
Joined: Thu Jan 20, 2011 2:18 pm

Re: Create new enumeration values from the Wiki?

Postby gbonney » Thu Jan 20, 2011 2:49 pm

Hello there,

unfortunately i don't have SvnKit installed and my access levels wont allow me to change this.
So could you please give me a hint how to use the IRepositoryService from Polarion?

I'm actually accessing the repository this way:

#set($repoService = $polarionTool.repositoryService)
#set($connection = $repoService.getReadOnlyConnection($polarionTool.location))
#set($path = "/TT2/TT2TT2/.polarion/tracker/fields/environment-enum.xml")
#set($input = $connection.getContent($polarionTool.location.getLocation($path)))
#set($doc = $xmlTool.documentBuilderFactory.newDocumentBuilder().parse($input))

$path contains $doc.documentElement.getElementsByTagName("option").length options.

This works for me, $doc.documentElement.getElementsByTagName("option").length returns a number.

But when using $repoService.getConnection($polarionTool.location)) it fails with:

Error number 4001 in 4: Error while parsing velocity page project/TT2TT2/page/_default/Page2TestWiki Wrapped Exception: Invocation of method 'getConnection' in class $IRepositoryService_12d7b05114d threw exception class com.polarion.platform.service.repository.RepositoryException : Transaction problem: the connection can be created in active transaction context only

Any idea?

Tanks in advance and kind regards,
Gregory.

Sandro_F
Posts: 19
Joined: Wed Jan 19, 2011 8:40 am

Re: Create new enumeration values from the Wiki?

Postby Sandro_F » Fri Jan 21, 2011 12:25 pm

Hello,

well, SVNKit ist part of Polarion, so you don`t need to install it. When using servlets you are allowed to use every external library (also non Polarion libs).

However, I see that you want to use wiki code to solve your problem. I do not know whether DocumentBuilderFactory is able to write xml files. I think no!
But, to solve your exception you have to use ITransactionService interface like this $transactionService.beginTx() (see JavaDoc for further instructions). Just call it like $trackerService Interface.


Regards,
Sandro Frenzel

Tina99
Posts: 1
Joined: Thu Nov 28, 2013 7:55 am

Re: Create new enumeration values from the Wiki?

Postby Tina99 » Thu Nov 28, 2013 8:56 am

Hi everyone,
I guess I'm facing the same problem as Gregory two years ago:
I would like to create a new enumeration from a wiki page (with wiki code if possible) and add options to this enumeration.
Has anyone found a solution to this in the meantime or is an Extension for adding enum values over a Wiki page available by now?
Unfortunately I have not found any information regarding this.

Thanks in advance,

Best regards,
Bettina


Return to “Polarion Application Lifecycle Management (ALM)”

Who is online

Users browsing this forum: Kevenbot and 5 guests