How to integrate own java code in velocity reports

Harald Hotz-Behofsits
edited September 2016 in
In case you need a query or some special logic in velocity it would be fine to have the ability to add that easily in Java.

In velocity it is possible to access all logic being accessible in beans and some objects that are handed over by the caller.

To integrate own logic, it must get accessible in a bean.

To achieve that the contour-service-helper.xml can be patched the following way, insert:

<bean id="frequentisJamaUtils" class="com.jamasoftware.contour.plugin.jama.FrequentisJamaUtils">
</bean>

Where FrequentisJamaUtils is the java class, we have placed that in the plugin package.

In velocity you must add the following:
#set($fju = $applicationContext.getBean("frequentisJamaUtils"))

A call would look like the following:
#set($reviews = $fju.getReviewsForGlobalId($vDoc.document.globalId))

Here a query is called providing all reviews also reviews done in other projects on synched items.

The query looks like:

public List<Review> getReviewsForGlobalId( final String globalId )   {

      @SuppressWarnings("unchecked")
      final List<Review> reviews =
            this.getSession()
                  .createQuery(
                        "select rw from Review rw where rw.id in (select rev.review.id from Revision rev inner join rev.revisionItems ri where ri.version.originDocument.id in (select doc.id from Document doc where doc.globalId = :globalId))" )
                  .setParameter( "globalId", globalId ).list();
      return reviews;
   }


In case you make your own trials, don't forget the "@Autowired" at the class declaration.

Harald

Comments

  • [Deleted User]
    edited June 2016
    Thanks for sharing this, Harald. You are full of surprises.
  • [Deleted User]
    edited September 2016
    Hi Harald, this is so impressive and over my head I cannot even say I "like" it. How come in the Community there is no option for clicking on "wow?" :-) I will save this in the back of my head. If I ever need to do this, I know whom to beg and bribe :-) swoo
  • [Deleted User]
    [Deleted User] Product Team
    edited March 2020
    Just a note that with Jama Connect 8.49 this will no longer be possible.