{"action":"created","issue":{"url":"https://api.github.com/repos/couchbase/couchbase-lite-android/issues/602","labels_url":"https://api.github.com/repos/couchbase/couchbase-lite-android/issues/602/labels{/name}","comments_url":"https://api.github.com/repos/couchbase/couchbase-lite-android/issues/602/comments","events_url":"https://api.github.com/repos/couchbase/couchbase-lite-android/issues/602/events","html_url":"https://github.com/couchbase/couchbase-lite-android/issues/602","id":73298596,"number":602,"title":"Merge Document Conflicts and notification/db change callback details(Offline Mode).","user":{"login":"NitzDKoder","id":1461456,"avatar_url":"https://avatars.githubusercontent.com/u/1461456?v=3","gravatar_id":"","url":"https://api.github.com/users/NitzDKoder","html_url":"https://github.com/NitzDKoder","followers_url":"https://api.github.com/users/NitzDKoder/followers","following_url":"https://api.github.com/users/NitzDKoder/following{/other_user}","gists_url":"https://api.github.com/users/NitzDKoder/gists{/gist_id}","starred_url":"https://api.github.com/users/NitzDKoder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NitzDKoder/subscriptions","organizations_url":"https://api.github.com/users/NitzDKoder/orgs","repos_url":"https://api.github.com/users/NitzDKoder/repos","events_url":"https://api.github.com/users/NitzDKoder/events{/privacy}","received_events_url":"https://api.github.com/users/NitzDKoder/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/couchbase/couchbase-lite-android/labels/waffle:ready","name":"waffle:ready","color":"ededed"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-05-05T12:09:25Z","updated_at":"2015-05-28T21:18:13Z","closed_at":null,"body":"Hi Folks,\r\n\r\nhttp://developer.couchbase.com/mobile/develop/guides/couchbase-lite/native-api/document/index.html#Understanding Conflicts\r\n\r\nWhen client is offline and their were changes made at client and server on a document, now both has same _rev.\r\n\r\nAfter i come online i start  push and pull replication , later get database change callback.\r\n\r\nFollowed this documentation and tried to merge the conflicts and save as below after i get database change callback .\r\n\r\n\r\n\tprivate void mergeRevisonUpdated(DocumentChange change){\r\n\t\r\n\t\t\r\n\t\tboolean isConflict = change.isConflict();\r\n\t\tboolean isCurrentRev = change.isCurrentRevision(); // for checking addded revision and winning revision are identical\r\n\t\tif(isConflict){\r\n\t\t\ttry{\r\n\t\t\t\tDocument document = database.getDocument(change.getDocumentId());\r\n\t\t\t\tList <SavedRevision> revList = document.getConflictingRevisions();\r\n\t\t\t //server revision is winning revision\r\n\t\t\t\t\t\r\n\t\t\t\t\tSavedRevision serverRevision = revList.get(0);\r\n\t\t\t\t\tSavedRevision clientRevision = revList.get(1);\r\n\t\t\t\t\t\r\n\t\t\t\t\tSavedRevision updatedRev = document.createRevision().save();\r\n\t\t\t\t\t\r\n\t\t\t\t\t\r\n\t\t\t\t\tfinal Map<String, Object> serverDocMap = serverRevision.getProperties();\r\n\t\t\t\t\tfinal Map<String, Object> clientDocMap = clientRevision.getProperties();\r\n\t\t\t\t\t.\r\n\t\t\t\t\tMap<String, Object> properties = updatedRev.getUserProperties();\r\n\t\t\t\t\tif(serverDocMap.get(\"doc_type\").equals(\"item\")){\r\n\t\t\t\t\t\tproperties.put(\"channels\", userChannel);\r\n\t\t\t\t\t\tproperties.put(\"itemName\", clientDocMap.get(\"itemName\"));\r\n\t\t\t\t\t\tproperties.put(\"id\", serverDocMap.get(\"id\"));\r\n\t\t\t\t\t\tproperties.put(\"doc_type\",  serverDocMap.get(\"doc_type\"));\r\n\t\t\t\t\t\tproperties.put(\"itemvalue\", serverDocMap.get(\"value\"));\r\n\t\t\t\t\t\tproperties.put(\"_rev\", serverDocMap.get(\"_rev\"));\r\n\t\t\t\t\t}\r\n\t\t\t\t\tupdatedRev.createRevision(properties);//Client - Server Merge.\r\n\t\t\t\t\tSavedRevision finalRev = updatedRev.createRevision().save(true);\r\n\t\t\t\t\tclientRevision.deleteDocument();//Once merge delete the loser.\r\n\t\t\t\t\r\n\t\t\t}catch(CouchbaseLiteException e){\r\n\t\t\t\t// TODO Auto-generated catch block\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\nitemName i want client changed value , and itemvalue as server changed value.\r\n\r\n\r\nSomehow i end up with wrong data also get too many database change callback on this document with conflict true.\r\n\r\nWhen and where to make conflict management is not clearly mentions in the docs,a example will help me to proceed.\r\n\r\n\r\nThanks\r\nNithin\r\n"},"comment":{"url":"https://api.github.com/repos/couchbase/couchbase-lite-android/issues/comments/106603221","html_url":"https://github.com/couchbase/couchbase-lite-android/issues/602#issuecomment-106603221","issue_url":"https://api.github.com/repos/couchbase/couchbase-lite-android/issues/602","id":106603221,"user":{"login":"hideki","id":15889,"avatar_url":"https://avatars.githubusercontent.com/u/15889?v=3","gravatar_id":"","url":"https://api.github.com/users/hideki","html_url":"https://github.com/hideki","followers_url":"https://api.github.com/users/hideki/followers","following_url":"https://api.github.com/users/hideki/following{/other_user}","gists_url":"https://api.github.com/users/hideki/gists{/gist_id}","starred_url":"https://api.github.com/users/hideki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hideki/subscriptions","organizations_url":"https://api.github.com/users/hideki/orgs","repos_url":"https://api.github.com/users/hideki/repos","events_url":"https://api.github.com/users/hideki/events{/privacy}","received_events_url":"https://api.github.com/users/hideki/received_events","type":"User","site_admin":false},"created_at":"2015-05-28T21:18:13Z","updated_at":"2015-05-28T21:18:13Z","body":"Hi @NitzDKoder,\r\nDoes @jamiltz comment solve your problem? Please let us know!\r\nThanks!"}}