Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@

package com.linkedplanet.kotlininsightclient.api.model

import java.time.LocalDate
import java.time.ZonedDateTime

fun InsightObject.getAttribute(id: InsightAttributeId): InsightAttribute? =
this.attributes.singleOrNull { it.attributeId == id }

inline fun <reified T : InsightAttribute> InsightObject.getAttributeValue(id: InsightAttributeId): T? =
inline fun <reified T : InsightAttribute> InsightObject.getAttributeAs(id: InsightAttributeId): T? =
getAttribute(id) as? T

inline fun <reified T : InsightAttribute> InsightObject.getAttributeValueByName(name: String): T? =
inline fun <reified T : InsightAttribute> InsightObject.getAttributeByNameAs(name: String): T? =
getAttributeByName(name) as? T

fun InsightObject.getAttributeIdByName(name: String) = getAttributeByName(name)?.attributeId
Expand All @@ -46,9 +47,18 @@ fun InsightObject.isValueAttribute(id: InsightAttributeId): Boolean =
fun InsightObject.exists(id: InsightAttributeId): Boolean =
getAttribute(id) != null

fun InsightObject.setUrlValues(attributeId: InsightAttributeId, values: List<String>) {
this.attributes = attributes
.filter { it.attributeId != attributeId } +
InsightAttribute.Url(attributeId, values, null)
}

fun InsightObject.getUrlValues(id: InsightAttributeId): List<String> =
getAttributeAs<InsightAttribute.Url>(id)?.values ?: emptyList()

// region ObjectAttributeValue.Select
fun InsightObject.getSelectValues(id: InsightAttributeId): List<String> =
getAttributeValue<InsightAttribute.Select>(id)?.values ?: emptyList()
getAttributeAs<InsightAttribute.Select>(id)?.values ?: emptyList()

