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
24 changes: 24 additions & 0 deletions kotlin-atlassian-client-core-common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.linked-planet.client</groupId>
<artifactId>kotlin-atlassian-client</artifactId>
<version>0.12.10-SNAPSHOT</version>
</parent>

<artifactId>kotlin-atlassian-client-core-common</artifactId>
<name>kotlin-atlassian-client-core-common</name>

<dependencies>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
@@ -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<T> (
@field:NotNull val items: List<T>,
@field:NotNull val totalItems: Int,
@field:NotNull val totalPages: Int,
@field:NotNull val currentPageIndex: Int,
@field:NotNull val pageSize: Int
)
Original file line number Diff line number Diff line change
@@ -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 : AtlassianClientError, T> ERROR.asEither(): Either<ERROR, T> = Either.Left(this)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 5 additions & 0 deletions kotlin-insight-client/kotlin-insight-client-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,10 @@
<version>2.2.2-atlassian-1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.linked-planet.client</groupId>
<artifactId>kotlin-atlassian-client-core-common</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -58,7 +60,6 @@ sealed class InsightClientError(

}
}
fun <T> InsightClientError.asEither(): Either<InsightClientError, T> = Either.Left(this)

class InvalidArgumentInsightClientError(message: String) : InsightClientError("Unerwarteter Parameter", message)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<DomainType> : InsightObjectRepository<DomainType> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -169,7 +169,7 @@ abstract class AbstractNameMappedRepository<DomainType : Any>(
is InsightAttribute.Select -> attribute.values// List<String>
else -> InvalidArgumentInsightClientError(
"kType.classifier ${kType.classifier} is not supported."
).asEither<DomainType?>(
).asEither<InsightClientError, DomainType?>(
).bind()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -141,7 +142,7 @@ fun InsightObject.getDateTimeValue(id: InsightAttributeId): ZonedDateTime? =


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

Expand All @@ -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
Expand All @@ -167,9 +169,10 @@ fun InsightObject.getMultiReferenceValue(id: InsightAttributeId): List<InsightRe
?.let { it as? InsightAttribute.Reference }
?.referencedObjects
?.map {
val objectType = it.objectType!!
InsightReference(
it.objectType!!.id,
it.objectType!!.name,
objectType.id,
objectType.name,
it.id,
it.objectKey,
it.label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package com.linkedplanet.kotlininsightclient.api.model

import com.linkedplanet.kotlinatlassianclientcore.common.api.JiraUser
import io.swagger.v3.oas.annotations.media.Schema
import java.time.LocalDate
import java.time.LocalTime
Expand Down Expand Up @@ -54,14 +55,6 @@ data class InsightObjectPage<T>(
@field:NotNull val objects: List<T> = emptyList(),
)

data class Page<T> (
@field:NotNull val items: List<T>,
@field:NotNull val totalItems: Int,
@field:NotNull val totalPages: Int,
@field:NotNull val currentPageIndex: Int,
@field:NotNull val pageSize: Int
)

fun <T> InsightObjectPage<T>.plus(insightObjectPage: InsightObjectPage<T>): InsightObjectPage<T> =
InsightObjectPage(
this.totalFilterCount + insightObjectPage.totalFilterCount,
Expand Down Expand Up @@ -253,7 +246,7 @@ sealed class InsightAttribute(
data class User(
@get:JvmName("getAttributeId")
@field:NotNull override val attributeId: InsightAttributeId,
@field:NotNull val users: List<InsightUser>,
@field:NotNull val users: List<JiraUser>,
override val schema: ObjectTypeSchemaAttribute?
) : InsightAttribute(attributeId, schema, AttributeTypeEnum.User){
override fun toString() = users.joinToString(",") { it.key }
Expand Down Expand Up @@ -356,10 +349,10 @@ sealed class InsightAttribute(
infix fun InsightAttributeId.toUrlValues(values: List<String>) =
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<InsightUser>) =
infix fun InsightAttributeId.toUsers(users: List<JiraUser>) =
User(this, users, schema = null)

infix fun InsightAttributeId.toReference(referencedObjectId: InsightObjectId?) =
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<InsightAttachment>().bind()
).asEither<InsightClientError, InsightAttachment>().bind()
}

override suspend fun deleteAttachment(attachmentId: AttachmentId): Either<InsightClientError, Unit> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {

Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -68,7 +68,7 @@ class HttpInsightObjectTypeOperator(private val context: HttpInsightClientContex
?.let { rootObject ->
listOf(rootObject).plus(findObjectTypeChildren(allObjectTypes, rootObjectTypeId))
}
?: ObjectTypeNotFoundError(rootObjectTypeId).asEither<List<ObjectTypeSchema>>().bind()
?: ObjectTypeNotFoundError(rootObjectTypeId).asEither<InsightClientError, List<ObjectTypeSchema>>().bind()
}

override suspend fun getObjectTypesBySchema(schemaId: InsightSchemaId): Either<InsightClientError, List<ObjectTypeSchema>> =
Expand Down
Loading