Skip to content

Commit e6d5150

Browse files
committed
use services for SdkJiraProjectOperator
1 parent 630a42f commit e6d5150

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

kotlin-jira-client/kotlin-jira-client-sdk/src/main/kotlin/com/linkedplanet/kotlinjiraclient/sdk/SdkJiraProjectOperator.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,32 @@
2020
package com.linkedplanet.kotlinjiraclient.sdk
2121

2222
import arrow.core.Either
23+
import com.atlassian.jira.bc.project.ProjectService
2324
import com.atlassian.jira.component.ComponentAccessor
2425
import com.linkedplanet.kotlinjiraclient.api.error.JiraClientError
2526
import com.linkedplanet.kotlinjiraclient.api.interfaces.JiraProjectOperator
2627
import com.linkedplanet.kotlinjiraclient.api.model.JiraProject
2728
import com.linkedplanet.kotlinjiraclient.sdk.util.catchJiraClientError
29+
import com.linkedplanet.kotlinjiraclient.sdk.util.eitherAndCatch
30+
import com.linkedplanet.kotlinjiraclient.sdk.util.toEither
2831

2932
object SdkJiraProjectOperator : JiraProjectOperator {
3033

31-
private val projectManager by lazy { ComponentAccessor.getProjectManager() }
34+
private val projectService = ComponentAccessor.getComponent(ProjectService::class.java)
35+
private val jiraAuthenticationContext = ComponentAccessor.getJiraAuthenticationContext()
36+
37+
private fun user() = jiraAuthenticationContext.loggedInUser
3238

3339
override suspend fun getProject(projectId: Number): Either<JiraClientError, JiraProject?> =
34-
Either.catchJiraClientError {
35-
projectManager.getProjectObj(projectId.toLong())?.let {
40+
eitherAndCatch {
41+
projectService.getProjectById(user(), projectId.toLong()).toEither().bind().get().let {
3642
JiraProject(it.id.toString(), it.key, it.name)
3743
}
3844
}
3945

4046
override suspend fun getProjects(): Either<JiraClientError, List<JiraProject>> =
41-
Either.catchJiraClientError {
42-
return Either.Right(projectManager.projects.map {
47+
eitherAndCatch {
48+
return Either.Right(projectService.getAllProjects(user()).toEither().bind().get().map {
4349
JiraProject(it.id.toString(), it.key, it.name)
4450
})
4551
}

0 commit comments

Comments
 (0)