fun InsightObject.setSelectValues(attributeId: InsightAttributeId, values: List<String>) {
this.attributes = attributes
Expand Down Expand Up @@ -94,8 +104,12 @@ fun InsightObject.setValue(id: InsightAttributeId, value: Double?) {
setValue(id, InsightAttribute.DoubleNumber(id, value, null))
}

fun InsightObject.setValue(id: InsightAttributeId, value: ZonedDateTime?, displayValue: String) {
setValue(id, InsightAttribute.DateTime(id, value, displayValue, null))
fun InsightObject.setValue(id: InsightAttributeId, value: LocalDate?) {
setValue(id, InsightAttribute.Date(id, value, null, null))
}

fun InsightObject.setValue(id: InsightAttributeId, value: ZonedDateTime?) {
setValue(id, InsightAttribute.DateTime(id, value, null, null))
}
// endregion setters

Expand All @@ -111,24 +125,22 @@ fun <T> InsightObject.getValueByName(name: String, transform: (InsightAttribute)

fun InsightObject.getStringValue(id: InsightAttributeId): String? =
this.getValue(id) { it.toString() }

fun InsightObject.getIntValue(id: InsightAttributeId): Int? =
getStringValue(id)?.toInt()

getAttributeAs<InsightAttribute.Integer>(id)?.value
fun InsightObject.getDoubleValue(id: InsightAttributeId): Double? =
getStringValue(id)?.toDouble()

getAttributeAs<InsightAttribute.DoubleNumber>(id)?.value
fun InsightObject.getBooleanValue(id: InsightAttributeId): Boolean? =
getStringValue(id)?.toBoolean()

getAttributeAs<InsightAttribute.Bool>(id)?.value
fun InsightObject.getDateValue(id: InsightAttributeId): LocalDate? =
getAttributeAs<InsightAttribute.Date>(id)?.value
fun InsightObject.getDateTimeValue(id: InsightAttributeId): ZonedDateTime? =
getStringValue(id)?.let { ZonedDateTime.parse(it) }
getAttributeAs<InsightAttribute.DateTime>(id)?.value
//endregion getters


//region ObjectAttributeValue.User
fun InsightObject.getUserList(id: InsightAttributeId): List<InsightUser> =
getAttributeValue<InsightAttribute.User>(id)?.users ?: emptyList()
getAttributeAs<InsightAttribute.User>(id)?.users ?: emptyList()
// endregion user


Expand Down Expand Up @@ -164,7 +176,7 @@ fun InsightObject.getMultiReferenceValue(id: InsightAttributeId): List<InsightRe
?: emptyList()

fun InsightObject.removeReference(attributeId: InsightAttributeId, referencedObjectId: InsightObjectId) {
val existingList = getAttributeValue<InsightAttribute.Reference>(attributeId)?.referencedObjects ?: emptyList()
val existingList = getAttributeAs<InsightAttribute.Reference>(attributeId)?.referencedObjects ?: emptyList()
val referenceAttributeList = existingList.filter { it.id != referencedObjectId }
this.attributes = attributes
.filter { it.attributeId != attributeId } +
Expand All @@ -178,7 +190,7 @@ fun InsightObject.clearReferenceValue(attributeId: InsightAttributeId) {
}

fun InsightObject.addReference(attributeId: InsightAttributeId, referencedObjectId: InsightObjectId) {
val existingList = getAttributeValue<InsightAttribute.Reference>(attributeId)?.referencedObjects ?: emptyList()
val existingList = getAttributeAs<InsightAttribute.Reference>(attributeId)?.referencedObjects ?: emptyList()
val referenceAttributeList = existingList + ReferencedObject(referencedObjectId, "", "", null)
this.attributes = attributes
.filter { it.attributeId != attributeId } +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,12 @@ sealed class InsightAttribute(
is Reference -> referencedObjects.joinToString(",") { it.objectKey }
is User -> users.joinToString(",") { it.key }

is Group -> "" // TODO
is Project -> ""
is Status -> ""
is Version -> ""
is Confluence -> ""
// TODO support additional attribute types
is Group -> "Group attributeId=$attributeId"
is Project -> "Project attributeId=$attributeId"
is Status -> "Status attributeId=$attributeId"
is Version -> "Version attributeId=$attributeId"
is Confluence -> "Confluence attributeId=$attributeId"
is Unknown -> ""
}

Expand Down Expand Up @@ -201,6 +202,12 @@ sealed class InsightAttribute(
infix fun InsightAttributeId.toUrlValues(values: List<String>) =
Url(this, values = values, schema = null)

infix fun InsightAttributeId.toUser(user: InsightUser?) =
User(this, listOfNotNull(user), schema = null)

infix fun InsightAttributeId.toUsers(users: List<InsightUser>) =
User(this, users, schema = null)

infix fun InsightAttributeId.toReference(referencedObjectId: InsightObjectId?) =
Reference(
this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,11 @@ class HttpInsightObjectOperator(private val context: HttpInsightClientContext) :
}
InsightAttribute.User(attributeId, users, schema)
}
InsightObjectAttributeType.CONFLUENCE -> TODO()
InsightObjectAttributeType.GROUP -> TODO()
InsightObjectAttributeType.VERSION -> TODO()
InsightObjectAttributeType.PROJECT -> TODO()
InsightObjectAttributeType.STATUS -> TODO()
InsightObjectAttributeType.CONFLUENCE -> InsightAttribute.Confluence(attributeId, schema)
InsightObjectAttributeType.GROUP -> InsightAttribute.Group(attributeId, schema)
InsightObjectAttributeType.VERSION -> InsightAttribute.Version(attributeId, schema)
InsightObjectAttributeType.PROJECT -> InsightAttribute.Project(attributeId, schema)
InsightObjectAttributeType.STATUS -> InsightAttribute.Status(attributeId, schema)
else -> internalError("Unsupported objectTypeAttributeBean.type (${attributeType})").bind()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@ internal fun InsightObject.getEditAttributes(): List<ObjectEditItemAttribute> =
is InsightAttribute.Select -> attr.values

is InsightAttribute.Reference -> attr.referencedObjects.map { it.id.raw }
is InsightAttribute.User -> attr.users.map { it.key } //TODO: needs a test
is InsightAttribute.User -> attr.users.map { it.key }

is InsightAttribute.Group -> TODO()
is InsightAttribute.Project -> TODO()
is InsightAttribute.Status -> TODO()
is InsightAttribute.Version -> TODO()
is InsightAttribute.Confluence -> TODO()
is InsightAttribute.Unknown -> TODO()
// TODO support additional attribute types
is InsightAttribute.Group -> emptyList()
is InsightAttribute.Project -> emptyList()
is InsightAttribute.Status -> emptyList()
is InsightAttribute.Version -> emptyList()
is InsightAttribute.Confluence -> emptyList()

is InsightAttribute.Unknown -> emptyList()
}

ObjectEditItemAttribute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,13 @@ object SdkInsightObjectOperator : InsightObjectOperator {
objectAttributeBeanFactory.createUserAttributeValueByKey(ota, *userKeys.toTypedArray())
}

is InsightAttribute.Group -> TODO()
is InsightAttribute.Project -> TODO()
is InsightAttribute.Status -> TODO()
is InsightAttribute.Version -> TODO()
is InsightAttribute.Confluence -> TODO()
is InsightAttribute.Unknown -> TODO()
// TODO support additional attribute types
is InsightAttribute.Group -> objectAttributeBeanFactory.createObjectAttributeBeanForObject(bean, ota)
is InsightAttribute.Project -> objectAttributeBeanFactory.createObjectAttributeBeanForObject(bean, ota)
is InsightAttribute.Status -> objectAttributeBeanFactory.createObjectAttributeBeanForObject(bean, ota)
is InsightAttribute.Version -> objectAttributeBeanFactory.createObjectAttributeBeanForObject(bean, ota)
is InsightAttribute.Confluence -> objectAttributeBeanFactory.createObjectAttributeBeanForObject(bean, ota)
is InsightAttribute.Unknown -> objectAttributeBeanFactory.createObjectAttributeBeanForObject(bean, ota)
}
}
bean.setObjectAttributeBeans(attributeBeans)
Expand Down Expand Up @@ -368,11 +369,11 @@ object SdkInsightObjectOperator : InsightObjectOperator {
}
InsightAttribute.User(attributeId, users, schema)
}
Type.CONFLUENCE -> TODO()
Type.GROUP -> TODO()
Type.VERSION -> TODO()
Type.PROJECT -> TODO()
Type.STATUS -> TODO()
Type.CONFLUENCE -> InsightAttribute.Confluence(attributeId, schema)
Type.GROUP -> InsightAttribute.Group(attributeId, schema)
Type.VERSION -> InsightAttribute.Version(attributeId, schema)
Type.PROJECT -> InsightAttribute.Project(attributeId, schema)
Type.STATUS -> InsightAttribute.Status(attributeId, schema)
else -> internalError("Unsupported objectTypeAttributeBean.type (${objectTypeAttributeBean.type})").bind()
}
}
Expand Down
Loading