This is a migrated thread and some comments may be shown as answers.

Data Synchronization in Offline Mode

6 Answers 121 Views
JavaScript SDK
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
ZORN
Top achievements
Rank 1
ZORN asked on 24 Jul 2015, 09:34 AM

Hi,

I activated the offlineStorage mode for my Everlive. 

offlineStorage: {
 conflicts: {
    strategy: Everlive.Constants.ConflictResolutionStrategy.ServerWins
 }
}

 In the app I only read the data with the DataSource and outputs it to a ListView

My problem is, if I change the permission and deny reading for one data resource on the Telerik Platform Backend and run in the code something like this:

if(app.isOnline) {

el.online();
el.sync();​

}

Then nothing happens, but I thought the SDK will check if there are any changes and request the new list or remove the denied resource from my offlineStorage.

 So my question is simple, how can I remove in the offlineStorage the resource the user have no more access to it?

 

Cheers,

Mustafa

 

6 Answers, 1 is accepted

Sort by
0
Anton Dobrev
Telerik team
answered on 29 Jul 2015, 10:31 AM
Hi Mustafa,

Thank you for posting to the Telerik Developer Forums.

Allow me to explain better the workflow in greater details.

1. App Setup

The permissions on the server are restricted and the app has some previously saved items in the offline storage. At a given moment of time the app becomes online and the synchronization is invoked.

2. App Action 

The app tries to sync the items to the server (either read or write or both). Because the current user making the request has no permissions - the server returns an error with message that states that you do not have permissions to access the content type ("Access denied"). This error is interpreted in the SDK as synchronization error.

3. Solution

The answer to your question is:
 - Handle the synchronization error in your code - el.on('syncEnd', function(syncInfo) {...});
 - Remove all saved data locally using the purge method
 - Make sure that you are using the latest JS SDK version - 1.4.1

The relevant articles in the documentation are:
 
 - Data Synchronization in Offline Mode
 - Managing Offline Storage (see the Purging Offline Data section)

Let me know if this answers your question.

Regards,
Anton Dobrev
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
0
ZORN
Top achievements
Rank 1
answered on 30 Jul 2015, 09:20 PM

Hi Anton,

I know that the app has some previously saved items in the offline storage and at this moment when the app goes online and the sync runs ... YEAH then I am lost also with the documentation. 

 

