-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introducing Upload Strategies (#2171)
* refactoring for upload request generator * spotless application * spotless application * added UploadRequestGeneratorFactory * Spotless applications * review comments * Upload Strategy * Adding factories * patch generator mode in same class as patch generator * making local fetch mode not internal * addressed review comments * using bundle request
- Loading branch information
Showing
2 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
engine/src/main/java/com/google/android/fhir/sync/upload/UploadStrategy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.android.fhir.sync.upload | ||
|
||
import com.google.android.fhir.sync.upload.patch.PatchGeneratorMode | ||
import com.google.android.fhir.sync.upload.request.UploadRequestGeneratorMode | ||
import org.hl7.fhir.r4.model.Bundle | ||
import org.hl7.fhir.r4.model.codesystems.HttpVerb | ||
|
||
/** | ||
* Strategy to define how to upload the [LocalChange]s to the FHIR server. | ||
* | ||
* Each strategy comprises of deciding appropriate modes for [LocalChangeFetcher], | ||
* [PatchGeneratorMode], [UploadRequestGeneratorMode]. The strategies mentioned here are exhaustive | ||
* as the different modes for the components mentioned above can only be used together in some | ||
* specific ways. | ||
*/ | ||
sealed class UploadStrategy | ||
private constructor( | ||
internal val localChangesFetchMode: LocalChangesFetchMode, | ||
internal val patchGeneratorMode: PatchGeneratorMode, | ||
internal val requestGeneratorMode: UploadRequestGeneratorMode, | ||
) { | ||
object SingleChangePut : | ||
UploadStrategy( | ||
LocalChangesFetchMode.EarliestChange, | ||
PatchGeneratorMode.PerChange, | ||
UploadRequestGeneratorMode.UrlRequest(HttpVerb.PUT, HttpVerb.PATCH), | ||
) | ||
|
||
object SingleChangePost : | ||
UploadStrategy( | ||
LocalChangesFetchMode.EarliestChange, | ||
PatchGeneratorMode.PerChange, | ||
UploadRequestGeneratorMode.UrlRequest(HttpVerb.POST, HttpVerb.PATCH), | ||
) | ||
|
||
object SingleResourcePut : | ||
UploadStrategy( | ||
LocalChangesFetchMode.PerResource, | ||
PatchGeneratorMode.PerResource, | ||
UploadRequestGeneratorMode.UrlRequest(HttpVerb.PUT, HttpVerb.PATCH), | ||
) | ||
|
||
object SingleResourcePost : | ||
UploadStrategy( | ||
LocalChangesFetchMode.PerResource, | ||
PatchGeneratorMode.PerResource, | ||
UploadRequestGeneratorMode.UrlRequest(HttpVerb.POST, HttpVerb.PATCH), | ||
) | ||
|
||
object AllChangesBundlePut : | ||
UploadStrategy( | ||
LocalChangesFetchMode.AllChanges, | ||
PatchGeneratorMode.PerChange, | ||
UploadRequestGeneratorMode.BundleRequest(Bundle.HTTPVerb.PUT, Bundle.HTTPVerb.PATCH), | ||
) | ||
|
||
object AllChangesBundlePost : | ||
UploadStrategy( | ||
LocalChangesFetchMode.AllChanges, | ||
PatchGeneratorMode.PerChange, | ||
UploadRequestGeneratorMode.BundleRequest(Bundle.HTTPVerb.POST, Bundle.HTTPVerb.PATCH), | ||
) | ||
|
||
object AllChangesSquashedBundlePut : | ||
UploadStrategy( | ||
LocalChangesFetchMode.AllChanges, | ||
PatchGeneratorMode.PerResource, | ||
UploadRequestGeneratorMode.BundleRequest(Bundle.HTTPVerb.PUT, Bundle.HTTPVerb.PATCH), | ||
) | ||
|
||
object AllChangesSquashedBundlePost : | ||
UploadStrategy( | ||
LocalChangesFetchMode.AllChanges, | ||
PatchGeneratorMode.PerResource, | ||
UploadRequestGeneratorMode.BundleRequest(Bundle.HTTPVerb.POST, Bundle.HTTPVerb.PATCH), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters