Reuse document from a velocity script ?

Description
victorien
Posts: 7
Joined: Wed Mar 14, 2018 1:41 pm

Reuse document from a velocity script ?

Postby victorien » Wed Mar 14, 2018 1:50 pm

Hello, I am having trouble figuring this one out.

I would like to create a live report page to create (reuse) a new wiki document pased on a template.
I saw that there is a reuse function that would do what I want but I have no idea how to implement that into the code, I tried to call $trackerWebService.reuseDocument(#parametersHere) but nothing happens.

ALMighty
Posts: 80
Joined: Wed Apr 27, 2016 10:34 am
Location: Austria

Re: Reuse document from a velocity script ?

Postby ALMighty » Fri Mar 16, 2018 10:01 am

victorien wrote:I would like to create a live report page to create (reuse) a new wiki document pased on a template.
I saw that there is a reuse function that would do what I want but I have no idea how to implement that into the code, I tried to call $trackerWebService.reuseDocument(#parametersHere) but nothing happens.


TrackerWebService cannot be used for Wikipages, it is ITrackerService which you have to use.
Check out the second part of my answer in the thread No web service for deleting a work item? for more details.

There is no reuse function/method available as far as I can see it however however loading the DocuementManager and using the createDocumentFromTemplate function/method could do the trick.

If it does not work with createDocumentFromTemplate, I think an alternative would be that you get the DocuementManager, load the document which you want to reuse, create a new document and copy the contents via Velocity from the document you want to reuse to the newly created document functions in order to set the copied contents.

I guess getting the documents manager in your Velocity script is done that way:

Code: Select all

#set($dm = $trackerService = getDocumentsManager() )
---------------------------------------------------------------------------------------------------
Playing a good game is never lame. :D
Image

victorien
Posts: 7
Joined: Wed Mar 14, 2018 1:41 pm

Re: Reuse document from a velocity script ?

Postby victorien » Mon Mar 19, 2018 1:36 pm

Thanks a lot for your reply, I tried couple things but it seems that I cannot get content from the template.
Here is the code, commented lines are the ones I want to work but they return error.

Code: Select all

#set($dm = $trackerService.getDocumentsManager() )
#set($templateLoc = $dm.getDocumentLocation("project ID","correct path",null))
#set($newPath = $dm.getDocumentLocation("destination project ID","folder path for destination",null))

$templateLoc <br> $newPath ## Returns correct location

##set($test = $dm.createDocumentFromTemplate($newPath,"*Doc Title*",$templateLoc))
$test ## Error 1

#set($templateDoc = $dm.getDocument($templateLoc))
$templateDoc ## Returns correct document ID

##set($content = $dm.getDocumentContent($templateDoc))
$content ## Error 2


Error 1 :
There was an exception (see server log for details) Invocation of method 'createDocumentFromTemplate' in class $IDocumentsManager_161791f02c9 threw exception class java.lang.NullPointerException : null


Error 2 :
There was an exception (see server log for details) Invocation of method 'getDocumentContent' in class $IDocumentsManager_161791f02c9 threw exception class java.lang.NullPointerException : null


I dont really know where the issue comes from. If you know some alternative ways to do all that from velocity code, I appreciate

Thank you for your help already !
Last edited by victorien on Wed Mar 21, 2018 6:45 am, edited 1 time in total.

ALMighty
Posts: 80
Joined: Wed Apr 27, 2016 10:34 am
Location: Austria

Re: Reuse document from a velocity script ?

Postby ALMighty » Tue Mar 20, 2018 12:44 pm

I currently have not access to Polarion but meanwhile I have two questions. Probably the answers to those two contain some hints.

victorien wrote:

Code: Select all

$templateLoc <br> $newPath ## Returns correct location



You want to show me how the paths look like, hence what the page shows when you print does variables?
I do not want to see tha exact path names since they are confidential (you can use dummy names for the folders) but I want to see the "format" of the paths (if they are displayed with slashes or backslashes and so on).

victorien wrote:

Code: Select all

##set($test = $dm.createDocumentFromTemplate($newPath,"Regular RMQA MoM



I hope in the real version of your page the #set command is not in a comment. :lol: Just kidding.

But have you tried to create a page with a name that contains no spaces?
Polarion is a bit sensitive concerning that at least concerning IDs of work items, pages and plans.
I know the Javadoc says that the second parameter is the name (not the ID) of the document but
maybe an error is thrown when it tries to render the ID from the name or something like that.
---------------------------------------------------------------------------------------------------
Playing a good game is never lame. :D
Image

victorien
Posts: 7
Joined: Wed Mar 14, 2018 1:41 pm

Re: Reuse document from a velocity script ?

Postby victorien » Wed Mar 21, 2018 6:44 am

Code: Select all

$newPath -->  Location[repository default, path /*scope name*/Teams/*project ID*/wiki/*pagename*]
 $templateLoc -->  Location[repository default, path /*scope name*/Teams/*project ID*/wiki/*Document folder*/*document title*]
 


What I find interesting is that when I use "$page.fields.location.get", the format is different :

Code: Select all

$page.fields.location.get  -->  default:/*Scope folder*/Teams/*project ID*/.polarion/pages/spaces/*space name*/*page name*/page.xml


I hope in the real version of your page the #set command is not in a comment. :lol: Just kidding.

I now comment it otherwise I get the error (same with the other commented). But these are the ones I really want.

smarty
Posts: 50
Joined: Fri Jan 18, 2013 4:43 pm
Location: Germany / Frankfurt
Contact:

Re: Reuse document from a velocity script ?

Postby smarty » Thu Mar 22, 2018 11:53 am

Hello victorien

this post has a solution to duplicate a template document into another space using the Wiki API.
Although I am not sure to fully understand your goal - do you want to branch the source document with WI referenced to their source? - it may help.

Regards, Martin
My environment: Polarion ALM 2016 SR2 on Windows Server 2012,
Polarion-JIRA Connector to JIRA 7.x

victorien
Posts: 7
Joined: Wed Mar 14, 2018 1:41 pm

Re: Reuse document from a velocity script ?

Postby victorien » Fri Mar 23, 2018 12:21 pm

What I would like is a report page with date parameters and a dropdown to select a template(working now) and it will create a document based on the template with the specified date in the title.
Then I need a button or something to create a new document (a dupicate is ok) with the title I specify using variables. Destination project is fixed.
No links are needed between documents.

victorien
Posts: 7
Joined: Wed Mar 14, 2018 1:41 pm

Re: Reuse document from a velocity script ?

Postby victorien » Thu Mar 29, 2018 11:40 am

So I did try the duplicate function but it gives me path errors at first and once i fixed that, it gave me some kind of permission error :
There was an exception (see server log for details) Invocation of method 'duplicate' in class $IModuleManager_161791f02cb threw exception class com.polarion.platform.persistence.WrapperException : java.lang.UnsupportedOperationException: Modifications are prohibited in read only transaction.

smarty
Posts: 50
Joined: Fri Jan 18, 2013 4:43 pm
Location: Germany / Frankfurt
Contact:

Re: Reuse document from a velocity script ?

Postby smarty » Thu Mar 29, 2018 1:59 pm

Hello victorien,

please check this comment and following in the thread I mentioned before.
AFAIK any changes to data can only be done within a transaction, i.e.

Code: Select all

## a transaction must be opened:
$transactionService.beginTx()

## then create the new doc:
#set ($newDocument = $moduleManager.duplicate($templateDoc, $trackerProject, $targetSpaceLocation, ...)

## and finally close the transaction:
$transactionService.commitTx()


Regards, Martin
My environment: Polarion ALM 2016 SR2 on Windows Server 2012,
Polarion-JIRA Connector to JIRA 7.x


Return to “Polarion Application Lifecycle Management (ALM)”

Who is online

Users browsing this forum: No registered users and 10 guests