We want to receive notifications from google when we do anychange(Add,Edit OR Delete) on google drive folder for these purpose we have integrated google watch api in our spring boot application.
code snippet :
public Channel setUpWatch() throws IOException, GeneralSecurityException {
Channel channel = new Channel();
channel.setAddress("https://somedomain.com/notifications");
channel.setType("web_hook");
channel.setId(UUID.randomUUID().toString());
channel.setKind("api#channel");
StartPageToken pageToken =
driveServiceProvider.getDriveService().changes().getStartPageToken().execute();
System.out.println(pageToken.getStartPageToken());
Channel changesChannel = driveServiceProvider.getDriveService().changes()
.watch(pageToken.getStartPageToken(), channel).execute();
System.out.println(changesChannel.getExpiration());return
return changesChannel;
}
After running this code we are getting 200 in response, but we are not receiving any push notification from google when we do any operation in google drive. We are getting empty changeList
We are checking this code on local with no domain registration
Is there any other way to get the edit, add or deleted files list from google drive?
We do not want any notification on any domain or address. Whenever we trigger the api and if any file(s) is changed, we want that file(s) details like drive url, file name.
It seems that you are passing the current token to the changeList api.
This will return no results.
Actually, the solution is to find the changes since last token till the current token using a loop. So, store the last token somewhere and iterate till last token to current and pass the iterative value to chageList api to get the files changed.
Hope that works.
Push-notification channel will not send you requests for files inside a folder inside of a folder, just because you set up a watch on the folder itself.
To request push notifications, you need to set up a notification channel for each resource you want to watch.
If you preform a watch on a folder you will get a notification if for example the name of the folder is changed.
If you want to know if there are changes to a file then you will need to set up the watch for each of the files.
Related
I have spring boot application with basic REST API.
My question is what shall we use to download some bulk data? What is preferable way how to download bulk data without memory leak? Let's suppose we have 10 million records.
Here are some approaches but not sure:
download with PipedInputStream when data are written with PipedOutputStream in separated thread. Is it fine or it is not good choice?
download with ByteArrayOutputStream when data are written into temp file in separated thread and after finish it is ready to download. We can mark this operation with some flags for end user eg. DOWNLOAD_ACTIVE, DOWNLOAD_DONE. The user is just initiating download with result flag DOWNLOAD_ACTIVE and trying to ping server for response flag DOWNLOAD_DONE. When it is done then the user is going to send request to download data.
Summary 2)
1. initiate request to download data - ACTIVE state
2. ping server and server returns current state - ACTIVE or DONE
3. if final state is DONE then user initiate final request to download data
Thanks
You can use the second approach. Which can prepare data in the background and once it's ready you can download it.
Send a request to prepare data. The server responds with a UUID.
Server starts preparing files in the background. The server has a Map that has the key with a new UUID and value as status ACTIVE.
Client saved UUID and checks the server after a certain interval by passing the UUID.
Once the server finishes the task it will update the Map for the given UUID value as status DONE.
As the status is DONE next request will provide the status DONE and UI and send another request to download the file.
The above approach will only work if you don't refresh the page. As page refresh will clear the UUID and you have to proceed again.
To achieve this after refresh/cross-logins then you need to use a database table instead of Map. Store the username along with other information and inform the user once it's ready.
I'm reading and processing emails received from IMAP using JODD mail library. API is very nice but I struggle with one logical issue. I'm using code as following:
EmailFilter filter= new EmailFilter();
filter.flag(Flags.Flag.SEEN, false);
session.receiveEmailAndMarkSeen(filter);
By calling session.receiveEmailAndMarkSeen I receive all unread emails and these are marked as read immediately. Now when processing fails in my code for any reason, and I try to receive emails again all these unprocessed emails are marked as read already and not downloaded anymore. I would rather download emails and mark them as read individualy as beeing processed successfully.
So I tried to receive them with session.receiveEmail but not sure how to mark them as read when processed? Any hint how to do it? I can see that email object has 'flag' property I can set but not sure how to send this information back to server.
To summarize possible solutions:
Re-fetch email with Seen flag. The downside is that email is fetched again.
What you wrote - using a Session and a Folder.
Finally - starting from the next version of Jodd, you will have the method updateEmailFlags that would give you options to just call it:
mymail.flags(newFlags);
ReceiveMailSession.updateEmailFlags(mymail);
The result would be the same.
SOLVED: I'm creating connection manualy using common JAVA mail classes - Session and Store.
Session sess = Session.getDefaultInstance(props, null);
Store store = sess.getStore("imaps");
store.connect("imapServerHost", "username","password");
... then I create folder object (points to Inbox)
Folder folder = store.getFolder(this.imapFolder);
folder.open(Folder.READ_WRITE);
... then I receive emails using session and store
ReceiveMailSession session=new ReceiveMailSession(sess, store);
... after email processed, I send back SEEN=true message using folder object.
Flags f=new Flags();
f.add(Flags.Flag.SEEN);
folder.setFlags(new int[] {email.getMessageNumber()}, f,true);
I'm using azure-notificationhubs-java-backend to send notifications to Azure hub. I have Azure tags created per application user. Business require me to send notification to multiple users (this part is achieved), and report back the execution status, i.e. whom Azure was able to deliver the notification, and who all were missed (so that other communication can be made with those users). We've this scenario that not all users are yet registered with Azure. Below is the call I am making:
SyncCallback<NotificationOutcome> callback = new SyncCallback<>();
notificationHub.sendNotificationAsync(templateNotification, recipientTags, callback);
NotificationOutcome outcome = callback.getResult();
// outcome has just the notificationId, and trackingId
Any suggestion how can I get success and failed tags. Or there's some other call I can make using the notificationId or trackingId to meet the desired. Thanks!
You can get this data from per message telemetry. Please see below blog for more information.
https://azure.microsoft.com/en-us/blog/retrieve-platform-notification-system-error-details-with-azure-notification-hubs/
I am programming a mobile app using Cordova. I am implementing the push notifications using Push Plugin. The app is meant to run on all platforms but right now I am testing on Android and Windows.
In a particular javascript file I am saving a value call it 'category' in the localstorage:
localStorage.setItem("category", JSON.stringify(categoryarray));
Now when sending a push notification, the category is essential to decide whether to show the notification or not. If a user is subscribed to that particular category, then, the notification is to be shown, otherwise not. For this I simply create a condition and check whether the user has subscribed to the category included in the notification (but this is not really relevant to the point of the question). When the app is running this condition can be handled in javascript. When the app is not running, this is handled in java code:
else {
extras.putBoolean("foreground", false);
// Send a notification if there is a message
if (extras.getString("message") != null && extras.getString("message").length() != 0) {
createNotification(context, extras);
}
}
Now I want to get the value from the local storage at that instance that the notification is being pushed when the app is not running (and be able to check whether the notification should be shown or not).
I came into this link: Android Service reads localStorage?
But it seems to be meant for Android native code (reference to the webview). Apart from that I haven't really understood how it works and furthermore if it is applicable for my problem.
What do you suggest? How can I do it?
Edit: I didn't initially realise that the Push plugin java code won't be compiled with the Cordova app. So editing the code that is retrievable from the Cordova directory is in reality useless. Unless, someone can still suggest something, I know that this is an unanswerable question. Will have to re-attempt to create an API for this purpose and handle who to receive which notification at server side! (The reason why I resorted to this method was because I wasn't managing to create an API for notification purposes)
I didn't initially realise that the Push plugin java code won't be compiled with the Cordova app. So editing the code that is retrievable from the Cordova directory is in reality useless. Unless, someone can still suggest something, I know that this is an unanswerable question.
This isn't true, Cordova plugin code is compiled when you compile your Cordova app. All Cordova plugin's provide native source code that gets compiled into the app when you run cordova build (or cordova run <platform>).
If you wanted to solve this completely on the client side (rather than managing the categories that a user is subscribed to on the backend and only sending a notification if the user is subscribed to a category), you could extend the PushPlugin to manage subscriptions to categories.
As a rough sketch:
In PushNotification.js, add a method to subscribe to a channel:
PushNotification.prototype.subscribeToChannel(successCallback, errorCallback, channel) {
cordova.exec(successCallback, errorCallback, "PushPlugin", "subscribeToChannel", [{channel: channel}]);
}
In PushPlugin.java catch the subscribeToChannel action in the execute function:
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) {
...
if ("subscribeToChannel".equals(action)) {
//get the attached data
JSONObject jo = data.getJSONObject(0);
String channel = (String) jo.get("channel");
addChannelToSubscriptions(channel);
}
...
}
public void addChannelToSubscriptions(String channel) {
//store as a list in a sharedpreferences list
}
Then when a notification is received, you can check if the channel is a channel that has been subscribed to.
// Send a notification if subscribed to the channel
if (extras.getString("channel") != null && isSubscribedTo(extras.getString("channel"))) {
createNotification(context, extras);
}
public boolean isSubscribedTo(String channel) {
//see if the channel is in the shared preferences.
}
Personally, I think it'd be easier to manage subscriptions on the backend as to manage it in the app, you'd have to implement this logic for each platform you support. It would be easier to just add a webservice call in your Javascript. As a further alternative, if you don't want to handle the subscription logic on your backend, you could look at a service like Parse where the concept of subscribing to channels is built into the service.
I'm new to server side.
I'm creating a database app for my company that stores links to all our marketing videos. Each entry is a url(to video), description, industry etc.
I already have the front end somewhat set up in HTML/JavaScript. Using a local XML source file, it populates a list with video names, and has text fields for all props of the video item.
Here's my question:
How do I handle updating my view when I send the form data (new entry) to the back end?
Should I insert a new entry based on local data?
Should I wait for the response from the server, and if success then update view based on local data?
Or, same as above, but update view based on back end data?
The goal is to make sure my view always reflects the state of data on the back end.
(Back end is Java / Google App Engine)
When using AJAX:
There is a callback function included in it, which triggers asynchronously when the response of the request comes back from the server.
In this function you can call your page update functions to execute on the page updating processes.