1. Read the ​resources of a Content Type, all is running well. Everlive creates the localStorage Item and so on ...
2. When I deny the read for ONE resource of that Content Type in the backend and make again a request (dataSource.read()) I get in the request result the JSON without the denied resource
3. set everlive to online
4. call everlive.sync() -> network monitor do not show me a request to the server, if I am in online mode the denied resource is not in my data, after switching to offline mode, the resource is available. And the syncEnd event is not giving me any sync error :(

5. I tried the following: 
everlive.online();
everlive.purge("Content Type"); //removes the localStorage item
everlive.sync(); //no request and no sync error on syncEnd event
myDataSource.read() //everlive creates again the localStorage item of the Content Type with the denied resource 
although this resource was not in the request result

 

I use Everlive Version 1.4.1

 

Best regards,
Mustafa

0
Anton Dobrev
Telerik team
answered on 04 Aug 2015, 03:48 PM
Hello Mustafa,

Thanks for getting back to us and for the provided details. We are investigating the behavior you encountered.

Below I will try to explain the expected behavior as to the steps in your workflow and ask you for some further details.

1. Read the resources of a Content Type, all is running well. Everlive creates the localStorage Item and so on...

Yes, at this point the items are read from the online connection and you are then going in offline mode.

2. When I deny the read for ONE resource of that Content Type in the backend and make again a request (dataSource.read()) I get in the request result the JSON without the denied resource

My understanding is that you are applying an item – level permission to just a single item – is that correct? Can you specify how do you deny the READ operation for an item in a content type?

3. set everlive to online

Switch to online after working for a while in offline mode.

4. call everlive.sync() -> network monitor do not show me a request to the server, if I am in online mode the denied resource is not in my data, after switching to offline mode, the resource is available. And the syncEnd event is not giving me any sync error :(

Perhaps there are no changes in the offline files that is why the sync invocation does not make an actual request to the server.Could you elaborate?

5. I tried the following: 
everlive.online();
everlive.purge("Content Type"); //removes the localStorage item
everlive.sync(); //no request and no sync error on syncEnd event
myDataSource.read() //everlive creates again the localStorage item of the Content Type with the denied resource although this resource was not in the request result

Your application logic seems correct. However, I am assuming that the data source instance was still alive in the simulator/device. This means that the UI is bound to the data even if it is not available.

 Can you confirm that:

-          You reloaded forcefully the simulator after the changes in the code were made?

-          The denied resource was in the localStorage

-          The user making the request cannot read it?

-          The issue is persisting if you upgrade to version 1.5.1 of the JavaScript SDK (http://docs.telerik.com/platform/backend-services/development/javascript-sdk/introduction)


We will appreciate if you could provide a simple client project that represents the issue and explain the setup of your backend project (permissions and content types).

On a side note, could you specify which sections of the documentation are not clear?

I look forward to your reply.  

 
Regards,

Anton Dobrev
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
0
ZORN
Top achievements
Rank 1
answered on 04 Aug 2015, 07:43 PM

My understanding is that you are applying an item – level permission to just a single item – is that correct? Can you specify how do you deny the READ operation for an item in a content type?

Yes, thats correct. I simply do it in the Telerik Backend: Select Content Type -> Select one specific item -> Remove all permissions

--- 

Switch to online after working for a while in offline mode.

Yes, because our apps is most of offline. 

--- 

Perhaps there are no changes in the offline files that is why the sync invocation does not make an actual request to the server.Could you elaborate?

Yes thats right, thats the reason i manuell switch to online mode (if network connection available) then I read the datasource and get in the result the items without the denied one. So I thought if I run then the sync it will automatically update my localStorage of that Content Type.

---

Your application logic seems correct. However, I am assuming that the data source instance was still alive in the simulator/device. This means that the UI is bound to the data even if it is not available.

Yeah, but after the read in online mode the datasource do not have my denied resource in the list. So the bounded data is then correct. 

---
Can you confirm that:
-         You reloaded forcefully the simulator after the changes in the code were made?
Yes
-         The denied resource was in the localStorage
Yes, but only if I purge the Content Type and reload the simulator right after that then the result in the localStorage is correct and the denied resource is no more there.
-         The user making the request cannot read it?
NO, this denied resource is also not in the result of the request. 
-         The issue is persisting if you upgrade to version 1.5.1 of the JavaScript SDK (http://docs.telerik.com/platform/backend-services/development/javascript-sdk/introduction)
Yes the issue is persisting also with version 1.5.1. I tested it right after your reply. 

 

---

We will appreciate if you could provide a simple client project that represents the issue and explain the setup of your backend project (permissions and content types). 

Download: https://www.dropbox.com/s/8sy6k8ksofixrjx/index.html?dl=1

--- 

On a side note, could you specify which sections of the documentation are not clear? 
I think the sync logic should be described better.

0
Anton Dobrev
Telerik team
answered on 07 Aug 2015, 12:21 PM
Hi Mustafa,

Thanks for providing the code sample. We examined it and reproduced the behavior you reported. It is connected to the purge("TypeName") method not behaving correctly. For a temporary workaround you can replace this with the usage of the purgeAll() method.

For example:
everlive.online(true);
alert("Everlive is now in online mode");
 
everlive.offlineStorage.purgeAll();
alert("everlive.offlineStorage.purge('Presentations') executed");
 
dataSource.read().done(function (result) {
// other implementation

This should fix the behavior on your side. We will address the issue with the next release of our JavaScript SDK and will update this thread when it is released.

Let me know if this helps and if you have further questions.

As a small token of gratitude for your cooperation on the matter we updated your Telerik Points.

Regards,
Anton Dobrev
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
0
Tsvetomir Nedyalkov
Telerik team
answered on 14 Aug 2015, 12:57 PM
Hi Mustafa,

The behaviour of purge("TypeName") method is fixed in the newly released version (1.5.4) of the sdk.

Please, excuse us for the caused inconvenience.

Regards,
Tsvetomir Nedyalkov
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
Tags
JavaScript SDK
Asked by
ZORN
Top achievements
Rank 1
Answers by
Anton Dobrev
Telerik team
ZORN
Top achievements
Rank 1
Tsvetomir Nedyalkov
Telerik team
Share this question
or