Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add APIs for local changes #105

Closed
wants to merge 4 commits into from
Closed

Conversation

deepankarb
Copy link
Contributor

  • Get all local updates
  • Delete all local changes by resource (id, type)

import java.util.Date
import java.util.Locale

object Util {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need a class for this.
The function can just be a top level extension function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function can be re-used. I copied it from ResourceSynchronizer.kt#100.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it can be reused, just that it doesn't need to be part of a class. You can declare the function outside the class, as a top level extension function


package com.google.fhirengine.db

class InvalidLocalChangeException(message: String?) : Exception(message)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in file name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix.

* Get a list of all updates
*/
override fun getUpdates(): List<Update> {
val TEST_INSERT = "{\n" +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that this is just dummy for now, but can we move it to it's own file, so we don't pollute this class?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for TEST_UPDATE

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Will fix in next commit(s).

@@ -86,6 +91,9 @@ internal abstract class ResourceDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
abstract fun insertNumberIndex(numberIndexEntity: NumberIndexEntity)

@Insert(onConflict = OnConflictStrategy.IGNORE)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want to replace the local change if it's already there?
Should this kind of conflict ever happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such a conflict should never happen. It can be avoided by adding the timestamp to the primary key.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change the strategy to ABORT.

val index = fhirIndexer.index(resource)
updateIndicesForResource(index, entity)
} else {
val topChange = localChanges.last()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't insertResource called also when we get data from the network?
This means that if something was retrieved from the network after an insert was made, then the network data will also be added to the local changes table.

* Result of squashing local changes of a resource for sync with a remote server.
* [payload] is the body of HTTP request as per https://www.hl7.org/fhir/http.html
*/
data class Update(val resId: String, val resType: String, val payload: String, val type: Type) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add info about all params, please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, sorry. Will do.

* Get all local updates
* Delete all local changes by resource (id, type)
* Moved interface for getting updates and deleteing local changes to
  Database.
* Added mock implemetation for sync mechanism development.
* Moved db revision interface
* db rev mgmt : insert, update or delete a resoource revsion
* db rev merge, squash and diff
@deepankarb
Copy link
Contributor Author

Implemented in #146

@deepankarb deepankarb closed this Feb 11, 2021
@deepankarb deepankarb deleted the db/db_delta_upload_api branch February 11, 2021 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants