Home Analytics Developing analytics applications
The community of Analytics developers are invited to follow and participate in the developer network.
OpenText technical experts collaborate with supported customers and partners in the Magellan product area.

scripted datasource cannot access public methods

<p style="font-size:15px;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;color:rgb(36,39,41);">I´m trying to set up a scripted Datasource using pojos from my app (java 1.8). I embedded a reportengine (4.4.0) in my app via maven and created a report with a scripted datasourse. The pojos can be seen by the report.</p>
<pre class="_prettyXprint">
bookSrv = Packages.de.me.service.ReportDataService;
</pre>
<p><span style="color:rgb(36,39,41);font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;font-size:15px;">works.</span></p>
<p style="font-size:15px;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;color:rgb(36,39,41);">I can access static methods of my object, but whatever i try, accessing public methods or fields results in an exception.</p>
<p style="font-size:15px;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;color:rgb(36,39,41);">So</p>
<pre class="_prettyXprint">
books = bookSrv.books;
</pre>
<p><span style="color:rgb(36,39,41);font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;font-size:15px;">gives</span></p>
<p style="font-size:15px;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;color:rgb(36,39,41);">org.mozilla.javascript.EvaluatorException: Java class "de.me.service.ReportDataService" has no public instance field or method named "books". (/report/data-sets/script-data-set[@id=&quot;5"]/method[@name=&quot;open"]#11) or</p>
<pre class="_prettyXprint">
books = bookSrv.showMyBooks('Peter');
</pre>
<p><span style="color:rgb(36,39,41);font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;font-size:15px;">gives</span></p>
<p style="font-size:15px;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;color:rgb(36,39,41);">org.mozilla.javascript.EvaluatorException: Java class "de.my.service.ReportDataService" has no public instance field or method named "showMyBooks". (/report/data-sets/script-data-set[@id=&quot;5"]/method[@name=&quot;open"]#11)</p>
<p style="font-size:15px;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;color:rgb(36,39,41);">But:</p>
<pre class="_prettyXprint">
books = Packages.me.tdesk.service.ReportDataService.myBooksStatic('Peter');
</pre>
<p><span style="color:rgb(36,39,41);font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;font-size:15px;">works like expected. (Simply a static wrapper around my method)</span></p>
<p style="font-size:15px;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;color:rgb(36,39,41);">here is my java class:</p>
<div>
<pre class="_prettyXprint">
package de.me.service;
import de.me.model.dto.BookDto;
import java.util.ArrayList;
import java.util.List;


public class ReportDataService {

    public ReportDataService() {
        books = showMyBooks("Peter");
        System.out.println("ReportDataService.init()");
    }

    private List<BookDto> books;

    public List<BookDto> getBooks() {
        return books;
    }

    public void setBooks(List<BookDto> books) {
        this.books = books;
    }

    public List<BookDto> showMyBooks(String commodity){
        BookDto dto = new BookDto(12l, "otto", "My", 12l);
        List<BookDto> books = new ArrayList<>();
        books.add(dto);
        dto = new BookDto(122l, "paul", "My", 122l);
        books.add(dto);
        return books;
    }

    public static List<BookDto> myBooksStatic(String commodity){
        ReportDataService rep = new ReportDataService();
        return rep.showMyBooks(commodity);
    }
}
</pre>
</div>
<p style="font-size:15px;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;color:rgb(36,39,41);">Many thanks,</p>
<p style="font-size:15px;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;color:rgb(36,39,41);">Uli</p>

Comments

Sign In or Register to comment.