diff --git a/kotlin-atlassian-client-core-common/pom.xml b/kotlin-atlassian-client-core-common/pom.xml new file mode 100644 index 00000000..c58dc23b --- /dev/null +++ b/kotlin-atlassian-client-core-common/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + + com.linked-planet.client + kotlin-atlassian-client + 0.12.10-SNAPSHOT + + + kotlin-atlassian-client-core-common + kotlin-atlassian-client-core-common + + + + javax.validation + validation-api + 2.0.1.Final + provided + + + + \ No newline at end of file diff --git a/kotlin-atlassian-client-core-common/src/main/kotlin/com/linkedplanet/kotlinatlassianclientcore/common/api/JiraUser.kt b/kotlin-atlassian-client-core-common/src/main/kotlin/com/linkedplanet/kotlinatlassianclientcore/common/api/JiraUser.kt new file mode 100644 index 00000000..e9c1b1bb --- /dev/null +++ b/kotlin-atlassian-client-core-common/src/main/kotlin/com/linkedplanet/kotlinatlassianclientcore/common/api/JiraUser.kt @@ -0,0 +1,30 @@ +/*- + * #%L + * kotlin-atlassian-client-core-common + * %% + * Copyright (C) 2022 - 2023 linked-planet GmbH + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ +package com.linkedplanet.kotlinatlassianclientcore.common.api + +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, + @field:NotNull val displayName: String +) \ No newline at end of file diff --git a/kotlin-atlassian-client-core-common/src/main/kotlin/com/linkedplanet/kotlinatlassianclientcore/common/api/Page.kt b/kotlin-atlassian-client-core-common/src/main/kotlin/com/linkedplanet/kotlinatlassianclientcore/common/api/Page.kt new file mode 100644 index 00000000..3942d49a --- /dev/null +++ b/kotlin-atlassian-client-core-common/src/main/kotlin/com/linkedplanet/kotlinatlassianclientcore/common/api/Page.kt @@ -0,0 +1,30 @@ +/*- + * #%L + * kotlin-atlassian-client-core-common + * %% + * Copyright (C) 2022 - 2023 linked-planet GmbH + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ +package com.linkedplanet.kotlinatlassianclientcore.common.api + +import javax.validation.constraints.NotNull + +data class Page ( + @field:NotNull val items: List, + @field:NotNull val totalItems: Int, + @field:NotNull val totalPages: Int, + @field:NotNull val currentPageIndex: Int, + @field:NotNull val pageSize: Int +) \ No newline at end of file diff --git a/kotlin-atlassian-client-core-common/src/main/kotlin/com/linkedplanet/kotlinatlassianclientcore/common/error/AtlassianClientError.kt b/kotlin-atlassian-client-core-common/src/main/kotlin/com/linkedplanet/kotlinatlassianclientcore/common/error/AtlassianClientError.kt new file mode 100644 index 00000000..573d5919 --- /dev/null +++ b/kotlin-atlassian-client-core-common/src/main/kotlin/com/linkedplanet/kotlinatlassianclientcore/common/error/AtlassianClientError.kt @@ -0,0 +1,35 @@ +/*- + * #%L + * kotlin-atlassian-client-core-common + * %% + * Copyright (C) 2022 - 2023 linked-planet GmbH + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ +@file:Suppress("CanBeParameter", "unused") // we want clients to access the additional information + +package com.linkedplanet.kotlinatlassianclientcore.common.error + +import arrow.core.Either +import javax.validation.constraints.NotNull + +open class AtlassianClientError( + @field:NotNull val error: String, + @field:NotNull val message: String, + @field:NotNull val stacktrace: String = "" +) { + companion object +} + +fun ERROR.asEither(): Either = Either.Left(this) diff --git a/kotlin-http-client/kotlin-http-client-api/src/main/kotlin/com/linkedplanet/kotlinhttpclient/error/DomainError.kt b/kotlin-http-client/kotlin-http-client-api/src/main/kotlin/com/linkedplanet/kotlinhttpclient/error/HttpDomainError.kt similarity index 59% rename from kotlin-http-client/kotlin-http-client-api/src/main/kotlin/com/linkedplanet/kotlinhttpclient/error/DomainError.kt rename to kotlin-http-client/kotlin-http-client-api/src/main/kotlin/com/linkedplanet/kotlinhttpclient/error/HttpDomainError.kt index be82b53f..634ba0ae 100644 --- a/kotlin-http-client/kotlin-http-client-api/src/main/kotlin/com/linkedplanet/kotlinhttpclient/error/DomainError.kt +++ b/kotlin-http-client/kotlin-http-client-api/src/main/kotlin/com/linkedplanet/kotlinhttpclient/error/HttpDomainError.kt @@ -19,17 +19,4 @@ */ package com.linkedplanet.kotlinhttpclient.error -import com.linkedplanet.kotlinhttpclient.api.http.GSON - -data class DomainErrorObject( - val error: String, - val message: String -) - -open class DomainError(val error: String, val message: String) { - fun toJson(): String = - GSON.toJson(DomainErrorObject(error, message)) -} - -class HttpDomainError(val statusCode: Int, error: String, message: String) : DomainError(error, message) -class ResponseError(message: String) : DomainError("Schnittstellen-Fehler", message) +class HttpDomainError(val statusCode: Int, val error: String, val message: String) diff --git a/kotlin-insight-client/kotlin-insight-client-api/pom.xml b/kotlin-insight-client/kotlin-insight-client-api/pom.xml index a10a5729..59b85409 100644 --- a/kotlin-insight-client/kotlin-insight-client-api/pom.xml +++ b/kotlin-insight-client/kotlin-insight-client-api/pom.xml @@ -34,5 +34,10 @@ 2.2.2-atlassian-1 provided + + com.linked-planet.client + kotlin-atlassian-client-core-common + ${project.version} + diff --git a/kotlin-insight-client/kotlin-insight-client-api/src/main/kotlin/com/linkedplanet/kotlininsightclient/api/error/InsightClientError.kt b/kotlin-insight-client/kotlin-insight-client-api/src/main/kotlin/com/linkedplanet/kotlininsightclient/api/error/InsightClientError.kt index 29a947dd..3342b2fa 100644 --- a/kotlin-insight-client/kotlin-insight-client-api/src/main/kotlin/com/linkedplanet/kotlininsightclient/api/error/InsightClientError.kt +++ b/kotlin-insight-client/kotlin-insight-client-api/src/main/kotlin/com/linkedplanet/kotlininsightclient/api/error/InsightClientError.kt @@ -22,6 +22,8 @@ package com.linkedplanet.kotlininsightclient.api.error import arrow.core.Either +import com.linkedplanet.kotlinatlassianclientcore.common.error.AtlassianClientError +import com.linkedplanet.kotlinatlassianclientcore.common.error.asEither import com.linkedplanet.kotlininsightclient.api.model.InsightAttribute import com.linkedplanet.kotlininsightclient.api.model.InsightObjectId import com.linkedplanet.kotlininsightclient.api.model.InsightObjectTypeId @@ -43,10 +45,10 @@ import io.swagger.v3.oas.annotations.media.Schema @Suppress("unused") sealed class InsightClientError( - val error: String, - val message: String, - val stacktrace: String = "" -) { + error: String, + message: String, + stacktrace: String = "" +) : AtlassianClientError(error, message, stacktrace) { companion object { private const val internalErrorString = "Jira/Insight hat ein internes Problem festgestellt" @@ -58,7 +60,6 @@ sealed class InsightClientError( } } -fun InsightClientError.asEither(): Either = Either.Left(this) class InvalidArgumentInsightClientError(message: String) : InsightClientError("Unerwarteter Parameter", message) diff --git a/kotlin-insight-client/kotlin-insight-client-api/src/main/kotlin/com/linkedplanet/kotlininsightclient/api/impl/AbstractInsightObjectRepository.kt b/kotlin-insight-client/kotlin-insight-client-api/src/main/kotlin/com/linkedplanet/kotlininsightclient/api/impl/AbstractInsightObjectRepository.kt index 7c8aaf6c..c6e1356c 100644 --- a/kotlin-insight-client/kotlin-insight-client-api/src/main/kotlin/com/linkedplanet/kotlininsightclient/api/impl/AbstractInsightObjectRepository.kt +++ b/kotlin-insight-client/kotlin-insight-client-api/src/main/kotlin/com/linkedplanet/kotlininsightclient/api/impl/AbstractInsightObjectRepository.kt @@ -22,6 +22,7 @@ package com.linkedplanet.kotlininsightclient.api.impl import arrow.core.Either import arrow.core.computations.either import arrow.core.rightIfNotNull +import com.linkedplanet.kotlinatlassianclientcore.common.api.Page import com.linkedplanet.kotlininsightclient.api.error.InsightClientError import com.linkedplanet.kotlininsightclient.api.error.OtherNotFoundError import com.linkedplanet.kotlininsightclient.api.interfaces.InsightObjectRepository @@ -30,7 +31,6 @@ import com.linkedplanet.kotlininsightclient.api.model.InsightAttribute import com.linkedplanet.kotlininsightclient.api.model.InsightObject import com.linkedplanet.kotlininsightclient.api.model.InsightObjectId import com.linkedplanet.kotlininsightclient.api.model.InsightObjectTypeId -import com.linkedplanet.kotlininsightclient.api.model.Page import kotlin.math.ceil abstract class AbstractInsightObjectRepository : InsightObjectRepository { diff --git a/kotlin-insight-client/kotlin-insight-client-api/src/main/kotlin/com/linkedplanet/kotlininsightclient/api/impl/AbstractNameMappedRepository.kt b/kotlin-insight-client/kotlin-insight-client-api/src/main/kotlin/com/linkedplanet/kotlininsightclient/api/impl/AbstractNameMappedRepository.kt index 186d28fe..dc6fe5a7 100644 --- a/kotlin-insight-client/kotlin-insight-client-api/src/main/kotlin/com/linkedplanet/kotlininsightclient/api/impl/AbstractNameMappedRepository.kt +++ b/kotlin-insight-client/kotlin-insight-client-api/src/main/kotlin/com/linkedplanet/kotlininsightclient/api/impl/AbstractNameMappedRepository.kt @@ -23,9 +23,9 @@ import arrow.core.Either import arrow.core.computations.either import arrow.core.right import arrow.core.sequenceEither +import com.linkedplanet.kotlinatlassianclientcore.common.error.asEither import com.linkedplanet.kotlininsightclient.api.error.InsightClientError import com.linkedplanet.kotlininsightclient.api.error.InvalidArgumentInsightClientError -import com.linkedplanet.kotlininsightclient.api.error.asEither import com.linkedplanet.kotlininsightclient.api.interfaces.InsightObjectTypeOperator import com.linkedplanet.kotlininsightclient.api.interfaces.InsightSchemaOperator import com.linkedplanet.kotlininsightclient.api.model.InsightAttribute.Companion.toReferences @@ -169,7 +169,7 @@ abstract class AbstractNameMappedRepository( is InsightAttribute.Select -> attribute.values// List else -> InvalidArgumentInsightClientError( "kType.classifier ${kType.classifier} is not supported." - ).asEither( + ).asEither( ).bind() } } diff --git a/kotlin-insight-client/kotlin-insight-client-api/src/main/kotlin/com/linkedplanet/kotlininsightclient/api/interfaces/InsightObjectRepository.kt b/kotlin-insight-client/kotlin-insight-client-api/src/main/kotlin/com/linkedplanet/kotlininsightclient/api/interfaces/InsightObjectRepository.kt index 6df71294..0acee03a 100644 --- a/kotlin-insight-client/kotlin-insight-client-api/src/main/kotlin/com/linkedplanet/kotlininsightclient/api/interfaces/InsightObjectRepository.kt +++ b/kotlin-insight-client/kotlin-insight-client-api/src/main/kotlin/com/linkedplanet/kotlininsightclient/api/interfaces/InsightObjectRepository.kt @@ -22,7 +22,7 @@ package com.linkedplanet.kotlininsightclient.api.interfaces import arrow.core.Either import com.linkedplanet.kotlininsightclient.api.error.InsightClientError import com.linkedplanet.kotlininsightclient.api.model.InsightObjectId -import com.linkedplanet.kotlininsightclient.api.model.Page +import com.linkedplanet.kotlinatlassianclientcore.common.api.Page /** * Generic Interface to CRUD one type of domain object, like a customer, to Insight. diff --git a/kotlin-insight-client/kotlin-insight-client-api/src/main/kotlin/com/linkedplanet/kotlininsightclient/api/model/InsightObjectExtensions.kt b/kotlin-insight-client/kotlin-insight-client-api/src/main/kotlin/com/linkedplanet/kotlininsightclient/api/model/InsightObjectExtensions.kt index b6da6e6d..6bd38e9b 100644 --- a/kotlin-insight-client/kotlin-insight-client-api/src/main/kotlin/com/linkedplanet/kotlininsightclient/api/model/InsightObjectExtensions.kt +++ b/kotlin-insight-client/kotlin-insight-client-api/src/main/kotlin/com/linkedplanet/kotlininsightclient/api/model/InsightObjectExtensions.kt @@ -21,6 +21,7 @@ package com.linkedplanet.kotlininsightclient.api.model +import com.linkedplanet.kotlinatlassianclientcore.common.api.JiraUser import java.time.LocalDate import java.time.ZonedDateTime @@ -141,7 +142,7 @@ fun InsightObject.getDateTimeValue(id: InsightAttributeId): ZonedDateTime? = //region ObjectAttributeValue.User -fun InsightObject.getUserList(id: InsightAttributeId): List = +fun InsightObject.getUserList(id: InsightAttributeId): List = getAttributeAs(id)?.users ?: emptyList() // endregion user @@ -153,9 +154,10 @@ fun InsightObject.getSingleReferenceValue(id: InsightAttributeId): InsightRefere ?.referencedObjects ?.firstOrNull() ?.let { + val objectType = it.objectType!! InsightReference( - it.objectType!!.id, - it.objectType!!.name, + objectType.id, + objectType.name, it.id, it.objectKey, it.label @@ -167,9 +169,10 @@ fun InsightObject.getMultiReferenceValue(id: InsightAttributeId): List( @field:NotNull val objects: List = emptyList(), ) -data class Page ( - @field:NotNull val items: List, - @field:NotNull val totalItems: Int, - @field:NotNull val totalPages: Int, - @field:NotNull val currentPageIndex: Int, - @field:NotNull val pageSize: Int -) - fun InsightObjectPage.plus(insightObjectPage: InsightObjectPage): InsightObjectPage = InsightObjectPage( this.totalFilterCount + insightObjectPage.totalFilterCount, @@ -253,7 +246,7 @@ sealed class InsightAttribute( data class User( @get:JvmName("getAttributeId") @field:NotNull override val attributeId: InsightAttributeId, - @field:NotNull val users: List, + @field:NotNull val users: List, override val schema: ObjectTypeSchemaAttribute? ) : InsightAttribute(attributeId, schema, AttributeTypeEnum.User){ override fun toString() = users.joinToString(",") { it.key } @@ -356,10 +349,10 @@ sealed class InsightAttribute( infix fun InsightAttributeId.toUrlValues(values: List) = Url(this, values = values, schema = null) - infix fun InsightAttributeId.toUser(user: InsightUser?) = + infix fun InsightAttributeId.toUser(user: JiraUser?) = User(this, listOfNotNull(user), schema = null) - infix fun InsightAttributeId.toUsers(users: List) = + infix fun InsightAttributeId.toUsers(users: List) = User(this, users, schema = null) infix fun InsightAttributeId.toReference(referencedObjectId: InsightObjectId?) = @@ -682,13 +675,6 @@ data class InsightSchema( ) // endregion InsightSchemaOperator -data class InsightUser( - @field:NotNull val displayName: String, - @field:NotNull val name: String, - @field:NotNull val emailAddress: String, - @field:NotNull val key: String -) - data class ReferencedObject( @get:JvmName("getId") @field:NotNull val id: InsightObjectId, diff --git a/kotlin-insight-client/kotlin-insight-client-http/src/main/kotlin/com/linkedplanet/kotlininsightclient/http/HttpInsightAttachmentOperator.kt b/kotlin-insight-client/kotlin-insight-client-http/src/main/kotlin/com/linkedplanet/kotlininsightclient/http/HttpInsightAttachmentOperator.kt index 6da6d2f7..aac40fd3 100644 --- a/kotlin-insight-client/kotlin-insight-client-http/src/main/kotlin/com/linkedplanet/kotlininsightclient/http/HttpInsightAttachmentOperator.kt +++ b/kotlin-insight-client/kotlin-insight-client-http/src/main/kotlin/com/linkedplanet/kotlininsightclient/http/HttpInsightAttachmentOperator.kt @@ -22,9 +22,9 @@ package com.linkedplanet.kotlininsightclient.http import arrow.core.Either import arrow.core.computations.either import com.google.gson.reflect.TypeToken +import com.linkedplanet.kotlinatlassianclientcore.common.error.asEither import com.linkedplanet.kotlininsightclient.api.error.InsightClientError import com.linkedplanet.kotlininsightclient.api.error.OtherNotFoundError -import com.linkedplanet.kotlininsightclient.api.error.asEither import com.linkedplanet.kotlininsightclient.api.interfaces.InsightAttachmentOperator import com.linkedplanet.kotlininsightclient.api.model.AttachmentId import com.linkedplanet.kotlininsightclient.api.model.InsightAttachment @@ -85,7 +85,7 @@ class HttpInsightAttachmentOperator(private val context: HttpInsightClientContex ?: OtherNotFoundError( "Attachment with Filename ($filename) for " + "object (id=$objectId) was created but could not be retrieved." - ).asEither().bind() + ).asEither().bind() } override suspend fun deleteAttachment(attachmentId: AttachmentId): Either = diff --git a/kotlin-insight-client/kotlin-insight-client-http/src/main/kotlin/com/linkedplanet/kotlininsightclient/http/HttpInsightObjectOperator.kt b/kotlin-insight-client/kotlin-insight-client-http/src/main/kotlin/com/linkedplanet/kotlininsightclient/http/HttpInsightObjectOperator.kt index ea11f715..282cf4cb 100644 --- a/kotlin-insight-client/kotlin-insight-client-http/src/main/kotlin/com/linkedplanet/kotlininsightclient/http/HttpInsightObjectOperator.kt +++ b/kotlin-insight-client/kotlin-insight-client-http/src/main/kotlin/com/linkedplanet/kotlininsightclient/http/HttpInsightObjectOperator.kt @@ -24,6 +24,7 @@ import arrow.core.computations.either import arrow.core.flatten import arrow.core.rightIfNotNull import com.google.gson.JsonParser +import com.linkedplanet.kotlinatlassianclientcore.common.api.JiraUser import com.linkedplanet.kotlinhttpclient.api.http.GSON import com.linkedplanet.kotlininsightclient.api.error.InsightClientError import com.linkedplanet.kotlininsightclient.api.error.InsightClientError.Companion.internalError @@ -47,7 +48,6 @@ import com.linkedplanet.kotlininsightclient.http.util.toInsightClientError import java.time.LocalDate import java.time.LocalTime import java.time.ZonedDateTime -import java.util.* class HttpInsightObjectOperator(private val context: HttpInsightClientContext) : InsightObjectOperator { @@ -307,7 +307,7 @@ class HttpInsightObjectOperator(private val context: HttpInsightClientContext) : } InsightObjectAttributeType.USER -> { val users = apiAttribute.objectAttributeValues.mapNotNull { av: ObjectAttributeValueApiResponse -> - av.user?.run { InsightUser(displayName, name, emailAddress ?: "", key) } + av.user?.run { JiraUser(key, name, emailAddress ?: "", displayName = displayName) } } InsightAttribute.User(attributeId, users, schema) } diff --git a/kotlin-insight-client/kotlin-insight-client-http/src/main/kotlin/com/linkedplanet/kotlininsightclient/http/HttpInsightObjectTypeOperator.kt b/kotlin-insight-client/kotlin-insight-client-http/src/main/kotlin/com/linkedplanet/kotlininsightclient/http/HttpInsightObjectTypeOperator.kt index 6cb04987..2693f23b 100644 --- a/kotlin-insight-client/kotlin-insight-client-http/src/main/kotlin/com/linkedplanet/kotlininsightclient/http/HttpInsightObjectTypeOperator.kt +++ b/kotlin-insight-client/kotlin-insight-client-http/src/main/kotlin/com/linkedplanet/kotlininsightclient/http/HttpInsightObjectTypeOperator.kt @@ -22,9 +22,9 @@ package com.linkedplanet.kotlininsightclient.http import arrow.core.Either import arrow.core.computations.either import com.google.gson.reflect.TypeToken +import com.linkedplanet.kotlinatlassianclientcore.common.error.asEither import com.linkedplanet.kotlininsightclient.api.error.InsightClientError import com.linkedplanet.kotlininsightclient.api.error.ObjectTypeNotFoundError -import com.linkedplanet.kotlininsightclient.api.error.asEither import com.linkedplanet.kotlininsightclient.api.interfaces.InsightObjectTypeOperator import com.linkedplanet.kotlininsightclient.api.model.InsightAttributeId import com.linkedplanet.kotlininsightclient.api.model.InsightObjectTypeId @@ -68,7 +68,7 @@ class HttpInsightObjectTypeOperator(private val context: HttpInsightClientContex ?.let { rootObject -> listOf(rootObject).plus(findObjectTypeChildren(allObjectTypes, rootObjectTypeId)) } - ?: ObjectTypeNotFoundError(rootObjectTypeId).asEither>().bind() + ?: ObjectTypeNotFoundError(rootObjectTypeId).asEither>().bind() } override suspend fun getObjectTypesBySchema(schemaId: InsightSchemaId): Either> = diff --git a/kotlin-insight-client/kotlin-insight-client-http/src/main/kotlin/com/linkedplanet/kotlininsightclient/http/model/InsightObjectRestApiResponseObjects.kt b/kotlin-insight-client/kotlin-insight-client-http/src/main/kotlin/com/linkedplanet/kotlininsightclient/http/model/InsightObjectRestApiResponseObjects.kt index 33032ee3..f178ab62 100644 --- a/kotlin-insight-client/kotlin-insight-client-http/src/main/kotlin/com/linkedplanet/kotlininsightclient/http/model/InsightObjectRestApiResponseObjects.kt +++ b/kotlin-insight-client/kotlin-insight-client-http/src/main/kotlin/com/linkedplanet/kotlininsightclient/http/model/InsightObjectRestApiResponseObjects.kt @@ -71,14 +71,15 @@ internal data class ObjectAttributeValueApiResponse( var value: Any?, var displayValue: Any?, var referencedObject: ReferencedObjectApiResponse?, - var user: InsightUserApiResponse? + var user: AtlassianUserApiResponse? ) -internal data class InsightUserApiResponse( +internal data class AtlassianUserApiResponse( val displayName: String, val name: String, val emailAddress: String?, - val key: String + val key: String, + val avatarUrl: String? ) internal data class ReferencedObjectApiResponse( diff --git a/kotlin-insight-client/kotlin-insight-client-sdk/src/main/kotlin/com/linkedplanet/kotlininsightclient/sdk/SdkInsightObjectOperator.kt b/kotlin-insight-client/kotlin-insight-client-sdk/src/main/kotlin/com/linkedplanet/kotlininsightclient/sdk/SdkInsightObjectOperator.kt index 65a43b34..93999164 100644 --- a/kotlin-insight-client/kotlin-insight-client-sdk/src/main/kotlin/com/linkedplanet/kotlininsightclient/sdk/SdkInsightObjectOperator.kt +++ b/kotlin-insight-client/kotlin-insight-client-sdk/src/main/kotlin/com/linkedplanet/kotlininsightclient/sdk/SdkInsightObjectOperator.kt @@ -25,9 +25,11 @@ import arrow.core.flatMap import arrow.core.left import arrow.core.right import arrow.core.rightIfNotNull +import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.component.ComponentAccessor.getOSGiComponentInstanceOfType import com.atlassian.jira.config.properties.ApplicationProperties import com.atlassian.jira.user.util.UserManager +import com.linkedplanet.kotlinatlassianclientcore.common.api.JiraUser import com.linkedplanet.kotlininsightclient.api.error.InsightClientError import com.linkedplanet.kotlininsightclient.api.error.InsightClientError.Companion.internalError import com.linkedplanet.kotlininsightclient.api.error.ObjectNotFoundError @@ -41,7 +43,6 @@ import com.linkedplanet.kotlininsightclient.api.model.InsightObject import com.linkedplanet.kotlininsightclient.api.model.InsightObjectId import com.linkedplanet.kotlininsightclient.api.model.InsightObjectPage import com.linkedplanet.kotlininsightclient.api.model.InsightObjectTypeId -import com.linkedplanet.kotlininsightclient.api.model.InsightUser import com.linkedplanet.kotlininsightclient.api.model.ObjectTypeSchemaAttribute import com.linkedplanet.kotlininsightclient.api.model.ReferencedObject import com.linkedplanet.kotlininsightclient.api.model.ReferencedObjectType @@ -369,7 +370,7 @@ object SdkInsightObjectOperator : InsightObjectOperator { } Type.USER -> { val users = objectAttributeBean.objectAttributeValueBeans.mapNotNull { attribute -> - loadInsightUserByKey(attribute.textValue).bind() + loadAtlassianUserByKey(attribute.textValue).bind() } InsightAttribute.User(attributeId, users, schema) } @@ -446,11 +447,12 @@ object SdkInsightObjectOperator : InsightObjectOperator { ) } } - - private fun loadInsightUserByKey(userKey: String): Either = + private val avatarService by lazy { ComponentAccessor.getAvatarService() } + private fun loadAtlassianUserByKey(userKey: String): Either = catchAsInsightClientError { userManager.getUserByKey(userKey)?.run { - InsightUser(displayName, name, emailAddress, key) + val avatarUrl = avatarService.getAvatarURL(this, this).toASCIIString() + JiraUser(key, name, emailAddress, avatarUrl, displayName) } } diff --git a/kotlin-insight-client/kotlin-insight-client-test-base/src/main/kotlin/com/linkedplanet/kotlininsightclient/InsightObjectOperatorTest.kt b/kotlin-insight-client/kotlin-insight-client-test-base/src/main/kotlin/com/linkedplanet/kotlininsightclient/InsightObjectOperatorTest.kt index 4c87f171..a34cd60a 100644 --- a/kotlin-insight-client/kotlin-insight-client-test-base/src/main/kotlin/com/linkedplanet/kotlininsightclient/InsightObjectOperatorTest.kt +++ b/kotlin-insight-client/kotlin-insight-client-test-base/src/main/kotlin/com/linkedplanet/kotlininsightclient/InsightObjectOperatorTest.kt @@ -37,7 +37,7 @@ import com.linkedplanet.kotlininsightclient.api.model.InsightAttribute.Companion import com.linkedplanet.kotlininsightclient.api.model.InsightObject import com.linkedplanet.kotlininsightclient.api.model.InsightObjectId import com.linkedplanet.kotlininsightclient.api.model.InsightObjectTypeId -import com.linkedplanet.kotlininsightclient.api.model.InsightUser +import com.linkedplanet.kotlinatlassianclientcore.common.api.JiraUser import com.linkedplanet.kotlininsightclient.api.model.ObjectTypeSchemaAttribute import com.linkedplanet.kotlininsightclient.api.model.addSelectValue import com.linkedplanet.kotlininsightclient.api.model.getAttributeAs @@ -652,7 +652,7 @@ interface InsightObjectOperatorTest { @Test fun testUserCrud() = runBlocking { - suspend fun getUserAttributes(objectId: InsightObjectId): Pair?, List> { + suspend fun getUserAttributes(objectId: InsightObjectId): Pair?, List> { val insightObject = insightObjectOperator.getObjectById(objectId, ::identity).orFail()!! val attrUser = insightObject.getAttributeAs(UserTestUser.attributeId)?.users val attrUsers = insightObject.getUserList(UserTestUsers.attributeId) @@ -661,8 +661,8 @@ interface InsightObjectOperatorTest { val objectName = "createdByUnitTest" autoClean(clean = { deleteObjectByName(InsightObjectType.User.id, objectName).orFail() }) { - val user1 = InsightUser("", "", "", "JIRAUSER10100") - val user2 = InsightUser("", "", "", "JIRAUSER10101") + val user1 = JiraUser("JIRAUSER10100", "", "", displayName = "") + val user2 = JiraUser("JIRAUSER10101", "", "", displayName = "") val objectId = insightObjectOperator.createInsightObject( InsightObjectType.User.id, UserTestName.attributeId toValue objectName, diff --git a/kotlin-insight-client/kotlin-insight-client-test-base/src/main/kotlin/com/linkedplanet/kotlininsightclient/repositories/CompanyTestRepositoryManualImpl.kt b/kotlin-insight-client/kotlin-insight-client-test-base/src/main/kotlin/com/linkedplanet/kotlininsightclient/repositories/CompanyTestRepositoryManualImpl.kt index d4b70e8a..e9c07e45 100644 --- a/kotlin-insight-client/kotlin-insight-client-test-base/src/main/kotlin/com/linkedplanet/kotlininsightclient/repositories/CompanyTestRepositoryManualImpl.kt +++ b/kotlin-insight-client/kotlin-insight-client-test-base/src/main/kotlin/com/linkedplanet/kotlininsightclient/repositories/CompanyTestRepositoryManualImpl.kt @@ -33,7 +33,7 @@ import com.linkedplanet.kotlininsightclient.api.model.InsightAttribute.Companion import com.linkedplanet.kotlininsightclient.api.model.InsightAttribute.Companion.toValue import com.linkedplanet.kotlininsightclient.api.model.InsightObject import com.linkedplanet.kotlininsightclient.api.model.InsightObjectId -import com.linkedplanet.kotlininsightclient.api.model.Page +import com.linkedplanet.kotlinatlassianclientcore.common.api.Page import com.linkedplanet.kotlininsightclient.api.model.getSingleReferenceValue import com.linkedplanet.kotlininsightclient.api.model.getStringValue import kotlin.math.ceil diff --git a/kotlin-insight-client/kotlin-insight-client-test-base/src/main/kotlin/com/linkedplanet/kotlininsightclient/repositories/CountryTestRepositoryManualImpl.kt b/kotlin-insight-client/kotlin-insight-client-test-base/src/main/kotlin/com/linkedplanet/kotlininsightclient/repositories/CountryTestRepositoryManualImpl.kt index b465fa10..626b3f4a 100644 --- a/kotlin-insight-client/kotlin-insight-client-test-base/src/main/kotlin/com/linkedplanet/kotlininsightclient/repositories/CountryTestRepositoryManualImpl.kt +++ b/kotlin-insight-client/kotlin-insight-client-test-base/src/main/kotlin/com/linkedplanet/kotlininsightclient/repositories/CountryTestRepositoryManualImpl.kt @@ -32,7 +32,7 @@ import com.linkedplanet.kotlininsightclient.api.interfaces.InsightObjectOperator import com.linkedplanet.kotlininsightclient.api.model.InsightAttribute.Companion.toValue import com.linkedplanet.kotlininsightclient.api.model.InsightObject import com.linkedplanet.kotlininsightclient.api.model.InsightObjectId -import com.linkedplanet.kotlininsightclient.api.model.Page +import com.linkedplanet.kotlinatlassianclientcore.common.api.Page import com.linkedplanet.kotlininsightclient.api.model.getStringValue import kotlin.math.ceil diff --git a/kotlin-jira-client/kotlin-jira-client-api/pom.xml b/kotlin-jira-client/kotlin-jira-client-api/pom.xml index 6284b9de..fbac589a 100644 --- a/kotlin-jira-client/kotlin-jira-client-api/pom.xml +++ b/kotlin-jira-client/kotlin-jira-client-api/pom.xml @@ -19,5 +19,10 @@ gson 2.10.1 + + com.linked-planet.client + kotlin-atlassian-client-core-common + ${project.version} + diff --git a/kotlin-jira-client/kotlin-jira-client-api/src/main/kotlin/com/linkedplanet/kotlinjiraclient/api/error/JiraClientError.kt b/kotlin-jira-client/kotlin-jira-client-api/src/main/kotlin/com/linkedplanet/kotlinjiraclient/api/error/JiraClientError.kt index 0b0d3fcd..6cc4b676 100644 --- a/kotlin-jira-client/kotlin-jira-client-api/src/main/kotlin/com/linkedplanet/kotlinjiraclient/api/error/JiraClientError.kt +++ b/kotlin-jira-client/kotlin-jira-client-api/src/main/kotlin/com/linkedplanet/kotlinjiraclient/api/error/JiraClientError.kt @@ -19,12 +19,14 @@ */ package com.linkedplanet.kotlinjiraclient.api.error +import com.linkedplanet.kotlinatlassianclientcore.common.error.AtlassianClientError + @Suppress("unused") open class JiraClientError( - val error: String, - val message: String, - val stacktrace: String = "" -) { + error: String, + message: String, + stacktrace: String = "" +) : AtlassianClientError(error, message, stacktrace) { companion object } diff --git a/kotlin-jira-client/kotlin-jira-client-api/src/main/kotlin/com/linkedplanet/kotlinjiraclient/api/interfaces/JiraIssueOperator.kt b/kotlin-jira-client/kotlin-jira-client-api/src/main/kotlin/com/linkedplanet/kotlinjiraclient/api/interfaces/JiraIssueOperator.kt index 6a88c7c2..ed7aa423 100644 --- a/kotlin-jira-client/kotlin-jira-client-api/src/main/kotlin/com/linkedplanet/kotlinjiraclient/api/interfaces/JiraIssueOperator.kt +++ b/kotlin-jira-client/kotlin-jira-client-api/src/main/kotlin/com/linkedplanet/kotlinjiraclient/api/interfaces/JiraIssueOperator.kt @@ -21,9 +21,9 @@ package com.linkedplanet.kotlinjiraclient.api.interfaces import arrow.core.Either import com.google.gson.JsonObject +import com.linkedplanet.kotlinatlassianclientcore.common.api.Page import com.linkedplanet.kotlinjiraclient.api.error.JiraClientError import com.linkedplanet.kotlinjiraclient.api.model.JiraIssue -import com.linkedplanet.kotlinjiraclient.api.model.Page /** * Provides methods for working with Jira issues, including retrieving issues by JQL query, issue type, or key; creating and updating issues; and deleting issues. diff --git a/kotlin-jira-client/kotlin-jira-client-api/src/main/kotlin/com/linkedplanet/kotlinjiraclient/api/interfaces/JiraUserOperator.kt b/kotlin-jira-client/kotlin-jira-client-api/src/main/kotlin/com/linkedplanet/kotlinjiraclient/api/interfaces/JiraUserOperator.kt index e0971b46..c44e7098 100644 --- a/kotlin-jira-client/kotlin-jira-client-api/src/main/kotlin/com/linkedplanet/kotlinjiraclient/api/interfaces/JiraUserOperator.kt +++ b/kotlin-jira-client/kotlin-jira-client-api/src/main/kotlin/com/linkedplanet/kotlinjiraclient/api/interfaces/JiraUserOperator.kt @@ -20,8 +20,8 @@ package com.linkedplanet.kotlinjiraclient.api.interfaces import arrow.core.Either +import com.linkedplanet.kotlinatlassianclientcore.common.api.JiraUser import com.linkedplanet.kotlinjiraclient.api.error.JiraClientError -import com.linkedplanet.kotlinjiraclient.api.model.JiraUser /** * Manages Jira users. diff --git a/kotlin-jira-client/kotlin-jira-client-api/src/main/kotlin/com/linkedplanet/kotlinjiraclient/api/model/Model.kt b/kotlin-jira-client/kotlin-jira-client-api/src/main/kotlin/com/linkedplanet/kotlinjiraclient/api/model/Model.kt index d8d10838..0c0b9d66 100644 --- a/kotlin-jira-client/kotlin-jira-client-api/src/main/kotlin/com/linkedplanet/kotlinjiraclient/api/model/Model.kt +++ b/kotlin-jira-client/kotlin-jira-client-api/src/main/kotlin/com/linkedplanet/kotlinjiraclient/api/model/Model.kt @@ -19,22 +19,6 @@ */ package com.linkedplanet.kotlinjiraclient.api.model -data class Page ( - val items: List, - val totalItems: Int, - val totalPages: Int, - val currentPageIndex: Int, - val pageSize: Int -) - -data class JiraUser( - val key: String, - val name: String, - val emailAddress: String, - var avatarUrl: String?, - val displayName: String -) - data class JiraStatus( val id: String, val name: String, diff --git a/kotlin-jira-client/kotlin-jira-client-http/src/main/kotlin/com/linkedplanet/kotlinjiraclient/http/HttpJiraIssueOperator.kt b/kotlin-jira-client/kotlin-jira-client-http/src/main/kotlin/com/linkedplanet/kotlinjiraclient/http/HttpJiraIssueOperator.kt index 15e9fce2..33eae360 100644 --- a/kotlin-jira-client/kotlin-jira-client-http/src/main/kotlin/com/linkedplanet/kotlinjiraclient/http/HttpJiraIssueOperator.kt +++ b/kotlin-jira-client/kotlin-jira-client-http/src/main/kotlin/com/linkedplanet/kotlinjiraclient/http/HttpJiraIssueOperator.kt @@ -27,7 +27,7 @@ import com.linkedplanet.kotlinhttpclient.api.http.* import com.linkedplanet.kotlinjiraclient.api.error.JiraClientError import com.linkedplanet.kotlinjiraclient.api.interfaces.JiraIssueOperator import com.linkedplanet.kotlinjiraclient.api.model.JiraIssue -import com.linkedplanet.kotlinjiraclient.api.model.Page +import com.linkedplanet.kotlinatlassianclientcore.common.api.Page import com.linkedplanet.kotlinjiraclient.http.field.HttpJiraField import com.linkedplanet.kotlinjiraclient.http.model.HttpMappingField import com.linkedplanet.kotlinjiraclient.http.util.fromHttpDomainError diff --git a/kotlin-jira-client/kotlin-jira-client-http/src/main/kotlin/com/linkedplanet/kotlinjiraclient/http/HttpJiraUserOperator.kt b/kotlin-jira-client/kotlin-jira-client-http/src/main/kotlin/com/linkedplanet/kotlinjiraclient/http/HttpJiraUserOperator.kt index 9c24edb7..5eeacaf2 100644 --- a/kotlin-jira-client/kotlin-jira-client-http/src/main/kotlin/com/linkedplanet/kotlinjiraclient/http/HttpJiraUserOperator.kt +++ b/kotlin-jira-client/kotlin-jira-client-http/src/main/kotlin/com/linkedplanet/kotlinjiraclient/http/HttpJiraUserOperator.kt @@ -27,7 +27,7 @@ import com.google.gson.reflect.TypeToken import com.linkedplanet.kotlinhttpclient.api.http.* import com.linkedplanet.kotlinjiraclient.api.error.JiraClientError import com.linkedplanet.kotlinjiraclient.api.interfaces.JiraUserOperator -import com.linkedplanet.kotlinjiraclient.api.model.JiraUser +import com.linkedplanet.kotlinatlassianclientcore.common.api.JiraUser import com.linkedplanet.kotlinjiraclient.http.model.* import com.linkedplanet.kotlinjiraclient.http.util.fromHttpDomainError diff --git a/kotlin-jira-client/kotlin-jira-client-http/src/main/kotlin/com/linkedplanet/kotlinjiraclient/http/model/HttpModel.kt b/kotlin-jira-client/kotlin-jira-client-http/src/main/kotlin/com/linkedplanet/kotlinjiraclient/http/model/HttpModel.kt index c2e500c0..88559b8d 100644 --- a/kotlin-jira-client/kotlin-jira-client-http/src/main/kotlin/com/linkedplanet/kotlinjiraclient/http/model/HttpModel.kt +++ b/kotlin-jira-client/kotlin-jira-client-http/src/main/kotlin/com/linkedplanet/kotlinjiraclient/http/model/HttpModel.kt @@ -19,6 +19,7 @@ */ package com.linkedplanet.kotlinjiraclient.http.model +import com.linkedplanet.kotlinatlassianclientcore.common.api.JiraUser import com.linkedplanet.kotlinhttpclient.api.http.HttpPage import com.linkedplanet.kotlinjiraclient.api.model.* diff --git a/kotlin-jira-client/kotlin-jira-client-sdk/src/main/kotlin/com/linkedplanet/kotlinjiraclient/sdk/SdkJiraIssueOperator.kt b/kotlin-jira-client/kotlin-jira-client-sdk/src/main/kotlin/com/linkedplanet/kotlinjiraclient/sdk/SdkJiraIssueOperator.kt index 7afb73ed..9098aee9 100644 --- a/kotlin-jira-client/kotlin-jira-client-sdk/src/main/kotlin/com/linkedplanet/kotlinjiraclient/sdk/SdkJiraIssueOperator.kt +++ b/kotlin-jira-client/kotlin-jira-client-sdk/src/main/kotlin/com/linkedplanet/kotlinjiraclient/sdk/SdkJiraIssueOperator.kt @@ -32,7 +32,8 @@ import com.google.gson.JsonObject import com.linkedplanet.kotlinjiraclient.api.error.JiraClientError import com.linkedplanet.kotlinjiraclient.api.interfaces.JiraIssueOperator import com.linkedplanet.kotlinjiraclient.api.model.JiraIssue -import com.linkedplanet.kotlinjiraclient.api.model.Page +import com.linkedplanet.kotlinatlassianclientcore.common.api.Page +import com.linkedplanet.kotlinatlassianclientcore.common.error.asEither import com.linkedplanet.kotlinjiraclient.sdk.field.SdkJiraField import com.linkedplanet.kotlinjiraclient.sdk.util.IssueJsonConverter import com.linkedplanet.kotlinjiraclient.sdk.util.catchJiraClientError @@ -108,7 +109,7 @@ object SdkJiraIssueOperator : JiraIssueOperator { ): Either = either { val potentiallyMultipleIssues = getIssuesByJQLPaginated(jql, 0, 1, parser).bind() if (potentiallyMultipleIssues.totalItems < 1) { - JiraClientError("Issue not found", "No issue was found.").left().bind() + JiraClientError("Issue not found", "No issue was found.").asEither().bind() } potentiallyMultipleIssues.items.first() } diff --git a/kotlin-jira-client/kotlin-jira-client-sdk/src/main/kotlin/com/linkedplanet/kotlinjiraclient/sdk/SdkJiraUserOperator.kt b/kotlin-jira-client/kotlin-jira-client-sdk/src/main/kotlin/com/linkedplanet/kotlinjiraclient/sdk/SdkJiraUserOperator.kt index 23763723..083ec387 100644 --- a/kotlin-jira-client/kotlin-jira-client-sdk/src/main/kotlin/com/linkedplanet/kotlinjiraclient/sdk/SdkJiraUserOperator.kt +++ b/kotlin-jira-client/kotlin-jira-client-sdk/src/main/kotlin/com/linkedplanet/kotlinjiraclient/sdk/SdkJiraUserOperator.kt @@ -31,7 +31,7 @@ import com.atlassian.jira.security.roles.ProjectRoleManager import com.atlassian.jira.user.ApplicationUser import com.linkedplanet.kotlinjiraclient.api.error.JiraClientError import com.linkedplanet.kotlinjiraclient.api.interfaces.JiraUserOperator -import com.linkedplanet.kotlinjiraclient.api.model.JiraUser +import com.linkedplanet.kotlinatlassianclientcore.common.api.JiraUser import com.linkedplanet.kotlinjiraclient.sdk.util.catchJiraClientError object SdkJiraUserOperator : JiraUserOperator { diff --git a/kotlin-jira-client/kotlin-jira-client-test-base/src/main/kotlin/com/linkedplanet/kotlinjiraclient/JiraIssueOperatorTest.kt b/kotlin-jira-client/kotlin-jira-client-test-base/src/main/kotlin/com/linkedplanet/kotlinjiraclient/JiraIssueOperatorTest.kt index f4da4cab..af4d5b0a 100644 --- a/kotlin-jira-client/kotlin-jira-client-test-base/src/main/kotlin/com/linkedplanet/kotlinjiraclient/JiraIssueOperatorTest.kt +++ b/kotlin-jira-client/kotlin-jira-client-test-base/src/main/kotlin/com/linkedplanet/kotlinjiraclient/JiraIssueOperatorTest.kt @@ -20,7 +20,7 @@ package com.linkedplanet.kotlinjiraclient import arrow.core.* -import com.linkedplanet.kotlinjiraclient.api.model.Page +import com.linkedplanet.kotlinatlassianclientcore.common.api.Page import com.linkedplanet.kotlinjiraclient.util.* import java.time.ZoneOffset import java.time.ZonedDateTime diff --git a/kotlin-jira-client/kotlin-jira-client-test-base/src/main/kotlin/com/linkedplanet/kotlinjiraclient/util/AssertionExtensions.kt b/kotlin-jira-client/kotlin-jira-client-test-base/src/main/kotlin/com/linkedplanet/kotlinjiraclient/util/AssertionExtensions.kt index bef43720..b872fd64 100644 --- a/kotlin-jira-client/kotlin-jira-client-test-base/src/main/kotlin/com/linkedplanet/kotlinjiraclient/util/AssertionExtensions.kt +++ b/kotlin-jira-client/kotlin-jira-client-test-base/src/main/kotlin/com/linkedplanet/kotlinjiraclient/util/AssertionExtensions.kt @@ -20,17 +20,9 @@ package com.linkedplanet.kotlinjiraclient.util import arrow.core.Either -import com.linkedplanet.kotlinhttpclient.error.DomainError import com.linkedplanet.kotlinjiraclient.api.error.JiraClientError import org.junit.Assert.fail -internal fun Either.rightAsserted(): R { - this.mapLeft { - fail("Unexpected DomainError: ${it.error} - ${it.message}") - } - return this.orNull()!! -} - internal fun Either.rightAssertedJiraClientError(): R { this.mapLeft { diff --git a/kotlin-jira-client/kotlin-jira-client-test-base/src/main/kotlin/com/linkedplanet/kotlinjiraclient/util/JiraUserTestHelper.kt b/kotlin-jira-client/kotlin-jira-client-test-base/src/main/kotlin/com/linkedplanet/kotlinjiraclient/util/JiraUserTestHelper.kt index e58d68c2..af18c931 100644 --- a/kotlin-jira-client/kotlin-jira-client-test-base/src/main/kotlin/com/linkedplanet/kotlinjiraclient/util/JiraUserTestHelper.kt +++ b/kotlin-jira-client/kotlin-jira-client-test-base/src/main/kotlin/com/linkedplanet/kotlinjiraclient/util/JiraUserTestHelper.kt @@ -19,7 +19,7 @@ */ package com.linkedplanet.kotlinjiraclient.util -import com.linkedplanet.kotlinjiraclient.api.model.JiraUser +import com.linkedplanet.kotlinatlassianclientcore.common.api.JiraUser import org.hamcrest.CoreMatchers.equalTo import org.hamcrest.CoreMatchers.notNullValue import org.hamcrest.MatcherAssert.assertThat diff --git a/pom.xml b/pom.xml index 260231e8..fa5f2937 100644 --- a/pom.xml +++ b/pom.xml @@ -15,6 +15,7 @@ kotlin-http-client kotlin-jira-client kotlin-insight-client + kotlin-atlassian-client-core-common