Skip to content

Commit 1b7799c

Browse files
committed
test(kotlin): pin and execute the decimal and float filter coercers (FR-044)
The previous commit gave field.decimal and field.float their own filter coercers in the generated controller. This pins that output and runs it, on an ordinary writable entity with no report involved. - A committed snapshot fixture, entity-with-decimal-float-filter: one filterable decimal and one filterable float. - DecimalFloatFilterControllerRunTest compiles the generated controller and drives it over MockMvc against H2. With the old coercer both filters threw ClassCastException (Double to BigDecimal, Double to Float). Also: the unresolved-owner message of KotlinGenUtil.reportEnumClasses named `dimension "null"` for a min/max measure. It now names the item and the field it reads.
1 parent 21641a1 commit 1b7799c

8 files changed

Lines changed: 734 additions & 3 deletions

File tree

‎server/java/codegen-kotlin/src/main/kotlin/com/metaobjects/generator/kotlin/KotlinGenUtil.kt‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -690,9 +690,9 @@ public object KotlinGenUtil {
690690
// about packages or @via is restated here.
691691
val owner = shape.ofEntity(f)
692692
?: throw GeneratorException(
693-
"report \"${report.shortName}\": its dimension \"${f.dimension?.shortName}\" reads the enum " +
694-
"\"${f.dimension?.of}\" through @via, and the entity that reference names does not " +
695-
"resolve, so the generated column has no enum class to be typed by."
693+
"report \"${report.shortName}\": its $item reads the enum \"${f.typeSourceKey()}\", and the " +
694+
"entity that reference names does not resolve, so the generated column has no enum " +
695+
"class to be typed by."
696696
)
697697
out[f.name] = KotlinTypeMapper.enumTypeName(f.typeSource, owner)
698698
?: throw GeneratorException(
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "generators": ["entity", "table", "filter-allowlist", "controller"] }
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"metadata.root": { "package": "acme::catalog", "children": [
3+
{ "object.entity": { "name": "Product", "children": [
4+
{ "source.rdb": { "@table": "products" } },
5+
{ "field.long": { "name": "id" } },
6+
{ "field.string": { "name": "name", "@maxLength": 40, "@required": true } },
7+
{ "field.decimal": { "name": "price", "@precision": 10, "@scale": 2, "@filterable": true } },
8+
{ "field.float": { "name": "rating", "@filterable": true } },
9+
{ "identity.primary": { "name": "pk", "@fields": "id", "@generation": "increment" } }
10+
] } }
11+
] }
12+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package acme.catalog
2+
3+
import jakarta.validation.constraints.NotNull
4+
import jakarta.validation.constraints.Size
5+
import java.math.BigDecimal
6+
import kotlin.Float
7+
import kotlin.Long
8+
import kotlin.String
9+
import kotlin.jvm.JvmStatic
10+
11+
/**
12+
* GENERATED — do not hand-edit. Regenerated from metadata.
13+
*/
14+
public data class Product(
15+
public val id: Long? = null,
16+
@field:NotNull
17+
@field:Size(min = 1, max = 40)
18+
public val name: String,
19+
public val price: BigDecimal? = null,
20+
public val rating: Float? = null,
21+
) {
22+
/**
23+
* Fluent builder — lets a JAVA caller set a subset of properties.
24+
*/
25+
public class Builder {
26+
private var id: Long? = null
27+
28+
private var name: String? = null
29+
30+
private var price: BigDecimal? = null
31+
32+
private var rating: Float? = null
33+
34+
public fun id(v: Long?): Builder {
35+
this.id = v
36+
return this
37+
}
38+
39+
public fun name(v: String?): Builder {
40+
this.name = v
41+
return this
42+
}
43+
44+
public fun price(v: BigDecimal?): Builder {
45+
this.price = v
46+
return this
47+
}
48+
49+
public fun rating(v: Float?): Builder {
50+
this.rating = v
51+
return this
52+
}
53+
54+
public fun build(): Product = Product(
55+
id = id,
56+
name = requireNotNull(name) { "name is required" },
57+
price = price,
58+
rating = rating
59+
)
60+
}
61+
62+
public companion object {
63+
@JvmStatic
64+
public fun builder(): Builder = Builder()
65+
}
66+
}

0 commit comments

Comments
 (0)