|
20 | 20 | package com.linkedplanet.kotlinjiraclient.sdk |
21 | 21 |
|
22 | 22 | import arrow.core.Either |
| 23 | +import com.atlassian.jira.bc.project.ProjectService |
23 | 24 | import com.atlassian.jira.component.ComponentAccessor |
24 | 25 | import com.linkedplanet.kotlinjiraclient.api.error.JiraClientError |
25 | 26 | import com.linkedplanet.kotlinjiraclient.api.interfaces.JiraProjectOperator |
26 | 27 | import com.linkedplanet.kotlinjiraclient.api.model.JiraProject |
27 | 28 | import com.linkedplanet.kotlinjiraclient.sdk.util.catchJiraClientError |
| 29 | +import com.linkedplanet.kotlinjiraclient.sdk.util.eitherAndCatch |
| 30 | +import com.linkedplanet.kotlinjiraclient.sdk.util.toEither |
28 | 31 |
|
29 | 32 | object SdkJiraProjectOperator : JiraProjectOperator { |
30 | 33 |
|
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 |
32 | 38 |
|
33 | 39 | 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 { |
36 | 42 | JiraProject(it.id.toString(), it.key, it.name) |
37 | 43 | } |
38 | 44 | } |
39 | 45 |
|
40 | 46 | 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 { |
43 | 49 | JiraProject(it.id.toString(), it.key, it.name) |
44 | 50 | }) |
45 | 51 | } |
|
0 commit comments