Skip to content

Commit d2dd07f

Browse files
committed
make isValueAttribute function an attribute, so it gets serialized
1 parent c7b619b commit d2dd07f

File tree

3 files changed

+55
-53
lines changed

3 files changed

+55
-53
lines changed

kotlin-insight-client/kotlin-insight-client-api/src/main/kotlin/com/linkedplanet/kotlininsightclient/api/impl/AbstractNameMappedRepository.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ abstract class AbstractNameMappedRepository<DomainType : Any>(
8686
val attributeType: ObjectTypeSchemaAttribute = attrsMap[prop.name.lowercase()] ?: return@mapNotNull null
8787
val value: Any? = prop.get(domainObject)
8888
when {
89-
attributeType.isValueAttribute() -> mapValueAttribute(value, attributeType)
89+
attributeType.isValueAttribute -> mapValueAttribute(value, attributeType)
9090

9191
attributeType is ObjectTypeSchemaAttribute.ReferenceSchema -> {
9292
val referencedObjectIds = attributeToReferencedObjectId(attributeType, value)
@@ -138,7 +138,7 @@ abstract class AbstractNameMappedRepository<DomainType : Any>(
138138
val attributeId = attrsMap[param.name?.lowercase()]?.id ?: return@map null
139139
val attribute = insightObject.getAttribute(attributeId)
140140
val mappedValue = when {
141-
attribute?.isReference() == true -> referenceAttributeToValue(attribute)
141+
attribute?.let { it is InsightAttribute.Reference } == true -> referenceAttributeToValue(attribute)
142142
attribute == null -> null
143143
else -> defaultAttributeToValue(attribute, param.type).bind()
144144
}

kotlin-insight-client/kotlin-insight-client-api/src/main/kotlin/com/linkedplanet/kotlininsightclient/api/model/InsightObjectExtensions.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ fun InsightObject.getAttributeByName(name: String): InsightAttribute? =
3939
this.attributes.firstOrNull { it.schema?.name == name }
4040

4141
fun InsightObject.isReferenceAttribute(id: InsightAttributeId): Boolean =
42-
getAttribute(id)?.isReference() ?: false
42+
getAttribute(id)?.isReferenceAttribute() ?: false
43+
44+
fun InsightAttribute.isReferenceAttribute() = this is InsightAttribute.Reference
4345

4446
fun InsightObject.isValueAttribute(id: InsightAttributeId): Boolean =
45-
getAttribute(id)?.isValueAttribute() ?: false
47+
getAttribute(id)?.isValueAttribute ?: false
4648

4749
fun InsightObject.exists(id: InsightAttributeId): Boolean =
4850
getAttribute(id) != null

kotlin-insight-client/kotlin-insight-client-api/src/main/kotlin/com/linkedplanet/kotlininsightclient/api/model/Model.kt

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
package com.linkedplanet.kotlininsightclient.api.model
2121

2222
import io.swagger.v3.oas.annotations.media.Schema
23-
import javax.validation.constraints.NotNull
2423
import java.time.LocalDate
2524
import java.time.LocalTime
2625
import java.time.ZonedDateTime
2726
import java.util.Collections.emptyList
27+
import javax.validation.constraints.NotNull
2828

2929
// region ID wrapper
3030

@@ -123,31 +123,31 @@ sealed class InsightAttribute(
123123
@field:NotNull val attributeId: InsightAttributeId,
124124
val schema: ObjectTypeSchemaAttribute?
125125
) {
126-
fun isValueAttribute(): Boolean = when(this){
127-
is Text -> true
128-
is Integer -> true
129-
is Bool -> true
130-
is DoubleNumber -> true
131-
is Select -> true
132-
is Date -> true
133-
is Time -> true
134-
is DateTime -> true
135-
is Url -> true
136-
is Email -> true
137-
is Textarea -> true
138-
is Ipaddress -> true
139-
140-
is Unknown -> false
141-
is Reference -> false
142-
is User -> false
143-
is Confluence -> false
144-
is Group -> false
145-
is Version -> false
146-
is Project -> false
147-
is Status -> false
126+
val isValueAttribute: Boolean by lazy {
127+
when (this) {
128+
is Text -> true
129+
is Integer -> true
130+
is Bool -> true
131+
is DoubleNumber -> true
132+
is Select -> true
133+
is Date -> true
134+
is Time -> true
135+
is DateTime -> true
136+
is Url -> true
137+
is Email -> true
138+
is Textarea -> true
139+
is Ipaddress -> true
140+
141+
is Unknown -> false
142+
is Reference -> false
143+
is User -> false
144+
is Confluence -> false
145+
is Group -> false
146+
is Version -> false
147+
is Project -> false
148+
is Status -> false
149+
}
148150
}
149-
fun isReference() : Boolean = this is Reference
150-
151151

152152
class Text(attributeId: InsightAttributeId, val value: String?, schema: ObjectTypeSchemaAttribute?) : InsightAttribute(attributeId, schema)
153153
class Integer(attributeId: InsightAttributeId,val value: Int?, schema: ObjectTypeSchemaAttribute?) : InsightAttribute(attributeId, schema)
@@ -303,32 +303,32 @@ sealed class ObjectTypeSchemaAttribute(
303303
@field:NotNull val includeChildObjectTypes: Boolean
304304
) {
305305

306-
fun isValueAttribute(): Boolean = when(this){
307-
is TextSchema -> true
308-
is IntegerSchema -> true
309-
is BoolSchema -> true
310-
is DoubleNumberSchema -> true
311-
is SelectSchema -> true
312-
is DateSchema -> true
313-
is TimeSchema -> true
314-
is DateTimeSchema -> true
315-
is UrlSchema -> true
316-
is EmailSchema -> true
317-
is TextareaSchema -> true
318-
is IpaddressSchema -> true
319-
320-
is UnknownSchema -> false
321-
is ReferenceSchema -> false
322-
is UserSchema -> false
323-
is ConfluenceSchema -> false
324-
is GroupSchema -> false
325-
is VersionSchema -> false
326-
is ProjectSchema -> false
327-
is StatusSchema -> false
306+
val isValueAttribute: Boolean by lazy {
307+
when(this){
308+
is TextSchema -> true
309+
is IntegerSchema -> true
310+
is BoolSchema -> true
311+
is DoubleNumberSchema -> true
312+
is SelectSchema -> true
313+
is DateSchema -> true
314+
is TimeSchema -> true
315+
is DateTimeSchema -> true
316+
is UrlSchema -> true
317+
is EmailSchema -> true
318+
is TextareaSchema -> true
319+
is IpaddressSchema -> true
320+
321+
is UnknownSchema -> false
322+
is ReferenceSchema -> false
323+
is UserSchema -> false
324+
is ConfluenceSchema -> false
325+
is GroupSchema -> false
326+
is VersionSchema -> false
327+
is ProjectSchema -> false
328+
is StatusSchema -> false
329+
}
328330
}
329331

330-
fun isReference() : Boolean = this is ReferenceSchema
331-
332332
class SelectSchema(
333333
id: InsightAttributeId,
334334
name: String,

0 commit comments

Comments
 (0)