This repository has been archived by the owner on Feb 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(common, service-common): combine both modules to common
- introduce Persistable, Entity, Wrapper - use kotlinx.serialization for JSON
- Loading branch information
1 parent
457ef4f
commit f896a10
Showing
45 changed files
with
919 additions
and
378 deletions.
There are no files selected for viewing
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
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
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,9 @@ | ||
package de.hpi.cloud.common | ||
|
||
import de.hpi.cloud.common.entity.Id | ||
import java.util.* | ||
|
||
data class Context( | ||
val author: Id<Party>, | ||
val languageRanges: List<Locale.LanguageRange> | ||
) |
This file was deleted.
Oops, something went wrong.
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,11 @@ | ||
package de.hpi.cloud.common | ||
|
||
import de.hpi.cloud.common.entity.Entity | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class Party( | ||
val name: String | ||
) : Entity<Party>() { | ||
companion object : Entity.Companion<Party>("party") | ||
} |
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,10 @@ | ||
package de.hpi.cloud.common | ||
|
||
import com.google.protobuf.GeneratedMessageV3 | ||
|
||
abstract class Persistable<P : Persistable<P>> { | ||
interface ProtoSerializer<P : Persistable<P>, Proto : GeneratedMessageV3> { | ||
fun fromProto(proto: Proto, context: Context): P | ||
fun toProto(persistable: P, context: Context): Proto | ||
} | ||
} |
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
5 changes: 3 additions & 2 deletions
5
...cloud/common/utils/couchbase/Constants.kt → ...e/hpi/cloud/common/couchbase/Constants.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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
package de.hpi.cloud.common.utils.couchbase | ||
package de.hpi.cloud.common.couchbase | ||
|
||
const val KEY_TYPE = "type" | ||
const val KEY_VERSION = "version" | ||
const val KEY_ID = "id" | ||
const val KEY_METADATA = "meta" | ||
const val KEY_METADATA_CREATED_AT = "createdAt" | ||
const val KEY_VALUE = "value" | ||
|
||
const val NESTED_SEPARATOR = "." | ||
|
||
fun devDesignDoc(designDoc: String) = "dev_$designDoc" | ||
const val VIEW_BY_ID = "byId" |
2 changes: 1 addition & 1 deletion
2
...ommon/utils/couchbase/CouchbaseCluster.kt → ...loud/common/couchbase/CouchbaseCluster.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
29 changes: 29 additions & 0 deletions
29
common/src/main/kotlin/de/hpi/cloud/common/couchbase/Document.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,29 @@ | ||
package de.hpi.cloud.common.couchbase | ||
|
||
import com.couchbase.client.java.AsyncBucket | ||
import com.couchbase.client.java.Bucket | ||
import com.couchbase.client.java.document.RawJsonDocument | ||
import de.hpi.cloud.common.entity.Entity | ||
import de.hpi.cloud.common.entity.Id | ||
import de.hpi.cloud.common.entity.Wrapper | ||
import de.hpi.cloud.common.entity.entityCompanion | ||
import kotlinx.serialization.json.Json | ||
import kotlinx.serialization.json.JsonConfiguration | ||
import rx.Observable | ||
|
||
val json = Json(JsonConfiguration.Stable) | ||
|
||
inline fun <reified E : Entity<E>> RawJsonDocument.parseWrapper(): Wrapper<E> { | ||
return json.parse(Wrapper.jsonSerializerFor<E>(), content()) | ||
} | ||
|
||
inline fun <reified E : Entity<E>> Bucket.get(id: Id<E>): Wrapper<E>? { | ||
val docId = Wrapper.createDocumentId(E::class.entityCompanion().type, id) | ||
return get(docId, RawJsonDocument::class.java)?.parseWrapper() ?: return null | ||
} | ||
|
||
inline fun <reified E : Entity<E>> AsyncBucket.get(id: Id<E>): Observable<Wrapper<E>> { | ||
val docId = Wrapper.createDocumentId(E::class.entityCompanion().type, id) | ||
return get(docId, RawJsonDocument::class.java) | ||
.map { it.parseWrapper<E>() } | ||
} |
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
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
Oops, something went wrong.