-
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.
Merge pull request #40 from ergon/feature/dope-244-use-type-convesion
DOPE-244: implemented extensions for CMConverters
- Loading branch information
Showing
86 changed files
with
1,938 additions
and
1,115 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
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
67 changes: 56 additions & 11 deletions
67
crystal-map-connector/src/main/kotlin/ch/ergon/dope/CrystalMapAdapter.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,48 +1,93 @@ | ||
package ch.ergon.dope | ||
|
||
import ch.ergon.dope.resolvable.expression.TypeExpression | ||
import ch.ergon.dope.resolvable.expression.unaliased.type.Field | ||
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType | ||
import ch.ergon.dope.resolvable.formatPathToQueryString | ||
import ch.ergon.dope.validtype.ArrayType | ||
import ch.ergon.dope.validtype.BooleanType | ||
import ch.ergon.dope.validtype.DopeSchemaArray | ||
import ch.ergon.dope.validtype.NumberType | ||
import ch.ergon.dope.validtype.StringType | ||
import ch.ergon.dope.validtype.ValidType | ||
import com.schwarz.crystalapi.schema.CMField | ||
import com.schwarz.crystalapi.schema.CMList | ||
import com.schwarz.crystalapi.schema.CMConverterField | ||
import com.schwarz.crystalapi.schema.CMConverterList | ||
import com.schwarz.crystalapi.schema.CMJsonField | ||
import com.schwarz.crystalapi.schema.CMJsonList | ||
import com.schwarz.crystalapi.schema.CMObject | ||
import com.schwarz.crystalapi.schema.CMObjectList | ||
import com.schwarz.crystalapi.schema.CMType | ||
import com.schwarz.crystalapi.schema.Schema | ||
import kotlin.reflect.KClass | ||
|
||
fun CMType.toDopeType(reference: String = path): Field<ValidType> = Field( | ||
when (this) { | ||
is CMField<*> -> this.name | ||
is CMList<*> -> this.name | ||
is CMJsonField<*> -> this.name | ||
is CMJsonList<*> -> this.name | ||
is CMObjectList<*> -> this.name | ||
is CMObject<*> -> TODO("DOPE-216") | ||
else -> throw IllegalArgumentException("Unsupported type $this") | ||
}, | ||
reference, | ||
) | ||
|
||
@JvmName("toDopeTypeNumber") | ||
fun <Convertable : Any, JsonType : Number> Convertable.toDopeType(other: CMConverterField<Convertable, JsonType>): TypeExpression<NumberType> = | ||
requireValidConvertable(other.typeConverter.write(this), Number::class).toDopeType() | ||
|
||
@JvmName("toDopeTypeString") | ||
fun <Convertable : Any> Convertable.toDopeType(other: CMConverterField<Convertable, String>): TypeExpression<StringType> = | ||
requireValidConvertable(other.typeConverter.write(this), String::class).toDopeType() | ||
|
||
@JvmName("toDopeTypeBoolean") | ||
fun <Convertable : Any> Convertable.toDopeType(other: CMConverterField<Convertable, Boolean>): TypeExpression<BooleanType> = | ||
requireValidConvertable(other.typeConverter.write(this), Boolean::class).toDopeType() | ||
|
||
@JvmName("toDopeTypeListNumber") | ||
fun <Convertable : Any, JsonType : Number> Convertable.toDopeType(other: CMConverterList<Convertable, JsonType>): TypeExpression<NumberType> = | ||
requireValidConvertable(other.typeConverter.write(this), Number::class).toDopeType() | ||
|
||
@JvmName("toDopeTypeListString") | ||
fun <Convertable : Any> Convertable.toDopeType(other: CMConverterList<Convertable, String>): TypeExpression<StringType> = | ||
requireValidConvertable(other.typeConverter.write(this), String::class).toDopeType() | ||
|
||
@JvmName("toDopeTypeListBoolean") | ||
fun <Convertable : Any> Convertable.toDopeType(other: CMConverterList<Convertable, Boolean>): TypeExpression<BooleanType> = | ||
requireValidConvertable(other.typeConverter.write(this), Boolean::class).toDopeType() | ||
|
||
fun <Convertable : Any, JsonType : Number> CMConverterField<Convertable, JsonType>.toDopeType(other: Convertable) = | ||
requireValidConvertable(typeConverter.write(other), Number::class).toDopeType() | ||
|
||
fun <Convertable : Any> CMConverterField<Convertable, String>.toDopeType(other: Convertable) = | ||
requireValidConvertable(typeConverter.write(other), String::class).toDopeType() | ||
|
||
fun <Convertable : Any> CMConverterField<Convertable, Boolean>.toDopeType(other: Convertable) = | ||
requireValidConvertable(typeConverter.write(other), Boolean::class).toDopeType() | ||
|
||
@JvmName("toDopeNumberField") | ||
fun CMField<out Number>.toDopeType(reference: String = path): Field<NumberType> = Field(name, reference) | ||
fun CMJsonField<out Number>.toDopeType(reference: String = path): Field<NumberType> = Field(name, reference) | ||
|
||
@JvmName("toDopeStringField") | ||
fun CMField<String>.toDopeType(reference: String = path): Field<StringType> = Field(name, reference) | ||
fun CMJsonField<String>.toDopeType(reference: String = path): Field<StringType> = Field(name, reference) | ||
|
||
@JvmName("toDopeBooleanField") | ||
fun CMField<Boolean>.toDopeType(reference: String = path): Field<BooleanType> = Field(name, reference) | ||
fun CMJsonField<Boolean>.toDopeType(reference: String = path): Field<BooleanType> = Field(name, reference) | ||
|
||
@JvmName("toDopeNumberArrayField") | ||
fun CMList<out Number>.toDopeType(): Field<ArrayType<NumberType>> = Field(name, path) | ||
fun CMJsonList<out Number>.toDopeType(): Field<ArrayType<NumberType>> = Field(name, path) | ||
|
||
@JvmName("toDopeStringArrayField") | ||
fun CMList<String>.toDopeType(): Field<ArrayType<StringType>> = Field(name, path) | ||
fun CMJsonList<String>.toDopeType(): Field<ArrayType<StringType>> = Field(name, path) | ||
|
||
@JvmName("toDopeBooleanArrayField") | ||
fun CMList<Boolean>.toDopeType(): Field<ArrayType<BooleanType>> = Field(name, path) | ||
fun CMJsonList<Boolean>.toDopeType(): Field<ArrayType<BooleanType>> = Field(name, path) | ||
|
||
fun CMJsonList<out Any>.toDopeType(): Field<ArrayType<ValidType>> = Field(name, path) | ||
|
||
// TODO: DOPE-192 | ||
fun <T : Schema> CMObjectList<T>.toDopeType() = DopeSchemaArray(element, formatPathToQueryString(name, path)) | ||
|
||
private fun <Convertable : Any, JsonType : Any> Convertable.requireValidConvertable(jsonType: JsonType?, jsonTypeClass: KClass<JsonType>) = | ||
requireNotNull(jsonType) { | ||
"Conversion failed: " + | ||
"The value of type '${this::class.simpleName}' couldn't be converted to the expected JSON type '${jsonTypeClass.simpleName}'. " | ||
} |
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
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
Oops, something went wrong.