1

Generate report in JAVA

Topic: Generate report in JAVA

We are creating a service that will send a report to the users using the JAVA SDK.
However I'm having trouble figuring out what to do exactly.

I'd like to generate a ride report for a user, and I understand how to get all the users under our account, but what now?

I realise I need to receive a report template using the searchItems method, so I'm doing this like this:

SearchSpec reportSearchSpec = new SearchSpec();
// get report templates
// Set items type to search avl_units
reportSearchSpec.setItemsType(Item.ItemType.avl_resource);

// Set sort type by units name
reportSearchSpec.setSortType("sys_name");

reportSearchSpec.setPropName("avl_resource");
reportSearchSpec.setPropValueMask("*");

session.searchItems(reportSearchSpec, 1, Resource.dataFlag.reports.getValue() , 0,
                                            Integer.MAX_VALUE, new SearchResponseHandler() {
                                                @Override
                                                public void onSuccessSearch(Item... reportTemplates) {
                                                    super.onSuccessSearch(reportTemplates);
                                                    
                                                    
                                                

                                                }

                                                @Override
                                                public void onFailure(int errorCode, Throwable throwableError) {
                                                    super.onFailure(errorCode, throwableError);
                                                    // search item failed, print error
                                                    System.out.println("error  " + Errors.getErrorText(errorCode));

                                                }
                                            });

This gives a lot of nullpointer exceptions for some reason.
Does anybody have an example of how to generate a report using the JAVA SDK?

I tried using the execReport function of the Report class but I have no idea what to put in the constructor and method parameters.

Thanks in advance!

2

Generate report in JAVA

Re: Generate report in JAVA

Dennis wrote:

I realise I need to receive a report template using the searchItems method

This is the right way, just pay attention to the parameters:

        SearchSpec searchSpec=new SearchSpec();
        //Set items type to search avl_resource
        searchSpec.setItemsType(Item.ItemType.avl_resource);
        //Set property name to search
        searchSpec.setPropName("sys_name");
        //Set property value mask to search all resources
        searchSpec.setPropValueMask("*");
        //Set sort type by resource name
        searchSpec.setSortType("sys_name");

You have found the correct dataFlag, but you need to add it to the base item's dataFlag

        session.searchItems(searchSpec, 1, Item.dataFlag.base.getValue() | Resource.dataFlag.reports.getValue(), 0, Integer.MAX_VALUE, new SearchResponseHandler());

And after in the onSuccessSearch you will receive all your resources. To get report templates you need to call resource.getReportPlugin()

            @Override
            public void onSuccessSearch(Item... items) {
                super.onSuccessSearch(items);
                // Search succeed
                System.out.println("Search items is successful");
                if (items!=null && items.length>0) {
                    for (Item item : items){
                        if (item instanceof Resource)
                           System.out.println(String.format("\t%s",((Resource)item).getReportPlugin().getProperties().toString()));
                    }
               }
            }

To execute the report and get tables and other report's data you can look at Remote API sample.
Unfortunately Java SDK does not contain all of the methods for easy work with reports, but sources is available on GitHub, and you can modify it for your purposes, or make something like JavaScript SDK ReportResult (example of usage).

Mobile Development
Gurtam
3

Generate report in JAVA

Re: Generate report in JAVA

Thank you, this helps a lot!

4

Generate report in JAVA

Re: Generate report in JAVA

One more question, I can't find the get_result_rows
https://sdk.wialon.com/wiki/en/sidebar/ … esult_rows
in the SDK. Is this not available or is it not inside the report object?

5

Generate report in JAVA

Re: Generate report in JAVA

Dennis it's not available at Java SDK, but you can implement it by yourself, and make a pull request on GitHub wink

Mobile Development
Gurtam
6

Generate report in JAVA

Re: Generate report in JAVA

Ok, no problem, but our programmer can't create a pull request,(button is grayed out) do we need to be authorized?

7

Generate report in JAVA

Re: Generate report in JAVA

Dennis I think yes. You can find more information at GitHub Help.

Mobile Development
Gurtam
8

Generate report in JAVA

(edited by Dennis 21/03/2017 23:13:15)

Re: Generate report in JAVA

I have one more question, the report templates I receive from get_result_rows are all grouped by date, is it possible to get the report details like in the webportal when we click detailed?
Or do we have to create a new report for that?

9

Generate report in JAVA

Re: Generate report in JAVA

Dennis, you can use report/select_result_rows request with this parameters:
to get all collapsed rows: params={"tableIndex":0,"config":{"type":"range","data":{"from":0,"to":0,"level":0}}}
to get all subrows of some row(s): params={"tableIndex":0,"config":{"type":"row","data":{"rows":["0"],"level":0}}}

Solutions Department
Gurtam
10

Generate report in JAVA

Re: Generate report in JAVA

This topic helped a lot. Very useful for me. Thank you.

11

Generate report in JAVA

Re: Generate report in JAVA

I agree with supriyala. I got valuable information here..Thanks for the share!