Is there any easy way to import exported report zip files from the command line? I have multiple client databases each running their own version of my Cuba app. Whenever I create a new report, I have to create it in one of the client’s databases, export it, then manually log in to all the others and import it.
I would like to automate this process. I can loop through all the client databases easily. Is there a command that would connect to a database and install a report zip file? Is this even possible?
Hi,
There is no such tool to import report from the command line. Importing a report requires the application context to be fully started.
However you can try to import reports by executing SQL commands in the database.
Report structure is stored in two tables: REPORT_REPORT and REPORT_TEMPLATE.
So in order to insert new report to the database, you will need to insert two rows, to each of those tables, with exact same content as on the source server.
OK, thanks. I guess I can try to copy the Import code you already use. There wouldn’t happen to be a REST interface to it, would there? Maybe that would be a simple solution?
I can authorize with the server and get an access token. I also have a zip file generated from your Report Export function.
Is it possible to use curl or some other command to upload the file to the service? The only example in your docs is using javascript and the file upload component.
I have tried this:
curl -X POST 'http://localhost:8080/rade/rest/v2/services/rade_ImportReportService' -H 'Authorization: Bearer <token>' --data-binary @OfferListing.zip
I get this:
Request method 'POST'; not supported
Description: The method received in the request-line is known by the origin server but not supported by the target resource.
I got a little farther. I discovered that my URL was missing the method to run in the service:
curl -X POST 'http://localhost:8080/rade/rest/v2/services/rade_ImportReportService/importReports' -H 'Authorization: Bearer <token>' --data-binary @OfferListing.zip
The “/importReports” was missing from my previous URL. Now I get the following reply:
{"error":"Server error","details":""}
Not very informative. However, the app.log contains:
2021-05-21 15:06:56.271 ERROR [http-nio-8080-exec-18/rade/admin] com.haulmont.addon.restapi.api.controllers.RestControllerExceptionHandler - Exception in REST controller
com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 646 path $
So, the problem seems to be that I need to pass some kind of JSON to the service. How do I know what that should be? And how do I put a ZIP file in it?
I think I finally got it! There are a bunch of moving parts. For this example, my service is named rade_importReportService with a method named importReport and a parameter named zipBytes.
encode client:secret as listed in web-app.properties
Use that to get a token
create a JSON stream with the zip file I want to upload encoded with base64. Feed that to the method
Of course, the JSON, service name and method name are specific to my particular need. You need to fill in <app URL>, <USERNAME>, <PASSWORD>, <CLIENT>, <SECRET> as defined in your setup.
The last thing I needed to do was to go into the Security system, create a role with REST-API access along with access to the entities required and assign that to my <USERNAME> user.
This presumes you have python3 installed on your system. Feel free to use any method you like to parse the json for the access_token field.
If anybody has an easier way to do this, please let me know. Otherwise, I hope somebody else finds this useful someday.