Export Salesforce Reports as CSV (Java) - java

I'm trying to automatise the exporting of Salesforce Reports as CSV's, so far I've managed to authenticate in the Salesforce API but I couldn't find any proper documentation on how to export the Salesforce Reports as CSV's or any other examples of doing it.
I've understood that there is a chance that could not be done, but you can still export it as a JSON and convert it to a CSV using a library, although I didn't find anything.

If you're authenticated (got session id back) you're almost there.
The hacky, not officially supported way is to send a GET request to the report export just like user would click a button. Check out How to download a report as a CSV directly from Salesforce Lightning? or Salesforce: Download Reports via URL in R examples (it's not Java but same principle). You'd have to send header that sets cookie with sid=sesionidgoeshere.
The more official way would be to use the reporting API

Related

How to send an automatic mail once file (one or multiple files) uploads into mysql database using jsp?

I am doing project using jsp in netbeans8.2, tomcat8, java, MySQL(xampp). I have done the coding till multiple file uploads. Now I want to send email to respective user mail id, once file uploads into MySQL database. I searched but on internet but I got for only one user mail id. I need for all users who will upload one or multiple files then immediately mail notification should be sent. Is there any tutorial or suggest me any tutorial(link) that I can refer to solve my problem??
It depends which framework you are using, there are multiple ways to achieve this.
In case you are using Spring Framework use this tutorial
https://www.baeldung.com/spring-email
https://www.javatpoint.com/spring-java-mail-tutorial
In case Plain Java
https://www.baeldung.com/spring-email
Happy to help further as and when needed.

How to export excel file in GWT?

My requirement is to export an excel from GWT application on click of export button. In my case There is no need to send data from client to server as I can directly obtain data from database(same data is being populated on the client that is being exported).
All I tried to send a RPC call from Client site . but I am not able to figure out how to export excel on receiving the RPC call at server site.
This is certainly possilbe 100% client side.
You can use an Excel JavaScript builder like https://github.com/stephenliberty/excel-builder.js and call it from GWT with jsni or jsinterop.
Later you can save the file by
For Internet explorer for example filesaver.js https://github.com/eligrey/FileSaver.js/ in the same way.
For other browsers using HTML5 downloadv (using FileDownloadBuilder.createFileDownload().generateTextDownloadLink()) from https://github.com/akjava/html5gwt
Note for the generating an Excem file you could also just create an html file with table tags and save it as .xls, it with filesaver.js.
I use the html solution and filesaver.js/html5 download in my project and this works without a problem, and without the need for any serverside code, or any plugin on the client. 100% HTML5/javascript.
There is no way generating a excel file on the client site with native GWT without adding a third party product. (see knarf answer below)
I personally prefer this solution:
open an new window on the client
use a url, that triggers a servlet on the server
let the server generate the excel file
save the newly generated file inside the webspace
return the url to the excel file to the client
This works for me.

How to Upload Image/Videos to Google Cloud Storage Using Java

I'm developing a server in Java which will provide URLs for images that clients uploaded. Basically the Android/iOS will send some kind of data (I still don't know which data would be sent for image and videos) then I'll upload those images/videos to Google Storage and provide URLs which the users (Android/iOS) will be able to stream.
I've just started with Google Storage and I can't find any example of how to upload an image using Java. All examples I found or are deprecated or it's in PHP or it's not clean.
I think I will need to use the JSON client Library but I can't find a good example for this library either.
Please any help will be VERY appreciate.
Based on your answer to my comment above, you could use the method I described in the following Stack Overflow response in order to save the file from your servlet to the Datastore and return the URL:
How to return a file with Google Cloud Endpoints?.
The two differences between your requirements and the method described in this response are:
The way the file is created: in your case through a file input stream, as you mentionned
The way you return the URL: since you will probably not use Google
Endpoints (because of file input stream) you don't need to return the URL in a string wrapper.

Google Identity Toolkit GAE user activation

I'm trying to set up Google Identity Toolkit (GIT) on a test webpage on localhost. I completed all the necessary steps on Google Console and downloaded the Java sample from the tutorial, and it's working.
Now what I want to do is disable self-registration (which I couln't disable), create users on GIT, send them an email link activation and set password for first time. I took a look at the API provided, but there's no way I can figure out how to use it.
I managed to create users and delete them with com.google.identitytoolkit classes like GitkitClient and GitkitUser, as seen in the example, but I cannot get the email activation and password reset working.
If anybody can point me to some good examples on how to do that, I'll really appreciate it.

window.open(...) with authorization

We have a GWT app that accesses REST API. REST API is meant for other uses too, and is secured using JAAS basic authorization. GWT app uses RestyGWT dispatcher and filter, as shown here, to add Authorization: Basic to header, and, so far, this works fine.
However, our app also allows users to work with files, either download generated (such as pdf reports) or upload/download any kind files. We used servlets on server side for upload and download of these files, and Window.open() call to receive them in GWT. Without JAAS this worked fine.
Now I'm trying to secure that part of the API, too. Window.open(...) won't work because it doesn't allow for adding headers.
Is there some kind of workaround for this?
I've tried RequestBuilder, and I receive correct response, that contains the requested file. However, I'm not able to initiate the download of the file. Is it maybe possible to encode this (AJAX) response as data:... URL and display it using, for example, iframe, which will, in turn, initiate file download?
I always handled downloads by producing regular links. Wouldn't it be ok to check if a user session is valid and only then deliver the file?
By the way you could obtain an opened window's document and populate it:
public static native Document open(String url, String name, String features)/*-{
return $wnd.open(url, name, features).document;
}-*/;

Categories

Resources