Skip to content

Commit

Permalink
use correct nullability annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
HighKo committed Jun 7, 2024
1 parent ac95880 commit a9aa0ca
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ import javax.validation.constraints.NotNull

data class JiraGroup(
@field:NotNull val name: String,
@field:NotNull val avatarUrl: String? = null,
@field:NotNull val avatarUrl: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import javax.validation.constraints.NotNull
data class JiraUser(
@field:NotNull val key: String,
@field:NotNull val name: String,
@field:NotNull val emailAddress: String,
@field:NotNull val avatarUrl: String? = null,
val emailAddress: String?,
val avatarUrl: String?,
@field:NotNull val displayName: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ sealed class InsightAttribute(
data class Status(
@get:JvmName("getAttributeId")
@field:NotNull override val attributeId: InsightAttributeId,
@field:NotNull val status: StatusAttribute?,
val status: StatusAttribute?,
override val schema: ObjectTypeSchemaAttribute?
) : InsightAttribute(
attributeId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ class HttpInsightObjectOperator(private val context: HttpInsightClientContext) :
}
USER -> {
val users = apiAttribute.objectAttributeValues.mapNotNull { av: ObjectAttributeValueApiResponse ->
av.user?.run { JiraUser(key, name, emailAddress ?: "", displayName = displayName) }
av.user?.run { JiraUser(key, name, emailAddress, avatarUrl, displayName) }
}
InsightAttribute.User(attributeId, users, schema)
}
Expand All @@ -323,10 +323,10 @@ class HttpInsightObjectOperator(private val context: HttpInsightClientContext) :
InsightAttribute.Confluence(attributeId, confluencePages, schema)
}
GROUP -> {
val group = apiAttribute.objectAttributeValues.mapNotNull { av: ObjectAttributeValueApiResponse ->
val groups = apiAttribute.objectAttributeValues.mapNotNull { av: ObjectAttributeValueApiResponse ->
av.group?.run { JiraGroup(name = name, avatarUrl = avatarUrl) }
}
InsightAttribute.Group(attributeId, group, schema)
InsightAttribute.Group(attributeId, groups, schema)
}
VERSION -> {
val version = apiAttribute.objectAttributeValues.mapNotNull { av: ObjectAttributeValueApiResponse ->
Expand Down Expand Up @@ -356,7 +356,7 @@ class HttpInsightObjectOperator(private val context: HttpInsightClientContext) :
}
}

private suspend fun handleDefaultValue(
private fun handleDefaultValue(
attributeId: InsightAttributeId,
apiAttribute: InsightAttributeApiResponse,
schema: ObjectTypeSchemaAttribute?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ object SdkInsightObjectOperator : InsightObjectOperator {
val attributeBeans = obj.attributes.map { attr ->
val ota = objectTypeAttributeFacade.loadObjectTypeAttribute(attr.attributeId.raw).createMutable()
when (attr) {
// primitive values
is InsightAttribute.Bool -> beanFromString(bean, ota, attr.value.toString())
is InsightAttribute.Date -> beanFromString(bean, ota, attr.value.toString())
is InsightAttribute.DateTime -> beanFromString(bean, ota, attr.value.toString())
Expand All @@ -225,13 +226,15 @@ object SdkInsightObjectOperator : InsightObjectOperator {
is InsightAttribute.Textarea -> beanFromString(bean, ota, attr.value.toString())
is InsightAttribute.Time -> beanFromString(bean, ota, attr.value.toString())

// multiple primitive values
is InsightAttribute.Url -> objectAttributeBeanFactory.createObjectAttributeBeanForObject(
bean, ota, *attr.values.toTypedArray()
)
is InsightAttribute.Select -> objectAttributeBeanFactory.createObjectAttributeBeanForObject(
bean, ota, *attr.values.toTypedArray()
)

// advanced types
is InsightAttribute.Reference -> {
val referenceIds = attr.referencedObjects.map { it.id.raw }.toTypedArray()
objectAttributeBeanFactory.createReferenceAttributeValue(ota) { referenceIds.contains(it.id) }
Expand All @@ -244,8 +247,6 @@ object SdkInsightObjectOperator : InsightObjectOperator {
val groupNames = attr.groups.map { it.name }
objectAttributeBeanFactory.createGroupAttributeValueByNames(ota, *groupNames.toTypedArray())
}

// TODO test additional attribute types
is InsightAttribute.Project -> {
val projectIds = attr.projects.map { it.id }
objectAttributeBeanFactory.createProjectAttributeValue(ota) { projectIds.contains(it.id()) }
Expand Down Expand Up @@ -461,7 +462,7 @@ object SdkInsightObjectOperator : InsightObjectOperator {
}
}

private suspend fun handleDefaultValue(
private fun handleDefaultValue(
id: InsightAttributeId,
schema: ObjectTypeSchemaAttribute,
objectAttributeBean: ObjectAttributeBean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,8 +677,8 @@ interface InsightObjectOperatorTest {

val objectName = "createdByUnitTest"
autoClean(clean = { deleteObjectByName(InsightObjectType.User.id, objectName).orFail() }) {
val user1 = JiraUser("JIRAUSER10100", "", "", displayName = "")
val user2 = JiraUser("JIRAUSER10101", "", "", displayName = "")
val user1 = JiraUser("JIRAUSER10100", "", null, null, "")
val user2 = JiraUser("JIRAUSER10101", "", null, null, "")
val objectId = insightObjectOperator.createInsightObject(
InsightObjectType.User.id,
UserTestName.attributeId toValue objectName,
Expand Down Expand Up @@ -710,8 +710,8 @@ interface InsightObjectOperatorTest {

val objectName = "createdByUnitTest"
autoClean(clean = { deleteObjectByName(InsightObjectType.Group.id, objectName).orFail() }) {
val group1 = JiraGroup("jira-administrators", null)
val group2 = JiraGroup("jira-servicedesk-users", null)
val group1 = JiraGroup("jira-administrators", "test url")
val group2 = JiraGroup("jira-servicedesk-users", "test url")
val objectId = insightObjectOperator.createInsightObject(
InsightObjectType.Group.id,
TestGroupName.attributeId toValue objectName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ data class HttpJiraUser(
val displayName: String
) {
fun toJiraUser() =
JiraUser(key, name, emailAddress, avatarUrls?.get(DEFAULT_AVATAR_SIZE), displayName)
JiraUser(
key = key,
name = name,
emailAddress = emailAddress,
avatarUrl = avatarUrls?.get(DEFAULT_AVATAR_SIZE) ?: avatarUrls?.values?.firstOrNull(),
displayName = displayName
)
}

fun List<HttpJiraUser>.toJiraUsers(): List<JiraUser> =
Expand Down

0 comments on commit a9aa0ca

Please sign in to comment.