Skip to content

Commit c280aff

Browse files
committed
Added user attribute to Insight's ObjectAttributeValue
1 parent 13c4f8c commit c280aff

File tree

6 files changed

+123
-84
lines changed

6 files changed

+123
-84
lines changed

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ fun <T> InsightObject.setValueList(id: Int, name: String? = null, values: List<T
8282
}
8383
getAttribute(id)
8484
?.value = values.map {
85-
ObjectAttributeValue(it, "", null)
85+
ObjectAttributeValue(it, "", null, null)
8686
}
8787
}
8888

@@ -93,7 +93,7 @@ fun <T> InsightObject.setValue(id: Int, name: String? = null, value: T?) {
9393
this.createAttribute(id, name, InsightObjectAttributeType.DEFAULT)
9494
}
9595
getAttribute(id)
96-
?.value = listOf(ObjectAttributeValue(value, "", null))
96+
?.value = listOf(ObjectAttributeValue(value, "", null, null))
9797
}
9898

9999
fun <T> InsightObject.removeValue(id: Int, value: T?) {
@@ -109,7 +109,7 @@ fun InsightObject.addValue(id: Int, name: String? = null, value: Any?) {
109109
}
110110
getAttribute(id)
111111
?.apply {
112-
this.value = this.value + ObjectAttributeValue(value, "", null)
112+
this.value = this.value + ObjectAttributeValue(value, "", null, null)
113113
}
114114
}
115115

@@ -210,8 +210,8 @@ fun InsightObject.addReference(attributeId: Int, name: String?, referencedObject
210210
"",
211211
"",
212212
null
213-
)
214-
213+
),
214+
null
215215
))
216216
}
217217
}
@@ -249,6 +249,13 @@ fun InsightObject.getEditAttributes() =
249249
)
250250
}
251251

252+
fun InsightObject.getUserList(id: Int): List<InsightUser> =
253+
this.attributes
254+
.firstOrNull { it.attributeId == id }
255+
?.value
256+
?.mapNotNull { it.user }
257+
?: emptyList()
258+
252259
/**
253260
* See type attribute in response of https://insight-javadoc.riada.io/insight-javadoc-8.6/insight-rest/#object__id__attributes_get
254261
*/
@@ -377,10 +384,18 @@ data class ObjectTypeAttribute(
377384
val type: Int
378385
)
379386

387+
data class InsightUser(
388+
val displayName: String,
389+
val name: String,
390+
val emailAddress: String,
391+
val key: String
392+
)
393+
380394
data class ObjectAttributeValue(
381395
var value: Any?,
382396
var displayValue: Any?,
383397
var referencedObject: ReferencedObject?,
398+
var user: InsightUser?
384399
)
385400

386401
data class ReferencedObject(

kotlin-insight-client/kotlin-insight-client-test-base/src/main/kotlin/com/linkedplanet/kotlininsightclient/InsightAttachmentOperatorTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ interface InsightAttachmentOperatorTest {
3434
fun testAttachments() {
3535
println("### START attachment_testGetAndDownloadAttachments")
3636
runBlocking {
37-
val country = insightObjectOperator.getObjectByName(InsightObject.Country.id, "Germany").orNull()!!
37+
val country = insightObjectOperator.getObjectByName(InsightObjectType.Country.id, "Germany").orNull()!!
3838
val attachments = insightAttachmentOperator.getAttachments(country.id).orNull() ?: emptyList()
3939
val firstAttachment = attachments.first()
4040
assertEquals(1, attachments.size)

kotlin-insight-client/kotlin-insight-client-test-base/src/main/kotlin/com/linkedplanet/kotlininsightclient/InsightHistoryOperatorTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ interface InsightHistoryOperatorTest {
3434
println("### START history_testHistory")
3535

3636
runBlocking {
37-
val country = insightObjectOperator.getObjectByName(InsightObject.Country.id, "Germany").orNull()!!
37+
val country = insightObjectOperator.getObjectByName(InsightObjectType.Country.id, "Germany").orNull()!!
3838
val historyItems = insightHistoryOperator.getHistory(country.id).orNull()!!
3939
assertTrue(historyItems.isNotEmpty())
4040
}

0 commit comments

Comments
 (0)