File tree Expand file tree Collapse file tree 4 files changed +20
-10
lines changed
kotlin-jira-client/kotlin-jira-client-sdk/src/main/kotlin/com/linkedplanet/kotlinjiraclient/sdk Expand file tree Collapse file tree 4 files changed +20
-10
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,6 @@ import com.atlassian.jira.bc.issue.comment.CommentService
2626import com.atlassian.jira.bc.issue.comment.CommentService.CommentParameters
2727import com.atlassian.jira.component.ComponentAccessor
2828import com.atlassian.jira.issue.MutableIssue
29- import com.atlassian.jira.util.SimpleErrorCollection
3029import com.linkedplanet.kotlinjiraclient.api.error.JiraClientError
3130import com.linkedplanet.kotlinjiraclient.api.interfaces.JiraCommentOperator
3231import com.linkedplanet.kotlinjiraclient.api.model.JiraIssueComment
@@ -69,9 +68,7 @@ object SdkJiraCommentOperator : JiraCommentOperator {
6968
7069 override suspend fun deleteComment (issueKey : String , id : String ): Either <JiraClientError , Unit > =
7170 eitherAndCatch {
72- val simpleErrorCollection = SimpleErrorCollection ()
73- val comment = commentService.getCommentById(user(), id.toLongOrNull()!! , simpleErrorCollection)
74- simpleErrorCollection.toEither().bind()
71+ val comment = withErrorCollection { commentService.getCommentById(user(), id.toLongOrNull()!! , it) }.bind()
7572 val jiraServiceContextImpl = JiraServiceContextImpl (user())
7673 commentService.delete(jiraServiceContextImpl, comment, DISPATCH_EVENT )
7774 jiraServiceContextImpl.errorCollection.toEither().bind()
Original file line number Diff line number Diff line change @@ -33,9 +33,9 @@ import com.linkedplanet.kotlinjiraclient.sdk.util.toEither
3333object SdkJiraTransitionOperator : JiraTransitionOperator {
3434
3535 private val issueService = ComponentAccessor .getIssueService()
36- private val workflowManager by lazy { ComponentAccessor .getWorkflowManager() }
37- private val transitionManager by lazy { ComponentAccessor .getComponent(TransitionManager ::class .java) }
38- private val jiraAuthenticationContext by lazy { ComponentAccessor .getJiraAuthenticationContext() }
36+ private val workflowManager = ComponentAccessor .getWorkflowManager()
37+ private val transitionManager = ComponentAccessor .getComponent(TransitionManager ::class .java)
38+ private val jiraAuthenticationContext = ComponentAccessor .getJiraAuthenticationContext()
3939 private fun user () = jiraAuthenticationContext.loggedInUser
4040
4141 override suspend fun doTransition (
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ import arrow.core.raise.fold
2626import arrow.core.right
2727import com.atlassian.jira.bc.ServiceResult
2828import com.atlassian.jira.util.ErrorCollection
29+ import com.atlassian.jira.util.SimpleErrorCollection
2930import com.linkedplanet.kotlinjiraclient.api.error.JiraClientError
3031import org.jetbrains.kotlin.util.removeSuffixIfPresent
3132
@@ -45,6 +46,18 @@ fun ErrorCollection.toEither(errorTitle: String = "SdkError") : Either<JiraClien
4546 else -> Unit .right()
4647 }
4748
49+ fun <T > withErrorCollection (
50+ errorTitle : String = "SdkError ",
51+ block : (errors: ErrorCollection ) -> T
52+ ): Either <JiraClientError , T > {
53+ val simpleErrorCollection = SimpleErrorCollection ()
54+ val result = block(simpleErrorCollection)
55+ return when {
56+ simpleErrorCollection.hasAnyErrors() -> jiraClientError(simpleErrorCollection, errorTitle).left()
57+ else -> result.right()
58+ }
59+ }
60+
4861fun jiraClientError (errorCollection : ErrorCollection , errorTitle : String = "SdkError "): JiraClientError {
4962 val worstReason: ErrorCollection .Reason ? = ErrorCollection .Reason .getWorstReason(errorCollection.reasons)
5063 val httpStatusSuffix = worstReason?.let { " (${it.httpStatusCode} )" } ? : " "
Original file line number Diff line number Diff line change @@ -43,12 +43,12 @@ import javax.xml.bind.annotation.XmlTransient
4343class IssueJsonConverter {
4444
4545 private val log = LoggerFactory .getLogger(FieldAccessorImpl ::class .java)
46- private val fieldLayoutManager by lazy { ComponentAccessor .getFieldLayoutManager() }
47- private val fieldManager by lazy { ComponentAccessor .getFieldManager() }
46+ private val fieldLayoutManager = ComponentAccessor .getFieldLayoutManager()
47+ private val fieldManager = ComponentAccessor .getFieldManager()
4848 private val beanBuilderFactory = ComponentAccessor .getOSGiComponentInstanceOfType(BeanBuilderFactory ::class .java)
4949 private val jiraBaseUrls: JiraBaseUrls = ComponentAccessor .getComponent(JiraBaseUrls ::class .java)
5050 private val uriBuilder: UriBuilder = UriBuilder .fromPath(jiraBaseUrls.restApi2BaseUrl())
51- private val gson by lazy { setupGson() }
51+ private val gson = setupGson()
5252
5353
5454 @Throws(FieldException ::class )
You can’t perform that action at this time.
0 commit comments